Skip to content

Commit

Permalink
[tests] Remove Builder.UseDotNet (#8441)
Browse files Browse the repository at this point in the history
The .NET versus Classic switches have been removed from the MSBuild
tests.  Tests / asserts that only applied to classic have been removed.
Test parameters that only applied to classic (`aapt` vs `aapt2`) have
been removed.  Some project properties that only applied to classic
(`UseLatestPlatformSdk`) have been removed.
  • Loading branch information
pjcollins authored Nov 8, 2023
1 parent 9808988 commit c13c94d
Show file tree
Hide file tree
Showing 48 changed files with 307 additions and 1,210 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ public void GetDependencyWhenBuildToolsAreMissingTest ()
var referencesPath = CreateFauxReferencesDirectory (Path.Combine (path, "xbuild-frameworks"), apis);
var proj = new XamarinAndroidApplicationProject () {
IsRelease = true,
TargetFrameworkVersion = "v8.0",
TargetSdkVersion = "26",
UseLatestPlatformSdk = false,
};
var parameters = new string [] {
$"TargetFrameworkRootPath={referencesPath}",
Expand All @@ -147,7 +145,7 @@ public void GetDependencyWhenBuildToolsAreMissingTest ()
builder.Target = "GetAndroidDependencies";
Assert.True (builder.Build (proj, parameters: parameters),
string.Format ("First Build should have succeeded"));
int apiLevel = Builder.UseDotNet ? XABuildConfig.AndroidDefaultTargetDotnetApiLevel : 26;
int apiLevel = XABuildConfig.AndroidDefaultTargetDotnetApiLevel;
StringAssertEx.Contains ($"platforms/android-{apiLevel}", builder.LastBuildOutput, $"platforms/android-{apiLevel} should be a dependency.");
StringAssertEx.Contains ($"build-tools/{buildToolsVersion}", builder.LastBuildOutput, $"build-tools/{buildToolsVersion} should be a dependency.");
StringAssertEx.Contains ("platform-tools", builder.LastBuildOutput, "platform-tools should be a dependency.");
Expand All @@ -168,9 +166,7 @@ public void GetDependencyWhenSDKIsMissingTest ([Values (true, false)] bool creat
var referencesPath = CreateFauxReferencesDirectory (Path.Combine (path, "xbuild-frameworks"), apis);
var proj = new XamarinAndroidApplicationProject () {
IsRelease = true,
TargetFrameworkVersion = "v8.0",
TargetSdkVersion = "26",
UseLatestPlatformSdk = false,
};
var parameters = new string [] {
$"TargetFrameworkRootPath={referencesPath}",
Expand All @@ -183,7 +179,7 @@ public void GetDependencyWhenSDKIsMissingTest ([Values (true, false)] bool creat
builder.Target = "GetAndroidDependencies";
Assert.True (builder.Build (proj, parameters: parameters),
string.Format ("First Build should have succeeded"));
int apiLevel = Builder.UseDotNet ? XABuildConfig.AndroidDefaultTargetDotnetApiLevel : 26;
int apiLevel = XABuildConfig.AndroidDefaultTargetDotnetApiLevel;
StringAssertEx.Contains ($"platforms/android-{apiLevel}", builder.LastBuildOutput, $"platforms/android-{apiLevel} should be a dependency.");
StringAssertEx.Contains ($"build-tools/{buildToolsVersion}", builder.LastBuildOutput, $"build-tools/{buildToolsVersion} should be a dependency.");
StringAssertEx.Contains ("platform-tools", builder.LastBuildOutput, "platform-tools should be a dependency.");
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,15 @@ public void TearDown ()

void AssertProfiledAotBuildMessages(ProjectBuilder b)
{
string filename = Builder.UseDotNet ? "dotnet" : "startup";
StringAssertEx.ContainsRegex (@$"Using profile data file.*{filename}\.aotprofile", b.LastBuildOutput, "Should use default AOT profile", RegexOptions.IgnoreCase);
StringAssertEx.ContainsRegex (@$"Using profile data file.*dotnet\.aotprofile", b.LastBuildOutput, "Should use default AOT profile", RegexOptions.IgnoreCase);
StringAssertEx.ContainsRegex (@$"Method.*emitted at", b.LastBuildOutput, "Should contain verbose AOT compiler output", RegexOptions.IgnoreCase);
}

[Test, Category ("ProfiledAOT")]
public void BuildBasicApplicationReleaseProfiledAot ([Values (true, false)] bool enableLLVM)
{
if (Builder.UseDotNet && enableLLVM) {
Assert.Ignore("https://github.com/dotnet/runtime/pull/71411");
if (TestEnvironment.IsWindows && enableLLVM) {
Assert.Ignore("https://github.com/dotnet/runtime/issues/93788");
}

var proj = new XamarinAndroidApplicationProject () {
Expand Down Expand Up @@ -108,8 +107,7 @@ public void BuildBasicApplicationReleaseProfiledAotWithoutDefaultProfile ()
proj.SetProperty (proj.ActiveConfigurationProperties, "AndroidUseDefaultAotProfile", "false");
using var b = CreateApkBuilder ();
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
string filename = Builder.UseDotNet ? "dotnet" : "startup";
StringAssertEx.DoesNotContainRegex (@$"Using profile data file.*{filename}\.aotprofile", b.LastBuildOutput, "Should not use default AOT profile", RegexOptions.IgnoreCase);
StringAssertEx.DoesNotContainRegex (@$"Using profile data file.*dotnet\.aotprofile", b.LastBuildOutput, "Should not use default AOT profile", RegexOptions.IgnoreCase);
}

[Test]
Expand Down Expand Up @@ -199,31 +197,9 @@ public void BuildAotApplicationWithNdkAndBundleAndÜmläüts (string supportedAb
using (var b = CreateApkBuilder (path)) {
b.ThrowOnBuildFailure = false;
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
//NOTE: Windows has shortened paths such as: C:\Users\myuser\ANDROI~3\ndk\PLATFO~1\AN3971~1\arch-x86\usr\lib\libc.so
if (checkMinLlvmPath && !IsWindows && !Builder.UseDotNet) {
Xamarin.Android.Tasks.NdkTools ndk = Xamarin.Android.Tasks.NdkTools.Create (AndroidNdkPath);
bool ndk22OrNewer = ndk.Version.Main.Major >= 22;

// LLVM passes a direct path to libc.so, and we need to use the libc.so
// which corresponds to the *minimum* SDK version specified in AndroidManifest.xml
// Since we overrode minSdkVersion=16, that means we should use libc.so from android-16.
if (ndk22OrNewer) {
// NDK r22 or newer store libc in [toolchain]/sysroot/usr/lib/[ARCH]/[API]/libc.so
StringAssertEx.ContainsRegex (@"\s*\[aot-compiler stdout].*sysroot.*.usr.lib.*19.libc\.so", b.LastBuildOutput, "AOT+LLVM should use libc.so from minSdkVersion!");
} else {
StringAssertEx.ContainsRegex (@"\s*\[aot-compiler stdout].*android-19.arch-.*.usr.lib.libc\.so", b.LastBuildOutput, "AOT+LLVM should use libc.so from minSdkVersion!");
}
}
foreach (var abi in supportedAbis.Split (new char [] { ';' })) {
var intermediate = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath);
if (!Builder.UseDotNet) {
var libapp = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath,
"bundles", abi, "libmonodroid_bundle_app.so");
Assert.IsTrue (File.Exists (libapp), abi + " libmonodroid_bundle_app.so does not exist");
}
var aotNativeLibrary = Builder.UseDotNet ?
Path.Combine (intermediate, AbiUtils.AbiToRuntimeIdentifier (abi), "aot", "UnnamedProject.dll.so") :
Path.Combine (intermediate, "aot", abi, "libaot-UnnamedProject.dll.so");
var aotNativeLibrary = Path.Combine (intermediate, AbiUtils.AbiToRuntimeIdentifier (abi), "aot", "UnnamedProject.dll.so");
FileAssert.Exists (aotNativeLibrary);
var apk = Path.Combine (Root, b.ProjectDirectory,
proj.OutputPath, $"{proj.PackageName}-Signed.apk");
Expand Down Expand Up @@ -268,9 +244,7 @@ public void BuildAotApplicationAndÜmläüts (string supportedAbis, bool enableL
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
foreach (var abi in supportedAbis.Split (new char [] { ';' })) {
var intermediate = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath);
var aotNativeLibrary = Builder.UseDotNet ?
Path.Combine (intermediate, AbiUtils.AbiToRuntimeIdentifier (abi), "aot", "UnnamedProject.dll.so") :
Path.Combine (intermediate, "aot", abi, "libaot-UnnamedProject.dll.so");
var aotNativeLibrary = Path.Combine (intermediate, AbiUtils.AbiToRuntimeIdentifier (abi), "aot", "UnnamedProject.dll.so");
FileAssert.Exists (aotNativeLibrary);
var apk = Path.Combine (Root, b.ProjectDirectory,
proj.OutputPath, $"{proj.PackageName}-Signed.apk");
Expand Down Expand Up @@ -304,19 +278,10 @@ public void BuildAMassiveApp ()
SolutionPath = Path.Combine (Root, testPath),
};
var app1 = new XamarinFormsMapsApplicationProject {
TargetFrameworkVersion = sb.LatestTargetFrameworkVersion (),
ProjectName = "App1",
AotAssemblies = true,
IsRelease = true,
};
if (Builder.UseDotNet) {
//TODO Re-enable if this test fails.
// app1.PackageReferences.Clear ();
// app1.PackageReferences.Add (KnownPackages.XamarinForms_5_0_0_2515);
// app1.PackageReferences.Add (KnownPackages.XamarinFormsMaps_5_0_0_2515);
// app1.PackageReferences.Add (KnownPackages.Xamarin_Build_Download_0_11_3);

}
//NOTE: BuildingInsideVisualStudio prevents the projects from being built as dependencies
sb.BuildingInsideVisualStudio = false;
app1.Imports.Add (new Import ("foo.targets") {
Expand Down Expand Up @@ -348,7 +313,6 @@ public void BuildAMassiveApp ()
for (int i = 0; i < 128; i++) {
var libName = $"Lib{i}";
var lib = new XamarinAndroidLibraryProject () {
TargetFrameworkVersion = sb.LatestTargetFrameworkVersion (),
ProjectName = libName,
IsRelease = true,
OtherBuildItems = {
Expand Down Expand Up @@ -482,13 +446,8 @@ public void CheckWhetherLibcAndLibmAreReferencedInAOTLibraries ()
proj.SetAndroidSupportedAbis (abis);

var libPaths = new List<string> ();
if (Builder.UseDotNet) {
libPaths.Add (Path.Combine ("android-arm64", "aot", "Mono.Android.dll.so"));
libPaths.Add (Path.Combine ("android-x64", "aot", "Mono.Android.dll.so"));
} else {
libPaths.Add (Path.Combine ("aot", "arm64-v8a", "libaot-Mono.Android.dll.so"));
libPaths.Add (Path.Combine ("aot", "x86_64", "libaot-Mono.Android.dll.so"));
}
libPaths.Add (Path.Combine ("android-arm64", "aot", "Mono.Android.dll.so"));
libPaths.Add (Path.Combine ("android-x64", "aot", "Mono.Android.dll.so"));

using (var b = CreateApkBuilder ()) {
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,8 @@ public void BindingLibraryIncremental (string classParser)
"GenerateBindings",
"_ResolveLibraryProjectImports",
"CoreCompile",
"_CreateAar",
};
if (Builder.UseDotNet) {
targets.Add ("_CreateAar");
} else {
targets.Add ("_CreateBindingResourceArchive");
//TODO: .NET 5+ cannot support javadoc yet, due to missing mdoc
targets.Add ("_ExtractJavaDocJars");
targets.Add ("BuildDocumentation");
}

var proj = new XamarinAndroidBindingProject () {
IsRelease = true,
Expand All @@ -102,7 +95,7 @@ public void BindingLibraryIncremental (string classParser)
}

//TODO: see https://github.com/dotnet/msbuild/issues/6609
if (!Builder.UseDotNet) {
if (false) {
//A list of properties we check exist in binding projects
var properties = new [] {
"AndroidSdkBuildToolsVersion",
Expand Down Expand Up @@ -155,7 +148,6 @@ public void CleanBasicBindingLibrary (string classParser)
public void BuildAarBindingLibraryStandalone (string classParser)
{
var proj = new XamarinAndroidBindingProject () {
UseLatestPlatformSdk = true,
IsRelease = true,
};
proj.Jars.Add (new AndroidItem.AndroidLibrary ("Jars\\material-menu-1.1.0.aar") {
Expand All @@ -164,9 +156,7 @@ public void BuildAarBindingLibraryStandalone (string classParser)
proj.AndroidClassParser = classParser;
using (var b = CreateDllBuilder ()) {
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
if (Builder.UseDotNet) {
FileAssert.Exists (Path.Combine (Root, b.ProjectDirectory, proj.OutputPath, "material-menu-1.1.0.aar"));
}
FileAssert.Exists (Path.Combine (Root, b.ProjectDirectory, proj.OutputPath, "material-menu-1.1.0.aar"));
}
}

Expand All @@ -175,7 +165,6 @@ public void BuildAarBindingLibraryStandalone (string classParser)
public void BuildAarBindigLibraryWithNuGetPackageOfJar (string classParser)
{
var proj = new XamarinAndroidBindingProject () {
UseLatestPlatformSdk = true,
IsRelease = true,
};
proj.PackageReferences.Add (KnownPackages.AndroidSupportV4_27_0_2_1);
Expand All @@ -201,7 +190,6 @@ public void BuildAarBindigLibraryWithNuGetPackageOfJar (string classParser)
public void BuildLibraryZipBindigLibraryWithAarOfJar (string classParser)
{
var proj = new XamarinAndroidBindingProject () {
UseLatestPlatformSdk = true,
IsRelease = true,
};
proj.AndroidClassParser = classParser;
Expand Down Expand Up @@ -398,15 +386,13 @@ public void BindingCheckHiddenFiles ()
FileAssert.Exists (assemblyMap);
var libraryProjects = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "lp");
var assemblyIdentityMap = b.Output.GetAssemblyMapCache ();
var assemblyIdentityName = Builder.UseDotNet ? "mylibrary.aar" : $"{binding.ProjectName}.dll";
var assemblyIdentityName = "mylibrary.aar";
var assemblyIdentity = assemblyIdentityMap.IndexOf (assemblyIdentityName).ToString ();
var dsStorePath = Path.Combine (libraryProjects, assemblyIdentity, "jl");
DirectoryAssert.Exists (dsStorePath);
FileAssert.DoesNotExist (Path.Combine (dsStorePath, ".DS_Store"));
DirectoryAssert.DoesNotExist (Path.Combine (dsStorePath, "_MACOSX"));
var svgJar = Builder.UseDotNet ?
Path.Combine (libraryProjects, assemblyIdentityMap.IndexOf ($"{binding.ProjectName}.aar").ToString (), "jl", "libs", "FD575F2BC294C4A9.jar") :
Path.Combine (dsStorePath, "svg-android.jar");
var svgJar = Path.Combine (libraryProjects, assemblyIdentityMap.IndexOf ($"{binding.ProjectName}.aar").ToString (), "jl", "libs", "FD575F2BC294C4A9.jar");
FileAssert.Exists (svgJar);
}
}
Expand Down Expand Up @@ -651,7 +637,6 @@ public void BindDefaultInterfaceMethods (string classParser)
proj.SetProperty ("LangVersion", "preview");

using (var b = CreateDllBuilder ()) {
proj.NuGetRestore (b.ProjectDirectory);
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");

string asmpath = Path.Combine (Root, b.ProjectDirectory, proj.OutputPath, $"{proj.ProjectName}.dll");
Expand Down Expand Up @@ -681,8 +666,6 @@ public void NothingToBind (string classParser)
[Test]
public void BindingWithAndroidJavaSource ()
{
if (!Builder.UseDotNet)
Assert.Ignore ("This Feature and Test is not available in Legacy Projects");
var path = Path.Combine ("temp", TestName);
var lib = new XamarinAndroidBindingProject () {
ProjectName = "BindingsProject",
Expand Down Expand Up @@ -732,10 +715,7 @@ public void BindingWithAndroidJavaSource ()
var hash = Files.HashString (Path.Combine (lib.IntermediateOutputPath,
"binding", "bin", $"{lib.ProjectName}.jar").Replace ("\\", "/"));
var intermediate = Path.Combine (Root, appBuilder.ProjectDirectory, app.IntermediateOutputPath);
var lpPath = Path.Combine ("0", "jl", $"{lib.ProjectName}.jar");
if (Builder.UseDotNet) {
lpPath = Path.Combine ("1", "jl", "libs", $"{hash}.jar");
}
var lpPath = Path.Combine ("1", "jl", "libs", $"{hash}.jar");
var jar = Path.Combine (intermediate, "lp", lpPath);
FileAssert.Exists (jar, $"'{jar}' should have been generated.");
var dexFile = Path.Combine (intermediate, "android", "bin", "classes.dex");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ public void CheckPostCompileAssetsIncludedInAPK ()
}

[Test]
public void CheckAssetsAreIncludedInAPK ([Values (true, false)] bool useAapt2)
public void CheckAssetsAreIncludedInAPK ()
{
AssertAaptSupported (useAapt2);
var projectPath = Path.Combine ("temp", TestName);
var libproj = new XamarinAndroidLibraryProject () {
ProjectName = "Library1",
Expand Down Expand Up @@ -106,7 +105,6 @@ public void CheckAssetsAreIncludedInAPK ([Values (true, false)] bool useAapt2)
},
}
};
proj.AndroidUseAapt2 = useAapt2;
proj.References.Add (new BuildItem ("ProjectReference", "..\\Library1\\Library1.csproj"));
using (var libb = CreateDllBuilder (Path.Combine (projectPath, libproj.ProjectName))) {
Assert.IsTrue (libb.Build (libproj), "{0} should have built successfully.", libproj.ProjectName);
Expand Down Expand Up @@ -151,19 +149,12 @@ public void FullPath ()
using (var b = CreateDllBuilder (Path.Combine ("temp", TestName, "SubDir"))) {
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
var libraryProjectImports = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "__AndroidLibraryProjects__.zip");
if (Builder.UseDotNet) {
var aarPath = Path.Combine (Root, b.ProjectDirectory, proj.OutputPath, $"{proj.ProjectName}.aar");
FileAssert.Exists (aarPath);
using (var aar = ZipHelper.OpenZip (aarPath)) {
aar.AssertEntryContents (aarPath, "assets/foo.txt", contents: "bar");
}
FileAssert.DoesNotExist (libraryProjectImports);
} else {
FileAssert.Exists (libraryProjectImports);
using (var zip = ZipHelper.OpenZip (libraryProjectImports)) {
zip.AssertEntryContents (libraryProjectImports, "library_project_imports/assets/foo.txt", contents: "bar");
}
var aarPath = Path.Combine (Root, b.ProjectDirectory, proj.OutputPath, $"{proj.ProjectName}.aar");
FileAssert.Exists (aarPath);
using (var aar = ZipHelper.OpenZip (aarPath)) {
aar.AssertEntryContents (aarPath, "assets/foo.txt", contents: "bar");
}
FileAssert.DoesNotExist (libraryProjectImports);
}
}
}
Expand Down
Loading

0 comments on commit c13c94d

Please sign in to comment.