|
3 | 3 | using System.Diagnostics; |
4 | 4 | using System.Diagnostics.CodeAnalysis; |
5 | 5 | using System.IO; |
| 6 | +using System.Linq; |
6 | 7 | using System.Runtime.InteropServices; |
7 | 8 | using System.Xml; |
8 | 9 | using Semmle.Util; |
@@ -119,10 +120,10 @@ public interface IBuildActions |
119 | 120 | bool IsMacOs(); |
120 | 121 |
|
121 | 122 | /// <summary> |
122 | | - /// Gets a value indicating whether we are running on arm. |
| 123 | + /// Gets a value indicating whether we are running on Apple Silicon. |
123 | 124 | /// </summary> |
124 | | - /// <returns>True if we are running on arm.</returns> |
125 | | - bool IsArm(); |
| 125 | + /// <returns>True if we are running on Apple Silicon.</returns> |
| 126 | + bool IsRunningOnAppleSilicon(); |
126 | 127 |
|
127 | 128 | /// <summary> |
128 | 129 | /// Combine path segments, Path.Combine(). |
@@ -240,9 +241,25 @@ int IBuildActions.RunProcess(string cmd, string args, string? workingDirectory, |
240 | 241 |
|
241 | 242 | bool IBuildActions.IsMacOs() => RuntimeInformation.IsOSPlatform(OSPlatform.OSX); |
242 | 243 |
|
243 | | - bool IBuildActions.IsArm() => |
244 | | - RuntimeInformation.ProcessArchitecture == Architecture.Arm64 || |
245 | | - RuntimeInformation.ProcessArchitecture == Architecture.Arm; |
| 244 | + bool IBuildActions.IsRunningOnAppleSilicon() |
| 245 | + { |
| 246 | + var thisBuildActions = (IBuildActions)this; |
| 247 | + |
| 248 | + if (!thisBuildActions.IsMacOs()) |
| 249 | + { |
| 250 | + return false; |
| 251 | + } |
| 252 | + |
| 253 | + try |
| 254 | + { |
| 255 | + thisBuildActions.RunProcess("sysctl", "machdep.cpu.brand_string", workingDirectory: null, env: null, out var stdOut); |
| 256 | + return stdOut?.Any(s => s?.ToLowerInvariant().Contains("apple") == true) ?? false; |
| 257 | + } |
| 258 | + catch (Exception) |
| 259 | + { |
| 260 | + return false; |
| 261 | + } |
| 262 | + } |
246 | 263 |
|
247 | 264 | string IBuildActions.PathCombine(params string[] parts) => Path.Combine(parts); |
248 | 265 |
|
|
0 commit comments