|
1 | 1 | using Semmle.Util.Logging; |
| 2 | +using System; |
2 | 3 | using System.Linq; |
| 4 | +using System.Runtime.InteropServices; |
3 | 5 |
|
4 | 6 | namespace Semmle.Autobuild.Shared |
5 | 7 | { |
| 8 | + internal static class MsBuildCommandExtensions |
| 9 | + { |
| 10 | + /// <summary> |
| 11 | + /// Appends a call to msbuild. |
| 12 | + /// </summary> |
| 13 | + /// <param name="cmdBuilder"></param> |
| 14 | + /// <param name="builder"></param> |
| 15 | + /// <returns></returns> |
| 16 | + public static CommandBuilder MsBuildCommand(this CommandBuilder cmdBuilder, IAutobuilder<AutobuildOptionsShared> builder) |
| 17 | + { |
| 18 | + var isArmMac = builder.Actions.IsMacOs() && builder.Actions.IsArm(); |
| 19 | + |
| 20 | + // mono doesn't ship with `msbuild` on Arm-based Macs, but we can fall back to |
| 21 | + // msbuild that ships with `dotnet` which can be invoked with `dotnet msbuild` |
| 22 | + // perhaps we should do this on all platforms? |
| 23 | + return isArmMac ? |
| 24 | + cmdBuilder.RunCommand("dotnet").Argument("msbuild") : |
| 25 | + cmdBuilder.RunCommand("msbuild"); |
| 26 | + } |
| 27 | + } |
| 28 | + |
6 | 29 | /// <summary> |
7 | 30 | /// A build rule using msbuild. |
8 | 31 | /// </summary> |
9 | 32 | public class MsBuildRule : IBuildRule<AutobuildOptionsShared> |
10 | 33 | { |
11 | | - /// <summary> |
12 | | - /// The name of the msbuild command. |
13 | | - /// </summary> |
14 | | - private const string msBuild = "msbuild"; |
15 | | - |
16 | 34 | public BuildScript Analyse(IAutobuilder<AutobuildOptionsShared> builder, bool auto) |
17 | 35 | { |
18 | 36 | if (!builder.ProjectsOrSolutionsToBuild.Any()) |
@@ -57,7 +75,7 @@ BuildScript GetNugetRestoreScript() => |
57 | 75 | Script; |
58 | 76 | var nugetRestore = GetNugetRestoreScript(); |
59 | 77 | var msbuildRestoreCommand = new CommandBuilder(builder.Actions). |
60 | | - RunCommand(msBuild). |
| 78 | + MsBuildCommand(builder). |
61 | 79 | Argument("/t:restore"). |
62 | 80 | QuoteArgument(projectOrSolution.FullPath); |
63 | 81 |
|
@@ -95,7 +113,7 @@ BuildScript GetNugetRestoreScript() => |
95 | 113 | command.RunCommand("set Platform=&& type NUL", quoteExe: false); |
96 | 114 | } |
97 | 115 |
|
98 | | - command.RunCommand(msBuild); |
| 116 | + command.MsBuildCommand(builder); |
99 | 117 | command.QuoteArgument(projectOrSolution.FullPath); |
100 | 118 |
|
101 | 119 | var target = builder.Options.MsBuildTarget ?? "rebuild"; |
|
0 commit comments