generate-deps-hash.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. const crypto = require('node:crypto');
  2. const fs = require('node:fs');
  3. const path = require('node:path');
  4. // Per platform hash versions to bust the cache on different platforms
  5. const HASH_VERSIONS = {
  6. darwin: 4,
  7. win32: 4,
  8. linux: 4
  9. };
  10. // Base files to hash
  11. const filesToHash = [
  12. path.resolve(__dirname, '../DEPS'),
  13. path.resolve(__dirname, '../yarn.lock'),
  14. path.resolve(__dirname, '../script/sysroots.json'),
  15. path.resolve(__dirname, '../.github/actions/checkout/action.yml')
  16. ];
  17. const addAllFiles = (dir) => {
  18. for (const child of fs.readdirSync(dir).sort()) {
  19. const childPath = path.resolve(dir, child);
  20. if (fs.statSync(childPath).isDirectory()) {
  21. addAllFiles(childPath);
  22. } else {
  23. filesToHash.push(childPath);
  24. }
  25. }
  26. };
  27. // Add all patch files to the hash
  28. addAllFiles(path.resolve(__dirname, '../patches'));
  29. // Create Hash
  30. const hasher = crypto.createHash('SHA256');
  31. const addToHashAndLog = (s) => {
  32. console.log('Hashing:', s);
  33. return hasher.update(s);
  34. };
  35. addToHashAndLog(`HASH_VERSION:${HASH_VERSIONS[process.platform]}`);
  36. for (const file of filesToHash) {
  37. console.log('Hashing Content:', file, crypto.createHash('SHA256').update(fs.readFileSync(file)).digest('hex'));
  38. hasher.update(fs.readFileSync(file));
  39. }
  40. // Add the GCLIENT_EXTRA_ARGS variable to the hash
  41. const extraArgs = process.env.GCLIENT_EXTRA_ARGS || 'no_extra_args';
  42. addToHashAndLog(extraArgs);
  43. // Write the hash to disk
  44. fs.writeFileSync(path.resolve(__dirname, '../.depshash'), hasher.digest('hex'));