Skip to content

Commit

Permalink
don't unconditionally write record_replay_driver.{h,cc} - only write …
Browse files Browse the repository at this point in the history
…them if they've changed. drops local mac arm build (on no local change, with no driver change) from 45s to 15s
  • Loading branch information
toshok committed Jan 26, 2024
1 parent ef5d2dc commit c7ea6e7
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand All @@ -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_
Expand All @@ -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" });
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit c7ea6e7

Please sign in to comment.