Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make rebuilds without code changes take less time #1086

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't normal ninja deps ensure this already?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure, I don't remember adding this part 😬

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