Skip to content

Commit b366ac1

Browse files
authored
[xaprepare] Do less when updating Mono (#4342)
When updating Mono from an older version (e.g. 6.6) `xaprepare` can crash as soon as the Mono package is installed with exceptions similar to the ones below: System.InvalidOperationException: Failed to obtain version information from the cc compiler at Xamarin.Android.Prepare.Unix.DetectCompilers () [0x00344] in build-tools/xaprepare/xaprepare/OperatingSystems/Unix.cs:102 at Xamarin.Android.Prepare.OS.ConfigureEnvironment () [0x00096] in build-tools/xaprepare/xaprepare/OperatingSystems/OS.cs:371 at Xamarin.Android.Prepare.OS.Init () [0x000e6] in build-tools/xaprepare/xaprepare/OperatingSystems/OS.cs:254 at Xamarin.Android.Prepare.Context.Init (System.String scenarioName) [0x0026c] in build-tools/xaprepare/xaprepare/Application/Context.cs:761 at Xamarin.Android.Prepare.App.Run (System.String[] args) [0x0078a] in build-tools/xaprepare/xaprepare/Main.cs:153 System.InvalidOperationException: Unable to determine the last version change commit at Xamarin.Android.Prepare.BuildInfo.DetermineLastVersionChangeCommit (Xamarin.Android.Prepare.Context context) [0x000fa] in build-tools/xaprepare/xaprepare/Application/BuildInfo.cs:130 at Xamarin.Android.Prepare.BuildInfo.GatherGitInfo (Xamarin.Android.Prepare.Context context) [0x0006d] in build-tools/xaprepare/xaprepare/Application/BuildInfo.cs:36 at Xamarin.Android.Prepare.Context.Init (System.String scenarioName) [0x00430] in build-tools/xaprepare/xaprepare/Application/Context.cs:780 at Xamarin.Android.Prepare.App.Run (System.String[] args) [0x0078a] in build-tools/xaprepare/xaprepare/Main.cs:153 This is most probably caused by the new Mono changing assemblies and shared libraries underneath the older Mono which is currently executing `xaprepare`. In order to avoid the crash, do as little as possible to update Mono and quit as quickly as possible.
1 parent c9e5f58 commit b366ac1

File tree

8 files changed

+33
-12
lines changed

8 files changed

+33
-12
lines changed

build-tools/xaprepare/xaprepare/Application/Context.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -765,16 +765,21 @@ public async Task<bool> Init (string scenarioName = null)
765765

766766
Tools.Init (this);
767767

768-
Banner ("Updating Git submodules");
768+
if (SelectedScenario.NeedsGitSubmodules) {
769+
Banner ("Updating Git submodules");
769770

770-
var git = new GitRunner (this);
771-
if (!await git.SubmoduleUpdate ()) {
772-
Log.ErrorLine ("Failed to update Git submodules");
773-
return false;
771+
var git = new GitRunner (this);
772+
if (!await git.SubmoduleUpdate ()) {
773+
Log.ErrorLine ("Failed to update Git submodules");
774+
return false;
775+
}
774776
}
775777

776778
BuildInfo = new BuildInfo ();
777-
await BuildInfo.GatherGitInfo (this);
779+
if (SelectedScenario.NeedsGitBuildInfo) {
780+
await BuildInfo.GatherGitInfo (this);
781+
}
782+
778783
AbiNames.LogAllNames (this);
779784

780785
if (MakeConcurrency == 0)

build-tools/xaprepare/xaprepare/Application/Scenario.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ abstract partial class Scenario : AppObject
1010
public string Description { get; }
1111
public string LogFilePath { get; protected set; }
1212
public List<Step> Steps { get; } = new List<Step> ();
13+
public bool NeedsGitSubmodules { get; protected set; }
14+
public bool NeedsGitBuildInfo { get; protected set; }
15+
public bool NeedsCompilers { get; protected set; }
1316

1417
protected Scenario (string name, string description, Context context)
1518
{

build-tools/xaprepare/xaprepare/OperatingSystems/OS.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,8 @@ void ConfigureEnvironment ()
368368
Environment.SetEnvironmentVariable (name, value);
369369
}
370370

371-
DetectCompilers ();
371+
if (Context.SelectedScenario.NeedsCompilers)
372+
DetectCompilers ();
372373
}
373374

374375
/// <summary>

build-tools/xaprepare/xaprepare/Scenarios/Scenario_PrepareExternal.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ partial class Scenario_PrepareExternal : ScenarioNoStandardEndSteps
77
{
88
public Scenario_PrepareExternal ()
99
: base ("PrepareExternal", "Prepare external submodules", Context.Instance)
10-
{}
10+
{
11+
NeedsGitSubmodules = true;
12+
}
1113

1214
protected override void AddSteps (Context context)
1315
{

build-tools/xaprepare/xaprepare/Scenarios/Scenario_Required.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ namespace Xamarin.Android.Prepare
77
class Scenario_Required : Scenario
88
{
99
public Scenario_Required () : base ("Required", "Just the basic steps to quickly install required tools and generate build files.", Context.Instance)
10-
{}
10+
{
11+
NeedsGitSubmodules = true;
12+
NeedsCompilers = true;
13+
NeedsGitBuildInfo = true;
14+
}
1115

1216
protected override void AddSteps (Context context)
1317
{

build-tools/xaprepare/xaprepare/Scenarios/Scenario_Standard.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ partial class Scenario_Standard : Scenario
77
{
88
public Scenario_Standard ()
99
: base ("Standard", "Standard init", Context.Instance)
10-
{}
10+
{
11+
NeedsGitSubmodules = true;
12+
NeedsCompilers = true;
13+
NeedsGitBuildInfo = true;
14+
}
1115

1216
protected override void AddSteps (Context context)
1317
{

build-tools/xaprepare/xaprepare/Scenarios/Scenario_ThirdPartyNotices.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ class Scenario_ThirdPartyNotices : Scenario
88
{
99
public Scenario_ThirdPartyNotices ()
1010
: base ("ThirdPartyNotices", "Generate the `ThirdPartyNotices.txt` files.", Context.Instance)
11-
{}
11+
{
12+
NeedsGitSubmodules = true;
13+
}
1214

1315
protected override void AddSteps (Context context)
1416
{

build-tools/xaprepare/xaprepare/Scenarios/Scenario_UpdateMono.Unix.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ protected override void AddSteps (Context context)
2626
// ...and disable installation of other programs...
2727
context.SetCondition (KnownConditions.AllowProgramInstallation, false);
2828

29-
// ...but do not signal an error when any are missing
29+
// ...but do not signal an error when any are missing...
3030
context.SetCondition (KnownConditions.IgnoreMissingPrograms, true);
3131
}
3232
}

0 commit comments

Comments
 (0)