gen-libc++-filenames.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. const fs = require('fs');
  2. const path = require('path');
  3. const check = process.argv.includes('--check');
  4. function findAllHeaders (basePath) {
  5. const allFiles = fs.readdirSync(basePath);
  6. const toReturn = [];
  7. for (const file of allFiles) {
  8. const absPath = path.resolve(basePath, file);
  9. if (fs.statSync(absPath).isDirectory()) {
  10. toReturn.push(...findAllHeaders(absPath));
  11. } else {
  12. toReturn.push(absPath);
  13. }
  14. }
  15. return toReturn;
  16. }
  17. for (const folder of ['libc++', 'libc++abi']) {
  18. const prettyName = folder.replace(/\+/g, 'x');
  19. const libcxxIncludeDir = path.resolve(__dirname, '..', '..', 'buildtools', 'third_party', folder, 'trunk', 'include');
  20. const gclientPath = `buildtools/third_party/${folder}/trunk/include`;
  21. const headers = findAllHeaders(libcxxIncludeDir).map(absPath => path.relative(path.resolve(__dirname, '../..', gclientPath), absPath));
  22. const content = `${prettyName}_headers = [
  23. ${headers.map(f => `"//${path.posix.join(gclientPath, f)}"`).join(',\n ')},
  24. ]
  25. ${prettyName}_licenses = [ "//buildtools/third_party/${folder}/trunk/LICENSE.TXT" ]
  26. `;
  27. const filenamesPath = path.resolve(__dirname, '..', `filenames.${prettyName}.gni`);
  28. if (check) {
  29. const currentContent = fs.readFileSync(filenamesPath, 'utf8');
  30. if (currentContent !== content) {
  31. console.log('currentContent: ', currentContent);
  32. console.log('content: ', content);
  33. throw new Error(`${prettyName} filenames need to be regenerated, latest generation does not match current file. Please run node gen-libc++-filenames.js`);
  34. }
  35. } else {
  36. console.log(filenamesPath);
  37. fs.writeFileSync(filenamesPath, content);
  38. }
  39. }