2023-06-22 14:21:42 +00:00
const fs = require ( 'node:fs' ) ;
const path = require ( 'node:path' ) ;
2021-05-22 18:48:38 +00:00
const check = process . argv . includes ( '--check' ) ;
function findAllHeaders ( basePath ) {
const allFiles = fs . readdirSync ( basePath ) ;
const toReturn = [ ] ;
for ( const file of allFiles ) {
const absPath = path . resolve ( basePath , file ) ;
if ( fs . statSync ( absPath ) . isDirectory ( ) ) {
toReturn . push ( ... findAllHeaders ( absPath ) ) ;
} else {
toReturn . push ( absPath ) ;
}
}
return toReturn ;
}
for ( const folder of [ 'libc++' , 'libc++abi' ] ) {
const prettyName = folder . replace ( /\+/g , 'x' ) ;
2023-08-15 15:49:41 +00:00
const libcxxIncludeDir = path . resolve ( _ _dirname , '..' , '..' , 'third_party' , folder , 'src' , 'include' ) ;
const gclientPath = ` third_party/ ${ folder } /src/include ` ;
2021-05-22 18:48:38 +00:00
const headers = findAllHeaders ( libcxxIncludeDir ) . map ( absPath => path . relative ( path . resolve ( _ _dirname , '../..' , gclientPath ) , absPath ) ) ;
const content = ` ${ prettyName } _headers = [
$ { headers . map ( f => ` "// ${ path . posix . join ( gclientPath , f ) } " ` ) . join ( ',\n ' ) } ,
]
2023-08-15 15:49:41 +00:00
$ { prettyName } _licenses = [ "//third_party/${folder}/src/LICENSE.TXT" ]
2021-05-22 18:48:38 +00:00
` ;
const filenamesPath = path . resolve ( _ _dirname , '..' , ` filenames. ${ prettyName } .gni ` ) ;
if ( check ) {
const currentContent = fs . readFileSync ( filenamesPath , 'utf8' ) ;
if ( currentContent !== content ) {
console . log ( 'currentContent: ' , currentContent ) ;
console . log ( 'content: ' , content ) ;
throw new Error ( ` ${ prettyName } filenames need to be regenerated, latest generation does not match current file. Please run node gen-libc++-filenames.js ` ) ;
}
} else {
console . log ( filenamesPath ) ;
fs . writeFileSync ( filenamesPath , content ) ;
}
}