Skip to content

Commit 572ede5

Browse files
authored
[xaprepare] Replace msbuild with dotnet build (#6388)
As part of a broader effort to `dotnet build` all the things, replace all usage of `msbuild` in xaprepare with `dotnet build`. I've also attempted to simplify local and external prepare steps, as there seemed to be a lot of duplicated restore logic in the various `make` and `msbuild` invocations in those steps. These changes should hopefully solve or reduce the frequency of the Linux failures we've been seeing during various restore operations: stderr | The SSL connection could not be established, see inner exception. stderr | Authentication failed, see inner exception. stderr | Ssl error:1000007d:SSL routines:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED stderr | at /build/mono-6.12.0.147/external/boringssl/ssl/handshake_client.c:1132
1 parent 9897ede commit 572ede5

File tree

9 files changed

+63
-122
lines changed

9 files changed

+63
-122
lines changed

build-tools/automation/azure-pipelines.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,10 +423,6 @@ stages:
423423
workingDirectory: $(System.DefaultWorkingDirectory)/xamarin-android
424424
displayName: make prepare-external-git-dependencies
425425

426-
- script: make prepare PREPARE_CI=1 PREPARE_AUTOPROVISION=1 CONFIGURATION=$(XA.Build.Configuration)
427-
workingDirectory: $(System.DefaultWorkingDirectory)/xamarin-android
428-
displayName: make prepare
429-
430426
- script: make jenkins PREPARE_CI=1 PREPARE_AUTOPROVISION=1 CONFIGURATION=$(XA.Build.Configuration)
431427
workingDirectory: $(System.DefaultWorkingDirectory)/xamarin-android
432428
displayName: make jenkins

build-tools/xaprepare/xaprepare/Steps/Step_PrepareExternal.Unix.cs

Lines changed: 0 additions & 26 deletions
This file was deleted.

build-tools/xaprepare/xaprepare/Steps/Step_PrepareExternal.Windows.cs

Lines changed: 0 additions & 24 deletions
This file was deleted.

build-tools/xaprepare/xaprepare/Steps/Step_PrepareExternal.cs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,21 @@ protected override async Task<bool> Execute (Context context)
1515
var msbuild = new MSBuildRunner (context);
1616

1717
string slnPath = Path.Combine (Configurables.Paths.ExternalDir, "debugger-libs", "debugger-libs.sln");
18-
bool result = await msbuild.Run (
18+
bool result = await msbuild.Restore (
1919
projectPath: slnPath,
2020
logTag: "debugger-libs-restore",
21-
arguments: new List <string> {
22-
"/t:Restore"
23-
},
2421
binlogName: "prepare-debugger-libs-restore"
2522
);
2623

2724
if (!result)
2825
return false;
2926

30-
return await ExecuteOSSpecific (context);
27+
return await msbuild.Restore (
28+
projectPath: Path.Combine (Configurables.Paths.ExternalXamarinAndroidToolsSln),
29+
logTag: "xat-restore",
30+
binlogName: "prepare-xat-restore"
31+
);
3132
}
3233

33-
async Task<bool> NuGetRestore (NuGetRunner nuget, string solutionFilePath)
34-
{
35-
if (!await nuget.Restore (solutionFilePath)) {
36-
Log.ErrorLine ($"NuGet restore for solution {solutionFilePath} failed");
37-
return false;
38-
}
39-
40-
return true;
41-
}
4234
}
4335
}

