diff --git a/Runner/Helpers/GitHelper.cs b/Runner/Helpers/GitHelper.cs index 94b0843..3eff0f8 100644 --- a/Runner/Helpers/GitHelper.cs +++ b/Runner/Helpers/GitHelper.cs @@ -30,4 +30,19 @@ private static bool ShouldSkipLine(string line) span.StartsWith("@@", StringComparison.Ordinal) || span.StartsWith("\\ No newline at end of file", StringComparison.Ordinal); } + + public static async Task> GetChangedFilesAsync(JobBase job, string baselineRef, string workDir) + { + List lines = []; + + await job.RunProcessAsync("git", + $"diff --name-only {baselineRef}", + lines, + workDir: workDir, + checkExitCode: false, + suppressOutputLogs: true, + suppressStartingLog: true); + + return lines; + } } diff --git a/Runner/Jobs/JitDiffJob.cs b/Runner/Jobs/JitDiffJob.cs index dc151c0..26df3b5 100644 --- a/Runner/Jobs/JitDiffJob.cs +++ b/Runner/Jobs/JitDiffJob.cs @@ -80,7 +80,9 @@ public static async Task BuildAndCopyRuntimeBranchBitsAsync(JobBase job, string { string arch = IsArm ? "arm64" : "x64"; - await job.RunProcessAsync("bash", $"build.sh clr+libs -c Release {RuntimeHelpers.LibrariesExtraBuildArgs}", logPrefix: $"{branch} release", workDir: "runtime"); + string targets = await ShouldBuildsLibsAsync() ? "clr+libs" : "clr"; + + await job.RunProcessAsync("bash", $"build.sh {targets} -c Release {RuntimeHelpers.LibrariesExtraBuildArgs}", logPrefix: $"{branch} release", workDir: "runtime"); Task copyReleaseBitsTask = RuntimeHelpers.CopyReleaseArtifactsAsync(job, branch, $"artifacts-{branch}"); @@ -94,6 +96,25 @@ public static async Task BuildAndCopyRuntimeBranchBitsAsync(JobBase job, string } await copyReleaseBitsTask; + + async Task ShouldBuildsLibsAsync() + { + if (job.TryGetFlag("forceRebuildLibs")) + { + return true; + } + + if (branch == "pr") + { + List changedFiles = await GitHelper.GetChangedFilesAsync(job, "main", "runtime"); + + return changedFiles.Any(f => + !f.StartsWith("src/coreclr/", StringComparison.OrdinalIgnoreCase) || + f.Contains("/System.Private.CoreLib/", StringComparison.OrdinalIgnoreCase)); + } + + return true; + } } private async Task CollectFrameworksDiffsAsync()