Skip to content

Commit 44d9845

Browse files
committed
Taken from from #10573
1 parent 1b0c77f commit 44d9845

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/BaseTest.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,32 @@ protected bool RunCommand (string command, string arguments)
564564
}
565565
}
566566

567+
protected bool IgnoreUnsupportedConfiguration (AndroidRuntime runtime, bool aot = false, bool release = false)
568+
{
569+
if (runtime == AndroidRuntime.NativeAOT) {
570+
// NativeAOT is release-only, AOT is always implied
571+
if (release) {
572+
return false;
573+
}
574+
575+
Assert.Ignore ($"NativeAOT: unsupported configuration (release == {release})");
576+
return true;
577+
}
578+
579+
if (runtime == AndroidRuntime.CoreCLR) {
580+
// CoreCLR doesn't support AOT
581+
if (!aot) {
582+
return false;
583+
}
584+
585+
Assert.Ignore ($"CoreCLR: unsupported configuration (aot == {aot})");
586+
return true;
587+
}
588+
589+
// MonoVM supports all the combinations
590+
return false;
591+
}
592+
567593
[SetUp]
568594
public void TestSetup ()
569595
{

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/ProjectExtensions.cs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System;
2+
13
using Xamarin.Android.Tasks;
24
using Xamarin.ProjectTools;
35

@@ -10,18 +12,45 @@ public static class ProjectExtensions
1012
/// NOTE: $(EnablePreviewFeatures) ignores warning XA1040: The NativeAOT runtime on Android is an experimental feature and not yet suitable for production use.
1113
/// </summary>
1214
public static void SetRuntime (this XamarinProject project, AndroidRuntime runtime)
15+
{
16+
DoSetRuntime (project, runtime);
17+
EnablePreviewFeaturesIfNeeded (project, runtime);
18+
}
19+
20+
public static void SetRuntime (this XamarinAndroidApplicationProject project, AndroidRuntime runtime)
21+
{
22+
if (runtime != AndroidRuntime.NativeAOT) {
23+
DoSetRuntime (project, runtime);
24+
return;
25+
}
26+
project.SetPublishAot (true, BaseTest.AndroidNdkPath);
27+
EnablePreviewFeaturesIfNeeded (project, runtime);
28+
}
29+
30+
static void EnablePreviewFeaturesIfNeeded (XamarinProject project, AndroidRuntime runtime)
31+
{
32+
if (runtime != AndroidRuntime.NativeAOT) {
33+
return;
34+
}
35+
36+
project.SetProperty ("EnablePreviewFeatures", "true");
37+
}
38+
39+
static void DoSetRuntime (XamarinProject project, AndroidRuntime runtime)
1340
{
1441
switch (runtime) {
1542
case AndroidRuntime.CoreCLR:
1643
project.SetProperty ("UseMonoRuntime", "false");
1744
break;
1845
case AndroidRuntime.NativeAOT:
1946
project.SetProperty ("PublishAot", "true");
20-
project.SetProperty ("EnablePreviewFeatures", "true");
2147
break;
22-
default:
48+
case AndroidRuntime.MonoVM:
2349
project.SetProperty ("UseMonoRuntime", "true");
2450
break;
51+
52+
default:
53+
throw new NotSupportedException ($"Unsupported runtime {runtime}");
2554
}
2655
}
2756
}

0 commit comments

Comments
 (0)