build-tools/xaprepare/xaprepare/Steps/Step_PrepareExternalJavaInterop.Unix.cs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,18 @@ async Task<bool> ExecuteOSSpecific (Context context)
1616
var make = new MakeRunner (context) {
1717
NoParallelJobs = true
1818
};
19-
var result = await make.Run (
20-
logTag: "java-interop-prepare",
19+
return await make.Run (
20+
logTag: "java-interop-prepare-core",
2121
workingDirectory: javaInteropDir,
2222
arguments: new List <string> {
23-
"prepare",
23+
"prepare-core",
2424
$"CONFIGURATION={context.Configuration}",
2525
$"JI_JAVA_HOME={context.OS.JavaHome}",
2626
$"JAVA_HOME={context.OS.JavaHome}",
2727
$"JI_MAX_JDK={Configurables.Defaults.MaxJDKVersion}",
2828
$"DOTNET_TOOL_PATH={dotnetTool}"
2929
}
3030
);
31-
if (!result)
32-
return false;
33-
34-
Log.StatusLine ();
35-
result = await make.Run (
36-
logTag: "java-interop-props",
37-
workingDirectory: javaInteropDir,
38-
arguments: new List <string> {
39-
$"bin/Build{context.Configuration}/JdkInfo.props",
40-
$"CONFIGURATION={context.Configuration}",
41-
$"JI_MAX_JDK={Configurables.Defaults.MaxJDKVersion}",
42-
$"DOTNET_TOOL_PATH={dotnetTool}"
43-
}
44-
);
45-
return result;
4631
}
4732
}
4833
}

build-tools/xaprepare/xaprepare/Steps/Step_PrepareExternalJavaInterop.Windows.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,6 @@ partial class Step_PrepareExternalJavaInterop
99
#pragma warning disable CS1998
1010
async Task<bool> ExecuteOSSpecific (Context context)
1111
{
12-
string javaInteropDir = context.Properties.GetRequiredValue (KnownProperties.JavaInteropFullPath);
13-
string projectPath = Path.Combine (javaInteropDir, "build-tools", "Java.Interop.BootstrapTasks", "Java.Interop.BootstrapTasks.csproj");
14-
var msbuild = new MSBuildRunner (context);
15-
bool result = await msbuild.Run (
16-
projectPath: projectPath,
17-
logTag: "java-interop-prepare",
18-
binlogName: "build-java-interop-prepare"
19-
);
20-
21-
if (!result) {
22-
Log.ErrorLine ("Failed to build java-interop-prepare");
23-
return false;
24-
}
2512
return true;
2613
}
2714
#pragma warning restore CS1998

build-tools/xaprepare/xaprepare/Steps/Step_PrepareExternalJavaInterop.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,29 @@ public Step_PrepareExternalJavaInterop ()
1212

1313
protected override async Task<bool> Execute (Context context)
1414
{
15-
return await ExecuteOSSpecific (context);
15+
// make prepare-core on Unix
16+
var result = await ExecuteOSSpecific (context);
17+
if (!result)
18+
return false;
19+
20+
string javaInteropDir = context.Properties.GetRequiredValue (KnownProperties.JavaInteropFullPath);
21+
var dotnetPath = context.Properties.GetRequiredValue (KnownProperties.DotNetPreviewPath);
22+
var dotnetTool = Path.Combine (dotnetPath, "dotnet");
23+
var msbuild = new MSBuildRunner (context);
24+
25+
return await msbuild.Run (
26+
projectPath: Path.Combine (javaInteropDir, "Java.Interop.sln"),
27+
logTag: "java-interop-prepare",
28+
arguments: new List<string> {
29+
"-t:Prepare",
30+
$"-p:MaximumJdkVersion={Configurables.Defaults.MaxJDKVersion}",
31+
$"-p:MaxJdkVersion={Configurables.Defaults.MaxJDKVersion}",
32+
$"-p:JdksRoot={context.OS.JavaHome}",
33+
$"-p:DotnetToolPath={dotnetTool}"
34+
},
35+
binlogName: "java-interop-prepare",
36+
workingDirectory: javaInteropDir
37+
);
1638
}
1739
}
1840
}

build-tools/xaprepare/xaprepare/Steps/Step_PrepareLocal.cs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,22 @@ public Step_PrepareLocal ()
1010
: base ("Preparing local components")
1111
{}
1212

13-
async Task<bool> Restore (MSBuildRunner msbuild, string csprojPath, string logTag, string binLogName, string additionalArgument = null)
14-
{
15-
var args = new List<string> { "/t:Restore" };
16-
if (additionalArgument != null)
17-
args.Add (additionalArgument);
18-
19-
return await msbuild.Run (
20-
projectPath: csprojPath,
21-
logTag: logTag,
22-
arguments: args,
23-
binlogName: binLogName
24-
);
25-
}
2613

