electron/script/generate-deps-hash.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

64 строки
2.1 KiB
JavaScript
Исходник Обычный вид История

const crypto = require('node:crypto');
const fs = require('node:fs');
const path = require('node:path');
// Fallback to blow away old cache keys
const FALLBACK_HASH_VERSION = 3;
// Per platform hash versions to bust the cache on different platforms
const HASH_VERSIONS = {
darwin: 3,
win32: 4,
linux: 3
};
// Base files to hash
const filesToHash = [
path.resolve(__dirname, '../DEPS'),
path.resolve(__dirname, '../yarn.lock'),
path.resolve(__dirname, '../script/sysroots.json')
];
const addAllFiles = (dir) => {
for (const child of fs.readdirSync(dir).sort()) {
const childPath = path.resolve(dir, child);
if (fs.statSync(childPath).isDirectory()) {
addAllFiles(childPath);
} else {
filesToHash.push(childPath);
}
}
};
// Add all patch files to the hash
addAllFiles(path.resolve(__dirname, '../patches'));
// Create Hash
const hasher = crypto.createHash('SHA256');
feat: I guess it's esm (#37535) * fix: allow ESM loads from within ASAR files * fix: ensure that ESM entry points finish loading before app ready * fix: allow loading ESM entrypoints via default_app * fix: allow ESM loading for renderer preloads * docs: document current known limitations of esm * chore: add patches to support blending esm handlers * refactor: use SetDefersLoading instead of JoinAppCode in renderers Blink has it's own event loop so pumping the uv loop in the renderer is not enough, luckily in blink we can suspend the loading of the frame while we do additional work. * chore: add patch to expose SetDefersLoading * fix: use fileURLToPath instead of pathname * chore: update per PR feedback * fix: fs.exists/existsSync should never throw * fix: convert path to file url before importing * fix: oops * fix: oops * Update docs/tutorial/esm-limitations.md Co-authored-by: Jeremy Rose <jeremya@chromium.org> * windows... * windows... * chore: update patches * spec: fix tests and document empty body edge case * Apply suggestions from code review Co-authored-by: Daniel Scalzi <d_scalzi@yahoo.com> Co-authored-by: Jeremy Rose <jeremya@chromium.org> * spec: add tests for esm * spec: windows * chore: update per PR feedback * chore: update patches * Update shell/common/node_bindings.h Co-authored-by: Jeremy Rose <jeremya@chromium.org> * chore: update patches * rebase * use cjs loader by default for preload scripts * chore: fix lint * chore: update patches * chore: update patches * chore: fix patches * build: debug depshash * ? * Revert "build: debug depshash" This reverts commit 0de82523fb93f475226356b37418ce4b69acdcdf. * chore: allow electron as builtin protocol in esm loader * Revert "Revert "build: debug depshash"" This reverts commit ff86b1243ca6d05c9b3b38e0a6d717fb380343a4. * chore: fix esm doc * chore: update node patches --------- Co-authored-by: Jeremy Rose <jeremya@chromium.org> Co-authored-by: electron-patch-conflict-fixer[bot] <83340002+electron-patch-conflict-fixer[bot]@users.noreply.github.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Daniel Scalzi <d_scalzi@yahoo.com>
2023-08-31 03:38:07 +03:00
const addToHashAndLog = (s) => {
console.log('Hashing:', s);
return hasher.update(s);
};
addToHashAndLog(`HASH_VERSION:${HASH_VERSIONS[process.platform] || FALLBACK_HASH_VERSION}`);
for (const file of filesToHash) {
feat: I guess it's esm (#37535) * fix: allow ESM loads from within ASAR files * fix: ensure that ESM entry points finish loading before app ready * fix: allow loading ESM entrypoints via default_app * fix: allow ESM loading for renderer preloads * docs: document current known limitations of esm * chore: add patches to support blending esm handlers * refactor: use SetDefersLoading instead of JoinAppCode in renderers Blink has it's own event loop so pumping the uv loop in the renderer is not enough, luckily in blink we can suspend the loading of the frame while we do additional work. * chore: add patch to expose SetDefersLoading * fix: use fileURLToPath instead of pathname * chore: update per PR feedback * fix: fs.exists/existsSync should never throw * fix: convert path to file url before importing * fix: oops * fix: oops * Update docs/tutorial/esm-limitations.md Co-authored-by: Jeremy Rose <jeremya@chromium.org> * windows... * windows... * chore: update patches * spec: fix tests and document empty body edge case * Apply suggestions from code review Co-authored-by: Daniel Scalzi <d_scalzi@yahoo.com> Co-authored-by: Jeremy Rose <jeremya@chromium.org> * spec: add tests for esm * spec: windows * chore: update per PR feedback * chore: update patches * Update shell/common/node_bindings.h Co-authored-by: Jeremy Rose <jeremya@chromium.org> * chore: update patches * rebase * use cjs loader by default for preload scripts * chore: fix lint * chore: update patches * chore: update patches * chore: fix patches * build: debug depshash * ? * Revert "build: debug depshash" This reverts commit 0de82523fb93f475226356b37418ce4b69acdcdf. * chore: allow electron as builtin protocol in esm loader * Revert "Revert "build: debug depshash"" This reverts commit ff86b1243ca6d05c9b3b38e0a6d717fb380343a4. * chore: fix esm doc * chore: update node patches --------- Co-authored-by: Jeremy Rose <jeremya@chromium.org> Co-authored-by: electron-patch-conflict-fixer[bot] <83340002+electron-patch-conflict-fixer[bot]@users.noreply.github.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Daniel Scalzi <d_scalzi@yahoo.com>
2023-08-31 03:38:07 +03:00
console.log('Hashing Content:', file, crypto.createHash('SHA256').update(fs.readFileSync(file)).digest('hex'));
hasher.update(fs.readFileSync(file));
}
// Add the GCLIENT_EXTRA_ARGS variable to the hash
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 03:29:53 +03:00
const extraArgs = process.env.GCLIENT_EXTRA_ARGS || 'no_extra_args';
feat: I guess it's esm (#37535) * fix: allow ESM loads from within ASAR files * fix: ensure that ESM entry points finish loading before app ready * fix: allow loading ESM entrypoints via default_app * fix: allow ESM loading for renderer preloads * docs: document current known limitations of esm * chore: add patches to support blending esm handlers * refactor: use SetDefersLoading instead of JoinAppCode in renderers Blink has it's own event loop so pumping the uv loop in the renderer is not enough, luckily in blink we can suspend the loading of the frame while we do additional work. * chore: add patch to expose SetDefersLoading * fix: use fileURLToPath instead of pathname * chore: update per PR feedback * fix: fs.exists/existsSync should never throw * fix: convert path to file url before importing * fix: oops * fix: oops * Update docs/tutorial/esm-limitations.md Co-authored-by: Jeremy Rose <jeremya@chromium.org> * windows... * windows... * chore: update patches * spec: fix tests and document empty body edge case * Apply suggestions from code review Co-authored-by: Daniel Scalzi <d_scalzi@yahoo.com> Co-authored-by: Jeremy Rose <jeremya@chromium.org> * spec: add tests for esm * spec: windows * chore: update per PR feedback * chore: update patches * Update shell/common/node_bindings.h Co-authored-by: Jeremy Rose <jeremya@chromium.org> * chore: update patches * rebase * use cjs loader by default for preload scripts * chore: fix lint * chore: update patches * chore: update patches * chore: fix patches * build: debug depshash * ? * Revert "build: debug depshash" This reverts commit 0de82523fb93f475226356b37418ce4b69acdcdf. * chore: allow electron as builtin protocol in esm loader * Revert "Revert "build: debug depshash"" This reverts commit ff86b1243ca6d05c9b3b38e0a6d717fb380343a4. * chore: fix esm doc * chore: update node patches --------- Co-authored-by: Jeremy Rose <jeremya@chromium.org> Co-authored-by: electron-patch-conflict-fixer[bot] <83340002+electron-patch-conflict-fixer[bot]@users.noreply.github.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Daniel Scalzi <d_scalzi@yahoo.com>
2023-08-31 03:38:07 +03:00
addToHashAndLog(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 03:29:53 +03:00
const effectivePlatform = extraArgs.includes('host_os=mac') ? 'darwin' : process.platform;
// Write the hash to disk
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 03:29:53 +03: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');
for (const argFile of fs.readdirSync(argsDir).sort()) {
targetContent += `\n${argFile}--${crypto.createHash('SHA1').update(fs.readFileSync(path.resolve(argsDir, argFile))).digest('hex')}`;
}
fs.writeFileSync(path.resolve(__dirname, '../.depshash-target'), targetContent);