2020-03-20 20:28:31 +00:00
|
|
|
const crypto = require('crypto');
|
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
2019-04-22 22:36:59 +00:00
|
|
|
|
|
|
|
// Fallback to blow away old cache keys
|
2020-03-20 20:28:31 +00:00
|
|
|
const HASH_VERSION = 3;
|
2019-04-22 22:36:59 +00:00
|
|
|
|
|
|
|
// Base files to hash
|
|
|
|
const filesToHash = [
|
|
|
|
path.resolve(__dirname, '../DEPS'),
|
2019-10-30 00:50:24 +00:00
|
|
|
path.resolve(__dirname, '../yarn.lock'),
|
|
|
|
path.resolve(__dirname, '../script/sysroots.json')
|
2020-03-20 20:28:31 +00:00
|
|
|
];
|
2019-04-22 22:36:59 +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);
|
2019-04-22 22:36:59 +00:00
|
|
|
if (fs.statSync(childPath).isDirectory()) {
|
2020-03-20 20:28:31 +00:00
|
|
|
addAllFiles(childPath);
|
2019-04-22 22:36:59 +00:00
|
|
|
} else {
|
2020-03-20 20:28:31 +00:00
|
|
|
filesToHash.push(childPath);
|
2019-04-22 22:36:59 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
};
|
2019-04-22 22:36:59 +00:00
|
|
|
|
|
|
|
// Add all patch files to the hash
|
2020-03-20 20:28:31 +00:00
|
|
|
addAllFiles(path.resolve(__dirname, '../patches'));
|
2019-04-22 22:36:59 +00:00
|
|
|
|
|
|
|
// Create Hash
|
2020-03-20 20:28:31 +00:00
|
|
|
const hasher = crypto.createHash('SHA256');
|
|
|
|
hasher.update(`HASH_VERSION:${HASH_VERSION}`);
|
2019-04-22 22:36:59 +00:00
|
|
|
for (const file of filesToHash) {
|
2020-03-20 20:28:31 +00:00
|
|
|
hasher.update(fs.readFileSync(file));
|
2019-04-22 22:36:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
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;
|
2019-04-22 22:36:59 +00:00
|
|
|
|
|
|
|
// Write the hash to disk
|
2020-03-20 20:28:31 +00:00
|
|
|
fs.writeFileSync(path.resolve(__dirname, '../.depshash'), hasher.digest('hex'));
|
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');
|
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')}`;
|
2019-11-28 00:29:53 +00:00
|
|
|
}
|
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
fs.writeFileSync(path.resolve(__dirname, '../.depshash-target'), targetContent);
|