-
Notifications
You must be signed in to change notification settings - Fork 1.7k
C#: Fix autobuild on macos without mono #19251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,15 +10,13 @@ internal static class MsBuildCommandExtensions | |
/// <summary> | ||
/// Appends a call to msbuild. | ||
/// </summary> | ||
/// <param name="cmdBuilder"></param> | ||
/// <param name="builder"></param> | ||
/// <returns></returns> | ||
public static CommandBuilder MsBuildCommand(this CommandBuilder cmdBuilder, IAutobuilder<AutobuildOptionsShared> builder) | ||
public static CommandBuilder MsBuildCommand(this CommandBuilder cmdBuilder, IAutobuilder<AutobuildOptionsShared> builder, bool preferDotnet) | ||
{ | ||
// mono doesn't ship with `msbuild` on Arm-based Macs, but we can fall back to | ||
// msbuild that ships with `dotnet` which can be invoked with `dotnet msbuild` | ||
// perhaps we should do this on all platforms? | ||
return builder.Actions.IsRunningOnAppleSilicon() | ||
return builder.Actions.IsRunningOnAppleSilicon() || preferDotnet | ||
? cmdBuilder.RunCommand("dotnet").Argument("msbuild") | ||
: cmdBuilder.RunCommand("msbuild"); | ||
} | ||
|
@@ -75,13 +73,21 @@ BuildScript GetNugetRestoreScript() => | |
QuoteArgument(projectOrSolution.FullPath). | ||
Argument("-DisableParallelProcessing"). | ||
Script; | ||
|
||
BuildScript GetMonoVersionScript() => new CommandBuilder(builder.Actions). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe rename to Would it be worth extending the Then it is possible to make an implementation like
which can be used in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you. I pushed a commit with your idea. |
||
RunCommand("mono"). | ||
Argument("--version"). | ||
Script; | ||
|
||
var preferDotnet = !builder.Actions.IsWindows() && GetMonoVersionScript().Run(builder.Actions, (_, _) => { }, (_, _, _) => { }) != 0; | ||
|
||
var nugetRestore = GetNugetRestoreScript(); | ||
var msbuildRestoreCommand = new CommandBuilder(builder.Actions). | ||
MsBuildCommand(builder). | ||
MsBuildCommand(builder, preferDotnet). | ||
Argument("/t:restore"). | ||
QuoteArgument(projectOrSolution.FullPath); | ||
|
||
if (builder.Actions.IsRunningOnAppleSilicon()) | ||
if (builder.Actions.IsRunningOnAppleSilicon() || preferDotnet) | ||
{ | ||
// On Apple Silicon, only try package restore with `dotnet msbuild /t:restore` | ||
ret &= BuildScript.Try(msbuildRestoreCommand.Script); | ||
|
@@ -119,7 +125,7 @@ BuildScript GetNugetRestoreScript() => | |
command.RunCommand("set Platform=&& type NUL", quoteExe: false); | ||
} | ||
|
||
command.MsBuildCommand(builder); | ||
command.MsBuildCommand(builder, preferDotnet); | ||
command.QuoteArgument(projectOrSolution.FullPath); | ||
|
||
var target = "rebuild"; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,2 @@ | ||
import pytest | ||
import runs_on | ||
|
||
|
||
# Skipping the test on macos-15, as we're running into trouble. | ||
@pytest.mark.only_if(not runs_on.macos_15) | ||
def test(codeql, csharp): | ||
codeql.database.create(_assert_failure=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit/Scope creep: There is a possible performance optimization, where we can avoid making multiple calls to
sysctl machdep.cpu.brand_string
.In
IBuildActions
we could declare a method that returns the value ofbuilder.Actions.IsRunningOnAppleSilicon() || !builder.Actions.IsWindows() && !builder.Actions.IsMonoInstalled();
and stores it in backing field for subsequent uses. (It is the same condition that is used on l. 19 and l. 85).Also perfectly fine, if you don't want to change it 😄