build(ENG-21466): Fix sccache not caching across builds (#24423)

This commit is contained in:
Marko Vejnovic
2025-11-07 14:33:26 -08:00
committed by GitHub
parent 0db90b2526
commit 3a810da66c
4 changed files with 66 additions and 9 deletions

View File

@@ -256,6 +256,30 @@ function Install-Tailscale {
Install-Package tailscale
}
function Create-Buildkite-Environment-Hooks {
param (
[Parameter(Mandatory = $true)]
[string]$BuildkiteHome
)
Write-Output "Creating Buildkite environment hooks..."
$hooksDir = Join-Path $BuildkiteHome "hooks"
if (-not (Test-Path $hooksDir)) {
New-Item -Path $hooksDir -ItemType Directory -Force | Out-Null
}
$environmentHook = Join-Path $hooksDir "environment.ps1"
$buildPath = Join-Path $BuildkiteHome "build"
@"
# Buildkite environment hook
`$env:BUILDKITE_BUILD_CHECKOUT_PATH = "$buildPath"
"@ | Set-Content -Path $environmentHook -Encoding UTF8
Write-Output "Environment hook created at $environmentHook"
}
function Install-Buildkite {
if (Which buildkite-agent) {
return
@@ -266,6 +290,14 @@ function Install-Buildkite {
$installScript = Download-File "https://raw.githubusercontent.com/buildkite/agent/main/install.ps1"
Execute-Script $installScript
Refresh-Path
if ($CI) {
$buildkiteHome = "C:\buildkite-agent"
if (-not (Test-Path $buildkiteHome)) {
New-Item -Path $buildkiteHome -ItemType Directory -Force | Out-Null
}
Create-Buildkite-Environment-Hooks -BuildkiteHome $buildkiteHome
}
}
function Install-Build-Essentials {

View File

@@ -1,5 +1,5 @@
#!/bin/sh
# Version: 19
# Version: 20
# A script that installs the dependencies needed to build and test Bun.
# This should work on macOS and Linux with a POSIX shell.
@@ -1391,6 +1391,25 @@ create_buildkite_user() {
for file in $buildkite_files; do
create_file "$file"
done
local opts=$-
set -ef
# I do not want to use create_file because it creates directories with 777
# permissions and files with 664 permissions. This is dumb, for obvious
# reasons.
local hook_dir="${home}/hooks"
mkdir -p -m 755 "${hook_dir}";
cat <<EOF > "${hook_dir}/environment"
#!/bin/sh
set -efu
export BUILDKITE_BUILD_CHECKOUT_PATH=${home}/build
EOF
execute_sudo chown -R "$user:$group" "$hook_dir"
execute_sudo chmod 744 "${hook_dir}/environment"
set +ef -"$opts"
}
install_buildkite() {

View File

@@ -103,7 +103,8 @@ async function build(args) {
await startGroup("CMake Build", () => spawn("cmake", buildArgs, { env }));
if (isCI) {
const target = buildOptions["--target"] || buildOptions["-t"];
if (isCI && target === "build-cpp") {
await startGroup("sccache stats", () => {
spawn("sccache", ["--show-stats"], { env });
});

View File

@@ -469,7 +469,12 @@ describe("browserify path tests", () => {
const failures = [];
const cwd = process.cwd();
const cwdParent = path.dirname(cwd);
const parentIsRoot = isWindows ? cwdParent.match(/^[A-Z]:\\$/) : cwdParent === "/";
const parentIsRoot = (levels = 1) => {
const dir = Array(levels)
.fill()
.reduce(wd => path.dirname(wd), cwd);
return isWindows ? dir.match(/^[a-zA-Z]:\\$/) : dir === "/";
};
const relativeTests = [
[
@@ -529,19 +534,19 @@ describe("browserify path tests", () => {
["/webp4ck-hot-middleware", "/webpack/buildin/module.js", "../webpack/buildin/module.js"],
["/webpack-hot-middleware", "/webp4ck/buildin/module.js", "../webp4ck/buildin/module.js"],
["/var/webpack-hot-middleware", "/var/webpack/buildin/module.js", "../webpack/buildin/module.js"],
["/app/node_modules/pkg", "../static", `../../..${parentIsRoot ? "" : path.posix.resolve("../")}/static`],
["/app/node_modules/pkg", "../static", `../../..${parentIsRoot() ? "" : path.posix.resolve("../")}/static`],
[
"/app/node_modules/pkg",
"../../static",
`../../..${parentIsRoot ? "" : path.posix.resolve("../../")}/static`,
`../../..${parentIsRoot(2) ? "" : path.posix.resolve("../../")}/static`,
],
["/app", "../static", `..${parentIsRoot ? "" : path.posix.resolve("../")}/static`],
["/app", "../static", `..${parentIsRoot() ? "" : path.posix.resolve("../")}/static`],
["/app", "../".repeat(64) + "static", "../static"],
[".", "../static", cwd == "/" ? "static" : "../static"],
["/", "../static", parentIsRoot ? "static" : `${path.posix.resolve("../")}/static`.slice(1)],
["/", "../static", parentIsRoot() ? "static" : `${path.posix.resolve("../")}/static`.slice(1)],
["../", "../", ""],
["../", "../../", parentIsRoot ? "" : ".."],
["../../", "../", parentIsRoot ? "" : path.basename(cwdParent)],
["../", "../../", parentIsRoot() ? "" : ".."],
["../../", "../", parentIsRoot() ? "" : path.basename(cwdParent)],
["../../", "../../", ""],
],
],