Skip to content

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

Merged
merged 4 commits into from
Apr 15, 2025
Merged

Conversation

tamasvajk
Copy link
Contributor

@tamasvajk tamasvajk commented Apr 8, 2025

This pull request includes several changes to improve the handling of the autobuild process, particularly for different operating systems and scenarios where mono is or isn't available. The main changes involve updating the process execution logic and adding new test cases for better coverage.

@github-actions github-actions bot added the C# label Apr 8, 2025
@tamasvajk tamasvajk changed the title Fix autobuild on macos 15 C#: Fix autobuild on macos 15 Apr 8, 2025
@tamasvajk tamasvajk force-pushed the fix/macos15 branch 4 times, most recently from 40776c2 to 68da44e Compare April 11, 2025 12:44
@tamasvajk tamasvajk changed the title C#: Fix autobuild on macos 15 C#: Fix autobuild on macos without mono Apr 11, 2025
@tamasvajk tamasvajk marked this pull request as ready for review April 14, 2025 08:18
@Copilot Copilot bot review requested due to automatic review settings April 14, 2025 08:18
@tamasvajk tamasvajk requested a review from a team as a code owner April 14, 2025 08:18
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves the autobuild process for C# by addressing issues with msbuild execution on macOS without mono and by enhancing test coverage for different operating system scenarios.

  • Updated the MsBuildCommand method to conditionally use dotnet msbuild based on a new parameter and operating system checks.
  • Removed the previously skipped decorator in an integration test to run tests unconditionally.
  • Added new test cases for Linux scenarios with and without mono.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
csharp/ql/integration-tests/all-platforms/diag_missing_project_files/test.py Removed the macOS-specific skip to allow the test to run on all platforms.
csharp/autobuilder/Semmle.Autobuild.Shared/MsBuildRule.cs Updated the msbuild command logic to include a new boolean parameter for preferring dotnet.
csharp/autobuilder/Semmle.Autobuild.CSharp.Tests/BuildScripts.cs Added new test cases and adjusted execution mappings for mono/dotnet scenarios.
Comments suppressed due to low confidence (3)

csharp/ql/integration-tests/all-platforms/diag_missing_project_files/test.py:1

  • The removal of the macOS-15 skip may lead to unexpected failures if underlying issues persist; please verify that tests run successfully on macOS.
def test(codeql, csharp):

csharp/autobuilder/Semmle.Autobuild.CSharp.Tests/BuildScripts.cs:805

  • [nitpick] Consider standardizing the test method names for clarity; for example, using names that clearly distinguish between scenarios when mono is available versus when it is not.
public void TestDirsProjLinux_WithMono()

csharp/autobuilder/Semmle.Autobuild.Shared/MsBuildRule.cs:19

  • Combining the Apple Silicon check with the preferDotnet flag forces 'dotnet msbuild' when preferDotnet is true; please confirm that this behavior is intended for all non-Windows platforms.
return builder.Actions.IsRunningOnAppleSilicon() || preferDotnet

@@ -75,13 +73,21 @@ BuildScript GetNugetRestoreScript() =>
QuoteArgument(projectOrSolution.FullPath).
Argument("-DisableParallelProcessing").
Script;

BuildScript GetMonoVersionScript() => new CommandBuilder(builder.Actions).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename to IsMonoInstalled (even though an exit code is returned - the important thing is whether mono is installed)?

Would it be worth extending the IBuildActions interface (with a method returning af bool) instead of making a script that is immediately executed?

Then it is possible to make an implementation like

public bool UseDotnet() => IsRunningOnAppleSilicon() || (!IsWIndows() && !IsMonoInstalled())

which can be used in MsBuildCommand and on l. 90.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I pushed a commit with your idea.

@tamasvajk tamasvajk requested a review from a team as a code owner April 14, 2025 11:51
michaelnebel
michaelnebel previously approved these changes Apr 14, 2025
Copy link
Contributor

@michaelnebel michaelnebel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@@ -261,6 +266,25 @@ bool IBuildActions.IsRunningOnAppleSilicon()
}
}

bool IBuildActions.IsMonoInstalled()
Copy link
Contributor

@michaelnebel michaelnebel Apr 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

{
// 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
Copy link
Contributor

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 of builder.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 😄

Copy link
Contributor

@michaelnebel michaelnebel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@tamasvajk tamasvajk merged commit de9c1fb into github:main Apr 15, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants