Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try using MSbuild for at least one test #9727

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -730,8 +730,11 @@ public void FooMethod () {{
}

[Test]
public void SwitchBetweenDesignTimeBuild ()
public void SwitchBetweenDesignTimeBuild ([Values (false, true)] bool useMSBuild)
{
if (useMSBuild && !IsWindows) {
Assert.Ignore ("This test is only relevant when using Windows");
}
var proj = new XamarinAndroidApplicationProject ();
proj.AndroidResources.Add (new AndroidItem.AndroidResource ("Resources\\layout\\custom_text.xml") {
TextContent = () => @"<?xml version=""1.0"" encoding=""utf-8"" ?>
Expand Down Expand Up @@ -767,14 +770,14 @@ public CustomTextView(Context context, IAttributeSet attributes) : base(context,
});

using (var b = CreateApkBuilder (Path.Combine ("temp", TestName))) {
b.UseMSBuild = useMSBuild;
Assert.IsTrue (b.Build (proj), "first *regular* build should have succeeded.");
var build_props = b.Output.GetIntermediaryPath ("build.props");
var designtime_build_props = b.Output.GetIntermediaryPath (Path.Combine ("designtime", "build.props"));
FileAssert.Exists (build_props, "build.props should exist after a first `Build`.");
FileAssert.DoesNotExist (designtime_build_props, "designtime/build.props should *not* exist after a first `Build`.");

b.Target = "Compile";
Assert.IsTrue (b.Build (proj, parameters: new [] { "DesignTimeBuild=True" }), "first design-time build should have succeeded.");
Assert.IsTrue (b.DesignTimeBuild (proj), "first design-time build should have succeeded.");
FileAssert.Exists (build_props, "build.props should exist after a design-time build.");
FileAssert.Exists (designtime_build_props, "designtime/build.props should exist after a design-time build.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Threading;
using System.Xml.XPath;
using System.Xml.Linq;
using Xamarin.Android.Tools.VSWhere;

using Xamarin.Android.Tasks;

Expand Down Expand Up @@ -57,6 +58,19 @@ public IEnumerable<string> LastBuildOutput {
/// </summary>
public bool AutomaticNuGetRestore { get; set; } = true;

public bool UseMSBuild {get; set; } = false;

/// <summary>
/// Value for %MSBuildSdksPath%, points to bin\Release\dotnet\sdk\*\Sdks
/// </summary>
public string MSBuildSdksPath {
get {
var sdk = Path.Combine (TestEnvironment.DotNetPreviewDirectory, "sdk");
var sdk_version = Directory.EnumerateDirectories (sdk).OrderByDescending (x => x).First ();
return Path.Combine (sdk_version, "Sdks");
}
}

public bool CrossCompilerAvailable (string supportedAbis)
{
var crossCompilerLookup = new Dictionary<string, string> {
Expand Down Expand Up @@ -185,14 +199,26 @@ protected bool BuildInternal (string projectOrSolution, string target, string []

var start = DateTime.UtcNow;
var args = new StringBuilder ();
var psi = new ProcessStartInfo (Path.Combine (TestEnvironment.DotNetPreviewDirectory, "dotnet"));
var psi = new ProcessStartInfo ();
var responseFile = Path.Combine (XABuildPaths.TestOutputDirectory, Path.GetDirectoryName (projectOrSolution), "project.rsp");
args.Append ("build ");
psi.FileName = Path.Combine (TestEnvironment.DotNetPreviewDirectory, "dotnet");
if (UseMSBuild) {
psi.FileName = MSBuildLocator.QueryLatest ().MSBuildPath;
} else {
args.Append ("build ");
}

if (TestEnvironment.UseLocalBuildOutput) {
psi.SetEnvironmentVariable ("DOTNETSDK_WORKLOAD_MANIFEST_ROOTS", TestEnvironment.WorkloadManifestOverridePath);
psi.SetEnvironmentVariable ("DOTNETSDK_WORKLOAD_PACK_ROOTS", TestEnvironment.WorkloadPackOverridePath);
}
if (UseMSBuild) {
psi.SetEnvironmentVariable ("DOTNETSDK_WORKLOAD_PACK_ROOTS", Path.Combine (TestEnvironment.DotNetPreviewDirectory, "packs"));
psi.SetEnvironmentVariable ("DOTNETSDK_WORKLOAD_MANIFEST_ROOTS", Path.Combine (TestEnvironment.DotNetPreviewDirectory, "sdk-manifests"));
psi.SetEnvironmentVariable ("MSBUILDLOGALLENVIRONMENTVARIABLES", "1");
psi.SetEnvironmentVariable ("MSBuildSDKsPath", MSBuildSdksPath);
psi.SetEnvironmentVariable ("PATH", TestEnvironment.DotNetPreviewDirectory + Path.PathSeparator + Environment.GetEnvironmentVariable ("PATH"));
}

args.AppendFormat ("{0} /t:{1} {2}",
QuoteFileName (Path.Combine (XABuildPaths.TestOutputDirectory, projectOrSolution)), target, logger);
Expand Down
Loading