diff --git a/ui2abc/fast-arktsc/src/main.ts b/ui2abc/fast-arktsc/src/main.ts index ee8fa3cbb153c4affd3a6f515ba4316d0260ad30..1d5881dce90ebf9d72d641f1fa95455e6c8b65b5 100644 --- a/ui2abc/fast-arktsc/src/main.ts +++ b/ui2abc/fast-arktsc/src/main.ts @@ -33,8 +33,6 @@ export const options = program .option('--link-name ', 'Path to final linked file', "all") .option('--group-by ', 'Group files by groups before passing them to compiler') - .option('--restart-states', 'Compilation with plugins and compiler restarting') - .option('--cache', 'Enable AST cache in the compiler') .option('--simultaneous', 'Use simultaneous compilation') .option('--output-dir ', 'Path to output dir (only used by AOT compilation)') @@ -84,116 +82,61 @@ function produceNinjafile( files: string[], config: string, linkPath: string, - baseUrl: string, - intermediateOutDirs: string[] ): string { // We have no Panda SDK for macOS. const tools_prefix = process.platform == "darwin" ? "echo " : "" let result: string[] = [] let basename = path.basename(compiler) let linker = compiler.replace(basename, 'arklink') - const stages = intermediateOutDirs.length const passFlags = [ - options.restartStages ? `--restart-stages` : ``, - options.cache ? `--cache` : ``, - options.simultaneous ? `--simultaneous` : ``, - ].join(` `) - let flags = options.compilerFlags ?? '' - const buildCommand = (stage: number, _in: string, _out: string) => { - return `${tools_prefix}${compiler} ${options.compilerFlags ?? ''} --ets-module --arktsconfig ${path.resolve(config)} --output ${_out} ${stages > 1 ? `--stage ${stage}` : ``} ${passFlags} ${_in}` - } + options.simultaneous ? '--simultaneous' : '', + ].filter(it => it != '').join(' ') let linker_prefix = ` rule arkts_linker - command = ${tools_prefix}${linker} --output $out -- $in + command = ${tools_prefix}${linker} --output $out -- @$out.rsp + rspfile = $out.rsp + rspfile_content = $in_newline description = "Linking ARKTS $out" ` - if (options.simultaneous) { - const groupBy = Number(options.groupBy ?? files.length) - - if (options.restartStages) { - throw new Error(`Do not mix "--simultaneous" and "--restart-stages" flags together`) - } - if (options.cache) { - throw new Error(`Do not mix "--simultaneous" and "--cache" flags together`) - } + let compiler_prefix = ` +rule arkts_compiler + command = ${tools_prefix}${compiler} ${options.compilerFlags ?? ''} --ets-module --arktsconfig ${path.resolve(config)} --output $out ${passFlags} @$out.rsp + rspfile = $out.rsp + rspfile_content = $in + description = "Compiling ARKTS $out" +` - const groupOutputs: string[] = [] + const groupBy = Number(options.groupBy ?? (options.simultaneous ? files.length : 1)) + const groupOutputs: string[] = [] + const oneGroup = groupBy >= files.length - let index = 0 - for (var j = 0; j < files.length; j += groupBy) { - const output = `${linkPath}_${index}.abc` - groupOutputs.push(output) + let index = 0 + for (var i = 0; i < files.length; i += groupBy) { + const output = oneGroup ? linkPath : `${linkPath}_${index}.abc` + groupOutputs.push(output) - const synthetic_rule = `synthetic_rule_${output}`.replaceAll('/', '_').replaceAll(':', '_') - result.push( + result.push( ` -rule ${synthetic_rule} - command = ${buildCommand(0, getFileGroupAsString(files, groupBy, j, ':', ''), output)} - -build ${output}: ${synthetic_rule} | ${getFileGroupAsString(files, groupBy, j, ' ', '')} +build ${output}: arkts_compiler ${getFileGroupAsString(files, groupBy, i, ' ', '')} ` - ) - ++index - } + ) + ++index + } + if (!oneGroup) { result.push(`build ${linkPath}: arkts_linker ${groupOutputs.join(' ')}\n`) result.push(`build link: phony ${linkPath}\n`) result.push(`build all: phony link\n`) - result.push("default all\n") - - return linker_prefix + '\n' + result.join('') - return result.join('\n') - } - - let compilerPrefix = [...Array(stages).keys()].map((i) => ` -rule arkts_compiler_stage${i} - command = ${buildCommand(i, '$in', '$out')} - description = "Compiling ARKTS ${stages > 1 ? `(stage ${i})` : ``} $in" -`).join('') - - const getTargets = (stage: number) => { - return files.map((it) => { - let output = path.resolve(intermediateOutDirs[stage], relativeOrDot(baseUrl, it)) - if (stage + 1 == stages) { - output = `${path.dirname(output)}/${path.basename(output, path.extname(output))}.abc` - } - return output - }) + } else { + result.push(`build all: phony ${linkPath}\n`) } - - const targets: string[][] = [] - for (var i = 0; i < stages; i++) { - targets.push(getTargets(i)) - } - - const groupBy = Number(options.groupBy ?? 1) - for (var i = 0; i < stages; i++) { - for (var j = 0; j < targets[i].length; j += groupBy) { - const synthetic_rule = getFileGroupAsString(targets[i], groupBy, j, ':', 'synthetic_rule_').replaceAll('/', '_').replaceAll(':', '_') - result.push( -` -rule ${synthetic_rule} - command = ${buildCommand(i, getFileGroupAsString(files, groupBy, j, ':', ''), getFileGroupAsString(targets[i], groupBy, j, ':', ''))} - -build ${getFileGroupAsString(targets[i], groupBy, j, ' ', '')}: ${synthetic_rule} | ${getFileGroupAsString(files, groupBy, j, ' ', '')}${i > 0 ? ` || stage${i - 1}` : ``} -` - ) - } - } - - for (var i = 0; i < stages; i++) { - result.push(`build stage${i}: phony ${i > 0 ? `stage${i - 1} ` : ``}${targets[i].join(' ')}\n`) - } - - result.push(`build ${linkPath}: arkts_linker ${targets[stages - 1].join(' ')}\n`) - result.push(`build link: phony ${linkPath}\n`) - result.push(`build all: phony link\n`) result.push("default all\n") - return compilerPrefix + linker_prefix + '\n' + result.join('') + + return compiler_prefix + '\n' + linker_prefix + '\n' + result.join('') } function main(configPath: string, linkName: string) { @@ -214,7 +157,7 @@ function main(configPath: string, linkName: string) { throw new Error(`No files matching include "${include.join(",")}" exclude "${exclude.join(",")}"`) } - let ninja = produceNinjafile(path.resolve(options.compiler), files, firstConfigPath, linkPath, baseUrl, intermediateOutDirs) + let ninja = produceNinjafile(path.resolve(options.compiler), files, firstConfigPath, linkPath) fs.writeFileSync(`${outDir}/build.ninja`, ninja) } diff --git a/ui2abc/libarkts/src-host/es2panda.ts b/ui2abc/libarkts/src-host/es2panda.ts index 54d08b8d4d2038aaf02e15fc4f4fc843e765d244..c176d3399dda173427633e1ecb6e3d94fa821a45 100644 --- a/ui2abc/libarkts/src-host/es2panda.ts +++ b/ui2abc/libarkts/src-host/es2panda.ts @@ -30,17 +30,17 @@ interface CommandLineOptions { simultaneous: boolean } -function maybeFromFile(argv: string[]): string[] { - const firstArg = argv[2] - if (!firstArg.startsWith('@')) return argv - const fileName = firstArg.slice(1) - const fileText = fs.readFileSync(fileName).toString() - const options = fileText.split(/[\r\n]/g).filter(it => it != '') - return [argv[0], argv[1], ...options] +function readResponseFile(arg: string | undefined): string | undefined { + if (!arg) { + return undefined + } + if (!arg.startsWith('@')) { + return arg + } + return fs.readFileSync(arg.slice(1), 'utf-8') } function parseCommandLineArgs(): CommandLineOptions { - const args = maybeFromFile(process.argv) const commander = new Command() .argument('[file]', 'Path to files to be compiled') .option('--file, ', 'Path to file to be compiled (deprecated)') @@ -49,15 +49,15 @@ function parseCommandLineArgs(): CommandLineOptions { .option('--output, ', 'The name of result file') .option('--dump-plugin-ast', 'Dump ast before and after each plugin') .option('--simultaneous', 'Use "simultaneous" mode of compilation') - .parse(args) + .parse(process.argv) const cliOptions = commander.opts() const cliArgs = commander.args - const fileArg = cliOptions.file ?? cliArgs[0] + const fileArg = readResponseFile(cliOptions.file ?? cliArgs[0]) if (!fileArg) { reportErrorAndExit(`Either --file option or file argument is required`) } - const files = fileArg.split(':').map((it: string) => path.resolve(it)) + const files = fileArg.split(/[ :]/g).map((it: string) => path.resolve(it)) const configPath = path.resolve(cliOptions.arktsconfig) const outputArg = cliOptions.output const outputs = outputArg.split(':').map((it: string) => path.resolve(it))