mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
C#: Change IsARM to Apple silicon check
This commit is contained in:
@@ -145,9 +145,9 @@ namespace Semmle.Autobuild.Cpp.Tests
|
|||||||
|
|
||||||
bool IBuildActions.IsMacOs() => IsMacOs;
|
bool IBuildActions.IsMacOs() => IsMacOs;
|
||||||
|
|
||||||
public bool IsArm { get; set; }
|
public bool IsRunningOnAppleSilicon { get; set; }
|
||||||
|
|
||||||
bool IBuildActions.IsArm() => IsArm;
|
bool IBuildActions.IsRunningOnAppleSilicon() => IsRunningOnAppleSilicon;
|
||||||
|
|
||||||
string IBuildActions.PathCombine(params string[] parts)
|
string IBuildActions.PathCombine(params string[] parts)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -159,9 +159,9 @@ namespace Semmle.Autobuild.CSharp.Tests
|
|||||||
|
|
||||||
bool IBuildActions.IsMacOs() => IsMacOs;
|
bool IBuildActions.IsMacOs() => IsMacOs;
|
||||||
|
|
||||||
public bool IsArm { get; set; }
|
public bool IsRunningOnAppleSilicon { get; set; }
|
||||||
|
|
||||||
bool IBuildActions.IsArm() => IsArm;
|
bool IBuildActions.IsRunningOnAppleSilicon() => IsRunningOnAppleSilicon;
|
||||||
|
|
||||||
public string PathCombine(params string[] parts)
|
public string PathCombine(params string[] parts)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using Semmle.Util;
|
using Semmle.Util;
|
||||||
@@ -119,10 +120,10 @@ namespace Semmle.Autobuild.Shared
|
|||||||
bool IsMacOs();
|
bool IsMacOs();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a value indicating whether we are running on arm.
|
/// Gets a value indicating whether we are running on Apple Silicon.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>True if we are running on arm.</returns>
|
/// <returns>True if we are running on Apple Silicon.</returns>
|
||||||
bool IsArm();
|
bool IsRunningOnAppleSilicon();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Combine path segments, Path.Combine().
|
/// Combine path segments, Path.Combine().
|
||||||
@@ -240,9 +241,25 @@ namespace Semmle.Autobuild.Shared
|
|||||||
|
|
||||||
bool IBuildActions.IsMacOs() => RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
|
bool IBuildActions.IsMacOs() => RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
|
||||||
|
|
||||||
bool IBuildActions.IsArm() =>
|
bool IBuildActions.IsRunningOnAppleSilicon()
|
||||||
RuntimeInformation.ProcessArchitecture == Architecture.Arm64 ||
|
{
|
||||||
RuntimeInformation.ProcessArchitecture == Architecture.Arm;
|
var thisBuildActions = (IBuildActions)this;
|
||||||
|
|
||||||
|
if (!thisBuildActions.IsMacOs())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var res = thisBuildActions.RunProcess("sysctl", "machdep.cpu.brand_string", workingDirectory: null, env: null, out var stdOut);
|
||||||
|
return stdOut?.Any(s => s?.ToLowerInvariant().Contains("apple") == true) ?? false;
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
string IBuildActions.PathCombine(params string[] parts) => Path.Combine(parts);
|
string IBuildActions.PathCombine(params string[] parts) => Path.Combine(parts);
|
||||||
|
|
||||||
|
|||||||
@@ -15,12 +15,12 @@ namespace Semmle.Autobuild.Shared
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static CommandBuilder MsBuildCommand(this CommandBuilder cmdBuilder, IAutobuilder<AutobuildOptionsShared> builder)
|
public static CommandBuilder MsBuildCommand(this CommandBuilder cmdBuilder, IAutobuilder<AutobuildOptionsShared> builder)
|
||||||
{
|
{
|
||||||
var isArmMac = builder.Actions.IsMacOs() && builder.Actions.IsArm();
|
var IsRunningOnAppleSiliconMac = builder.Actions.IsMacOs() && builder.Actions.IsRunningOnAppleSilicon();
|
||||||
|
|
||||||
// mono doesn't ship with `msbuild` on Arm-based Macs, but we can fall back to
|
// 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`
|
// msbuild that ships with `dotnet` which can be invoked with `dotnet msbuild`
|
||||||
// perhaps we should do this on all platforms?
|
// perhaps we should do this on all platforms?
|
||||||
return isArmMac ?
|
return IsRunningOnAppleSiliconMac ?
|
||||||
cmdBuilder.RunCommand("dotnet").Argument("msbuild") :
|
cmdBuilder.RunCommand("dotnet").Argument("msbuild") :
|
||||||
cmdBuilder.RunCommand("msbuild");
|
cmdBuilder.RunCommand("msbuild");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user