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

[Xamarin.Android.Build.Tasks] Only report ndk-bundle if required. #1298

Merged
merged 2 commits into from
Feb 13, 2018
Merged
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 @@ -26,6 +26,8 @@ public class CalculateProjectDependencies : Task

public string NdkVersion { get; set; }

public bool NdkRequired { get; set; }

[Output]
public ITaskItem [] Dependencies { get; set; }

Expand Down Expand Up @@ -57,7 +59,7 @@ public override bool Execute ()
if (!string.IsNullOrEmpty (ToolsVersion)) {
dependencies.Add (CreateAndroidDependency ("tools", ToolsVersion));
}
if (!string.IsNullOrEmpty (NdkVersion)) {
if (!string.IsNullOrEmpty (NdkVersion) && NdkRequired) {
dependencies.Add (CreateAndroidDependency ("ndk-bundle", NdkVersion));
}
Dependencies = dependencies.ToArray ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,46 @@ namespace Xamarin.Android.Build.Tests {
[TestFixture]
[Parallelizable (ParallelScope.Children)]
public class GetDependenciesTest : BaseTest {

[Test]
public void CheckNdkBundle ([Values(true, false)] bool ndkRequred)
{
var path = Path.Combine ("temp", TestName);
var referencePath = CreateFauxReferencesDirectory (Path.Combine (path, "references"), new ApiInfo [] {
new ApiInfo () { Id = 26, Level = 26, Name = "Oreo", FrameworkVersion = "v8.0", Stable = true },
});
MonoAndroidHelper.RefreshSupportedVersions (new string [] { referencePath });
IBuildEngine engine = new MockBuildEngine (TestContext.Out);
var task = new CalculateProjectDependencies {
BuildEngine = engine
};

task.PlatformToolsVersion = "26.0.3";
task.ToolsVersion = "26.0.1";
task.NdkVersion = "12.1";
task.NdkRequired = ndkRequred;
task.BuildToolsVersion = "26.0.1";
task.TargetFrameworkVersion = "v8.0";
task.ManifestFile = new TaskItem (Path.Combine (path, "AndroidManifest.xml"));
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"),
"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") == ""),
"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");
if (ndkRequred) {
Assert.IsNotNull (task.Dependencies.FirstOrDefault (x => x.ItemSpec == "ndk-bundle" && x.GetMetadata ("Version") == "12.1"),
"Dependencies should contain a ndk-bundle version 12.1");
} else {
Assert.IsNull (task.Dependencies.FirstOrDefault (x => x.ItemSpec == "ndk-bundle"),
"Dependencies should not contain a ndk-bundle item");
}
}

[Test]
public void ManifestFileDoesNotExist ()
Expand All @@ -30,6 +70,7 @@ public void ManifestFileDoesNotExist ()
task.PlatformToolsVersion = "26.0.3";
task.ToolsVersion = "26.0.1";
task.NdkVersion = "12.1";
task.NdkRequired = true;
task.BuildToolsVersion = "26.0.1";
task.TargetFrameworkVersion = "v8.0";
task.ManifestFile = new TaskItem (Path.Combine (path, "AndroidManifest.xml"));
Expand Down Expand Up @@ -72,6 +113,7 @@ public void ManifestFileExists ()
task.PlatformToolsVersion = "26.0.3";
task.ToolsVersion = "26.0.1";
task.NdkVersion = "12.1";
task.NdkRequired = true;
task.BuildToolsVersion = "26.0.1";
task.TargetFrameworkVersion = "v8.0";
task.ManifestFile = new TaskItem (manifestFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2773,6 +2773,8 @@ because xbuild doesn't support framework reference assemblies.
<Target Name="GetAndroidDependencies" DependsOnTargets="$(GetAndroidDependenciesDependsOn)" Returns="@(AndroidDependency)">
<PropertyGroup>
<_ProjectAndroidManifest>$(ProjectDir)$(AndroidManifest)</_ProjectAndroidManifest>
<_NdkRequired Condition="'$(BundleAssemblies)' == 'True' Or '$(AotAssemblies)' == 'True'">true</_NdkRequired>
<_NdkRequired Condition="'$(_NdkRequired)' == ''">false</_NdkRequired>
</PropertyGroup>
<Error Text="AndroidManifest file does not exist" Condition="'$(_ProjectAndroidManifest)'!='' And !Exists ('$(_ProjectAndroidManifest)')"/>
<CalculateProjectDependencies
Expand All @@ -2782,6 +2784,7 @@ because xbuild doesn't support framework reference assemblies.
PlatformToolsVersion="$(AndroidSdkPlatformToolsVersion)"
ToolsVersion="$(AndroidSdkToolsVersion)"
NdkVersion="$(AndroidNdkVersion)"
NdkRequired="$(_NdkRequired)"
>
<Output TaskParameter="Dependencies" ItemName="AndroidDependency" />
</CalculateProjectDependencies>
Expand Down