Skip to content

Commit c7ea6e7

Browse files
committed
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
1 parent ef5d2dc commit c7ea6e7

1 file changed

Lines changed: 25 additions & 7 deletions

File tree

build.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ spawnChecked("git", ["config", "--global", "--add", "safe.directory", __dirname]
2929
stdio: "inherit",
3030
});
3131

32-
if (currentPlatform() == "macOS") {
33-
// Make sure the main executable gets rebuilt with the new build ID.
34-
spawnChecked("touch", [`${__dirname}/chrome/app/chrome_exe_main_mac.cc`]);
35-
}
36-
3732
const archSuffix = buildArm ? "-arm" : "";
3833

3934
if (!REPLAY_LOCAL_DRIVER_DIR) {
@@ -97,7 +92,7 @@ const buildSuffix =
9792
: process.env["LOCAL_DEVELOPER_BUILD_EXTENSION"] || "";
9893
const buildId = `${computeBuildId(driverDate, driverRevision)}${buildSuffix}`;
9994

100-
fs.writeFileSync(
95+
writeFileSyncIfChanged(
10196
`${__dirname}/base/record_replay_driver.cc`,
10297
`
10398
namespace recordreplay {
@@ -108,7 +103,7 @@ namespace recordreplay {
108103
`
109104
);
110105

111-
fs.writeFileSync(
106+
const drived_h_changed = writeFileSyncIfChanged(
112107
`${__dirname}/base/record_replay_driver.h`,
113108
`
114109
#ifndef BASE_RECORD_REPLAY_DRIVER_H_
@@ -120,6 +115,11 @@ fs.writeFileSync(
120115
`
121116
);
122117

118+
if (currentPlatform() == "macOS" && drived_h_changed) {
119+
// Make sure the main executable gets rebuilt with the new build ID.
120+
spawnChecked("touch", [`${__dirname}/chrome/app/chrome_exe_main_mac.cc`]);
121+
}
122+
123123
// ensure that build configuration is written with correct paths
124124
const gn = currentPlatform() == "windows" ? "gn.bat" : "gn";
125125
spawnChecked(gn, ["gen", outdir], { stdio: "inherit" });
@@ -152,6 +152,24 @@ spawnChecked(
152152

153153
console.log(`Build finished.`);
154154

155+
function writeFileSyncIfChanged(filename, newContents) {
156+
let changed = false;
157+
try {
158+
const oldContents = fs.readFileSync(filename, "utf8");
159+
changed = oldContents != newContents;
160+
} catch (e) {
161+
changed = true;
162+
}
163+
164+
if (!changed) {
165+
console.log(`Skipping ${filename} because it hasn't changed.`);
166+
} else {
167+
fs.writeFileSync(filename, newContents);
168+
}
169+
170+
return changed;
171+
}
172+
155173
function spawnChecked(cmd, args, options) {
156174
const prettyCmd = [cmd].concat(args).join(" ");
157175
console.error("$ " + prettyCmd);

0 commit comments

Comments
 (0)