From e4a75a816af0847b8db7ecd516b2721ce4a119b9 Mon Sep 17 00:00:00 2001 From: Peter Collins Date: Tue, 3 Sep 2024 10:12:53 -0400 Subject: [PATCH] [build] Remove make framework-assemblies target (#9269) I'm often running `make leeroy` to test changes while building on macOS, and I noticed that an extra handful of Mono.Android.csproj builds were running each time. The `framework-assemblies` target that is declared in the generated `rules.mk` file includes some additional project builds that don't seem to be necessary in a .NET only world. The build has been updated to stop generating `rules.mk` entirely, and the make targets in `BuildEverything.mk` have been simplified. --- Makefile | 1 - build-tools/scripts/BuildEverything.mk | 17 +- .../xaprepare/Application/Context.cs | 13 -- .../Application/GeneratedMakeRulesFile.cs | 207 ------------------ .../Application/RuleGeneratorDelegate.cs | 6 - .../xaprepare/ConfigAndData/Configurables.cs | 17 -- .../Steps/Step_GenerateFiles.Unix.cs | 1 - 7 files changed, 2 insertions(+), 260 deletions(-) delete mode 100644 build-tools/xaprepare/xaprepare/Application/GeneratedMakeRulesFile.cs delete mode 100644 build-tools/xaprepare/xaprepare/Application/RuleGeneratorDelegate.cs diff --git a/Makefile b/Makefile index 9422b0b71..103e43b74 100644 --- a/Makefile +++ b/Makefile @@ -24,7 +24,6 @@ all: $(call DOTNET_BINLOG,all) $(MSBUILD_FLAGS) $(SOLUTION) $(call DOTNET_BINLOG,setup-workload) -t:ConfigureLocalWorkload build-tools/create-packs/Microsoft.Android.Sdk.proj --include bin/Build$(CONFIGURATION)/rules.mk ifeq ($(OS_NAME),) export OS_NAME := $(shell uname) diff --git a/build-tools/scripts/BuildEverything.mk b/build-tools/scripts/BuildEverything.mk index e1e5ae370..88de59cbc 100644 --- a/build-tools/scripts/BuildEverything.mk +++ b/build-tools/scripts/BuildEverything.mk @@ -1,16 +1,5 @@ .PHONY: leeroy jenkins leeroy-all -# -# framework-assemblies lives in bin/Build$(CONFIGURATION)/rules.mk generated by `make prepare` -# -# It has to be invoked with $(MAKE) because otherwise rules.mk would not be included and we'd -# get a build failure. -# -# The other targets depended upon by leeroy also require rules.mk to be present and thus they -# are invoked in the same way framework-assemblies is -# -# Local `make jenkins` invocations should build everything by default. We need to ensure `-a` is passed to xaprepare when no CI flags are set. -# jenkins: ifeq ($(PREPARE_CI_PR)$(PREPARE_CI),00) $(MAKE) PREPARE_ARGS=-a prepare @@ -23,8 +12,6 @@ ifneq ("$(wildcard $(topdir)/external/monodroid/Makefile)","") endif $(MAKE) leeroy -leeroy: leeroy-all framework-assemblies - -leeroy-all: - $(call DOTNET_BINLOG,leeroy-all) $(SOLUTION) $(_MSBUILD_ARGS) +leeroy: + $(call DOTNET_BINLOG,leeroy) $(SOLUTION) $(_MSBUILD_ARGS) $(call DOTNET_BINLOG,setup-workload) -t:ConfigureLocalWorkload build-tools/create-packs/Microsoft.Android.Sdk.proj diff --git a/build-tools/xaprepare/xaprepare/Application/Context.cs b/build-tools/xaprepare/xaprepare/Application/Context.cs index b922a3a79..80cda24ed 100644 --- a/build-tools/xaprepare/xaprepare/Application/Context.cs +++ b/build-tools/xaprepare/xaprepare/Application/Context.cs @@ -42,7 +42,6 @@ namespace Xamarin.Android.Prepare bool? useColor; bool? dullMode; Scenario? defaultScenario; - List? ruleGenerators; string? debugFileExtension; CompressionFormat? compressionFormat; Dictionary conditions = new Dictionary (); @@ -262,18 +261,6 @@ namespace Xamarin.Android.Prepare } } - /// - /// A collection of delegates which can add rules to the `rules.mk` file generated at the end of - /// bootstrapper's run - /// - public List RuleGenerators { - get { - if (ruleGenerators == null) - ruleGenerators = new List (); - return ruleGenerators; - } - } - /// /// Extensions of files with debug information /// diff --git a/build-tools/xaprepare/xaprepare/Application/GeneratedMakeRulesFile.cs b/build-tools/xaprepare/xaprepare/Application/GeneratedMakeRulesFile.cs deleted file mode 100644 index 86423fa83..000000000 --- a/build-tools/xaprepare/xaprepare/Application/GeneratedMakeRulesFile.cs +++ /dev/null @@ -1,207 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; - -namespace Xamarin.Android.Prepare -{ - partial class GeneratedMakeRulesFile : GeneratedFile - { - public GeneratedMakeRulesFile (string outputPath) - : base (outputPath) - {} - - public override void Generate (Context context) - { - Log.Todo ("Generate some help for `make help`"); - - if (context == null) - throw new ArgumentNullException (nameof (context)); - - using (StreamWriter sw = Utilities.OpenStreamWriter (OutputPath)) { - Generate (context, sw); - sw.Flush (); - } - } - - string GetOutputFileName (Context context, string namePrefix) - { - return $"{namePrefix}-v{BuildInfo.XAVersion}.$(-num-commits-since-version-change)_{context.OS.Type}-{context.OS.Architecture}_$(GIT_BRANCH)_$(GIT_COMMIT)-$(CONFIGURATION)"; - } - - void Generate (Context context, StreamWriter sw) - { - string myPath = Path.Combine (BuildPaths.XAPrepareSourceDir, "Application", "GeneratedMakeRulesFile.cs"); - sw.WriteLine ( "#"); - sw.WriteLine ($"# Generated by {myPath}"); - sw.WriteLine ( "#"); - sw.WriteLine (); - - WriteVariable ("export OS_NAME", context.OS.Type); - WriteVariable ("export OS_ARCH", context.OS.Architecture); - WriteVariable ("export OS_ARCH_TRANSLATED", context.OS.ProcessIsTranslated ? "true" : "false"); - WriteVariable ("PRODUCT_VERSION", context.ProductVersion); - - // These must remain dynamic since the developer may change branches without re-running `prepare` - string getGitBranchScript = Utilities.GetRelativePath (BuildPaths.XamarinAndroidSourceRoot, Path.Combine (Configurables.Paths.BuildToolsScriptsDir, "get-git-branch.sh")); - WriteVariable ("GIT_BRANCH", $"$(shell LANG=C \"{getGitBranchScript}\" | tr -d '[[:space:]]' | tr -C a-zA-Z0-9- _)"); - WriteVariable ("GIT_COMMIT", $"$(shell LANG=C git log --no-color --first-parent -n1 --pretty=format:%h)"); - WriteVariable ("-num-commits-since-version-change", $"$(shell LANG=C git log {context.BuildInfo.CommitOfLastVersionChange}..HEAD --oneline 2>/dev/null | wc -l | sed 's/ //g')"); - - WriteVariable ("ZIP_EXTENSION", context.OS.ZipExtension); - WriteVariable ("ZIP_OUTPUT_BASENAME", GetOutputFileName (context, "xamarin.android-oss")); - WriteVariable ("ZIP_OUTPUT", "$(ZIP_OUTPUT_BASENAME).$(ZIP_EXTENSION)"); - - var allApiLevels = new List (); - var allPlatformIDs = new List (); - var allFrameworks = new List (); - var apiLevels = new List (); - var stableApiLevels = new List (); - var frameworks = new List (); - var stableFrameworks = new List (); - var platformIds = new List (); - - foreach (AndroidPlatform ap in BuildAndroidPlatforms.AllPlatforms) { - string api = ap.ApiLevel.ToString (); - - allApiLevels.Add (api); - allPlatformIDs.Add (ap.PlatformID); - if (!String.IsNullOrEmpty (ap.Framework)) { - allFrameworks.Add (ap.Framework); - frameworks.Add (ap.Framework); - if (ap.Stable) - stableFrameworks.Add (ap.Framework); - } else - allFrameworks.Add ("-"); - - if (!ap.Supported) - continue; - - apiLevels.Add (api); - platformIds.Add (ap.PlatformID); - if (ap.Stable) - stableApiLevels.Add (api); - } - - WriteVariable ("ALL_API_LEVELS", ToValue (allApiLevels)); - WriteVariable ("ALL_PLATFORM_IDS", ToValue (allPlatformIDs)); - WriteVariable ("ALL_FRAMEWORKS", ToValue (allFrameworks)); - WriteVariable ("API_LEVELS", ToValue (apiLevels)); - WriteVariable ("STABLE_API_LEVELS", ToValue (stableApiLevels)); - WriteVariable ("FRAMEWORKS", ToValue (frameworks)); - WriteVariable ("STABLE_FRAMEWORKS", ToValue (stableFrameworks)); - WriteVariable ("ANDROID_TOOLCHAIN_DIR", context.Properties.GetRequiredValue (KnownProperties.AndroidToolchainDirectory)); - if (context.MonoOptions != null && context.MonoOptions.Count > 0) { - WriteVariable ("MONO_OPTIONS", ToValue (context.MonoOptions)); - sw.WriteLine ("export MONO_OPTIONS"); - } - - sw.WriteLine ("_MSBUILD_ARGS = \\"); - sw.WriteLine ($"\t/p:{KnownProperties.AndroidSupportedTargetJitAbis}={context.Properties.GetRequiredValue (KnownProperties.AndroidSupportedTargetJitAbis)} \\"); - sw.WriteLine ($"\t/p:{KnownProperties.AndroidSupportedTargetAotAbis}={context.Properties.GetRequiredValue (KnownProperties.AndroidSupportedTargetAotAbis)}"); - - OutputOSVariables (context, sw); - - WriteListVariable ("_BUNDLE_ZIPS_INCLUDE", Configurables.Defaults.BundleZipsInclude); - WriteListVariable ("_BUNDLE_ZIPS_EXCLUDE", Configurables.Defaults.BundleZipsExclude); - - sw.WriteLine (); - sw.WriteLine (".PHONY: framework-assemblies"); - sw.WriteLine ("framework-assemblies:"); - - string prevVersion = "v1.0"; - string monoFrameworksRoot = Path.Combine ("bin", "$(CONFIGURATION)", context.Properties.GetRequiredValue (KnownProperties.XABinRelativeInstallPrefix), Configurables.Paths.MonoAndroidFrameworksSubDir); - for (int i = 0; i < apiLevels.Count; i++) { - string curVersion = frameworks [i]; - string apiLevel = apiLevels [i]; - string platformId = platformIds [i]; - string redistFile = Path.Combine (monoFrameworksRoot, curVersion, "RedistList", "FrameworkList.xml"); - WriteRuleLine ($"grep -q {prevVersion} {redistFile}; \\"); - WriteRuleLine ( "if [ $$? -ne 0 ] ; then \\"); - WriteRuleLine ($"\trm -f {redistFile}; \\"); - WriteRuleLine ( "fi; \\"); - WriteRuleLine ( "$(call DOTNET_BINLOG,Mono.Android) src/Mono.Android/Mono.Android.csproj \\"); - WriteRuleLine ( "\t$(_MSBUILD_ARGS) \\"); - WriteRuleLine ($"\t/p:AndroidApiLevel={apiLevel} /p:AndroidPlatformId={platformId} /p:AndroidFrameworkVersion={curVersion} \\"); - WriteRuleLine ($"\t/p:AndroidPreviousFrameworkVersion={prevVersion} || exit 1;"); - - prevVersion = curVersion; - } - - string firstApiLevel = apiLevels [0]; - string firstPlatformId = platformIds [0]; - string firstFramework = frameworks [0]; - string latestStableFramework = stableFrameworks [stableFrameworks.Count - 1]; - - WriteMSBuildCall ( - fileToRemovePath: $"{monoFrameworksRoot}/{latestStableFramework}/Mono.Android.Export.*", - projectPath: "src/Mono.Android.Export/Mono.Android.Export.csproj" - ); - sw.WriteLine (); - - if (context.RuleGenerators == null || context.RuleGenerators.Count == 0) - return; - - foreach (RuleGenerator rg in context.RuleGenerators) { - if (rg == null) - continue; - rg (this, sw); - } - - void WriteMSBuildCall (string fileToRemovePath, string projectPath) - { - WriteRuleLine ($"rm -f {fileToRemovePath}"); - WriteRuleLine ($"$(call DOTNET_BINLOG,NUnitLite) $(MSBUILD_FLAGS) {projectPath} \\"); - WriteRuleLine ( "\t$(_MSBUILD_ARGS) \\"); - WriteRuleLine ($"\t/p:AndroidApiLevel={firstApiLevel} /p:AndroidPlatformId={firstPlatformId} \\"); - WriteRuleLine ($"\t/p:AndroidFrameworkVersion={firstFramework} || exit 1;"); - } - - string ToValue (ICollection list, string? separator = null) - { - return String.Join (separator ?? " ", list); - } - - void WriteRuleLine (string line) - { - sw.Write ('\t'); - sw.WriteLine (line); - } - - void WriteVariable (string name, string value) - { - sw.WriteLine ($"{name} = {value}"); - } - - void WriteListVariable (string name, ICollection list, bool conditional = false) - { - if (list.Count == 0) - return; - - if (!conditional) - sw.Write ($"{name} ="); - - foreach (string i in list) { - string item = i.Trim (); - if (String.IsNullOrEmpty (item)) - continue; - - if (conditional) { - sw.WriteLine ($"ifneq ($(wildcard {item}),)"); - sw.WriteLine ($"{name} += {item}"); - sw.WriteLine ("endif"); - continue; - } - - sw.WriteLine (" \\"); - sw.Write ($"\t{item}"); - } - - if (!conditional) - sw.WriteLine (); - } - } - - partial void OutputOSVariables (Context context, StreamWriter sw); - } -} diff --git a/build-tools/xaprepare/xaprepare/Application/RuleGeneratorDelegate.cs b/build-tools/xaprepare/xaprepare/Application/RuleGeneratorDelegate.cs deleted file mode 100644 index 5db042e39..000000000 --- a/build-tools/xaprepare/xaprepare/Application/RuleGeneratorDelegate.cs +++ /dev/null @@ -1,6 +0,0 @@ -using System.IO; - -namespace Xamarin.Android.Prepare -{ - delegate void RuleGenerator (GeneratedMakeRulesFile file, StreamWriter rulesWriter); -} diff --git a/build-tools/xaprepare/xaprepare/ConfigAndData/Configurables.cs b/build-tools/xaprepare/xaprepare/ConfigAndData/Configurables.cs index e827f32e3..25228c589 100644 --- a/build-tools/xaprepare/xaprepare/ConfigAndData/Configurables.cs +++ b/build-tools/xaprepare/xaprepare/ConfigAndData/Configurables.cs @@ -146,23 +146,6 @@ namespace Xamarin.Android.Prepare { "x86_64", "x86_64-linux-android" }, }; - /// - /// Used in rules.mk generator. Files to include in the XA bundle archives. - /// - public static readonly List BundleZipsInclude = new List { - "$(ZIP_OUTPUT_BASENAME)/THIRD-PARTY-NOTICES.TXT", - "$(ZIP_OUTPUT_BASENAME)/bin/Debug", - "$(ZIP_OUTPUT_BASENAME)/bin/Release", - }; - - /// - /// Used in rules.mk generator. Files to exclude from the XA bundle archives. Must be syntactically - /// correct for GNU Make. - /// - public static readonly List BundleZipsExclude = new List { - "$(ZIP_OUTPUT_BASENAME)/bin/*/bundle-*.zip" - }; - public static readonly List NDKTools = new List { // Tools prefixed with architecture triple new NDKTool (name: "as", prefixed: true), diff --git a/build-tools/xaprepare/xaprepare/Steps/Step_GenerateFiles.Unix.cs b/build-tools/xaprepare/xaprepare/Steps/Step_GenerateFiles.Unix.cs index 6f02c3616..4389ac9e0 100644 --- a/build-tools/xaprepare/xaprepare/Steps/Step_GenerateFiles.Unix.cs +++ b/build-tools/xaprepare/xaprepare/Steps/Step_GenerateFiles.Unix.cs @@ -27,7 +27,6 @@ namespace Xamarin.Android.Prepare partial void AddUnixPostBuildSteps (Context context, List steps) { - steps.Add (new GeneratedMakeRulesFile (Path.Combine (Configurables.Paths.BuildBinDir, "rules.mk"))); steps.Add (new GeneratedConfigurationFile (Path.Combine (Configurables.Paths.BinDirRoot, "configuration.mk"))); } }