Skip to content

Commit

Permalink
Avoid rebuilding libs on CLR-only changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MihaZupan committed Nov 30, 2024
1 parent 8b40947 commit 13d76bd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
15 changes: 15 additions & 0 deletions Runner/Helpers/GitHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<string>> GetChangedFilesAsync(JobBase job, string baselineRef, string workDir)
{
List<string> lines = [];

await job.RunProcessAsync("git",
$"diff --name-only {baselineRef}",
lines,
workDir: workDir,
checkExitCode: false,
suppressOutputLogs: true,
suppressStartingLog: true);

return lines;
}
}
23 changes: 22 additions & 1 deletion Runner/Jobs/JitDiffJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");

Expand All @@ -94,6 +96,25 @@ public static async Task BuildAndCopyRuntimeBranchBitsAsync(JobBase job, string
}

await copyReleaseBitsTask;

async Task<bool> ShouldBuildsLibsAsync()
{
if (job.TryGetFlag("forceRebuildLibs"))
{
return true;
}

if (branch == "pr")
{
List<string> 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<string> CollectFrameworksDiffsAsync()
Expand Down

0 comments on commit 13d76bd

Please sign in to comment.