electron/script/generate-deps-hash.js

52 lines
1.7 KiB
JavaScript
Raw Normal View History

2020-03-20 20:28:31 +00:00
const crypto = require('crypto');
const fs = require('fs');
const path = require('path');
// Fallback to blow away old cache keys
2020-03-20 20:28:31 +00:00
const HASH_VERSION = 3;
// Base files to hash
const filesToHash = [
path.resolve(__dirname, '../DEPS'),
path.resolve(__dirname, '../yarn.lock'),
path.resolve(__dirname, '../script/sysroots.json')
2020-03-20 20:28:31 +00:00
];
const addAllFiles = (dir) => {
for (const child of fs.readdirSync(dir).sort()) {
2020-03-20 20:28:31 +00:00
const childPath = path.resolve(dir, child);
if (fs.statSync(childPath).isDirectory()) {
2020-03-20 20:28:31 +00:00
addAllFiles(childPath);
} else {
2020-03-20 20:28:31 +00:00
filesToHash.push(childPath);
}
}
2020-03-20 20:28:31 +00:00
};
// Add all patch files to the hash
2020-03-20 20:28:31 +00:00
addAllFiles(path.resolve(__dirname, '../patches'));
// Create Hash
2020-03-20 20:28:31 +00:00
const hasher = crypto.createHash('SHA256');
hasher.update(`HASH_VERSION:${HASH_VERSION}`);
for (const file of filesToHash) {
2020-03-20 20:28:31 +00:00
hasher.update(fs.readFileSync(file));
}
// Add the GCLIENT_EXTRA_ARGS variable to the hash
2020-03-20 20:28:31 +00:00
const extraArgs = process.env.GCLIENT_EXTRA_ARGS || 'no_extra_args';
hasher.update(extraArgs);
build: make CI faster, magic contained within (#21086) * build: cache the out directory for exact deps hash matches * chore: generate a target based depshash discriminator * fix: hash on gn args * build: share logic on the mac builds * build: ensure that the mksnapshot binary is built before stripping before zipping * build: attach the workspace on macOS * build: optimize the macOS checkout path for testing * build: fix mksnapshot zip generation * build: make the mac src cache restore work * build: v2 out cache * build: macOS cache restore is just stupidly slow * build: strip more binaries * build: attach the out cache to the workspace for macOS builds * build: allow linux boxes to restore darwin out caches * build: cat the deps hash target file * build: ensure that the deps target hash matches on the linux box * build: do not use host arch in target key * build: force undefined in the target hash file * build: only restore out cache when it isn't in the workspace * build: fix the macOS cache workspace trick * build: do not double restore * build: remove the big stuff from the out dir * build: workaround layer issue * build: try it back on macOS again but with smaller thingy * build: macOS needs the out cache now * build: clean up for omptimal macOS path * build: use old docker image * build: idek at this point * build: we need a deps hash * build: yeah we need a checkout too * chore: use testing env on save cache job * chore: well that should fix the cache key thing * chore: handle cross-OS path mismatch for src cache restore * build: use a /portal directory to transfer the src cache appropriately * build: use the correct docker image * build: super perms for /portal * build: increment out cache number * build: ensure target hash is correct for args + disable pre-compiled headers on macOS * build: wipe the cross-arch libffmpeg before building Electron
2019-11-28 00:29:53 +00:00
2020-03-20 20:28:31 +00:00
const effectivePlatform = extraArgs.includes('host_os=mac') ? 'darwin' : process.platform;
// Write the hash to disk
2020-03-20 20:28:31 +00:00
fs.writeFileSync(path.resolve(__dirname, '../.depshash'), hasher.digest('hex'));
build: make CI faster, magic contained within (#21086) * build: cache the out directory for exact deps hash matches * chore: generate a target based depshash discriminator * fix: hash on gn args * build: share logic on the mac builds * build: ensure that the mksnapshot binary is built before stripping before zipping * build: attach the workspace on macOS * build: optimize the macOS checkout path for testing * build: fix mksnapshot zip generation * build: make the mac src cache restore work * build: v2 out cache * build: macOS cache restore is just stupidly slow * build: strip more binaries * build: attach the out cache to the workspace for macOS builds * build: allow linux boxes to restore darwin out caches * build: cat the deps hash target file * build: ensure that the deps target hash matches on the linux box * build: do not use host arch in target key * build: force undefined in the target hash file * build: only restore out cache when it isn't in the workspace * build: fix the macOS cache workspace trick * build: do not double restore * build: remove the big stuff from the out dir * build: workaround layer issue * build: try it back on macOS again but with smaller thingy * build: macOS needs the out cache now * build: clean up for omptimal macOS path * build: use old docker image * build: idek at this point * build: we need a deps hash * build: yeah we need a checkout too * chore: use testing env on save cache job * chore: well that should fix the cache key thing * chore: handle cross-OS path mismatch for src cache restore * build: use a /portal directory to transfer the src cache appropriately * build: use the correct docker image * build: super perms for /portal * build: increment out cache number * build: ensure target hash is correct for args + disable pre-compiled headers on macOS * build: wipe the cross-arch libffmpeg before building Electron
2019-11-28 00:29:53 +00:00
2020-03-20 20:28:31 +00:00
let targetContent = `${effectivePlatform}\n${process.env.TARGET_ARCH}\n${process.env.GN_CONFIG}\n${undefined}\n${process.env.GN_EXTRA_ARGS}\n${process.env.GN_BUILDFLAG_ARGS}`;
const argsDir = path.resolve(__dirname, '../build/args');
build: make CI faster, magic contained within (#21086) * build: cache the out directory for exact deps hash matches * chore: generate a target based depshash discriminator * fix: hash on gn args * build: share logic on the mac builds * build: ensure that the mksnapshot binary is built before stripping before zipping * build: attach the workspace on macOS * build: optimize the macOS checkout path for testing * build: fix mksnapshot zip generation * build: make the mac src cache restore work * build: v2 out cache * build: macOS cache restore is just stupidly slow * build: strip more binaries * build: attach the out cache to the workspace for macOS builds * build: allow linux boxes to restore darwin out caches * build: cat the deps hash target file * build: ensure that the deps target hash matches on the linux box * build: do not use host arch in target key * build: force undefined in the target hash file * build: only restore out cache when it isn't in the workspace * build: fix the macOS cache workspace trick * build: do not double restore * build: remove the big stuff from the out dir * build: workaround layer issue * build: try it back on macOS again but with smaller thingy * build: macOS needs the out cache now * build: clean up for omptimal macOS path * build: use old docker image * build: idek at this point * build: we need a deps hash * build: yeah we need a checkout too * chore: use testing env on save cache job * chore: well that should fix the cache key thing * chore: handle cross-OS path mismatch for src cache restore * build: use a /portal directory to transfer the src cache appropriately * build: use the correct docker image * build: super perms for /portal * build: increment out cache number * build: ensure target hash is correct for args + disable pre-compiled headers on macOS * build: wipe the cross-arch libffmpeg before building Electron
2019-11-28 00:29:53 +00:00
for (const argFile of fs.readdirSync(argsDir).sort()) {
2020-03-20 20:28:31 +00:00
targetContent += `\n${argFile}--${crypto.createHash('SHA1').update(fs.readFileSync(path.resolve(argsDir, argFile))).digest('hex')}`;
build: make CI faster, magic contained within (#21086) * build: cache the out directory for exact deps hash matches * chore: generate a target based depshash discriminator * fix: hash on gn args * build: share logic on the mac builds * build: ensure that the mksnapshot binary is built before stripping before zipping * build: attach the workspace on macOS * build: optimize the macOS checkout path for testing * build: fix mksnapshot zip generation * build: make the mac src cache restore work * build: v2 out cache * build: macOS cache restore is just stupidly slow * build: strip more binaries * build: attach the out cache to the workspace for macOS builds * build: allow linux boxes to restore darwin out caches * build: cat the deps hash target file * build: ensure that the deps target hash matches on the linux box * build: do not use host arch in target key * build: force undefined in the target hash file * build: only restore out cache when it isn't in the workspace * build: fix the macOS cache workspace trick * build: do not double restore * build: remove the big stuff from the out dir * build: workaround layer issue * build: try it back on macOS again but with smaller thingy * build: macOS needs the out cache now * build: clean up for omptimal macOS path * build: use old docker image * build: idek at this point * build: we need a deps hash * build: yeah we need a checkout too * chore: use testing env on save cache job * chore: well that should fix the cache key thing * chore: handle cross-OS path mismatch for src cache restore * build: use a /portal directory to transfer the src cache appropriately * build: use the correct docker image * build: super perms for /portal * build: increment out cache number * build: ensure target hash is correct for args + disable pre-compiled headers on macOS * build: wipe the cross-arch libffmpeg before building Electron
2019-11-28 00:29:53 +00:00
}
2020-03-20 20:28:31 +00:00
fs.writeFileSync(path.resolve(__dirname, '../.depshash-target'), targetContent);