Skip to content

Commit

Permalink
[tests] Reduce default build output verbosity (#9002)
Browse files Browse the repository at this point in the history
Sets the default build verbosity for MSBuild desktop and device tests to
'normal' to reduce log sizes and hopefully slightly improve test run
timings.

Tests that need to validate target outputs or other build details have
been configured to use 'detailed' verbosity.

Runtime identifier information will no longer be gathered by reading
from the build log, we will instead read from the project file or assume
a default of 64-bit architectures.
  • Loading branch information
pjcollins authored Jun 7, 2024
1 parent b521487 commit b994441
Show file tree
Hide file tree
Showing 24 changed files with 80 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using NUnit.Framework;
using Xamarin.Android.Tools;
using Xamarin.ProjectTools;
using Microsoft.Build.Framework;

namespace Xamarin.Android.Build.Tests
{
Expand Down Expand Up @@ -45,6 +46,7 @@ public void InstallAndroidDependenciesTest ([Values ("GoogleV2", "Xamarin")] str
}

using (var b = CreateApkBuilder ()) {
b.Verbosity = LoggerVerbosity.Detailed;
b.CleanupAfterSuccessfulBuild = false;
string defaultTarget = b.Target;
b.Target = "InstallAndroidDependencies";
Expand Down Expand Up @@ -108,6 +110,7 @@ public void GetDependencyNdkRequiredConditions (string property, bool ndkRequire
proj.AotAssemblies = true;
proj.SetProperty (property, "true");
using (var builder = CreateApkBuilder ()) {
builder.Verbosity = LoggerVerbosity.Detailed;
builder.Target = "GetAndroidDependencies";
Assert.IsTrue (builder.Build (proj), "Build should have succeeded.");
IEnumerable<string> taskOutput = builder.LastBuildOutput
Expand Down Expand Up @@ -141,6 +144,7 @@ public void GetDependencyWhenBuildToolsAreMissingTest ()
};
string buildToolsVersion = GetExpectedBuildToolsVersion ();
using (var builder = CreateApkBuilder (Path.Combine (path, proj.ProjectName), cleanupAfterSuccessfulBuild: false, cleanupOnDispose: false)) {
builder.Verbosity = LoggerVerbosity.Detailed;
builder.ThrowOnBuildFailure = false;
builder.Target = "GetAndroidDependencies";
Assert.True (builder.Build (proj, parameters: parameters),
Expand Down Expand Up @@ -178,6 +182,7 @@ public void GetDependencyWhenSDKIsMissingTest ([Values (true, false)] bool creat

string buildToolsVersion = GetExpectedBuildToolsVersion ();
using (var builder = CreateApkBuilder (Path.Combine (path, proj.ProjectName), cleanupAfterSuccessfulBuild: false, cleanupOnDispose: false)) {
builder.Verbosity = LoggerVerbosity.Detailed;
builder.ThrowOnBuildFailure = false;
builder.Target = "GetAndroidDependencies";
Assert.True (builder.Build (proj, parameters: parameters),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,7 @@ public void BuildAppWithManagedResourceParser()
appProj.SetProperty ("AndroidUseManagedDesignTimeResourceGenerator", "True");
appProj.SetProperty ("AndroidUseDesignerAssembly", "false");
using (var appBuilder = CreateApkBuilder (Path.Combine (path, appProj.ProjectName))) {
appBuilder.Verbosity = LoggerVerbosity.Detailed;
Assert.IsTrue (appBuilder.DesignTimeBuild (appProj), "DesignTime Application Build should have succeeded.");
Assert.IsFalse (appProj.CreateBuildOutput (appBuilder).IsTargetSkipped ("_ManagedUpdateAndroidResgen"),
"Target '_ManagedUpdateAndroidResgen' should have run.");
Expand Down Expand Up @@ -1028,10 +1029,12 @@ public void BuildAppWithManagedResourceParserAndLibraries ()
appProj.SetProperty ("AndroidUseManagedDesignTimeResourceGenerator", "True");
appProj.SetProperty ("AndroidUseDesignerAssembly", "false");
using (var libBuilder = CreateDllBuilder (Path.Combine (path, libProj.ProjectName), false, false)) {
libBuilder.Verbosity = LoggerVerbosity.Detailed;
libBuilder.AutomaticNuGetRestore = false;
Assert.IsTrue (libBuilder.RunTarget (libProj, "Restore"), "Library project should have restored.");
libBuilder.ThrowOnBuildFailure = false;
using (var appBuilder = CreateApkBuilder (Path.Combine (path, appProj.ProjectName), false, false)) {
appBuilder.Verbosity = LoggerVerbosity.Detailed;
appBuilder.AutomaticNuGetRestore = false;
Assert.IsTrue (appBuilder.RunTarget (appProj, "Restore"), "App project should have restored.");
appBuilder.ThrowOnBuildFailure = false;
Expand Down Expand Up @@ -1209,6 +1212,7 @@ public void CustomViewAddResourceId ()
proj.LayoutMain = proj.LayoutMain.Replace ("</LinearLayout>", "<android.support.design.widget.BottomNavigationView android:id=\"@+id/navigation\" /></LinearLayout>");
proj.PackageReferences.Add (KnownPackages.AndroidXAppCompat);
using (var b = CreateApkBuilder (Path.Combine ("temp", TestName))) {
b.Verbosity = LoggerVerbosity.Detailed;
Assert.IsTrue (b.Build (proj), "first build should have succeeded");

//Add a new android:id
Expand Down Expand Up @@ -1237,6 +1241,7 @@ public void CheckNoVersionVectors ()
{
var proj = new XamarinFormsAndroidApplicationProject ();
using (var b = CreateApkBuilder (Path.Combine ("temp", TestName))) {
b.Verbosity = LoggerVerbosity.Detailed;
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");

string aaptCommand = "Executing link";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public void BuildBasicApplicationReleaseProfiledAot ([Values (true, false)] bool
proj.SetProperty ("EnableLLVM", enableLLVM.ToString ());
proj.SetProperty (proj.ActiveConfigurationProperties, "AndroidExtraAotOptions", "--verbose");
using var b = CreateApkBuilder ();
b.Verbosity = LoggerVerbosity.Detailed;
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
AssertProfiledAotBuildMessages (b);
}
Expand All @@ -93,6 +94,7 @@ public void BuildBasicApplicationReleaseWithCustomAotProfile ()
proj.OtherBuildItems.Add (new BuildItem ("AndroidAotProfile", "custom.aotprofile") { BinaryContent = () => custom_aot_profile });

using var b = CreateApkBuilder ();
b.Verbosity = LoggerVerbosity.Detailed;
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
AssertProfiledAotBuildMessages (b);
}
Expand All @@ -106,6 +108,7 @@ public void BuildBasicApplicationReleaseProfiledAotWithoutDefaultProfile ()
};
proj.SetProperty (proj.ActiveConfigurationProperties, "AndroidUseDefaultAotProfile", "false");
using var b = CreateApkBuilder ();
b.Verbosity = LoggerVerbosity.Detailed;
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
StringAssertEx.DoesNotContainRegex (@$"Using profile data file.*dotnet\.aotprofile", b.LastBuildOutput, "Should not use default AOT profile", RegexOptions.IgnoreCase);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Xml.Linq;
using Xamarin.ProjectTools;
using Microsoft.Android.Build.Tasks;
using Microsoft.Build.Framework;

namespace Xamarin.Android.Build.Tests
{
Expand Down Expand Up @@ -86,6 +87,7 @@ public void BindingLibraryIncremental (string classParser)
});
proj.AndroidClassParser = classParser;
using (var b = CreateDllBuilder ()) {
b.Verbosity = LoggerVerbosity.Detailed;
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");

var assemblyPath = Path.Combine (Root, b.ProjectDirectory, proj.OutputPath, $"{proj.ProjectName}.dll");
Expand Down Expand Up @@ -679,6 +681,7 @@ public void BindingWithAndroidJavaSource ()
};
using (var libBuilder = CreateDllBuilder (Path.Combine (path, lib.ProjectName), cleanupAfterSuccessfulBuild: false))
using (var appBuilder = CreateApkBuilder (Path.Combine (path, app.ProjectName))) {
libBuilder.Verbosity = LoggerVerbosity.Detailed;
Assert.IsTrue (libBuilder.Build (lib), "Library build should have succeeded.");
var generatedCode = Path.Combine (Root, libBuilder.ProjectDirectory, lib.IntermediateOutputPath,
"generated", "src", "Com.Xamarin.Android.Test.Msbuildtest.JavaSourceTestExtension.cs");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ public void CheckItemMetadata ([Values (true, false)] bool isRelease)
mainAxml.MetadataValues = "CustomData=ResourceMetaDataOK";

using (var builder = CreateApkBuilder (string.Format ("temp/CheckItemMetadata_{0}", isRelease))) {
builder.Verbosity = LoggerVerbosity.Detailed;
builder.Build (proj);
StringAssertEx.Contains ("AssetMetaDataOK", builder.LastBuildOutput, "Metadata was not copied for AndroidAsset");
StringAssertEx.Contains ("ResourceMetaDataOK", builder.LastBuildOutput, "Metadata was not copied for AndroidResource");
Expand Down Expand Up @@ -698,6 +699,7 @@ public void BuildAfterUpgradingNuget ()
//[TearDown] will still delete if test outcome successful, I need logs if assertions fail but build passes
b.CleanupAfterSuccessfulBuild =
b.CleanupOnDispose = false;
b.Verbosity = LoggerVerbosity.Detailed;
var projectDir = Path.Combine (Root, b.ProjectDirectory);
if (Directory.Exists (projectDir))
Directory.Delete (projectDir, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public void MarshalMethodsDefaultEnabledStatus (bool isRelease, bool marshalMeth
bool shouldMarshalMethodsBeEnabled = isRelease && marshalMethodsEnabled;

using (var b = CreateApkBuilder ()) {
b.Verbosity = LoggerVerbosity.Diagnostic;
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
Assert.IsTrue (
StringAssertEx.ContainsText (b.LastBuildOutput, $"_AndroidUseMarshalMethods = {shouldMarshalMethodsBeEnabled}"),
Expand Down Expand Up @@ -455,6 +456,7 @@ public void SkipConvertResourcesCases ()
WebContent = "https://repo1.maven.org/maven2/com/balysv/material-menu/1.1.0/material-menu-1.1.0.aar"
});
using (var b = CreateApkBuilder (Path.Combine ("temp", TestName))) {
b.Verbosity = LoggerVerbosity.Detailed;
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
Assert.IsFalse (b.Output.IsTargetSkipped (target), $"`{target}` should not be skipped.");

Expand Down Expand Up @@ -1207,9 +1209,7 @@ public void BuildBasicApplicationCheckPdb ()
var proj = new XamarinAndroidApplicationProject ();
using (var b = CreateApkBuilder ()) {
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
foreach (string rid in b.GetBuildRuntimeIdentifiers ()) {
string abi = MonoAndroidHelper.RidToAbi (rid);

foreach (string abi in proj.GetRuntimeIdentifiersAsAbis ()) {
Assert.IsTrue (File.Exists (Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, $"android/assets/{abi}/UnnamedProject.pdb")),
$"UnnamedProject.pdb must be copied to the Intermediate directory for ABI {abi}");
}
Expand All @@ -1223,18 +1223,14 @@ public void BuildBasicApplicationCheckPdbRepeatBuild ()
using (var b = CreateApkBuilder ()) {
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");

foreach (string rid in b.GetBuildRuntimeIdentifiers ()) {
string abi = MonoAndroidHelper.RidToAbi (rid);

foreach (string abi in proj.GetRuntimeIdentifiersAsAbis ()) {
Assert.IsTrue (File.Exists (Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, $"android/assets/{abi}/UnnamedProject.pdb")),
$"UnnamedProject.pdb must be copied to the Intermediate directory for ABI {abi}");
}

Assert.IsTrue (b.Build (proj), "second build failed");

foreach (string rid in b.GetBuildRuntimeIdentifiers ()) {
string abi = MonoAndroidHelper.RidToAbi (rid);

foreach (string abi in proj.GetRuntimeIdentifiersAsAbis ()) {
Assert.IsTrue (File.Exists (Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, $"android/assets/{abi}/UnnamedProject.pdb")),
$"UnnamedProject.pdb must be copied to the Intermediate directory for ABI {abi}");
}
Expand Down Expand Up @@ -1318,8 +1314,8 @@ public Class2 ()
};

string apkPath = Path.Combine (outputPath, proj.PackageName + "-Signed.apk");
var helper = new ArchiveAssemblyHelper (apkPath, useAssemblyStores: false, b.GetBuildRuntimeIdentifiers ().ToArray ());
foreach (string abi in b.GetBuildAbis ()) {
var helper = new ArchiveAssemblyHelper (apkPath, useAssemblyStores: false, proj.GetRuntimeIdentifiers ().ToArray ());
foreach (string abi in proj.GetRuntimeIdentifiersAsAbis ()) {
foreach ((string fileName, bool existsInBin) in fileNames) {
EnsureFilesAreTheSame (intermediate, existsInBin ? outputPath : null, fileName, abi, helper, uncompressIfNecessary: fileName.EndsWith (".dll", StringComparison.Ordinal));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,6 @@ public void BuildWithNativeLibraries ([Values (true, false)] bool isRelease)
}
}
}
Directory.Delete (path, recursive: true);
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ sealed class LocalBuilder : Builder
public LocalBuilder ()
{
BuildingInsideVisualStudio = false;
Verbosity = LoggerVerbosity.Detailed;
}

public bool Build (string projectOrSolution, string target, string [] parameters = null, Dictionary<string, string> environmentVariables = null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using NUnit.Framework;
using System.IO;
using Xamarin.ProjectTools;
using Microsoft.Build.Framework;

namespace Xamarin.Android.Build.Tests
{
Expand All @@ -19,6 +20,7 @@ public void SelectivelyRunUpdateAndroidResources ()
app.SetProperty ("AndroidUseIntermediateDesignerFile", "True");

using (var appBuilder = CreateApkBuilder (Path.Combine (path, app.ProjectName))) {
appBuilder.Verbosity = LoggerVerbosity.Detailed;
Assert.IsTrue (appBuilder.DesignTimeBuild (app, parameters: new string[]{
"BuildingInsideVisualStudio=true",
"DeferredBuildSupported=true",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Xml.Linq;
using NUnit.Framework;
using Xamarin.ProjectTools;
using Microsoft.Build.Framework;

namespace Xamarin.Android.Build.Tests
{
Expand Down Expand Up @@ -214,6 +215,7 @@ public void GetExtraLibraryLocationsForDesigner ()
// Each NuGet package and AAR file are in libraryprojectimports.cache, AndroidJavaSource is not
const int libraryProjectImportsJars = 55;
using (var b = CreateApkBuilder (Path.Combine ("temp", TestName), false, false)) {
b.Verbosity = LoggerVerbosity.Detailed;
// GetExtraLibraryLocationsForDesigner on new project
Assert.IsTrue (b.RunTarget (proj, target, parameters: DesignerParameters), $"build should have succeeded for target `{target}` 1");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ public void AppProjectTargetsDoNotBreak ()
Path.Combine (output, $"{proj.ProjectName}.dll.config"),
};

foreach (string abi in b.GetBuildAbis ()) {
foreach (string abi in proj.GetRuntimeIdentifiersAsAbis ()) {
filesToTouch.Add (Path.Combine (intermediate, "android", "assets", abi, $"{proj.ProjectName}.dll"));
}

Expand Down Expand Up @@ -647,7 +647,7 @@ public void TransitiveDependencyProduceReferenceAssembly ()

var lib2Output = Path.Combine (path, lib2.ProjectName, "bin", "Debug", "netstandard2.0", $"{lib2.ProjectName}.dll");

foreach (string abi in appBuilder.GetBuildAbis ()) {
foreach (string abi in app.GetRuntimeIdentifiersAsAbis ()) {
var lib2InAppOutput = Path.Combine (path, app.ProjectName, app.IntermediateOutputPath, "android", "assets", abi, $"{lib2.ProjectName}.dll");
FileAssert.AreEqual (lib2Output, lib2InAppOutput, $"new Library2 should have been copied to app output directory for abi '{abi}'");
}
Expand All @@ -662,8 +662,7 @@ public void LinkAssembliesNoShrink ()
Assert.IsTrue (b.Build (proj), "build should have succeeded.");

// Touch an assembly to a timestamp older than build.props
foreach (string rid in b.GetBuildRuntimeIdentifiers ()) {
string abi = MonoAndroidHelper.RidToAbi (rid);
foreach (string abi in proj.GetRuntimeIdentifiersAsAbis ()) {
var formsViewGroup = b.Output.GetIntermediaryPath (Path.Combine ("android", "assets", abi, "FormsViewGroup.dll"));
File.SetLastWriteTimeUtc (formsViewGroup, new DateTime (1970, 1, 1));
}
Expand Down Expand Up @@ -751,6 +750,7 @@ public CustomTextView(Context context, IAttributeSet attributes) : base(context,

using (var libBuilder = CreateDllBuilder (Path.Combine (path, lib.ProjectName), false))
using (var appBuilder = CreateApkBuilder (Path.Combine (path, app.ProjectName))) {
appBuilder.Verbosity = LoggerVerbosity.Detailed;
libBuilder.BuildLogFile = "build.log";
Assert.IsTrue (libBuilder.Build (lib), "first library build should have succeeded.");
appBuilder.BuildLogFile = "build.log";
Expand Down Expand Up @@ -1176,6 +1176,7 @@ public void DesignTimeBuildSignAndroidPackage ()
proj.SetProperty ("AndroidUseDesignerAssembly", "true");
var builder = CreateApkBuilder ();
var parameters = new [] { "BuildingInsideVisualStudio=true"};
builder.Verbosity = LoggerVerbosity.Detailed;
builder.BuildLogFile = "update.log";
Assert.IsTrue (builder.RunTarget (proj, "Compile", parameters: parameters), $"{proj.ProjectName} should succeed");
builder.Output.AssertTargetIsNotSkipped ("_GenerateResourceCaseMap", occurrence: 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Xamarin.Tools.Zip;
using Xamarin.Android.Tasks;
using Xamarin.Android.Tools;
using Microsoft.Build.Framework;

namespace Xamarin.Android.Build.Tests
{
Expand Down Expand Up @@ -466,8 +467,7 @@ public void MissingSatelliteAssemblyInLibrary ()
var helper = new ArchiveAssemblyHelper (apk);

foreach (string lang in languages) {
foreach (string rid in appBuilder.GetBuildRuntimeIdentifiers ()) {
string abi = MonoAndroidHelper.RidToAbi (rid);
foreach (string abi in app.GetRuntimeIdentifiersAsAbis ()) {
Assert.IsTrue (helper.Exists ($"assemblies/{abi}/{lang}/{lib.ProjectName}.resources.dll"), $"Apk should contain satellite assembly for language '{lang}'!");
}
}
Expand Down Expand Up @@ -498,8 +498,7 @@ public void MissingSatelliteAssemblyInApp ()
var apk = Path.Combine (Root, b.ProjectDirectory,
proj.OutputPath, $"{proj.PackageName}-Signed.apk");
var helper = new ArchiveAssemblyHelper (apk);
foreach (string rid in b.GetBuildRuntimeIdentifiers ()) {
string abi = MonoAndroidHelper.RidToAbi (rid);
foreach (string abi in proj.GetRuntimeIdentifiersAsAbis ()) {
Assert.IsTrue (helper.Exists ($"assemblies/{abi}/es/{proj.ProjectName}.resources.dll"), "Apk should contain satellite assemblies!");
}
}
Expand Down Expand Up @@ -546,6 +545,7 @@ public class Test
Assert.IsTrue (zip.ContainsEntry ($"AndroidManifest.xml"), "Jar should contain AndroidManifest.xml");
}
using (var b = CreateApkBuilder (Path.Combine (path, app.ProjectName))) {
b.Verbosity = LoggerVerbosity.Detailed;
Assert.IsTrue (b.Build (app), "Build of jar should have succeeded.");
var jar = "2965D0C9A2D5DB1E.jar";
string expected = $"Ignoring jar entry AndroidManifest.xml from {jar}: the same file already exists in the apk";
Expand All @@ -563,6 +563,7 @@ public void CheckExcludedFilesAreMissing ()
};
proj.PackageReferences.Add (KnownPackages.Xamarin_Kotlin_StdLib_Common);
using (var b = CreateApkBuilder ()) {
b.Verbosity = LoggerVerbosity.Detailed;
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
var apk = Path.Combine (Root, b.ProjectDirectory,
proj.OutputPath, $"{proj.PackageName}-Signed.apk");
Expand All @@ -583,6 +584,7 @@ public void CheckExcludedFilesCanBeModified ()
};
proj.PackageReferences.Add (KnownPackages.Xamarin_Kotlin_StdLib_Common);
using (var b = CreateApkBuilder ()) {
b.Verbosity = LoggerVerbosity.Detailed;
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
var apk = Path.Combine (Root, b.ProjectDirectory,
proj.OutputPath, $"{proj.PackageName}-Signed.apk");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void AndroidManifestProperties (string versionName, string versionCode, s
$"{versionName}.0.0" :
$"{versionName.Substring (0, index)}.0.0";

foreach (string abi in b.GetBuildAbis ()) {
foreach (string abi in proj.GetRuntimeIdentifiersAsAbis ()) {
var assemblyPath = b.Output.GetIntermediaryPath ($"android/assets/{abi}/{proj.ProjectName}.dll");
FileAssert.Exists (assemblyPath);
using var assembly = AssemblyDefinition.ReadAssembly (assemblyPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public void ErrorIsNotRaised (string handler)
};
proj.SetProperty ("AndroidHttpClientHandlerType", handler);
using (var b = CreateApkBuilder (path)) {
b.Verbosity = LoggerVerbosity.Detailed;
b.Build (proj);
intermediatePath = Path.Combine (path,proj.IntermediateOutputPath);
targetSkipped = b.Output.IsTargetSkipped ("_CheckAndroidHttpClientHandlerType");
Expand Down
Loading

0 comments on commit b994441

Please sign in to comment.