2714
protected override async Task<bool> Execute(Context context)
2815
{
2916
var msbuild = new MSBuildRunner (context);
30-
3117
string xfTestPath = Path.Combine (BuildPaths.XamarinAndroidSourceRoot, "tests", "Xamarin.Forms-Performance-Integration", "Xamarin.Forms.Performance.Integration.csproj");
32-
if (!await Restore (msbuild, xfTestPath, "xfperf", "prepare-restore"))
18+
19+
if (!await msbuild.Restore (projectPath: xfTestPath, logTag: "xfperf", binlogName: "prepare-local"))
3320
return false;
3421

35-
return await Restore (msbuild, xfTestPath, "xfperf", "prepare-restore", "/p:BundleAssemblies=true");
22+
// The Xamarin.Forms PackageReference version varies based on the value of $(BundleAssemblies)
23+
return await msbuild.Restore (
24+
projectPath: xfTestPath,
25+
logTag: "xfperfbundle",
26+
arguments: new List<string> { "-p:BundleAssemblies=true" },
27+
binlogName: "prepare-local-bundle"
28+
);
3629
}
3730
}
3831
}

build-tools/xaprepare/xaprepare/ToolRunners/MSBuildRunner.cs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ namespace Xamarin.Android.Prepare
77
{
88
partial class MSBuildRunner : ToolRunner
99
{
10-
protected override string DefaultToolExecutableName => "msbuild";
11-
protected override string ToolName => "MSBuild";
10+
protected override string DefaultToolExecutableName => "dotnet";
11+
protected override string ToolName => "dotnet";
1212

1313
public List<string> StandardArguments { get; }
1414

@@ -18,8 +18,8 @@ public MSBuildRunner (Context context, Log? log = null, string? msbuildPath = nu
1818
ProcessTimeout = TimeSpan.FromMinutes (30);
1919

2020
StandardArguments = new List<string> {
21-
$"/p:Configuration={context.Configuration}",
22-
"/restore",
21+
"build", // dotnet build includes implicit restore
22+
$"-p:Configuration={context.Configuration}",
2323
};
2424
}
2525

@@ -32,11 +32,12 @@ public async Task<bool> Run (string projectPath, string logTag, List<string>? ar
3232
workingDirectory = BuildPaths.XamarinAndroidSourceRoot;
3333

3434
ProcessRunner runner = CreateProcessRunner ();
35+
3536
AddArguments (runner, StandardArguments);
3637
if (!String.IsNullOrEmpty (binlogName)) {
3738
string logPath = Utilities.GetRelativePath (workingDirectory!, Path.Combine (Configurables.Paths.BuildBinDir, $"msbuild-{Context.BuildTimeStamp}-{binlogName}.binlog"));
38-
runner.AddArgument ("/v:normal");
39-
runner.AddQuotedArgument ($"/bl:{logPath}");
39+
runner.AddArgument ("-v:n");
40+
runner.AddQuotedArgument ($"-bl:{logPath}");
4041
}
4142
AddArguments (runner, arguments);
4243
runner.AddQuotedArgument (Utilities.GetRelativePath (workingDirectory!, projectPath));
@@ -60,6 +61,21 @@ public async Task<bool> Run (string projectPath, string logTag, List<string>? ar
6061
}
6162
}
6263

64+
public async Task<bool> Restore (string projectPath, string logTag, List<string>? arguments = null, string? binlogName = null, string? workingDirectory = null)
65+
{
66+
var args = new List<string> { "-t:Restore" };
67+
if (arguments != null)
68+
args.AddRange (arguments);
69+
70+
return await Run (
71+
projectPath: projectPath,
72+
logTag: logTag,
73+
arguments: args,
74+
binlogName: binlogName,
75+
workingDirectory: workingDirectory
76+
);
77+
}
78+
6379
protected override TextWriter CreateLogSink (string? logFilePath)
6480
{
6581
return new OutputSink (Log, logFilePath);

0 commit comments

Comments
 (0)