Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] Update CalculateProjectDependencies t…
Browse files Browse the repository at this point in the history
…o match spec (#1323)

The `GetAndroidDependencies` target (f9b2c97) is intended to be
called by an IDE on project-load, so that the IDE can install project
dependencies "in the background," and ideally have the dependencies
installed before the project is actually built.

As such, the semantics of the `@(AndroidDependency)` output item
group need to be agreed upon by xamarin-android, the IDEs, and
whatever the IDEs use to actually install the dependencies. The
`%(AndroidDependency.Identity)` values need to be well-defined
and consistent across these three different libraries.

In commit f9b2c97, certain values would have a version number
"embedded" within `%(AndroidDependency.Identity)`, using a `;` to
separate the name from the version, e.g. `build-tools;26.0.1`.
Use of `;` was chosen because that made it easier for the package
installation code to use (e.g. it would be identical to what the
Android SDK `sdkmanager` utility expects).

Unfortunately, the use of `;` was counter to the [spec][spec], and
also looks "weird" in the context of MSBuild, as `;` is *also* the
item group separator.

Change the version separator to instead be a `/`. This "looks" better
and is also consistent with the [installer manifest][manifest] schema
that we will use, wherein `%(AndroidDependency.Identity)` matches a
`//xamarin-android/*/@filesystem-path` attribute value:

	<xamarin-android sdk-version="0.0.0" generated-on="Tue, 20 Feb 2018 21:16:01 GMT">
	  <platform-tools filesystem-path="platform-tools" path="platform-tools" revision="27.0.1" manifest-url="https://dl.google.com/android/repository/repository2-1.xml" description="Android SDK Platform-Tools" obsolete="False" preview="False" license="android-sdk-license" original-type="generic:genericDetailsType">
	    <!-- ... -->
	  </platform-tools>
	  <build-tool filesystem-path="build-tools/27.0.3" path="build-tools;27.0.3" revision="27.0.3" manifest-url="https://dl.google.com/android/repository/repository2-1.xml" description="Android SDK Build-Tools 27.0.3" obsolete="False" preview="False" license="android-sdk-license" original-type="generic:genericDetailsType">
	  </build-tool>
	  <!-- ... -->
	</xamarin-android>

`@(AndroidDependency)` could be equivalent to:

	<ItemGroup>
	  <AndroidDependency Include="build-tools/27.0.3">
	    <Version>27.0.3</Version>
	  </AndroidDependency>
	  <AndroidDependency Include="platform-tools">
	    <Version>$(AndroidSdkPlatformToolsVersion)</Version>
	  </AndroidDependency>
	  <AndroidDependency Include="platforms/android-27">
	    <Version>27</Version>
	  </AndroidDependency>
	  <AndroidDependency Include="tools">
	    <Version>$(AndroidSdkToolsVersion)</Version>
	  </AndroidDependency>
	</ItemGroup>

[manifest]: https://gist.github.com/dellis1972/08ba76cc19cdce3dec89c68684664299
[spec]: https://microsoft-my.sharepoint.com/:w:/r/personal/mhutch_microsoft_com/_layouts/15/WopiFrame.aspx?sourcedoc=%7B0436dd38-c9ff-4cf2-b33c-ee4515b68546%7D&action=edit&wdPid=64869a58
  • Loading branch information
dellis1972 authored and jonpryor committed Feb 21, 2018
1 parent e489aae commit d3ad544
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public override bool Execute ()
manifestApiLevel = manifest.TargetSdkVersion ?? manifest.MinSdkVersion ?? DefaultMinSDKVersion;
}
var sdkVersion = Math.Max (targetApiLevel.Value, manifestApiLevel);
dependencies.Add (CreateAndroidDependency ($"platforms;android-{sdkVersion}", $""));
dependencies.Add (CreateAndroidDependency ($"build-tools;{BuildToolsVersion}", BuildToolsVersion));
dependencies.Add (CreateAndroidDependency ($"platforms/android-{sdkVersion}", $""));
dependencies.Add (CreateAndroidDependency ($"build-tools/{BuildToolsVersion}", BuildToolsVersion));
if (!string.IsNullOrEmpty (PlatformToolsVersion)) {
dependencies.Add (CreateAndroidDependency ("platform-tools", PlatformToolsVersion));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public void CheckNdkBundle ([Values(true, false)] bool ndkRequred)
Assert.IsTrue (task.Execute ());
Assert.IsNotNull (task.Dependencies);
Assert.AreEqual (ndkRequred ? 5 : 4, task.Dependencies.Length);
Assert.IsNotNull (task.Dependencies.FirstOrDefault (x => x.ItemSpec == "build-tools;26.0.1" && x.GetMetadata ("Version") == "26.0.1"),
Assert.IsNotNull (task.Dependencies.FirstOrDefault (x => x.ItemSpec == "build-tools/26.0.1" && x.GetMetadata ("Version") == "26.0.1"),
"Dependencies should contains a build-tools version 26.0.1");
Assert.IsNotNull (task.Dependencies.FirstOrDefault (x => x.ItemSpec == "tools" && x.GetMetadata ("Version") == "26.0.1"),
"Dependencies should contains a tools version 26.0.1");
Assert.IsNotNull (task.Dependencies.FirstOrDefault (x => x.ItemSpec == "platforms;android-26" && x.GetMetadata ("Version") == ""),
Assert.IsNotNull (task.Dependencies.FirstOrDefault (x => x.ItemSpec == "platforms/android-26" && x.GetMetadata ("Version") == ""),
"Dependencies should contains a platform version android-26");
Assert.IsNotNull (task.Dependencies.FirstOrDefault (x => x.ItemSpec == "platform-tools" && x.GetMetadata ("Version") == "26.0.3"),
"Dependencies should contains a platform-tools version 26.0.3");
Expand Down Expand Up @@ -77,11 +77,11 @@ public void ManifestFileDoesNotExist ()
Assert.IsTrue (task.Execute ());
Assert.IsNotNull (task.Dependencies);
Assert.AreEqual (5, task.Dependencies.Length);
Assert.IsNotNull (task.Dependencies.FirstOrDefault (x => x.ItemSpec == "build-tools;26.0.1" && x.GetMetadata ("Version") == "26.0.1"),
Assert.IsNotNull (task.Dependencies.FirstOrDefault (x => x.ItemSpec == "build-tools/26.0.1" && x.GetMetadata ("Version") == "26.0.1"),
"Dependencies should contains a build-tools version 26.0.1");
Assert.IsNotNull (task.Dependencies.FirstOrDefault (x => x.ItemSpec == "tools" && x.GetMetadata ("Version") == "26.0.1"),
"Dependencies should contains a tools version 26.0.1");
Assert.IsNotNull (task.Dependencies.FirstOrDefault (x => x.ItemSpec == "platforms;android-26" && x.GetMetadata ("Version") == ""),
Assert.IsNotNull (task.Dependencies.FirstOrDefault (x => x.ItemSpec == "platforms/android-26" && x.GetMetadata ("Version") == ""),
"Dependencies should contains a platform version android-26");
Assert.IsNotNull (task.Dependencies.FirstOrDefault (x => x.ItemSpec == "platform-tools" && x.GetMetadata ("Version") == "26.0.3"),
"Dependencies should contains a platform-tools version 26.0.3");
Expand Down Expand Up @@ -120,11 +120,11 @@ public void ManifestFileExists ()
Assert.IsTrue(task.Execute ());
Assert.IsNotNull (task.Dependencies);
Assert.AreEqual (5, task.Dependencies.Length);
Assert.IsNotNull (task.Dependencies.FirstOrDefault (x => x.ItemSpec == "build-tools;26.0.1" && x.GetMetadata ("Version") == "26.0.1"),
Assert.IsNotNull (task.Dependencies.FirstOrDefault (x => x.ItemSpec == "build-tools/26.0.1" && x.GetMetadata ("Version") == "26.0.1"),
"Dependencies should contains a build-tools version 26.0.1");
Assert.IsNotNull (task.Dependencies.FirstOrDefault (x => x.ItemSpec == "tools" && x.GetMetadata ("Version") == "26.0.1"),
"Dependencies should contains a tools version 26.0.1");
Assert.IsNotNull (task.Dependencies.FirstOrDefault (x => x.ItemSpec == "platforms;android-26" && x.GetMetadata ("Version") == ""),
Assert.IsNotNull (task.Dependencies.FirstOrDefault (x => x.ItemSpec == "platforms/android-26" && x.GetMetadata ("Version") == ""),
"Dependencies should contains a platform version android-26");
Assert.IsNotNull (task.Dependencies.FirstOrDefault (x => x.ItemSpec == "platform-tools" && x.GetMetadata ("Version") == "26.0.3"),
"Dependencies should contains a platform-tools version 26.0.3");
Expand Down

0 comments on commit d3ad544

Please sign in to comment.