Skip to content

Commit

Permalink
[build] Add option to skip Mono MDK provisioning (#8993)
Browse files Browse the repository at this point in the history
The mono related CLI parameters for xaprepare have been updated to make
it possible to skip installation of the Mono MDK via the following:

    make prepare-update-mono PREPARE_AUTOPROVISION=1 PREPARE_AUTOPROVISION_SKIP_MONO=1
    make prepare PREPARE_AUTOPROVISION=1 PREPARE_AUTOPROVISION_SKIP_MONO=1

Unused `ignore-*-mono-version=` parameters have been removed and
replaced with their default values.

Build warnings in the project have also been fixed on macOS.
  • Loading branch information
pjcollins committed Jun 4, 2024
1 parent f5fcd4d commit dbc72c8
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 26 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ PREPARE_SCENARIO =
PREPARE_CI_PR ?= 0
PREPARE_CI ?= 0
PREPARE_AUTOPROVISION ?= 0
PREPARE_IGNORE_MONO_VERSION ?= 1
PREPARE_AUTOPROVISION_SKIP_MONO ?= 0

_PREPARE_CI_MODE_PR_ARGS = --no-emoji --run-mode=CI
_PREPARE_CI_MODE_ARGS = $(_PREPARE_CI_MODE_PR_ARGS) -a
Expand Down Expand Up @@ -59,6 +59,10 @@ ifneq ($(PREPARE_AUTOPROVISION),0)
_PREPARE_ARGS += --auto-provision=yes --auto-provision-uses-sudo=yes
endif

ifneq ($(PREPARE_AUTOPROVISION_SKIP_MONO),0)
_PREPARE_ARGS += --auto-provision-skip-mono=yes
endif

ifneq ($(PREPARE_SCENARIO),)
_PREPARE_ARGS += -s:"$(PREPARE_SCENARIO)"
endif
Expand Down
5 changes: 3 additions & 2 deletions build-tools/xaprepare/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ You can append the following parameters to the command line:
If set to `0` (the default), the utility will take notice of missing/outdated software the build depends on and exit with an error
should any such condition is detected. Setting the property to `1` will let the utility install the software (installation **may**
use `sudo` on Unix so you will need administrator/root credentials for it to work)
- `PREPARE_IGNORE_MONO_VERSION=0|1`
If set to `1` (the default), the utility will not enforce Mono version but rather will use any Mono version you have installed.
- `PREPARE_AUTOPROVISION_SKIP_MONO=0|1`
If set to `0` (the default), the utility will ensure the Mono MDK is installed.
Setting the property to `1` will allow you to skip Mono MDK installation.
- `V=1`
Causes the run to output much more information (making output much more messy in the process) to the console. Normally this additional
information is placed only in the log files generated by the utility.
Expand Down
9 changes: 2 additions & 7 deletions build-tools/xaprepare/xaprepare/Application/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,9 @@ partial class Context : AppObject
public bool AutoProvisionUsesSudo { get; set; }

/// <summary>
/// Do not terminate session when Mono is newer than specified in the dependencies
/// Skip automatic provision of the Mono MDK if missing
/// </summary>
public bool IgnoreMaxMonoVersion { get; set; } = true;

/// <summary>
/// Do not terminate session when Mono is older than specified in the dependencies
/// </summary>
public bool IgnoreMinMonoVersion { get; set; } = false;
public bool AutoProvisionSkipMono { get; set; } = false;

/// <summary>
/// Current session execution mode. See <see cref="t:ExecutionMode" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public override async Task<bool> Install ()

protected override bool CheckWhetherInstalled ()
{
IgnoreMaximumVersion = Context.Instance.IgnoreMaxMonoVersion;
IgnoreMinimumVersion = Context.Instance.IgnoreMinMonoVersion;
IgnoreMaximumVersion = true;
IgnoreMinimumVersion = false;
return base.CheckWhetherInstalled ();
}

Expand All @@ -55,13 +55,15 @@ protected override async Task<bool> DetermineCurrentVersion ()
return await base.DetermineCurrentVersion ();
}

#pragma warning disable 1998
protected override async Task AfterDetect (bool installed)
{
if (!installed)
return;

AddToInventory ();
}
#pragma warning restore 1998

public void AddToInventory ()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ partial class MacOS
new HomebrewProgram ("make"),
new HomebrewProgram ("ninja"),
new HomebrewProgram ("p7zip", "7za"),

new MonoPkgProgram ("Mono", "com.xamarin.mono-MDK.pkg", new Uri (Context.Instance.Properties.GetRequiredValue (KnownProperties.MonoDarwinPackageUrl))) {
MinimumVersion = Context.Instance.Properties.GetRequiredValue (KnownProperties.MonoRequiredMinimumVersion),
MaximumVersion = Context.Instance.Properties.GetRequiredValue (KnownProperties.MonoRequiredMaximumVersion),
},
};

