Repository navigation
[Xamarin.Android.Build.Tasks] Move GetAndroidDefineConstants to Microsoft.Android.Build.Tasks #13477
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
Open
simonrozsival
wants to merge
1
commit into
main
Choose a base branch
from
simonrozsival-move-get-android-define-constants
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+115
−68
Open
[Xamarin.Android.Build.Tasks] Move GetAndroidDefineConstants to Microsoft.Android.Build.Tasks #13477
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...d.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/Tasks/GetAndroidDefineConstantsTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| #nullable enable | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Xml.Linq; | ||
| using Microsoft.Build.Framework; | ||
| using NUnit.Framework; | ||
| using Microsoft.Android.Tasks; | ||
|
|
||
| namespace Xamarin.Android.Build.Tests | ||
| { | ||
| [TestFixture] | ||
| public class GetAndroidDefineConstantsTests : BaseTest | ||
| { | ||
| [TestCase ("36", null, 36, "")] | ||
| [TestCase ("36.1", null, 36, "__ANDROID_36_1__")] | ||
| [TestCase ("38.2", "11.0-rc+test", 38, "__ANDROID_36_1__;__ANDROID_37_1__;__ANDROID_37_2__;__ANDROID_37_3__;__ANDROID_37_4__;__ANDROID_38_1__;__ANDROID_38_2__")] | ||
| public void Constants (string apiLevel, string? productVersion, int major, string minorConstants) | ||
| { | ||
| var task = new GetAndroidDefineConstants { | ||
| AndroidApiLevel = apiLevel, | ||
| ProductVersion = productVersion, | ||
| }; | ||
| Assert.IsTrue (task.Execute ()); | ||
| var constants = task.AndroidDefineConstants ?? throw new InvalidOperationException ("No constants returned."); | ||
| var expected = new List<string> (); | ||
| if (productVersion != null) | ||
| expected.Add ("__XAMARIN_ANDROID_11_0_rc_test__"); | ||
| expected.AddRange (["__MOBILE__", "__ANDROID__"]); | ||
| expected.AddRange (Enumerable.Range (1, major).Select (i => $"__ANDROID_{i}__")); | ||
| expected.AddRange (minorConstants.Split (';', StringSplitOptions.RemoveEmptyEntries)); | ||
| CollectionAssert.AreEqual (expected, constants.Select (i => i.ItemSpec)); | ||
| } | ||
|
|
||
| [TestCase ("")] | ||
| [TestCase ("invalid")] | ||
| public void InvalidApiLevel (string apiLevel) | ||
| { | ||
| var errors = new List<BuildErrorEventArgs> (); | ||
| var task = new GetAndroidDefineConstants { | ||
| AndroidApiLevel = apiLevel, | ||
| BuildEngine = new MockBuildEngine (TestContext.Out, errors: errors), | ||
| }; | ||
| Assert.IsFalse (task.Execute ()); | ||
| Assert.IsNull (task.AndroidDefineConstants); | ||
| Assert.IsEmpty (errors); | ||
| } | ||
|
|
||
| [TestCase ("GetAndroidDefineConstants")] | ||
| [TestCase ("Microsoft.Android.Tasks.GetAndroidDefineConstants")] | ||
| public void RegisteredTaskNamesExecute (string taskName) | ||
| { | ||
| string directory = Path.Combine (Root, "temp", TestName); | ||
| Directory.CreateDirectory (directory); | ||
| string commonTargets = Path.Combine (NativeAotBootstrapTestTools.FindRepositoryRoot (), | ||
| "src", "Xamarin.Android.Build.Tasks", "Xamarin.Android.Common.targets"); | ||
| var registrations = XDocument.Load (commonTargets).Descendants () | ||
| .Where (e => e.Name.LocalName == "UsingTask" && (string?) e.Attribute ("TaskName") == "Microsoft.Android.Tasks.GetAndroidDefineConstants") | ||
| .Select (e => new XElement (e) { Name = "UsingTask" }) | ||
| .ToArray (); | ||
| Assert.AreEqual (2, registrations.Length); | ||
|
|
||
| string project = Path.Combine (directory, "constants.proj"); | ||
| string output = Path.Combine (directory, "constants.txt"); | ||
| new XDocument (new XElement ("Project", | ||
| new XElement ("PropertyGroup", | ||
| new XElement ("_MicrosoftAndroidBuildTasksAssembly", typeof (GetAndroidDefineConstants).Assembly.Location)), | ||
| registrations, | ||
| new XElement ("Target", new XAttribute ("Name", "Build"), | ||
| new XElement (taskName, | ||
| new XAttribute ("AndroidApiLevel", "36.1"), | ||
| new XAttribute ("ProductVersion", "11.0-rc+test"), | ||
| new XElement ("Output", new XAttribute ("TaskParameter", "AndroidDefineConstants"), new XAttribute ("ItemName", "_Constants"))), | ||
| new XElement ("WriteLinesToFile", | ||
| new XAttribute ("File", output), | ||
| new XAttribute ("Lines", "@(_Constants)"), | ||
| new XAttribute ("Overwrite", "true"))))) | ||
| .Save (project); | ||
|
|
||
| string dotnet = Environment.GetEnvironmentVariable ("DOTNET_HOST_PATH") ?? "dotnet"; | ||
| var result = NativeAotBootstrapTestTools.Run (dotnet, "msbuild", project, "-t:Build", "-v:minimal", "-nr:false"); | ||
| Assert.AreEqual (0, result.ExitCode, result.Output + result.Error); | ||
| var lines = File.ReadAllLines (output); | ||
| Assert.AreEqual ("__XAMARIN_ANDROID_11_0_rc_test__", lines [0]); | ||
| Assert.AreEqual ("__ANDROID_36_1__", lines [^1]); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 0 additions & 48 deletions
48
...oid.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/GetAndroidDefineConstantsTests.cs
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖 💡 Testing — Consider adding a Windows-only variant that runs this generated project with full-framework
MSBuild.exe. Both current cases invokedotnet msbuild, soMSBuildRuntimeTypeis alwaysCore; copying both registrations and asserting their count does not exercise theFullregistration or the new out-of-process task-host boundary. Running the same output assertions through that host would protect the Visual Studio path when migrating this task out of the netstandard assembly.{Rule: Test host-specific execution paths}