Skip to content

Commit 96d8319

Browse files
committed
Try replacing the global.json
1 parent 98aead0 commit 96d8319

4 files changed

Lines changed: 23 additions & 40 deletions

File tree

Runner/Helpers/DotnetHelpers.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ public static async Task KillRemainingDotnetProcessesAsync(JobBase job)
3737
}
3838
}
3939

40+
public static int GetDotnetVersion(string repository = "runtime")
41+
{
42+
// "version": "10.0.100-preview.1.12345.6", => 10
43+
return int.Parse(File.ReadAllLines($"{repository}/global.json")
44+
.First(line => line.Contains("version", StringComparison.OrdinalIgnoreCase))
45+
.Split(':')[1] // "10.0.100-preview.1.12345.6"
46+
.Split('.')[0] // "10
47+
.TrimStart(' ', '"'));
48+
}
49+
4050
public static async Task InstallDotnetSdkAsync(JobBase job, string globalJsonPath, string? installDir = null) =>
4151
await InstallDotnetSdkAsyncCore(job, $"--jsonfile {globalJsonPath}", installDir);
4252

Runner/Helpers/RuntimeHelpers.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,4 @@ public static async Task CopyReleaseArtifactsAsync(JobBase job, string logPrefix
223223

224224
await job.RunProcessAsync("cp", $"-r {BaseDirectory}/{folder}/. {destination}", logPrefix: logPrefix);
225225
}
226-
227-
public static int GetDotnetVersion(string repository = "runtime")
228-
{
229-
// "version": "10.0.100-preview.1.12345.6", => 10
230-
return int.Parse(File.ReadAllLines($"{repository}/global.json")
231-
.First(line => line.Contains("version", StringComparison.OrdinalIgnoreCase))
232-
.Split(':')[1] // "10.0.100-preview.1.12345.6"
233-
.Split('.')[0] // "10
234-
.TrimStart(' ', '"'));
235-
}
236226
}

Runner/Jobs/BenchmarkLibrariesJob.cs

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ namespace Runner.Jobs;
44

55
internal sealed partial class BenchmarkLibrariesJob : JobBase
66
{
7-
private const string DotnetInstallDir = "dotnet-performance";
8-
97
public BenchmarkLibrariesJob(HttpClient client, Dictionary<string, string> metadata) : base(client, metadata) { }
108

119
protected override async Task RunJobCoreAsync()
@@ -32,7 +30,7 @@ protected override async Task RunJobCoreAsync()
3230
{
3331
await clonePerformanceTask;
3432

35-
PendingTasks.Enqueue(DotnetHelpers.InstallDotnetDailySdkAsync(this, GetPerformanceDotnetVersion(), DotnetInstallDir));
33+
PendingTasks.Enqueue(DotnetHelpers.InstallDotnetSdkAsync(this, "performance/global.json"));
3634

3735
coreRuns = await DownloadCoreRootsAsync(entries);
3836
}
@@ -65,7 +63,7 @@ protected override async Task RunJobCoreAsync()
6563
await JitDiffJob.BuildAndCopyRuntimeBranchBitsAsync(this, "pr", uploadArtifacts: false, buildChecked: false, canSkipRebuild: false);
6664
}
6765

68-
await DotnetHelpers.InstallDotnetDailySdkAsync(this, GetPerformanceDotnetVersion(), DotnetInstallDir);
66+
await DotnetHelpers.InstallDotnetSdkAsync(this, "performance/global.json");
6967

7068
coreRuns = ["artifacts-main/corerun", "artifacts-pr/corerun"];
7169
}
@@ -83,6 +81,13 @@ private async Task CloneDotnetPerformanceAndSetupToolsAsync()
8381

8482
await RunProcessAsync("git", $"clone --no-tags --depth=1 -b {branch} --progress https://github.com/{repo} performance", logPrefix: "Clone performance");
8583