static readonly HomebrewProgram git = new HomebrewProgram ("git") {
Expand All @@ -28,10 +23,19 @@ protected override void InitializeDependencies ()
{
Dependencies.AddRange (programs);

if (!Context.Instance.AutoProvisionSkipMono) {
Dependencies.Add (
new MonoPkgProgram ("Mono", "com.xamarin.mono-MDK.pkg", new Uri (Context.Instance.Properties.GetRequiredValue (KnownProperties.MonoDarwinPackageUrl))) {
MinimumVersion = Context.Instance.Properties.GetRequiredValue (KnownProperties.MonoRequiredMinimumVersion),
MaximumVersion = Context.Instance.Properties.GetRequiredValue (KnownProperties.MonoRequiredMaximumVersion),
}
);
}

// Allow using git from $PATH if it has the right version
(bool success, string bv) = Utilities.GetProgramVersion (git.Name);
if (success && Version.TryParse (bv, out Version gitVersion) &&
Version.TryParse (git.MinimumVersion, out Version gitMinVersion)) {
if (success && Version.TryParse (bv, out Version? gitVersion) &&
Version.TryParse (git.MinimumVersion, out Version? gitMinVersion)) {
if (gitVersion < gitMinVersion)
Dependencies.Add (git);

Expand Down
10 changes: 3 additions & 7 deletions build-tools/xaprepare/xaprepare/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ sealed class ParsedOptions
public string? Configuration { get; set; }
public bool AutoProvision { get; set; }
public bool AutoProvisionUsesSudo { get; set; }
public bool IgnoreMaxMonoVersion { get; set; }
public bool IgnoreMinMonoVersion { get; set; }
public bool AutoProvisionSkipMono { get; set; }
public RefreshableComponent RefreshList { get; set; }
public IEnumerable<string> AndroidSdkPlatforms { get; set; } = new [] { "latest" };
}
Expand Down Expand Up @@ -80,7 +79,6 @@ static async Task<int> Run (string[] args)
ParsedOptions parsedOptions = new ParsedOptions {
AutoProvision = ParseBoolean (Context.Instance.Properties.GetValue (KnownProperties.AutoProvision)),
AutoProvisionUsesSudo = ParseBoolean (Context.Instance.Properties.GetValue (KnownProperties.AutoProvisionUsesSudo)),
IgnoreMaxMonoVersion = ParseBoolean (Context.Instance.Properties.GetValue (KnownProperties.IgnoreMaxMonoVersion)),
};

var opts = new OptionSet {
Expand All @@ -103,8 +101,7 @@ static async Task<int> Run (string[] args)
"",
{"auto-provision=", $"Automatically install software required by .NET for Android", v => parsedOptions.AutoProvision = ParseBoolean (v)},
{"auto-provision-uses-sudo=", $"Allow use of sudo(1) when provisioning", v => parsedOptions.AutoProvisionUsesSudo = ParseBoolean (v)},
{"ignore-max-mono-version=", $"Ignore the maximum supported Mono version restriction", v => parsedOptions.IgnoreMaxMonoVersion = ParseBoolean (v)},
{"ignore-min-mono-version=", $"Ignore the minimum supported Mono version restriction", v => parsedOptions.IgnoreMinMonoVersion = ParseBoolean (v)},
{"auto-provision-skip-mono=", $"Do not automatically install the Mono MDK", v => parsedOptions.AutoProvisionSkipMono = ParseBoolean (v)},
{"android-sdk-platforms=", "Comma separated list of Android SDK platform levels to be installed or 'latest' or 'all'. Defaults to 'latest' if no value is provided.", v => parsedOptions.AndroidSdkPlatforms = ParseAndroidSdkPlatformLevels (v?.Trim () ?? String.Empty) },
"",
{"h|help", "Show this help message", v => parsedOptions.ShowHelp = true },
Expand Down Expand Up @@ -135,8 +132,7 @@ static async Task<int> Run (string[] args)
Context.Instance.DebugFileExtension = parsedOptions.DebugFileExtension;
Context.Instance.AutoProvision = parsedOptions.AutoProvision;
Context.Instance.AutoProvisionUsesSudo = parsedOptions.AutoProvisionUsesSudo;
Context.Instance.IgnoreMaxMonoVersion = parsedOptions.IgnoreMaxMonoVersion;
Context.Instance.IgnoreMinMonoVersion = parsedOptions.IgnoreMinMonoVersion;
Context.Instance.AutoProvisionSkipMono = parsedOptions.AutoProvisionSkipMono;
Context.Instance.ComponentsToRefresh = parsedOptions.RefreshList;
Context.Instance.AndroidSdkPlatforms = parsedOptions.AndroidSdkPlatforms;

Expand Down

0 comments on commit dbc72c8

Please sign in to comment.