Skip to content

Commit

Permalink
Avoid rebuilding libs or clr on unrelated changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MihaZupan committed Nov 30, 2024
1 parent 8b40947 commit 7e42fc1
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 2 deletions.
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;
}
}
57 changes: 55 additions & 2 deletions Runner/Jobs/JitDiffJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,24 @@ 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");
(bool rebuildClr, bool rebuildLibs) = await ShouldRebuildAsync();

string targets = (rebuildClr, rebuildLibs) switch
{
(true, true) => "clr+libs",
(true, false) => "clr",
_ => "libs"
};

await job.RunProcessAsync("bash", $"build.sh {targets} -c Release {RuntimeHelpers.LibrariesExtraBuildArgs}", logPrefix: $"{branch} release", workDir: "runtime");

Task copyReleaseBitsTask = RuntimeHelpers.CopyReleaseArtifactsAsync(job, branch, $"artifacts-{branch}");

await job.RunProcessAsync("bash", "build.sh clr.jit -c Checked", logPrefix: $"{branch} checked", workDir: "runtime");
if (rebuildClr)
{
await job.RunProcessAsync("bash", "build.sh clr.jit -c Checked", logPrefix: $"{branch} checked", workDir: "runtime");
}

await job.RunProcessAsync("cp", $"-r runtime/artifacts/bin/coreclr/linux.{arch}.Checked/. clr-checked-{branch}", logPrefix: $"{branch} checked");

if (uploadArtifacts)
Expand All @@ -94,6 +107,46 @@ public static async Task BuildAndCopyRuntimeBranchBitsAsync(JobBase job, string
}

await copyReleaseBitsTask;

async Task<(bool Clr, bool Libs)> ShouldRebuildAsync()
{
if (branch == "pr" && !job.TryGetFlag("forceRebuildAll"))
{
bool clr = false;
bool libs = false;

foreach (string file in await GitHelper.GetChangedFilesAsync(job, "main", "runtime"))
{
if (file.StartsWith("src/coreclr/", StringComparison.OrdinalIgnoreCase))
{
clr = true;

if (file.Contains("/System.Private.CoreLib/", StringComparison.OrdinalIgnoreCase))
{
libs = true;
}
}
else if (file.StartsWith("src/libraries/", StringComparison.OrdinalIgnoreCase))
{
libs = true;
}
else if (!file.StartsWith("src/tests/", StringComparison.OrdinalIgnoreCase))
{
clr = true;
libs = true;
}
}

if (!clr && !libs)
{
await job.LogAsync($"WARNING: Don't need to rebuild anything? What is this PR?");
}

return (clr, libs);
}

return (true, true);
}
}

private async Task<string> CollectFrameworksDiffsAsync()
Expand Down

0 comments on commit 7e42fc1

Please sign in to comment.