From c7ea6e743df21daf4998a356a8a3253ffb5b609c Mon Sep 17 00:00:00 2001 From: Chris Toshok Date: Sat, 20 Jan 2024 18:25:11 -0800 Subject: [PATCH] don't unconditionally write record_replay_driver.{h,cc} - only write them if they've changed. drops local mac arm build (on no local change, with no driver change) from 45s to 15s --- build.js | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/build.js b/build.js index 20a7df6c6b2751..540e323865154a 100644 --- a/build.js +++ b/build.js @@ -29,11 +29,6 @@ spawnChecked("git", ["config", "--global", "--add", "safe.directory", __dirname] stdio: "inherit", }); -if (currentPlatform() == "macOS") { - // Make sure the main executable gets rebuilt with the new build ID. - spawnChecked("touch", [`${__dirname}/chrome/app/chrome_exe_main_mac.cc`]); -} - const archSuffix = buildArm ? "-arm" : ""; if (!REPLAY_LOCAL_DRIVER_DIR) { @@ -97,7 +92,7 @@ const buildSuffix = : process.env["LOCAL_DEVELOPER_BUILD_EXTENSION"] || ""; const buildId = `${computeBuildId(driverDate, driverRevision)}${buildSuffix}`; -fs.writeFileSync( +writeFileSyncIfChanged( `${__dirname}/base/record_replay_driver.cc`, ` namespace recordreplay { @@ -108,7 +103,7 @@ namespace recordreplay { ` ); -fs.writeFileSync( +const drived_h_changed = writeFileSyncIfChanged( `${__dirname}/base/record_replay_driver.h`, ` #ifndef BASE_RECORD_REPLAY_DRIVER_H_ @@ -120,6 +115,11 @@ fs.writeFileSync( ` ); +if (currentPlatform() == "macOS" && drived_h_changed) { + // Make sure the main executable gets rebuilt with the new build ID. + spawnChecked("touch", [`${__dirname}/chrome/app/chrome_exe_main_mac.cc`]); +} + // ensure that build configuration is written with correct paths const gn = currentPlatform() == "windows" ? "gn.bat" : "gn"; spawnChecked(gn, ["gen", outdir], { stdio: "inherit" }); @@ -152,6 +152,24 @@ spawnChecked( console.log(`Build finished.`); +function writeFileSyncIfChanged(filename, newContents) { + let changed = false; + try { + const oldContents = fs.readFileSync(filename, "utf8"); + changed = oldContents != newContents; + } catch (e) { + changed = true; + } + + if (!changed) { + console.log(`Skipping ${filename} because it hasn't changed.`); + } else { + fs.writeFileSync(filename, newContents); + } + + return changed; +} + function spawnChecked(cmd, args, options) { const prettyCmd = [cmd].concat(args).join(" "); console.error("$ " + prettyCmd);