generate-deps-hash.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. return hasher.update(s);
  33. };
  34. addToHashAndLog(`HASH_VERSION:${HASH_VERSIONS[process.platform]}`);
  35. for (const file of filesToHash) {
  36. hasher.update(fs.readFileSync(file));
  37. }
  38. // Add the GCLIENT_EXTRA_ARGS variable to the hash
  39. const extraArgs = process.env.GCLIENT_EXTRA_ARGS || 'no_extra_args';
  40. addToHashAndLog(extraArgs);
  41. // Write the hash to disk
  42. fs.writeFileSync(path.resolve(__dirname, '../.depshash'), hasher.digest('hex'));