84+
if (repo == "dotnet/performance" && branch == "main")
85+
{
86+
// Performance's global.json is out of date
87+
byte[] bytes = await HttpClient.GetByteArrayAsync("https://raw.githubusercontent.com/dotnet/runtime/refs/heads/main/global.json");
88+
await File.WriteAllBytesAsync("performance/global.json", bytes);
89+
}
90+
8691
if (TryGetFlag("medium") || TryGetFlag("long"))
8792
{
8893
string? path = Directory.EnumerateFiles("performance", "*.cs", SearchOption.AllDirectories)
@@ -195,23 +200,6 @@ private async Task CloneDotnetPerformanceAndSetupToolsAsync()
195200
}
196201
}
197202

198-
private int GetPerformanceDotnetVersion()
199-
{
200-
string source = File.ReadAllText("performance/src/benchmarks/micro/MicroBenchmarks.csproj");
201-
// <SupportedTargetFrameworks>net6.0;net7.0;net8.0;net9.0;net10.0;net11.0</SupportedTargetFrameworks>
202-
203-
Match match = DotnetVersionFromCsprojRegex().Match(source);
204-
205-
if (!match.Success)
206-
{
207-
throw new Exception("Failed to determine the dotnet version from MicroBenchmarks.csproj");
208-
}
209-
210-
// ["net6.0", "net7.0", ...]
211-
string[] frameworks = match.Groups[1].Value.Split(';', StringSplitOptions.RemoveEmptyEntries);
212-
return frameworks.Max(f => int.Parse(f.AsSpan(3, f.IndexOf('.') - 3)));
213-
}
214-
215203
private async Task<string[]> DownloadCoreRootsAsync(CoreRootAPI.CoreRootEntry[] entries)
216204
{
217205
for (int i = 0; i < entries.Length; i++)
@@ -248,7 +236,7 @@ private async Task RunBenchmarksAsync(string[] coreRunPaths)
248236
filter = $"*{filter}*";
249237
}
250238

251-
int dotnetVersion = GetPerformanceDotnetVersion();
239+
int dotnetVersion = DotnetHelpers.GetDotnetVersion("performance");
252240

253241
string coreRuns = string.Join(' ', coreRunPaths.Select(p => $"\"{Path.GetFullPath(p)}\""));
254242

@@ -263,10 +251,8 @@ private async Task RunBenchmarksAsync(string[] coreRunPaths)
263251

264252
string? artifactsDir = null;
265253

266-
string dotnetPath = Path.GetFullPath($"{DotnetInstallDir}/dotnet");
267-
268-
await RunProcessAsync(dotnetPath,
269-
$"run -c Release --framework net{dotnetVersion}.0 -- --cli \"{dotnetPath}\" --filter {filter} -h {HiddenColumns} --corerun {coreRuns} {parallelSuffix}",
254+
await RunProcessAsync("/usr/lib/dotnet/dotnet",
255+
$"run -c Release --framework net{dotnetVersion}.0 -- --filter {filter} -h {HiddenColumns} --corerun {coreRuns} {parallelSuffix}",
270256
workDir: "performance/src/benchmarks/micro",
271257
processLogs: line =>
272258
{
@@ -405,7 +391,4 @@ await RunProcessAsync(dotnetPath,
405391

406392
[GeneratedRegex(@"BenchmarkDotNet\.(\d.*?)\.nupkg")]
407393
private static partial Regex BenchmarkDotNetPackageVersionRegex();
408-
409-
[GeneratedRegex(@"Frameworks>((?:net\d+\.\d+);?)+<\/")]
410-
private static partial Regex DotnetVersionFromCsprojRegex();
411394
}

Runner/Jobs/RegexDiffJob.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ await Parallel.ForAsync(0, Environment.ProcessorCount, async (processorId, _) =>
567567
<Project Sdk="Microsoft.NET.Sdk">
568568
<PropertyGroup>
569569
<OutputType>Library</OutputType>
570-
<TargetFramework>net{RuntimeHelpers.GetDotnetVersion()}.0</TargetFramework>
570+
<TargetFramework>net{DotnetHelpers.GetDotnetVersion()}.0</TargetFramework>
571571
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
572572
</PropertyGroup>
573573
</Project>

0 commit comments

Comments
 (0)