From f5f00606f89828d1db8b306962f6d53baf40ae40 Mon Sep 17 00:00:00 2001 From: Ofek Date: Tue, 1 Oct 2024 12:26:46 +0300 Subject: [PATCH] Tsifications galore (#6916) Still mostly mindless numb work, one rename that touched many files (`getArgumentParser` -> `getArgumentParserCls`), and a few real improvements. The goal is to be able to turn on `noImplicitAny` for the project, to enforce higher code quality. 600 violations to go. --- compiler-args-app.ts | 4 +- lib/base-compiler.ts | 193 ++++++++++++-------- lib/clientstate.ts | 4 +- lib/compilers/assembly.ts | 6 +- lib/compilers/avrgcc6502.ts | 4 +- lib/compilers/beebasm.ts | 4 +- lib/compilers/carbon.ts | 4 +- lib/compilers/cc65.ts | 2 +- lib/compilers/circle.ts | 6 +- lib/compilers/circt.ts | 2 +- lib/compilers/clang.ts | 17 +- lib/compilers/clean.ts | 4 +- lib/compilers/clspv.ts | 4 +- lib/compilers/cmakescript.ts | 6 +- lib/compilers/crystal.ts | 2 +- lib/compilers/d8.ts | 4 +- lib/compilers/dart.ts | 2 +- lib/compilers/dex2oat.ts | 9 +- lib/compilers/dmd.ts | 6 +- lib/compilers/dosbox-compiler.ts | 17 +- lib/compilers/dotnet.ts | 13 +- lib/compilers/elixir.ts | 2 +- lib/compilers/erlang.ts | 2 +- lib/compilers/erlangasm.ts | 2 +- lib/compilers/flang.ts | 2 +- lib/compilers/fortran.ts | 6 +- lib/compilers/gimple.ts | 4 +- lib/compilers/gnucobol.ts | 6 +- lib/compilers/golang.ts | 2 +- lib/compilers/haskell.ts | 2 +- lib/compilers/hook.ts | 8 +- lib/compilers/ispc.ts | 2 +- lib/compilers/java.ts | 4 +- lib/compilers/julia.ts | 14 +- lib/compilers/kotlin.ts | 2 +- lib/compilers/ldc.ts | 2 +- lib/compilers/llc.ts | 2 +- lib/compilers/llvm-mca.ts | 2 +- lib/compilers/llvm-mos.ts | 7 +- lib/compilers/madpascal.ts | 6 +- lib/compilers/mlir.ts | 2 +- lib/compilers/mrustc.ts | 6 +- lib/compilers/nim.ts | 2 +- lib/compilers/nvcc.ts | 6 +- lib/compilers/nvcpp.ts | 4 +- lib/compilers/nvrtc.ts | 2 +- lib/compilers/ocaml.ts | 2 +- lib/compilers/opt.ts | 2 +- lib/compilers/osaca.ts | 2 +- lib/compilers/pascal-win.ts | 4 +- lib/compilers/pascal.ts | 8 +- lib/compilers/pony.ts | 4 +- lib/compilers/ptxas.ts | 6 +- lib/compilers/python.ts | 2 +- lib/compilers/r8.ts | 4 +- lib/compilers/racket.ts | 3 +- lib/compilers/rga.ts | 8 +- lib/compilers/ruby.ts | 2 +- lib/compilers/rust.ts | 6 +- lib/compilers/scala.ts | 2 +- lib/compilers/solidity-zksync.ts | 2 +- lib/compilers/solidity.ts | 2 +- lib/compilers/spice.ts | 4 +- lib/compilers/spirv.ts | 6 +- lib/compilers/swift.ts | 2 +- lib/compilers/tablegen.ts | 2 +- lib/compilers/tendra.ts | 2 +- lib/compilers/toit.ts | 2 +- lib/compilers/turboc.ts | 7 +- lib/compilers/typescript-native.ts | 2 +- lib/compilers/v.ts | 4 +- lib/compilers/wasmtime.ts | 2 +- lib/compilers/win32-mingw-clang.ts | 2 +- lib/compilers/win32-mingw-gcc.ts | 2 +- lib/compilers/win32-vc.ts | 2 +- lib/compilers/win32-vc6.ts | 2 +- lib/compilers/wine-vc.ts | 6 +- lib/compilers/wsl-vc.ts | 4 +- lib/compilers/wyrm.ts | 9 +- lib/compilers/z88dk.ts | 8 +- lib/compilers/zigcxx.ts | 2 +- lib/exec.ts | 4 +- lib/execution/base-execution-env.ts | 11 +- lib/handlers/compile.ts | 15 +- lib/handlers/route-api.ts | 18 +- lib/llvm-ast.ts | 2 +- lib/utils.ts | 5 +- lib/win-utils.ts | 8 +- test/base-compiler-tests.ts | 2 +- test/handlers/compile-tests.ts | 1 + types/compilation/compilation.interfaces.ts | 33 ++-- types/compiler.interfaces.ts | 11 +- 92 files changed, 376 insertions(+), 275 deletions(-) diff --git a/compiler-args-app.ts b/compiler-args-app.ts index 3f5044c380b..f7279b2190a 100644 --- a/compiler-args-app.ts +++ b/compiler-args-app.ts @@ -108,8 +108,8 @@ class CompilerArgsApp { } getParser() { - if (compilerParsers[this.parserName]) { - return compilerParsers[this.parserName]; + if (compilerParsers[this.parserName as keyof typeof compilerParsers]) { + return compilerParsers[this.parserName as keyof typeof compilerParsers]; } else { console.error('Unknown parser type'); process.exit(1); diff --git a/lib/base-compiler.ts b/lib/base-compiler.ts index fe6a5a67113..4bfe0a5a37d 100644 --- a/lib/base-compiler.ts +++ b/lib/base-compiler.ts @@ -31,6 +31,7 @@ import temp from 'temp'; import _ from 'underscore'; import {unique} from '../shared/common-utils.js'; +import {PPOptions} from '../static/panes/pp-view.interfaces.js'; import {ParsedAsmResultLine} from '../types/asmresult/asmresult.interfaces.js'; import { BuildResult, @@ -47,6 +48,10 @@ import { CompileChildLibraries, CustomInputForTool, ExecutionOptions, + ExecutionOptionsWithEnv, + FiledataPair, + GccDumpOptions, + LibsAndOptions, } from '../types/compilation/compilation.interfaces.js'; import { CompilerOverrideOption, @@ -81,6 +86,7 @@ import * as cfg from './cfg/cfg.js'; import {CompilationEnvironment} from './compilation-env.js'; import {CompilerArguments} from './compiler-arguments.js'; import { + BaseParser, ClangCParser, ClangirParser, ClangParser, @@ -95,6 +101,7 @@ import {IExecutionEnvironment} from './execution/execution-env.interfaces.js'; import {getExecutionEnvironmentByKey} from './execution/index.js'; import {ExternalParserBase} from './external-parsers/base.js'; import {getExternalParserByKey} from './external-parsers/index.js'; +import {ParsedRequest} from './handlers/compile.js'; import {InstructionSets} from './instructionsets.js'; import {languages} from './languages.js'; import {LlvmAstParser} from './llvm-ast.js'; @@ -168,7 +175,7 @@ export interface SimpleOutputFilenameCompiler { } export class BaseCompiler implements ICompiler { - protected compiler: CompilerInfo; // TODO: Some missing types still present in Compiler type + public compiler: CompilerInfo; // TODO: Some missing types still present in Compiler type public lang: Language; protected compileFilename: string; protected env: CompilationEnvironment; @@ -319,7 +326,7 @@ export class BaseCompiler implements ICompiler { filterLibIds.add(lib.id); }); - const copiedLibraries = {}; + const copiedLibraries: Record = {}; _.each(allLibraries, (lib, libid) => { if (!filterLibIds.has(libid)) return; @@ -417,11 +424,19 @@ export class BaseCompiler implements ICompiler { return await exec.execute(filepath, args, execOptions); } - protected getCompilerCacheKey(compiler, args, options): CompilationCacheKey { + protected getCompilerCacheKey( + compiler: string, + args: string[], + options: ExecutionOptionsWithEnv, + ): CompilationCacheKey { return {mtime: this.mtime, compiler, args, options}; } - protected async execCompilerCached(compiler, args, options) { + protected async execCompilerCached( + compiler: string, + args: string[], + options?: ExecutionOptionsWithEnv, + ): Promise { if (this.mtime === null) { throw new Error('Attempt to access cached compiler before initialise() called'); } @@ -456,7 +471,7 @@ export class BaseCompiler implements ICompiler { } } - if (options.createAndUseTempDir) fs.remove(options.customCwd, () => {}); + if (options.createAndUseTempDir) fs.remove(options.customCwd!, () => {}); return result; } @@ -469,7 +484,7 @@ export class BaseCompiler implements ICompiler { return [ninjaPath]; } - getDefaultExecOptions(): ExecutionOptions & {env: Record} { + getDefaultExecOptions(): ExecutionOptionsWithEnv { const env = this.env.getEnv(this.compiler.needsMulti); if (!env.PATH) env.PATH = ''; env.PATH = [...this.getExtraPaths(), env.PATH].filter(Boolean).join(path.delimiter); @@ -547,7 +562,7 @@ export class BaseCompiler implements ICompiler { compiler: string, options: string[], inputFilename: string, - execOptions: ExecutionOptions & {env: Record}, + execOptions: ExecutionOptionsWithEnv, filters?: ParseFiltersAndOutputOptions, ): Promise { if (!execOptions) { @@ -566,7 +581,12 @@ export class BaseCompiler implements ICompiler { }; } - async runCompilerRawOutput(compiler, options, inputFilename, execOptions) { + async runCompilerRawOutput( + compiler: string, + options: string[], + inputFilename: string, + execOptions: ExecutionOptionsWithEnv, + ) { if (!execOptions) { execOptions = this.getDefaultExecOptions(); } @@ -590,7 +610,7 @@ export class BaseCompiler implements ICompiler { return defaultOutputFilename; } - postProcessObjdumpOutput(output) { + postProcessObjdumpOutput(output: string) { return output; } @@ -648,7 +668,7 @@ export class BaseCompiler implements ICompiler { return result; } - transformToCompilationResult(input: UnprocessedExecResult, inputFilename): CompilationResult { + transformToCompilationResult(input: UnprocessedExecResult, inputFilename: string): CompilationResult { const transformedInput = input.filenameTransform(inputFilename); return { @@ -666,7 +686,7 @@ export class BaseCompiler implements ICompiler { return utils.changeExtension(outputFilename, '.dump'); } - getGccDumpOptions(gccDumpOptions, outputFilename: string) { + getGccDumpOptions(gccDumpOptions: Record, outputFilename: string) { const addOpts = ['-fdump-passes']; // Build dump options to append to the end of the -fdump command-line flag. @@ -1198,9 +1218,9 @@ export class BaseCompiler implements ICompiler { } async generatePP( - inputFilename, - compilerOptions, - rawPpOptions, + inputFilename: string, + compilerOptions: string[], + rawPpOptions: PPOptions, ): Promise<{numberOfLinesFiltered: number; output: string}> { // -E to dump preprocessor output, remove -o so it is dumped to stdout compilerOptions = compilerOptions.concat(['-E']); @@ -1241,7 +1261,7 @@ export class BaseCompiler implements ICompiler { }; } - filterPP(stdout): any[] { + filterPP(stdout: string): any[] { // Every compiler except Chibicc, as far as I've tested, outputs these line annotations // Compiler test: https://godbolt.org/z/K7Pncjs4o // Matching things like: @@ -1282,7 +1302,7 @@ export class BaseCompiler implements ICompiler { return [numberOfLinesFiltered, filteredLines.join('\n')]; } - async applyClangFormat(output): Promise { + async applyClangFormat(output: string): Promise { // Currently hard-coding llvm style try { const [stdout, stderr] = await this.env.formatHandler.internalFormat('clangformat', 'LLVM', output); @@ -1348,14 +1368,14 @@ export class BaseCompiler implements ICompiler { } async processIrOutput( - output, + output: CompilationResult, irOptions: LLVMIrBackendOptions, filters: ParseFiltersAndOutputOptions, ): Promise<{ asm: ParsedAsmResultLine[]; languageId: string; }> { - const irPath = this.getIrOutputFilename(output.inputFilename, filters); + const irPath = this.getIrOutputFilename(output.inputFilename!, filters); if (await fs.pathExists(irPath)) { const output = await fs.readFile(irPath, 'utf8'); return await this.llvmIr.process(output, irOptions); @@ -1366,11 +1386,11 @@ export class BaseCompiler implements ICompiler { }; } - getClangirOutputFilename(inputFilename) { + getClangirOutputFilename(inputFilename: string) { return utils.changeExtension(inputFilename, '.cir'); } - async generateClangir(inputFilename, options): Promise { + async generateClangir(inputFilename: string, options: string[]): Promise { const outputFilename = this.getClangirOutputFilename(inputFilename); let newOptions = [...options]; @@ -1515,8 +1535,8 @@ export class BaseCompiler implements ICompiler { // The outputFriendlyName is a free form string used in case of error. async generateRustUnprettyOutput( inputFilename: string, - options, - unprettyOpt, + options: string[], + unprettyOpt: string, outputFilename: string, outputFriendlyName: string, ): Promise { @@ -1743,12 +1763,7 @@ export class BaseCompiler implements ICompiler { return tooling; } - buildExecutable( - compiler: string, - options: string[], - inputFilename: string, - execOptions: ExecutionOptions & {env: Record}, - ) { + buildExecutable(compiler: string, options: string[], inputFilename: string, execOptions: ExecutionOptionsWithEnv) { // default implementation, but should be overridden by compilers return this.runCompiler(compiler, options, inputFilename, execOptions); } @@ -1779,7 +1794,7 @@ export class BaseCompiler implements ICompiler { } } - protected async writeMultipleFiles(files: any[], dirPath: string) { + protected async writeMultipleFiles(files: FiledataPair[], dirPath: string) { const filesToWrite: Promise[] = []; for (const file of files) { @@ -1795,7 +1810,7 @@ export class BaseCompiler implements ICompiler { protected async writeAllFiles( dirPath: string, source: string, - files: any[], + files: FiledataPair[], filters: ParseFiltersAndOutputOptions, ) { if (!source) throw new Error(`File ${this.compileFilename} has no content or file is missing`); @@ -1812,7 +1827,12 @@ export class BaseCompiler implements ICompiler { }; } - protected async writeAllFilesCMake(dirPath: string, source: string, files, filters: ParseFiltersAndOutputOptions) { + protected async writeAllFilesCMake( + dirPath: string, + source: string, + files: FiledataPair[], + filters: ParseFiltersAndOutputOptions, + ) { if (!source) throw new Error('File CMakeLists.txt has no content or file is missing'); const inputFilename = path.join(dirPath, 'CMakeLists.txt'); @@ -1938,7 +1958,7 @@ export class BaseCompiler implements ICompiler { return false; } - async storePackageWithExecutable(key, dirPath, compilationResult) { + async storePackageWithExecutable(key: CacheKey, dirPath: string, compilationResult: CompilationResult) { const compilationResultFilename = 'compilation-result.json'; const packDir = await this.newTempDir(); @@ -1977,7 +1997,10 @@ export class BaseCompiler implements ICompiler { return execEnv.execBinary(executable, execOptionsCopy, homeDir); } - protected fixExecuteParametersForInterpreting(executeParameters, outputFilename, key) { + protected fixExecuteParametersForInterpreting( + executeParameters: ExecutableExecutionOptions, + outputFilename: string, + ) { executeParameters.args.unshift(outputFilename); } @@ -1994,7 +2017,7 @@ export class BaseCompiler implements ICompiler { await this.writeMultipleFiles(key.files, dirPath); } - this.fixExecuteParametersForInterpreting(executeParameters, outputFilename, key); + this.fixExecuteParametersForInterpreting(executeParameters, outputFilename); const result = await this.runExecutable(this.compiler.exe, executeParameters, dirPath); return { @@ -2097,20 +2120,41 @@ export class BaseCompiler implements ICompiler { return result; } - getCacheKey(source, options, backendOptions, filters, tools, libraries, files): CacheKey { + getCacheKey( + source: string, + options: string[], + backendOptions: Record, + filters: ParseFiltersAndOutputOptions, + tools, + libraries: CompileChildLibraries[], + files: FiledataPair[], + ): CacheKey { return {compiler: this.compiler, source, options, backendOptions, filters, tools, libraries, files}; } - getCmakeCacheKey(key, files): CmakeCacheKey { - const cacheKey = Object.assign({}, key); - cacheKey.compiler = this.compiler; - cacheKey.files = files; - cacheKey.api = 'cmake'; + // source: string; + // options: string[]; + // backendOptions: Record; + // filters: ParseFiltersAndOutputOptions; + // bypassCache: BypassCache; + // tools: any; + // executeParameters: ExecutionParams; + // libraries: CompileChildLibraries[]; + + getCmakeCacheKey(key: ParsedRequest, files: FiledataPair[]): CmakeCacheKey { + const cacheKey: CmakeCacheKey = { + source: key.source, + options: key.options, + backendOptions: key.backendOptions, + filters: key.filters, + libraries: key.libraries, + + compiler: this.compiler, + files: files, + api: 'cmake', + }; if (cacheKey.filters) delete cacheKey.filters.execute; - delete cacheKey.executeParameters; - delete cacheKey.tools; - return cacheKey; } @@ -2141,7 +2185,7 @@ export class BaseCompiler implements ICompiler { } as any as CompilationInfo2; } - tryAutodetectLibraries(libsAndOptions) { + tryAutodetectLibraries(libsAndOptions: LibsAndOptions): boolean { const linkFlag = this.compiler.linkFlag || '-l'; const detectedLibs: SelectedLibraryVersion[] = []; @@ -2373,7 +2417,7 @@ export class BaseCompiler implements ICompiler { buildResult.dirPath = undefined; } - getCompilerEnvironmentVariables(compilerflags) { + getCompilerEnvironmentVariables(compilerflags: string) { if (this.lang.id === 'c++') { return {...this.cmakeBaseEnv, CXXFLAGS: compilerflags}; } else if (this.lang.id === 'fortran') { @@ -2390,7 +2434,7 @@ export class BaseCompiler implements ICompiler { return this.processExecutionResult(result); } - handleUserError(error, dirPath): CompilationResult { + handleUserError(error, dirPath: string): CompilationResult { return { dirPath, okToCache: false, @@ -2414,11 +2458,11 @@ export class BaseCompiler implements ICompiler { } createCmakeExecParams( - execParams: ExecutionOptions & {env: Record}, + execParams: ExecutionOptionsWithEnv, dirPath: string, - libsAndOptions, + libsAndOptions: LibsAndOptions, toolchainPath: string, - ) { + ): ExecutionOptionsWithEnv { const cmakeExecParams = Object.assign({}, execParams); const libIncludes = this.getIncludeArguments(libsAndOptions.libraries, dirPath); @@ -2445,7 +2489,7 @@ export class BaseCompiler implements ICompiler { return cmakeExecParams; } - createLibsAndOptions(key) { + createLibsAndOptions(key: ParsedRequest): LibsAndOptions { const libsAndOptions = {libraries: key.libraries, options: key.options}; if (this.tryAutodetectLibraries(libsAndOptions)) { key.libraries = libsAndOptions.libraries; @@ -2454,7 +2498,7 @@ export class BaseCompiler implements ICompiler { return libsAndOptions; } - getExtraCMakeArgs(key): string[] { + getExtraCMakeArgs(key: ParsedRequest): string[] { return []; } @@ -2467,7 +2511,7 @@ export class BaseCompiler implements ICompiler { return ''; } - getUsedEnvironmentVariableFlags(makeExecParams) { + getUsedEnvironmentVariableFlags(makeExecParams: ExecutionOptionsWithEnv) { if (this.lang.id === 'c++') { return utils.splitArguments(makeExecParams.env.CXXFLAGS); } else if (this.lang.id === 'fortran') { @@ -2479,7 +2523,7 @@ export class BaseCompiler implements ICompiler { } } - async cmake(files, key, bypassCache: BypassCache): Promise { + async cmake(files: FiledataPair[], key: ParsedRequest, bypassCache: BypassCache): Promise { // key = {source, options, backendOptions, filters, bypassCache, tools, executeParameters, libraries}; if (!this.compiler.supportsBinary) { @@ -2508,7 +2552,7 @@ export class BaseCompiler implements ICompiler { const doExecute = key.filters.execute; const executeOptions: ExecutableExecutionOptions = { - args: key.executeParameters.args || [], + args: (key.executeParameters.args as string[]) || [], stdin: key.executeParameters.stdin || '', ldPath: this.getSharedLibraryPathsAsLdLibraryPaths(key.libraries, dirPath), runtimeTools: key.executeParameters?.runtimeTools || [], @@ -2517,7 +2561,7 @@ export class BaseCompiler implements ICompiler { const cacheKey = this.getCmakeCacheKey(key, files); - const outputFilename = this.getExecutableFilename(path.join(dirPath, 'build'), this.outputFilebase, key); + const outputFilename = this.getExecutableFilename(path.join(dirPath, 'build'), this.outputFilebase, cacheKey); let fullResult: CompilationResult = bypassExecutionCache(bypassCache) ? null @@ -2667,7 +2711,7 @@ export class BaseCompiler implements ICompiler { return fullResult; } - protected getExtraFilepath(dirPath, filename) { + protected getExtraFilepath(dirPath: string, filename: string) { // note: it's vitally important that the resulting path does not escape dirPath // (filename is user input and thus unsafe) @@ -2683,7 +2727,7 @@ export class BaseCompiler implements ICompiler { return normalized; } - fixFiltersBeforeCacheKey(filters, options, files) { + fixFiltersBeforeCacheKey(filters: ParseFiltersAndOutputOptions, options: string[], files: FiledataPair[]) { // Don't run binary for unsupported compilers, even if we're asked. if (filters.binary && !this.compiler.supportsBinary) { delete filters.binary; @@ -2716,7 +2760,7 @@ export class BaseCompiler implements ICompiler { tools, executeParameters, libraries: CompileChildLibraries[], - files, + files: FiledataPair[], ) { const optionsError = this.checkOptions(options); if (optionsError) throw optionsError; @@ -2817,7 +2861,7 @@ export class BaseCompiler implements ICompiler { return await this.afterCompilation( result, - doExecute, + doExecute!, key, executeOptions, tools, @@ -2838,13 +2882,13 @@ export class BaseCompiler implements ICompiler { async afterCompilation( result, - doExecute, - key, + doExecute: boolean, + key: CacheKey, executeOptions: ExecutableExecutionOptions, tools, backendOptions, filters, - options, + options: string[], optOutput, stackUsageOutput, bypassCache: BypassCache, @@ -2991,7 +3035,7 @@ export class BaseCompiler implements ICompiler { return output; } - async processStackUsageOutput(suPath): Promise { + async processStackUsageOutput(suPath: string): Promise { const output = StackUsageTransformer.parse(await fs.readFile(suPath, 'utf8')); if (this.compiler.demangler) { @@ -3033,7 +3077,7 @@ export class BaseCompiler implements ICompiler { ); } - async processGccDumpOutput(opts, result, removeEmptyPasses, outputFilename) { + async processGccDumpOutput(opts: GccDumpOptions, result, removeEmptyPasses, outputFilename) { const rootDir = path.dirname(result.inputFilename); if (opts.treeDump === false && opts.rtlDump === false && opts.ipaDump === false) { @@ -3145,7 +3189,7 @@ but nothing was dumped. Possible causes are: } // eslint-disable-next-line no-unused-vars - async extractDeviceCode(result, filters, compilationInfo) { + async extractDeviceCode(result: CompilationResult, filters, compilationInfo) { return result; } @@ -3200,7 +3244,7 @@ but nothing was dumped. Possible causes are: return Promise.all([asmPromise, optPromise, stackUsagePromise]); } - handlePostProcessResult(result, postResult): CompilationResult { + handlePostProcessResult(result, postResult: UnprocessedExecResult): CompilationResult { result.asm = postResult.stdout; if (postResult.code !== 0) { result.asm = ``; @@ -3219,7 +3263,7 @@ but nothing was dumped. Possible causes are: // can be circumvented in more than one way. The goal here is to respond // to simple attempts with a clear diagnostic; the service still needs to // assume that malicious actors can make the compiler open arbitrary files. - checkSource(source) { + checkSource(source: string) { const re = /^\s*#\s*i(nclude|mport)(_next)?\s+["<]((\.{1,2}|\/)[^">]*)[">]/; const failed: string[] = []; for (const [index, line] of utils.splitLines(source).entries()) { @@ -3231,7 +3275,7 @@ but nothing was dumped. Possible causes are: return null; } - protected getArgumentParser(): any { + protected getArgumentParserClass(): typeof BaseParser { const exe = this.compiler.exe.toLowerCase(); const exeFilename = path.basename(exe); if (exeFilename.includes('icc')) { @@ -3257,7 +3301,7 @@ but nothing was dumped. Possible causes are: logger.info(`Gathering ${this.compiler.id} version information on ${this.compiler.exe}...`); if (this.compiler.explicitVersion) { logger.debug(`${this.compiler.id} has forced version output: ${this.compiler.explicitVersion}`); - return {stdout: [this.compiler.explicitVersion], stderr: [], code: 0}; + return {stdout: this.compiler.explicitVersion, stderr: '', code: 0}; } const execOptions = this.getDefaultExecOptions(); const versionFlag = this.compiler.versionFlag || ['--version']; @@ -3265,7 +3309,8 @@ but nothing was dumped. Possible causes are: execOptions.ldPath = this.getSharedLibraryPathsAsLdLibraryPaths([]); try { - return await this.execCompilerCached(this.compiler.exe, versionFlag, execOptions); + const res = await this.execCompilerCached(this.compiler.exe, versionFlag, execOptions); + return {stdout: res.stdout, stderr: res.stderr, code: res.code}; } catch (err) { logger.error(`Unable to get version for compiler '${this.compiler.exe}' - ${err}`); return null; @@ -3281,8 +3326,8 @@ but nothing was dumped. Possible causes are: async getTargetsAsOverrideValues(): Promise { if (!this.buildenvsetup || !this.buildenvsetup.getCompilerArch()) { - const parser = this.getArgumentParser(); - const targets = await parser.getPossibleTargets(this); + const parserCls = this.getArgumentParserClass(); + const targets = await parserCls.getPossibleTargets(this); return targets.map(target => { return { @@ -3296,7 +3341,7 @@ but nothing was dumped. Possible causes are: } async getPossibleStdversAsOverrideValues(): Promise { - const parser = this.getArgumentParser(); + const parser = this.getArgumentParserClass(); return await parser.getPossibleStdvers(this); } @@ -3472,7 +3517,7 @@ but nothing was dumped. Possible causes are: } return this; } else { - const initResult = await this.getArgumentParser().parse(this); + const initResult = await this.getArgumentParserClass().parse(this); await this.populatePossibleOverrides(); await this.populatePossibleRuntimeTools(); diff --git a/lib/clientstate.ts b/lib/clientstate.ts index 79c0750cf60..ee1fde9450e 100644 --- a/lib/clientstate.ts +++ b/lib/clientstate.ts @@ -22,6 +22,8 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. +import {LanguageKey} from '../types/languages.interfaces.js'; + export class ClientStateCompilerOptions { binary = false; binaryObject = false; @@ -208,7 +210,7 @@ export class ClientStateTree { cmakeArgs = ''; customOutputFilename = ''; isCMakeProject = false; - compilerLanguageId = 'c++'; + compilerLanguageId: LanguageKey = 'c++'; files: MultifileFile[] = []; newFileId = 1; compilers: ClientStateCompiler[] = []; diff --git a/lib/compilers/assembly.ts b/lib/compilers/assembly.ts index c7f3ee34d30..68bb1b26d9d 100644 --- a/lib/compilers/assembly.ts +++ b/lib/compilers/assembly.ts @@ -27,7 +27,7 @@ import path from 'path'; import _ from 'underscore'; -import type {BuildResult, CompilationResult} from '../../types/compilation/compilation.interfaces.js'; +import type {BuildResult, CacheKey, CompilationResult} from '../../types/compilation/compilation.interfaces.js'; import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js'; import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; import {BaseCompiler} from '../base-compiler.js'; @@ -51,7 +51,7 @@ export class AssemblyCompiler extends BaseCompiler { return []; } - override getArgumentParser() { + override getArgumentParserClass() { return BaseParser; } @@ -132,7 +132,7 @@ export class AssemblyCompiler extends BaseCompiler { return path.join(dirPath, 'ce-asm-executable'); } - override async buildExecutableInFolder(key, dirPath: string): Promise { + override async buildExecutableInFolder(key: CacheKey, dirPath: string): Promise { const buildEnvironment = this.setupBuildEnvironment(key, dirPath, true); const writeSummary = await this.writeAllFiles(dirPath, key.source, key.files, key.filters); diff --git a/lib/compilers/avrgcc6502.ts b/lib/compilers/avrgcc6502.ts index 33aed852d87..d0e27fd1552 100644 --- a/lib/compilers/avrgcc6502.ts +++ b/lib/compilers/avrgcc6502.ts @@ -24,7 +24,7 @@ import path from 'path'; -import type {ExecutionOptions} from '../../types/compilation/compilation.interfaces.js'; +import type {ExecutionOptionsWithEnv} from '../../types/compilation/compilation.interfaces.js'; import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js'; import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; import {BaseCompiler} from '../base-compiler.js'; @@ -71,7 +71,7 @@ export class AvrGcc6502Compiler extends BaseCompiler { compiler: string, options: string[], inputFilename: string, - execOptions: ExecutionOptions & {env: Record}, + execOptions: ExecutionOptionsWithEnv, ) { if (!execOptions) { execOptions = this.getDefaultExecOptions(); diff --git a/lib/compilers/beebasm.ts b/lib/compilers/beebasm.ts index ff41ca75ea7..ba9563146e6 100644 --- a/lib/compilers/beebasm.ts +++ b/lib/compilers/beebasm.ts @@ -26,7 +26,7 @@ import path from 'path'; import fs from 'fs-extra'; -import type {ExecutionOptions} from '../../types/compilation/compilation.interfaces.js'; +import type {ExecutionOptionsWithEnv} from '../../types/compilation/compilation.interfaces.js'; import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js'; import {ArtifactType} from '../../types/tool.interfaces.js'; import {addArtifactToResult} from '../artifact-utils.js'; @@ -58,7 +58,7 @@ export class BeebAsmCompiler extends BaseCompiler { compiler: string, options: string[], inputFilename: string, - execOptions: ExecutionOptions & {env: Record}, + execOptions: ExecutionOptionsWithEnv, ) { if (!execOptions) { execOptions = this.getDefaultExecOptions(); diff --git a/lib/compilers/carbon.ts b/lib/compilers/carbon.ts index 15602153fa7..87c5b0dd3a6 100644 --- a/lib/compilers/carbon.ts +++ b/lib/compilers/carbon.ts @@ -78,7 +78,7 @@ export class CarbonCompiler extends BaseCompiler { if (result.code === 0) { // Hook to parse out the "result: 123" line at the end of the interpreted execution run. const re = /^result: (\d+)$/; - const match = re.exec(this.lastLine(result.asm)); + const match = re.exec(this.lastLine(result.asm as ResultLine[])); const code = match ? parseInt(match[1]) : -1; result.execResult = { stdout: result.stdout, @@ -102,7 +102,7 @@ export class CarbonCompiler extends BaseCompiler { return result; } - override getArgumentParser() { + override getArgumentParserClass() { // TODO: may need a custom one, based on/borrowing from ClangParser return BaseParser; } diff --git a/lib/compilers/cc65.ts b/lib/compilers/cc65.ts index 662940b5531..8191a724c65 100644 --- a/lib/compilers/cc65.ts +++ b/lib/compilers/cc65.ts @@ -71,7 +71,7 @@ export class Cc65Compiler extends BaseCompiler { } } - override getCompilerEnvironmentVariables(compilerflags) { + override getCompilerEnvironmentVariables(compilerflags: string) { const allOptions = (this.compiler.options + ' ' + compilerflags).trim(); return {...this.cmakeBaseEnv, CFLAGS: allOptions}; } diff --git a/lib/compilers/circle.ts b/lib/compilers/circle.ts index 75bf978a44b..d5e4d1ff977 100644 --- a/lib/compilers/circle.ts +++ b/lib/compilers/circle.ts @@ -24,7 +24,7 @@ import path from 'path'; -import {ExecutionOptions} from '../../types/compilation/compilation.interfaces.js'; +import {ExecutionOptionsWithEnv} from '../../types/compilation/compilation.interfaces.js'; import {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; import {BaseCompiler} from '../base-compiler.js'; @@ -35,7 +35,7 @@ export class CircleCompiler extends BaseCompiler { return 'circle'; } - protected override getArgumentParser() { + protected override getArgumentParserClass() { return CircleParser; } @@ -60,7 +60,7 @@ export class CircleCompiler extends BaseCompiler { compiler: string, options: string[], inputFilename: string, - execOptions: ExecutionOptions & {env: Record}, + execOptions: ExecutionOptionsWithEnv, ) { if (!execOptions) { execOptions = this.getDefaultExecOptions(); diff --git a/lib/compilers/circt.ts b/lib/compilers/circt.ts index fa316438d5a..ea75d7142b5 100644 --- a/lib/compilers/circt.ts +++ b/lib/compilers/circt.ts @@ -64,7 +64,7 @@ export class CIRCTCompiler extends BaseCompiler { return ['-o', outputFilename]; } - override getArgumentParser(): any { + override getArgumentParserClass(): any { return BaseParser; } diff --git a/lib/compilers/clang.ts b/lib/compilers/clang.ts index b446711750e..cde1cce6dd5 100644 --- a/lib/compilers/clang.ts +++ b/lib/compilers/clang.ts @@ -30,8 +30,9 @@ import _ from 'underscore'; import type { BuildResult, BypassCache, + CacheKey, CompilationResult, - ExecutionOptions, + ExecutionOptionsWithEnv, } from '../../types/compilation/compilation.interfaces.js'; import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js'; import type {ExecutableExecutionOptions, UnprocessedExecResult} from '../../types/execution/execution.interfaces.js'; @@ -185,13 +186,13 @@ export class ClangCompiler extends BaseCompiler { override async afterCompilation( result, - doExecute, - key, - executeParameters, + doExecute: boolean, + key: CacheKey, + executeParameters: ExecutableExecutionOptions, tools, backendOptions, filters, - options, + options: string[], optOutput, stackUsageOutput, bypassCache: BypassCache, @@ -223,7 +224,7 @@ export class ClangCompiler extends BaseCompiler { compiler: string, options: string[], inputFilename: string, - execOptions: ExecutionOptions & {env: Record}, + execOptions: ExecutionOptionsWithEnv, ) { if (!execOptions) { execOptions = this.getDefaultExecOptions(); @@ -253,7 +254,7 @@ export class ClangCompiler extends BaseCompiler { return devices; } - override async extractDeviceCode(result, filters, compilationInfo) { + override async extractDeviceCode(result: CompilationResult, filters, compilationInfo) { const split = await this.splitDeviceCode(result.asm); if (!split) return result; @@ -376,7 +377,7 @@ export class ClangIntelCompiler extends ClangCompiler { } } - override getDefaultExecOptions(): ExecutionOptions & {env: Record} { + override getDefaultExecOptions(): ExecutionOptionsWithEnv { const opts = super.getDefaultExecOptions(); opts.env.PATH = process.env.PATH + path.delimiter + path.dirname(this.compiler.exe); diff --git a/lib/compilers/clean.ts b/lib/compilers/clean.ts index 169b964eab2..34594cafa7c 100644 --- a/lib/compilers/clean.ts +++ b/lib/compilers/clean.ts @@ -26,7 +26,7 @@ import path from 'path'; import fs from 'fs-extra'; -import type {ExecutionOptions} from '../../types/compilation/compilation.interfaces.js'; +import type {ExecutionOptionsWithEnv} from '../../types/compilation/compilation.interfaces.js'; import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; import {BaseCompiler} from '../base-compiler.js'; import * as utils from '../utils.js'; @@ -96,7 +96,7 @@ export class CleanCompiler extends BaseCompiler { compiler: string, options: string[], inputFilename: string, - execOptions: ExecutionOptions & {env: Record}, + execOptions: ExecutionOptionsWithEnv, ) { const tmpDir = path.dirname(inputFilename); const moduleName = path.basename(inputFilename, '.icl'); diff --git a/lib/compilers/clspv.ts b/lib/compilers/clspv.ts index 862fb0a9da8..d3719d5d300 100644 --- a/lib/compilers/clspv.ts +++ b/lib/compilers/clspv.ts @@ -24,7 +24,7 @@ import path from 'path'; -import type {ExecutionOptions} from '../../types/compilation/compilation.interfaces.js'; +import type {ExecutionOptionsWithEnv} from '../../types/compilation/compilation.interfaces.js'; import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js'; import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; import {BaseCompiler} from '../base-compiler.js'; @@ -67,7 +67,7 @@ export class CLSPVCompiler extends BaseCompiler { compiler: string, options: string[], inputFilename: string, - execOptions: ExecutionOptions & {env: Record}, + execOptions: ExecutionOptionsWithEnv, ) { const sourceDir = path.dirname(inputFilename); const spvBinFilename = this.getPrimaryOutputFilename(sourceDir, this.outputFilebase); diff --git a/lib/compilers/cmakescript.ts b/lib/compilers/cmakescript.ts index 7390d2fd6bf..91dfe62b176 100644 --- a/lib/compilers/cmakescript.ts +++ b/lib/compilers/cmakescript.ts @@ -22,6 +22,7 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. +import {ExecutableExecutionOptions} from '../../types/execution/execution.interfaces.js'; import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; import {BaseCompiler} from '../base-compiler.js'; @@ -41,7 +42,10 @@ export class CMakeScriptCompiler extends BaseCompiler { return userOptions; } - override fixExecuteParametersForInterpreting(executeParameters, outputFilename, key) { + override fixExecuteParametersForInterpreting( + executeParameters: ExecutableExecutionOptions, + outputFilename: string, + ) { executeParameters.args.push('-P', outputFilename); } } diff --git a/lib/compilers/crystal.ts b/lib/compilers/crystal.ts index 44ef3e6ab2e..4eb3e9a2b51 100644 --- a/lib/compilers/crystal.ts +++ b/lib/compilers/crystal.ts @@ -101,7 +101,7 @@ export class CrystalCompiler extends BaseCompiler { return this.getExecutableFilename(path.dirname(defaultOutputFilename), this.outputFilebase); } - override getArgumentParser() { + override getArgumentParserClass() { return CrystalParser; } diff --git a/lib/compilers/d8.ts b/lib/compilers/d8.ts index cd0b3c8c40d..4002f491f18 100644 --- a/lib/compilers/d8.ts +++ b/lib/compilers/d8.ts @@ -28,7 +28,7 @@ import fs from 'fs-extra'; import _ from 'underscore'; import type {ParsedAsmResult, ParsedAsmResultLine} from '../../types/asmresult/asmresult.interfaces.js'; -import {CompilationResult, ExecutionOptions} from '../../types/compilation/compilation.interfaces.js'; +import {CompilationResult, ExecutionOptionsWithEnv} from '../../types/compilation/compilation.interfaces.js'; import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js'; import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; import type {SelectedLibraryVersion} from '../../types/libraries/libraries.interfaces.js'; @@ -78,7 +78,7 @@ export class D8Compiler extends BaseCompiler implements SimpleOutputFilenameComp compiler: string, options: string[], inputFilename: string, - execOptions: ExecutionOptions & {env: Record}, + execOptions: ExecutionOptionsWithEnv, filters?: ParseFiltersAndOutputOptions, ): Promise { const preliminaryCompilePath = path.dirname(inputFilename); diff --git a/lib/compilers/dart.ts b/lib/compilers/dart.ts index c465f239d64..8b72d2ee52e 100644 --- a/lib/compilers/dart.ts +++ b/lib/compilers/dart.ts @@ -84,7 +84,7 @@ export class DartCompiler extends BaseCompiler { } } - override getArgumentParser() { + override getArgumentParserClass() { return BaseParser; } } diff --git a/lib/compilers/dex2oat.ts b/lib/compilers/dex2oat.ts index 5f9c0281c56..33f022dbc29 100644 --- a/lib/compilers/dex2oat.ts +++ b/lib/compilers/dex2oat.ts @@ -28,7 +28,7 @@ import fs from 'fs-extra'; import _ from 'underscore'; import type {ParsedAsmResult, ParsedAsmResultLine} from '../../types/asmresult/asmresult.interfaces.js'; -import {CompilationResult, ExecutionOptions} from '../../types/compilation/compilation.interfaces.js'; +import {CompilationResult, ExecutionOptionsWithEnv} from '../../types/compilation/compilation.interfaces.js'; import type { OptPipelineBackendOptions, OptPipelineOutput, @@ -129,7 +129,7 @@ export class Dex2OatCompiler extends BaseCompiler { compiler: string, options: string[], inputFilename: string, - execOptions: ExecutionOptions & {env: Record}, + execOptions: ExecutionOptionsWithEnv, filters?: ParseFiltersAndOutputOptions, ): Promise { // Make sure --full-output from previous invocations doesn't persist. @@ -355,8 +355,9 @@ export class Dex2OatCompiler extends BaseCompiler { const versionFile = this.artArtifactDir + '/snapshot-creation-build-number.txt'; const version = fs.readFileSync(versionFile, {encoding: 'utf8'}); return { - stdout: ['Android Build ' + version], - stderr: [], + stdout: 'Android Build ' + version, + stderr: '', + code: 0, }; } diff --git a/lib/compilers/dmd.ts b/lib/compilers/dmd.ts index c198fa29943..92df38fd0a3 100644 --- a/lib/compilers/dmd.ts +++ b/lib/compilers/dmd.ts @@ -24,7 +24,7 @@ import path from 'path'; -import {ExecutionOptions} from '../../types/compilation/compilation.interfaces.js'; +import {ExecutionOptionsWithEnv} from '../../types/compilation/compilation.interfaces.js'; import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js'; import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; import {BaseCompiler} from '../base-compiler.js'; @@ -69,14 +69,14 @@ export class DMDCompiler extends BaseCompiler { compiler: string, options: string[], inputFilename: string, - execOptions: ExecutionOptions & {env: Record}, + execOptions: ExecutionOptionsWithEnv, ) { options = options.filter(param => param !== '-c'); return this.runCompiler(compiler, options, inputFilename, execOptions); } - override getArgumentParser() { + override getArgumentParserClass() { return ClangParser; } diff --git a/lib/compilers/dosbox-compiler.ts b/lib/compilers/dosbox-compiler.ts index 690d41f4474..c0d5313d6e8 100644 --- a/lib/compilers/dosbox-compiler.ts +++ b/lib/compilers/dosbox-compiler.ts @@ -26,8 +26,9 @@ import path from 'path'; import fs from 'fs-extra'; -import type {ExecutionOptions} from '../../types/compilation/compilation.interfaces.js'; +import type {ExecutionOptionsWithEnv} from '../../types/compilation/compilation.interfaces.js'; import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js'; +import {UnprocessedExecResult} from '../../types/execution/execution.interfaces.js'; import {BaseCompiler} from '../base-compiler.js'; import {CompilationEnvironment} from '../compilation-env.js'; import * as exec from '../exec.js'; @@ -103,8 +104,8 @@ export class DosboxCompiler extends BaseCompiler { protected override async execCompilerCached( compiler: string, args: string[], - options: ExecutionOptions & {env: Record}, - ) { + options?: ExecutionOptionsWithEnv, + ): Promise { if (this.mtime === null) { throw new Error('Attempt to access cached compiler before initialise() called'); } @@ -115,10 +116,12 @@ export class DosboxCompiler extends BaseCompiler { } const key = this.getCompilerCacheKey(compiler, args, options); - let result = await this.env.compilerCacheGet(key as any); + let result: UnprocessedExecResult = await this.env.compilerCacheGet(key as any); if (!result) { - result = await this.env.enqueue(async () => this.exec(compiler, args, options)); - if (result.okToCache) { + result = await (this.env.enqueue(async () => + this.exec(compiler, args, options), + ) as Promise); + if (result && result.okToCache) { this.env .compilerCachePut(key as any, result, undefined) .then(() => { @@ -160,7 +163,7 @@ export class DosboxCompiler extends BaseCompiler { compiler: string, options: string[], inputFilename: string, - execOptions: ExecutionOptions & {env: Record}, + execOptions: ExecutionOptionsWithEnv, ) { return super.runCompiler( compiler, diff --git a/lib/compilers/dotnet.ts b/lib/compilers/dotnet.ts index 505ff19aeaa..a2f62c06398 100644 --- a/lib/compilers/dotnet.ts +++ b/lib/compilers/dotnet.ts @@ -31,6 +31,7 @@ import type { CompilationResult, CompileChildLibraries, ExecutionOptions, + ExecutionOptionsWithEnv, } from '../../types/compilation/compilation.interfaces.js'; import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js'; import {ExecutableExecutionOptions} from '../../types/execution/execution.interfaces.js'; @@ -191,11 +192,7 @@ class DotNetCompiler extends BaseCompiler { } } - setCompilerExecOptions( - execOptions: ExecutionOptions & {env: Record}, - programDir: string, - skipNuget: boolean = false, - ) { + setCompilerExecOptions(execOptions: ExecutionOptionsWithEnv, programDir: string, skipNuget: boolean = false) { if (!execOptions) { execOptions = this.getDefaultExecOptions(); } @@ -228,7 +225,7 @@ class DotNetCompiler extends BaseCompiler { compiler: string, options: string[], inputFilename: string, - execOptions: ExecutionOptions & {env: Record}, + execOptions: ExecutionOptionsWithEnv, ) { const dirPath = path.dirname(inputFilename); const inputFilenameSafe = this.filename(inputFilename); @@ -256,7 +253,7 @@ class DotNetCompiler extends BaseCompiler { async buildToDll( compiler: string, inputFilename: string, - execOptions: ExecutionOptions & {env: Record}, + execOptions: ExecutionOptionsWithEnv, buildToBinary?: boolean, ): Promise { const programDir = path.dirname(inputFilename); @@ -310,7 +307,7 @@ class DotNetCompiler extends BaseCompiler { compiler: string, options: string[], inputFilename: string, - execOptions: ExecutionOptions & {env: Record}, + execOptions: ExecutionOptionsWithEnv, filters: ParseFiltersAndOutputOptions, ): Promise { const corerunArgs: string[] = []; diff --git a/lib/compilers/elixir.ts b/lib/compilers/elixir.ts index 31ecb98498a..c4087ee0d8a 100644 --- a/lib/compilers/elixir.ts +++ b/lib/compilers/elixir.ts @@ -63,7 +63,7 @@ export class ElixirCompiler extends BaseCompiler { return path.join(dirPath, `${outputFilebase}`); } - override getArgumentParser() { + override getArgumentParserClass() { return ElixirParser; } } diff --git a/lib/compilers/erlang.ts b/lib/compilers/erlang.ts index c84c2a79987..66cc6af03b6 100644 --- a/lib/compilers/erlang.ts +++ b/lib/compilers/erlang.ts @@ -65,7 +65,7 @@ export class ErlangCompiler extends BaseCompiler { return path.join(dirPath, `${outputFilebase}.S`); } - override getArgumentParser() { + override getArgumentParserClass() { return ErlangParser; } } diff --git a/lib/compilers/erlangasm.ts b/lib/compilers/erlangasm.ts index 6471803f429..0aee2b0a28b 100644 --- a/lib/compilers/erlangasm.ts +++ b/lib/compilers/erlangasm.ts @@ -69,7 +69,7 @@ export class ErlangAsmCompiler extends BaseCompiler { return path.join(dirPath, `${outputFilebase}.asm`); } - override getArgumentParser() { + override getArgumentParserClass() { return ErlangParser; } } diff --git a/lib/compilers/flang.ts b/lib/compilers/flang.ts index 5f36ee0fc27..89994fec188 100644 --- a/lib/compilers/flang.ts +++ b/lib/compilers/flang.ts @@ -36,7 +36,7 @@ export class FlangCompiler extends FortranCompiler { return 'flang'; } - protected override getArgumentParser(): any { + protected override getArgumentParserClass(): any { return FlangParser; } diff --git a/lib/compilers/fortran.ts b/lib/compilers/fortran.ts index aaf6d475e1c..5e4ed5a7703 100644 --- a/lib/compilers/fortran.ts +++ b/lib/compilers/fortran.ts @@ -28,7 +28,7 @@ import path from 'path'; import type { CompilationResult, CompileChildLibraries, - ExecutionOptions, + ExecutionOptionsWithEnv, } from '../../types/compilation/compilation.interfaces.js'; import {SelectedLibraryVersion} from '../../types/libraries/libraries.interfaces.js'; import {BaseCompiler} from '../base-compiler.js'; @@ -41,7 +41,7 @@ export class FortranCompiler extends BaseCompiler { return 'fortran'; } - protected override getArgumentParser(): any { + protected override getArgumentParserClass(): any { return GccFortranParser; } @@ -91,7 +91,7 @@ export class FortranCompiler extends BaseCompiler { compiler: string, options: string[], inputFilename: string, - execOptions: ExecutionOptions & {env: Record}, + execOptions: ExecutionOptionsWithEnv, ): Promise { if (!execOptions) { execOptions = this.getDefaultExecOptions(); diff --git a/lib/compilers/gimple.ts b/lib/compilers/gimple.ts index aaaf1746dcc..2d5db604cac 100644 --- a/lib/compilers/gimple.ts +++ b/lib/compilers/gimple.ts @@ -23,7 +23,7 @@ // POSSIBILITY OF SUCH DAMAGE. import path from 'path'; -import {ExecutionOptions} from '../../types/compilation/compilation.interfaces.js'; +import {ExecutionOptionsWithEnv} from '../../types/compilation/compilation.interfaces.js'; import {BaseCompiler} from '../base-compiler.js'; export class GCCGimpleCompiler extends BaseCompiler { @@ -35,7 +35,7 @@ export class GCCGimpleCompiler extends BaseCompiler { compiler: string, options: string[], inputFilename: string, - execOptions: ExecutionOptions & {env: Record}, + execOptions: ExecutionOptionsWithEnv, ) { if (!execOptions) { execOptions = this.getDefaultExecOptions(); diff --git a/lib/compilers/gnucobol.ts b/lib/compilers/gnucobol.ts index b0ea7e681a3..399a89510a2 100644 --- a/lib/compilers/gnucobol.ts +++ b/lib/compilers/gnucobol.ts @@ -24,7 +24,7 @@ import path from 'path'; -import type {CompileChildLibraries, ExecutionOptions} from '../../types/compilation/compilation.interfaces.js'; +import type {CompileChildLibraries, ExecutionOptionsWithEnv} from '../../types/compilation/compilation.interfaces.js'; import {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js'; import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; import {BaseCompiler} from '../base-compiler.js'; @@ -66,7 +66,7 @@ export class GnuCobolCompiler extends BaseCompiler { return 'asm'; } - override getDefaultExecOptions(): ExecutionOptions & {env: Record} { + override getDefaultExecOptions(): ExecutionOptionsWithEnv { const result = super.getDefaultExecOptions(); result.env.COB_CONFIG_DIR = this.configDir; result.env.COB_COPY_DIR = this.copyDir; @@ -130,7 +130,7 @@ export class GnuCobolCompiler extends BaseCompiler { return []; } - protected override getArgumentParser() { + protected override getArgumentParserClass() { return GnuCobolParser; } } diff --git a/lib/compilers/golang.ts b/lib/compilers/golang.ts index 3c8cca9bad7..cf376856f31 100644 --- a/lib/compilers/golang.ts +++ b/lib/compilers/golang.ts @@ -270,7 +270,7 @@ export class GolangCompiler extends BaseCompiler { return options; } - override getArgumentParser(): any { + override getArgumentParserClass(): any { return GolangParser; } diff --git a/lib/compilers/haskell.ts b/lib/compilers/haskell.ts index 1248bcebc14..26a55f893bc 100644 --- a/lib/compilers/haskell.ts +++ b/lib/compilers/haskell.ts @@ -78,7 +78,7 @@ export class HaskellCompiler extends BaseCompiler { return [libPathFlag + '.', ...this.getSharedLibraryPaths(libraries).map(path => libPathFlag + path)]; } - override getArgumentParser(): any { + override getArgumentParserClass(): any { return GHCParser; } } diff --git a/lib/compilers/hook.ts b/lib/compilers/hook.ts index 50aa420a3ad..91959cbc253 100644 --- a/lib/compilers/hook.ts +++ b/lib/compilers/hook.ts @@ -24,7 +24,11 @@ import path from 'path'; -import type {CacheKey, CompilationResult, ExecutionOptions} from '../../types/compilation/compilation.interfaces.js'; +import type { + CacheKey, + CompilationResult, + ExecutionOptionsWithEnv, +} from '../../types/compilation/compilation.interfaces.js'; import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js'; import type {ExecutableExecutionOptions} from '../../types/execution/execution.interfaces.js'; import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; @@ -67,7 +71,7 @@ export class HookCompiler extends BaseCompiler { compiler: string, options: string[], inputFilename: string, - execOptions: ExecutionOptions & {env: Record}, + execOptions: ExecutionOptionsWithEnv, ): Promise { const dirPath = path.dirname(inputFilename); const outputFilename = this.getOutputFilename(dirPath); diff --git a/lib/compilers/ispc.ts b/lib/compilers/ispc.ts index 4955dc4aeda..271b527b8df 100644 --- a/lib/compilers/ispc.ts +++ b/lib/compilers/ispc.ts @@ -74,7 +74,7 @@ export class ISPCCompiler extends BaseCompiler { return super.generateIR(inputFilename, newOptions, irOptions, produceCfg, filters); } - override getArgumentParser() { + override getArgumentParserClass() { return ISPCParser; } diff --git a/lib/compilers/java.ts b/lib/compilers/java.ts index 465b7f7896a..9f590c45660 100644 --- a/lib/compilers/java.ts +++ b/lib/compilers/java.ts @@ -203,7 +203,7 @@ export class JavaCompiler extends BaseCompiler implements SimpleOutputFilenameCo return 'Main'; } - override getArgumentParser() { + override getArgumentParserClass() { return JavaParser; } @@ -292,7 +292,7 @@ export class JavaCompiler extends BaseCompiler implements SimpleOutputFilenameCo return {asm: segments}; } - parseAsmForClass(javapOut) { + parseAsmForClass(javapOut: string) { const textsBeforeMethod: string[] = []; const methods: {instructions: any[]; startLine?: number}[] = []; // javap output puts ` Code:` after every signature. (Line will not be shown to user) diff --git a/lib/compilers/julia.ts b/lib/compilers/julia.ts index c099ddbcb56..4600a36221a 100644 --- a/lib/compilers/julia.ts +++ b/lib/compilers/julia.ts @@ -24,8 +24,9 @@ import path from 'path'; -import type {CompilationResult, ExecutionOptions} from '../../types/compilation/compilation.interfaces.js'; +import type {CompilationResult, ExecutionOptionsWithEnv} from '../../types/compilation/compilation.interfaces.js'; import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js'; +import {ExecutableExecutionOptions} from '../../types/execution/execution.interfaces.js'; import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; import {BaseCompiler} from '../base-compiler.js'; import {CompilationEnvironment} from '../compilation-env.js'; @@ -65,12 +66,15 @@ export class JuliaCompiler extends BaseCompiler { return []; } - override getArgumentParser() { + override getArgumentParserClass() { return JuliaParser; } - override fixExecuteParametersForInterpreting(executeParameters, outputFilename, key) { - super.fixExecuteParametersForInterpreting(executeParameters, outputFilename, key); + override fixExecuteParametersForInterpreting( + executeParameters: ExecutableExecutionOptions, + outputFilename: string, + ) { + super.fixExecuteParametersForInterpreting(executeParameters, outputFilename); executeParameters.args.unshift('--'); } @@ -78,7 +82,7 @@ export class JuliaCompiler extends BaseCompiler { compiler: string, options: string[], inputFilename: string, - execOptions: ExecutionOptions & {env: Record}, + execOptions: ExecutionOptionsWithEnv, filters?: ParseFiltersAndOutputOptions, ): Promise { if (!execOptions) { diff --git a/lib/compilers/kotlin.ts b/lib/compilers/kotlin.ts index 5afcfe19374..e8a0902082f 100644 --- a/lib/compilers/kotlin.ts +++ b/lib/compilers/kotlin.ts @@ -140,7 +140,7 @@ export class KotlinCompiler extends JavaCompiler implements SimpleOutputFilename }; } - override getArgumentParser() { + override getArgumentParserClass() { return KotlinParser; } } diff --git a/lib/compilers/ldc.ts b/lib/compilers/ldc.ts index bd426d8c1cc..65ee6e59922 100644 --- a/lib/compilers/ldc.ts +++ b/lib/compilers/ldc.ts @@ -87,7 +87,7 @@ export class LDCCompiler extends BaseCompiler { return options; } - override getArgumentParser() { + override getArgumentParserClass() { return LDCParser; } diff --git a/lib/compilers/llc.ts b/lib/compilers/llc.ts index 6dafebd4e3e..2f3c673c0c2 100644 --- a/lib/compilers/llc.ts +++ b/lib/compilers/llc.ts @@ -55,7 +55,7 @@ export class LLCCompiler extends BaseCompiler { return options; } - override getArgumentParser() { + override getArgumentParserClass() { return ClangParser; } } diff --git a/lib/compilers/llvm-mca.ts b/lib/compilers/llvm-mca.ts index b60645262af..9d9071b694b 100644 --- a/lib/compilers/llvm-mca.ts +++ b/lib/compilers/llvm-mca.ts @@ -49,7 +49,7 @@ export class LLVMmcaTool extends AnalysisTool { return options; } - override getArgumentParser() { + override getArgumentParserClass() { return ClangParser; } } diff --git a/lib/compilers/llvm-mos.ts b/lib/compilers/llvm-mos.ts index ee72f142818..736e2c5e091 100644 --- a/lib/compilers/llvm-mos.ts +++ b/lib/compilers/llvm-mos.ts @@ -24,12 +24,13 @@ import path from 'path'; -import type {CompilationResult} from '../../types/compilation/compilation.interfaces.js'; +import type {CompilationResult, FiledataPair} from '../../types/compilation/compilation.interfaces.js'; import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js'; import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; import {ArtifactType} from '../../types/tool.interfaces.js'; import {addArtifactToResult} from '../artifact-utils.js'; import {CompilationEnvironment} from '../compilation-env.js'; +import {ParsedRequest} from '../handlers/compile.js'; import * as utils from '../utils.js'; import {ClangCompiler} from './clang.js'; @@ -45,11 +46,11 @@ export class LLVMMOSCompiler extends ClangCompiler { this.toolchainPath = path.normalize(path.join(path.dirname(this.compiler.exe), '..')); } - override getExtraCMakeArgs(key): string[] { + override getExtraCMakeArgs(key: ParsedRequest): string[] { return [`-DCMAKE_PREFIX_PATH=${this.toolchainPath}`]; } - override fixFiltersBeforeCacheKey(filters, options, files) { + override fixFiltersBeforeCacheKey(filters: ParseFiltersAndOutputOptions, options: string[], files: FiledataPair[]) { filters.binary = false; } diff --git a/lib/compilers/madpascal.ts b/lib/compilers/madpascal.ts index 00a7ae02478..d084ba16fdb 100644 --- a/lib/compilers/madpascal.ts +++ b/lib/compilers/madpascal.ts @@ -26,7 +26,7 @@ import path from 'path'; import fs from 'fs-extra'; -import {CompilationResult, ExecutionOptions} from '../../types/compilation/compilation.interfaces.js'; +import {CompilationResult, ExecutionOptionsWithEnv} from '../../types/compilation/compilation.interfaces.js'; import {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js'; import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; import {ArtifactType} from '../../types/tool.interfaces.js'; @@ -84,7 +84,7 @@ export class MadPascalCompiler extends BaseCompiler { return this.getCompilerOutputFilename(dirPath, outputFilebase); } - protected override getArgumentParser(): any { + protected override getArgumentParserClass(): any { return MadpascalParser; } @@ -112,7 +112,7 @@ export class MadPascalCompiler extends BaseCompiler { compiler: string, options: string[], inputFilename: string, - execOptions: ExecutionOptions & {env: Record}, + execOptions: ExecutionOptionsWithEnv, filters?: ParseFiltersAndOutputOptions, ): Promise { if (!execOptions) { diff --git a/lib/compilers/mlir.ts b/lib/compilers/mlir.ts index 38143f1952f..4803f09a9a3 100644 --- a/lib/compilers/mlir.ts +++ b/lib/compilers/mlir.ts @@ -69,7 +69,7 @@ export class MLIRCompiler extends BaseCompiler { return ['-o', outputFilename]; } - override getArgumentParser(): any { + override getArgumentParserClass(): any { return BaseParser; } diff --git a/lib/compilers/mrustc.ts b/lib/compilers/mrustc.ts index 8f015578585..e929d87e60a 100644 --- a/lib/compilers/mrustc.ts +++ b/lib/compilers/mrustc.ts @@ -24,7 +24,7 @@ import path from 'path'; -import type {ExecutionOptions} from '../../types/compilation/compilation.interfaces.js'; +import type {ExecutionOptionsWithEnv} from '../../types/compilation/compilation.interfaces.js'; import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; import {BaseCompiler} from '../base-compiler.js'; @@ -60,7 +60,7 @@ export class MrustcCompiler extends BaseCompiler { compiler: string, options: string[], inputFilename: string, - execOptions: ExecutionOptions & {env: Record}, + execOptions: ExecutionOptionsWithEnv, ) { // mrustc will always invoke a C compiler on its C output to create a final exec/object. // There's no easy way to disable this last step, so simply faking it with 'true' works. @@ -73,7 +73,7 @@ export class MrustcCompiler extends BaseCompiler { return path.join(dirPath, `${path.basename(this.compileFilename, this.lang.extensions[0])}.c`); } - override getArgumentParser() { + override getArgumentParserClass() { return MrustcParser; } diff --git a/lib/compilers/nim.ts b/lib/compilers/nim.ts index 9903a7acd41..dc2940c2e2c 100644 --- a/lib/compilers/nim.ts +++ b/lib/compilers/nim.ts @@ -111,7 +111,7 @@ export class NimCompiler extends BaseCompiler { return []; } - override getArgumentParser() { + override getArgumentParserClass() { return NimParser; } diff --git a/lib/compilers/nvcc.ts b/lib/compilers/nvcc.ts index be86a51b67a..f81136eeddd 100644 --- a/lib/compilers/nvcc.ts +++ b/lib/compilers/nvcc.ts @@ -28,7 +28,7 @@ import Path from 'path'; import Semver from 'semver'; import _ from 'underscore'; -import type {CompilationInfo} from '../../types/compilation/compilation.interfaces.js'; +import type {CompilationInfo, CompilationResult} from '../../types/compilation/compilation.interfaces.js'; import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js'; import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; import {unwrap} from '../assert.js'; @@ -68,7 +68,7 @@ export class NvccCompiler extends BaseCompiler { return opts; } - override getArgumentParser() { + override getArgumentParserClass() { return ClangParser; } @@ -134,7 +134,7 @@ export class NvccCompiler extends BaseCompiler { return Promise.all([asmPromise, optPromise, '']); } - override async extractDeviceCode(result, filters, compilationInfo: CompilationInfo) { + override async extractDeviceCode(result: CompilationResult, filters, compilationInfo: CompilationInfo) { const {dirPath} = result; const {demangle} = filters; const devices = {...result.devices}; diff --git a/lib/compilers/nvcpp.ts b/lib/compilers/nvcpp.ts index f63d1521e6d..dfdb13d73d7 100644 --- a/lib/compilers/nvcpp.ts +++ b/lib/compilers/nvcpp.ts @@ -25,7 +25,7 @@ import * as fs from 'fs/promises'; import path from 'path'; -import {CompilationInfo} from '../../types/compilation/compilation.interfaces.js'; +import {CompilationInfo, CompilationResult} from '../../types/compilation/compilation.interfaces.js'; import {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js'; import {unwrap} from '../assert.js'; import {BaseCompiler} from '../base-compiler.js'; @@ -89,7 +89,7 @@ export class NvcppCompiler extends BaseCompiler { return false; } - override async extractDeviceCode(result, filters, compilationInfo: CompilationInfo) { + override async extractDeviceCode(result: CompilationResult, filters, compilationInfo: CompilationInfo) { const {dirPath} = result; const {demangle} = filters; const devices = {...result.devices}; diff --git a/lib/compilers/nvrtc.ts b/lib/compilers/nvrtc.ts index 6fd8525407a..dcb828c6454 100644 --- a/lib/compilers/nvrtc.ts +++ b/lib/compilers/nvrtc.ts @@ -51,7 +51,7 @@ export class NvrtcCompiler extends BaseCompiler { return ['-o', this.filename(outputFilename), '-lineinfo', filters.binary ? '-cubin' : '-ptx']; } - override getArgumentParser() { + override getArgumentParserClass() { return ClangParser; } diff --git a/lib/compilers/ocaml.ts b/lib/compilers/ocaml.ts index b5bc18e1cc3..c57ec618415 100644 --- a/lib/compilers/ocaml.ts +++ b/lib/compilers/ocaml.ts @@ -57,7 +57,7 @@ export class OCamlCompiler extends BaseCompiler { return options; } - override getArgumentParser() { + override getArgumentParserClass() { return PascalParser; } } diff --git a/lib/compilers/opt.ts b/lib/compilers/opt.ts index ed5ee769a40..23bfcb00adf 100644 --- a/lib/compilers/opt.ts +++ b/lib/compilers/opt.ts @@ -51,7 +51,7 @@ export class OptCompiler extends BaseCompiler { return ['-o', this.filename(outputFilename), '-S']; } - override getArgumentParser() { + override getArgumentParserClass() { return ClangParser; } } diff --git a/lib/compilers/osaca.ts b/lib/compilers/osaca.ts index f8df4982ac8..d9b549f2a1f 100644 --- a/lib/compilers/osaca.ts +++ b/lib/compilers/osaca.ts @@ -63,7 +63,7 @@ export class OSACATool extends AnalysisTool { }; } - override getArgumentParser() { + override getArgumentParserClass() { return BaseParser; } } diff --git a/lib/compilers/pascal-win.ts b/lib/compilers/pascal-win.ts index eac44c2daee..5110fc39a9e 100644 --- a/lib/compilers/pascal-win.ts +++ b/lib/compilers/pascal-win.ts @@ -26,7 +26,7 @@ import path from 'path'; import fs from 'fs-extra'; -import type {ExecutionOptions} from '../../types/compilation/compilation.interfaces.js'; +import type {ExecutionOptions, ExecutionOptionsWithEnv} from '../../types/compilation/compilation.interfaces.js'; import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js'; import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; import {unwrap} from '../assert.js'; @@ -152,7 +152,7 @@ export class PascalWinCompiler extends BaseCompiler { compiler: string, options: string[], inputFilename: string, - execOptions: ExecutionOptions & {env: Record}, + execOptions: ExecutionOptionsWithEnv, ) { if (!execOptions) { execOptions = this.getDefaultExecOptions(); diff --git a/lib/compilers/pascal.ts b/lib/compilers/pascal.ts index cd4bcf38cfa..425c740da0f 100644 --- a/lib/compilers/pascal.ts +++ b/lib/compilers/pascal.ts @@ -27,7 +27,7 @@ import path from 'path'; import fs from 'fs-extra'; import _ from 'underscore'; -import type {ExecutionOptions} from '../../types/compilation/compilation.interfaces.js'; +import type {ExecutionOptionsWithEnv} from '../../types/compilation/compilation.interfaces.js'; import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js'; import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; import {unwrap} from '../assert.js'; @@ -188,7 +188,7 @@ export class FPCCompiler extends BaseCompiler { return newSource.replaceAll('/app//', '/app/'); } - override postProcessObjdumpOutput(output) { + override postProcessObjdumpOutput(output: string) { return FPCCompiler.preProcessBinaryAsm(output); } @@ -239,7 +239,7 @@ export class FPCCompiler extends BaseCompiler { compiler: string, options: string[], inputFilename: string, - execOptions: ExecutionOptions & {env: Record}, + execOptions: ExecutionOptionsWithEnv, ) { if (!execOptions) { execOptions = this.getDefaultExecOptions(); @@ -279,7 +279,7 @@ export class FPCCompiler extends BaseCompiler { return result; } - override getArgumentParser() { + override getArgumentParserClass() { return PascalParser; } diff --git a/lib/compilers/pony.ts b/lib/compilers/pony.ts index 99b3c524c91..96f85bff81d 100644 --- a/lib/compilers/pony.ts +++ b/lib/compilers/pony.ts @@ -24,7 +24,7 @@ import path from 'path'; -import type {CompilationResult, ExecutionOptions} from '../../types/compilation/compilation.interfaces.js'; +import type {CompilationResult, ExecutionOptionsWithEnv} from '../../types/compilation/compilation.interfaces.js'; import {LLVMIrBackendOptions} from '../../types/compilation/ir.interfaces.js'; import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; import {unwrap} from '../assert.js'; @@ -93,7 +93,7 @@ export class PonyCompiler extends BaseCompiler { compiler: string, options: string[], inputFilename: string, - execOptions: ExecutionOptions & {env: Record}, + execOptions: ExecutionOptionsWithEnv, ): Promise { if (!execOptions) { execOptions = this.getDefaultExecOptions(); diff --git a/lib/compilers/ptxas.ts b/lib/compilers/ptxas.ts index f08a43e4df9..05e97da2ba7 100644 --- a/lib/compilers/ptxas.ts +++ b/lib/compilers/ptxas.ts @@ -24,7 +24,7 @@ import path from 'path'; -import type {CompilationResult, ExecutionOptions} from '../../types/compilation/compilation.interfaces.js'; +import type {CompilationResult, ExecutionOptionsWithEnv} from '../../types/compilation/compilation.interfaces.js'; import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js'; import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; import type {ResultLine} from '../../types/resultline/resultline.interfaces.js'; @@ -81,7 +81,7 @@ export class PtxAssembler extends BaseCompiler { return []; } - override getArgumentParser() { + override getArgumentParserClass() { return BaseParser; } @@ -94,7 +94,7 @@ export class PtxAssembler extends BaseCompiler { compiler: string, options: string[], inputFilename: string, - execOptions: ExecutionOptions & {env: Record}, + execOptions: ExecutionOptionsWithEnv, ) { if (!execOptions) { execOptions = this.getDefaultExecOptions(); diff --git a/lib/compilers/python.ts b/lib/compilers/python.ts index 9c5e933fcef..68c83e7ab89 100644 --- a/lib/compilers/python.ts +++ b/lib/compilers/python.ts @@ -80,7 +80,7 @@ export class PythonCompiler extends BaseCompiler { return ['-I', this.disasmScriptPath, '--outputfile', outputFilename, '--inputfile']; } - override getArgumentParser() { + override getArgumentParserClass() { return BaseParser; } diff --git a/lib/compilers/r8.ts b/lib/compilers/r8.ts index 6b884d444dc..e1e57647dac 100644 --- a/lib/compilers/r8.ts +++ b/lib/compilers/r8.ts @@ -27,7 +27,7 @@ import path from 'path'; import fs from 'fs-extra'; import _ from 'underscore'; -import {CompilationResult, ExecutionOptions} from '../../types/compilation/compilation.interfaces.js'; +import {CompilationResult, ExecutionOptionsWithEnv} from '../../types/compilation/compilation.interfaces.js'; import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js'; import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; import {unwrap} from '../assert.js'; @@ -56,7 +56,7 @@ export class R8Compiler extends D8Compiler implements SimpleOutputFilenameCompil compiler: string, options: string[], inputFilename: string, - execOptions: ExecutionOptions & {env: Record}, + execOptions: ExecutionOptionsWithEnv, filters?: ParseFiltersAndOutputOptions, ): Promise { const preliminaryCompilePath = path.dirname(inputFilename); diff --git a/lib/compilers/racket.ts b/lib/compilers/racket.ts index 5f3c61a8b40..89c582274ab 100644 --- a/lib/compilers/racket.ts +++ b/lib/compilers/racket.ts @@ -30,6 +30,7 @@ import type { CompilationResult, CompileChildLibraries, ExecutionOptions, + ExecutionOptionsWithEnv, } from '../../types/compilation/compilation.interfaces.js'; import type { OptPipelineBackendOptions, @@ -118,7 +119,7 @@ export class RacketCompiler extends BaseCompiler { compiler: string, options: string[], inputFilename: string, - execOptions: ExecutionOptions & {env: Record}, + execOptions: ExecutionOptionsWithEnv, ): Promise { if (!execOptions) { execOptions = this.getDefaultExecOptions(); diff --git a/lib/compilers/rga.ts b/lib/compilers/rga.ts index 081de1a249c..0637b34db43 100644 --- a/lib/compilers/rga.ts +++ b/lib/compilers/rga.ts @@ -26,7 +26,11 @@ import path from 'path'; import fs from 'fs-extra'; -import type {CompilationResult, ExecutionOptions} from '../../types/compilation/compilation.interfaces.js'; +import type { + CompilationResult, + ExecutionOptions, + ExecutionOptionsWithEnv, +} from '../../types/compilation/compilation.interfaces.js'; import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; import {BaseCompiler} from '../base-compiler.js'; import * as exec from '../exec.js'; @@ -105,7 +109,7 @@ Please supply an ASIC from the following options:`, compiler: string, options: string[], inputFilename: string, - execOptions: ExecutionOptions & {env: Record}, + execOptions: ExecutionOptionsWithEnv, ): Promise { if (!execOptions) { execOptions = this.getDefaultExecOptions(); diff --git a/lib/compilers/ruby.ts b/lib/compilers/ruby.ts index bc7f6339f19..e12d64ef5ae 100644 --- a/lib/compilers/ruby.ts +++ b/lib/compilers/ruby.ts @@ -95,7 +95,7 @@ export class RubyCompiler extends BaseCompiler { ]; } - override getArgumentParser() { + override getArgumentParserClass() { return BaseParser; } } diff --git a/lib/compilers/rust.ts b/lib/compilers/rust.ts index e388675c334..ed9b496ca25 100644 --- a/lib/compilers/rust.ts +++ b/lib/compilers/rust.ts @@ -27,7 +27,7 @@ import path from 'path'; import {SemVer} from 'semver'; import _ from 'underscore'; -import {CompileChildLibraries, ExecutionOptions} from '../../types/compilation/compilation.interfaces.js'; +import {CompileChildLibraries, ExecutionOptionsWithEnv} from '../../types/compilation/compilation.interfaces.js'; import {CompilerOverrideType, ConfiguredOverrides} from '../../types/compilation/compiler-overrides.interfaces.js'; import {LLVMIrBackendOptions} from '../../types/compilation/ir.interfaces.js'; import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js'; @@ -258,7 +258,7 @@ export class RustCompiler extends BaseCompiler { return outputFilename; } - override getArgumentParser() { + override getArgumentParserClass() { return RustParser; } @@ -278,7 +278,7 @@ export class RustCompiler extends BaseCompiler { compiler: string, options: string[], inputFilename: string, - execOptions: ExecutionOptions & {env: Record}, + execOptions: ExecutionOptionsWithEnv, ) { // bug #5630: in presence of `--emit mir=..` rustc does not produce an executable. const newOptions = options.filter( diff --git a/lib/compilers/scala.ts b/lib/compilers/scala.ts index 1538ab1fb1a..36ec155bea3 100644 --- a/lib/compilers/scala.ts +++ b/lib/compilers/scala.ts @@ -78,7 +78,7 @@ export class ScalaCompiler extends JavaCompiler { return Semver.gte(asSafeVer(this.compiler.semver), '3.0.0', true) ? scala3Opts : scala2Opts; } - override getArgumentParser() { + override getArgumentParserClass() { return ScalaParser; } } diff --git a/lib/compilers/solidity-zksync.ts b/lib/compilers/solidity-zksync.ts index 1034aec2087..eafe1570008 100644 --- a/lib/compilers/solidity-zksync.ts +++ b/lib/compilers/solidity-zksync.ts @@ -37,7 +37,7 @@ export class SolidityZKsyncCompiler extends BaseCompiler { return []; } - override getArgumentParser() { + override getArgumentParserClass() { return ZksolcParser; } diff --git a/lib/compilers/solidity.ts b/lib/compilers/solidity.ts index cd65352c006..f7c8bbf1ad4 100644 --- a/lib/compilers/solidity.ts +++ b/lib/compilers/solidity.ts @@ -41,7 +41,7 @@ export class SolidityCompiler extends BaseCompiler { return []; } - override getArgumentParser() { + override getArgumentParserClass() { return ClangParser; } diff --git a/lib/compilers/spice.ts b/lib/compilers/spice.ts index 16e244c4845..717d2e1bac1 100644 --- a/lib/compilers/spice.ts +++ b/lib/compilers/spice.ts @@ -27,7 +27,7 @@ import path from 'path'; import Semver from 'semver'; import _ from 'underscore'; -import {ExecutionOptions} from '../../types/compilation/compilation.interfaces.js'; +import {ExecutionOptionsWithEnv} from '../../types/compilation/compilation.interfaces.js'; import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js'; import type {ExecutableExecutionOptions} from '../../types/execution/execution.interfaces.js'; import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; @@ -100,7 +100,7 @@ export class SpiceCompiler extends BaseCompiler { return options; } - override getDefaultExecOptions(): ExecutionOptions & {env: Record} { + override getDefaultExecOptions(): ExecutionOptionsWithEnv { const opts = super.getDefaultExecOptions(); opts.env.SPICE_STD_DIR = path.join(path.dirname(this.compiler.exe), 'std'); return opts; diff --git a/lib/compilers/spirv.ts b/lib/compilers/spirv.ts index 9d73b490ac7..f074a8dd0e0 100644 --- a/lib/compilers/spirv.ts +++ b/lib/compilers/spirv.ts @@ -24,7 +24,7 @@ import path from 'path'; -import type {CompileChildLibraries, ExecutionOptions} from '../../types/compilation/compilation.interfaces.js'; +import type {CompileChildLibraries, ExecutionOptionsWithEnv} from '../../types/compilation/compilation.interfaces.js'; import type {ConfiguredOverrides} from '../../types/compilation/compiler-overrides.interfaces.js'; import {LLVMIrBackendOptions} from '../../types/compilation/ir.interfaces.js'; import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js'; @@ -121,7 +121,7 @@ export class SPIRVCompiler extends BaseCompiler { compiler: string, options: string[], inputFilename: string, - execOptions: ExecutionOptions & {env: Record}, + execOptions: ExecutionOptionsWithEnv, ) { const sourceDir = path.dirname(inputFilename); const bitcodeFilename = path.join(sourceDir, this.outputFilebase + '.bc'); @@ -169,7 +169,7 @@ export class SPIRVCompiler extends BaseCompiler { compiler: string, options: any[], inputFilename: string, - execOptions: ExecutionOptions & {env: Record}, + execOptions: ExecutionOptionsWithEnv, ) { if (!execOptions) { execOptions = this.getDefaultExecOptions(); diff --git a/lib/compilers/swift.ts b/lib/compilers/swift.ts index 6a9dd740d2e..0a090792e54 100644 --- a/lib/compilers/swift.ts +++ b/lib/compilers/swift.ts @@ -46,7 +46,7 @@ export class SwiftCompiler extends BaseCompiler { return []; } - override getArgumentParser() { + override getArgumentParserClass() { return SwiftParser; } diff --git a/lib/compilers/tablegen.ts b/lib/compilers/tablegen.ts index ca1738543a4..0780af002e5 100644 --- a/lib/compilers/tablegen.ts +++ b/lib/compilers/tablegen.ts @@ -21,7 +21,7 @@ export class TableGenCompiler extends BaseCompiler { return false; } - override getArgumentParser() { + override getArgumentParserClass() { return TableGenParser; } diff --git a/lib/compilers/tendra.ts b/lib/compilers/tendra.ts index 9359a1b4079..509b50c3aa1 100644 --- a/lib/compilers/tendra.ts +++ b/lib/compilers/tendra.ts @@ -38,7 +38,7 @@ export class TenDRACompiler extends GCCCompiler { return options; } - protected override getArgumentParser(): any { + protected override getArgumentParserClass(): any { return TendraParser; } } diff --git a/lib/compilers/toit.ts b/lib/compilers/toit.ts index 0ec71851a29..b68fbc7aa45 100644 --- a/lib/compilers/toit.ts +++ b/lib/compilers/toit.ts @@ -56,7 +56,7 @@ export class ToitCompiler extends BaseCompiler { override getSharedLibraryPathsAsArguments(libraries: CompileChildLibraries[], libDownloadPath?: string) { return []; } - override getArgumentParser() { + override getArgumentParserClass() { return ToitParser; } override isCfgCompiler() { diff --git a/lib/compilers/turboc.ts b/lib/compilers/turboc.ts index 0a7d8cfd04b..e231221e232 100644 --- a/lib/compilers/turboc.ts +++ b/lib/compilers/turboc.ts @@ -51,7 +51,7 @@ export class TurboCCompiler extends DosboxCompiler { logger.info(`Gathering ${this.compiler.id} version information on ${this.compiler.exe}...`); if (this.compiler.explicitVersion) { logger.debug(`${this.compiler.id} has forced version output: ${this.compiler.explicitVersion}`); - return {stdout: [this.compiler.explicitVersion], stderr: [], code: 0}; + return {stdout: this.compiler.explicitVersion, stderr: '', code: 0}; } const execOptions = this.getDefaultExecOptions(); const versionFlag: string[] = []; @@ -59,7 +59,8 @@ export class TurboCCompiler extends DosboxCompiler { execOptions.ldPath = this.getSharedLibraryPathsAsLdLibraryPaths([]); try { - return this.execCompilerCached(this.compiler.exe, versionFlag, execOptions); + const res = await this.execCompilerCached(this.compiler.exe, versionFlag, execOptions); + return {stdout: res.stdout, stderr: res.stderr, code: res.code}; } catch (err) { logger.error(`Unable to get version for compiler '${this.compiler.exe}' - ${err}`); return null; @@ -70,7 +71,7 @@ export class TurboCCompiler extends DosboxCompiler { return path.join(dirPath, 'EXAMPLE.ASM'); } - override getArgumentParser() { + override getArgumentParserClass() { return TurboCParser; } } diff --git a/lib/compilers/typescript-native.ts b/lib/compilers/typescript-native.ts index 1990ab3b6b0..e978a6b5d50 100644 --- a/lib/compilers/typescript-native.ts +++ b/lib/compilers/typescript-native.ts @@ -134,7 +134,7 @@ export class TypeScriptNativeCompiler extends BaseCompiler { return true; } - override getArgumentParser() { + override getArgumentParserClass() { return TypeScriptNativeParser; } } diff --git a/lib/compilers/v.ts b/lib/compilers/v.ts index 009db5f6863..bb40b7a661d 100644 --- a/lib/compilers/v.ts +++ b/lib/compilers/v.ts @@ -27,7 +27,7 @@ import path from 'path'; import { CompilationResult, CompileChildLibraries, - ExecutionOptions, + ExecutionOptionsWithEnv, } from '../../types/compilation/compilation.interfaces.js'; import {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; import {unwrap} from '../assert.js'; @@ -101,7 +101,7 @@ export class VCompiler extends BaseCompiler { compiler: string, options: string[], inputFilename: string, - execOptions: ExecutionOptions & {env: Record}, + execOptions: ExecutionOptionsWithEnv, filters?: ParseFiltersAndOutputOptions, ): Promise { if (!execOptions) { diff --git a/lib/compilers/wasmtime.ts b/lib/compilers/wasmtime.ts index fd03fdd3f53..535c9054723 100644 --- a/lib/compilers/wasmtime.ts +++ b/lib/compilers/wasmtime.ts @@ -58,7 +58,7 @@ export class WasmtimeCompiler extends BaseCompiler { return path.join(dirPath, `${outputFilebase}.cwasm`); } - override getArgumentParser() { + override getArgumentParserClass() { return WasmtimeParser; } diff --git a/lib/compilers/win32-mingw-clang.ts b/lib/compilers/win32-mingw-clang.ts index 92e15da79d9..abfc4068e4a 100644 --- a/lib/compilers/win32-mingw-clang.ts +++ b/lib/compilers/win32-mingw-clang.ts @@ -79,7 +79,7 @@ export class Win32MingWClang extends ClangCompiler { ); } - override async buildExecutableInFolder(key, dirPath: string): Promise { + override async buildExecutableInFolder(key: CacheKey, dirPath: string): Promise { const result = await super.buildExecutableInFolder(key, dirPath); if (result.code === 0) { diff --git a/lib/compilers/win32-mingw-gcc.ts b/lib/compilers/win32-mingw-gcc.ts index 2d22d0c7845..865137e08fd 100644 --- a/lib/compilers/win32-mingw-gcc.ts +++ b/lib/compilers/win32-mingw-gcc.ts @@ -79,7 +79,7 @@ export class Win32MingWGcc extends GCCCompiler { ); } - override async buildExecutableInFolder(key, dirPath: string): Promise { + override async buildExecutableInFolder(key: CacheKey, dirPath: string): Promise { const result = await super.buildExecutableInFolder(key, dirPath); if (result.code === 0) { diff --git a/lib/compilers/win32-vc.ts b/lib/compilers/win32-vc.ts index ba2ca971294..85ab129d3dc 100644 --- a/lib/compilers/win32-vc.ts +++ b/lib/compilers/win32-vc.ts @@ -39,7 +39,7 @@ export class Win32VcCompiler extends Win32Compiler { this.asm = new VcAsmParser(this.compilerProps); } - override getArgumentParser() { + override getArgumentParserClass() { return VCParser; } } diff --git a/lib/compilers/win32-vc6.ts b/lib/compilers/win32-vc6.ts index cceb8c74af3..5ebc05697cf 100644 --- a/lib/compilers/win32-vc6.ts +++ b/lib/compilers/win32-vc6.ts @@ -39,7 +39,7 @@ export class Win32Vc6Compiler extends Win32Compiler { this.asm = new Vc6AsmParser(this.compilerProps); } - override getArgumentParser() { + override getArgumentParserClass() { return VCParser; } } diff --git a/lib/compilers/wine-vc.ts b/lib/compilers/wine-vc.ts index 95c05c84b49..6c0691ab2dd 100644 --- a/lib/compilers/wine-vc.ts +++ b/lib/compilers/wine-vc.ts @@ -24,7 +24,7 @@ import path from 'path'; -import type {ExecutionOptions} from '../../types/compilation/compilation.interfaces.js'; +import type {ExecutionOptionsWithEnv} from '../../types/compilation/compilation.interfaces.js'; import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js'; import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; import {BaseCompiler} from '../base-compiler.js'; @@ -54,7 +54,7 @@ export class WineVcCompiler extends BaseCompiler { compiler: string, options: string[], inputFilename: string, - execOptions: ExecutionOptions & {env: Record}, + execOptions: ExecutionOptionsWithEnv, ) { if (!execOptions) { execOptions = this.getDefaultExecOptions(); @@ -68,7 +68,7 @@ export class WineVcCompiler extends BaseCompiler { return await super.runCompiler(compiler, options, inputFilename, execOptions); } - override getArgumentParser() { + override getArgumentParserClass() { return VCParser; } diff --git a/lib/compilers/wsl-vc.ts b/lib/compilers/wsl-vc.ts index bdc2fd94b58..039d9f826f1 100644 --- a/lib/compilers/wsl-vc.ts +++ b/lib/compilers/wsl-vc.ts @@ -28,7 +28,7 @@ import os from 'os'; import path from 'path'; -import type {ExecutionOptions} from '../../types/compilation/compilation.interfaces.js'; +import type {ExecutionOptions, ExecutionOptionsWithEnv} from '../../types/compilation/compilation.interfaces.js'; import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js'; import {unwrap} from '../assert.js'; import {CompilationEnvironment} from '../compilation-env.js'; @@ -76,7 +76,7 @@ export class WslVcCompiler extends Win32VcCompiler { compiler: string, options: string[], inputFilename: string, - execOptions: ExecutionOptions & {env: Record}, + execOptions: ExecutionOptionsWithEnv, ) { if (!execOptions) { execOptions = this.getDefaultExecOptions(); diff --git a/lib/compilers/wyrm.ts b/lib/compilers/wyrm.ts index 45368c0296b..6ac761ba824 100644 --- a/lib/compilers/wyrm.ts +++ b/lib/compilers/wyrm.ts @@ -24,7 +24,7 @@ import fs from 'fs/promises'; import path from 'path'; -import {ExecutionOptions} from '../../types/compilation/compilation.interfaces.js'; +import {ExecutionOptionsWithEnv} from '../../types/compilation/compilation.interfaces.js'; import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js'; import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; import {unwrap} from '../assert.js'; @@ -56,7 +56,7 @@ export class WyrmCompiler extends BaseCompiler { compiler: string, options: string[], inputFilename: string, - execOptions: ExecutionOptions & {env: Record}, + execOptions: ExecutionOptionsWithEnv, filters?: ParseFiltersAndOutputOptions, ) { const gcc = this.getGcc(); @@ -76,8 +76,9 @@ export class WyrmCompiler extends BaseCompiler { override async getVersion() { return { - stdout: ['trunk'], - stderr: [], + stdout: 'trunk', + stderr: '', + code: 0, }; } diff --git a/lib/compilers/z88dk.ts b/lib/compilers/z88dk.ts index 57d665cbab9..6364ae58d63 100644 --- a/lib/compilers/z88dk.ts +++ b/lib/compilers/z88dk.ts @@ -24,7 +24,7 @@ import path from 'path'; -import type {ExecutionOptions} from '../../types/compilation/compilation.interfaces.js'; +import type {ExecutionOptions, ExecutionOptionsWithEnv} from '../../types/compilation/compilation.interfaces.js'; import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js'; import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; import {ArtifactType} from '../../types/tool.interfaces.js'; @@ -48,7 +48,7 @@ export class z88dkCompiler extends BaseCompiler { this.asm = new AsmParserZ88dk(this.compilerProps); } - protected override getArgumentParser() { + protected override getArgumentParserClass() { return Z88dkParser; } @@ -111,7 +111,7 @@ export class z88dkCompiler extends BaseCompiler { } } - override getDefaultExecOptions(): ExecutionOptions & {env: Record} { + override getDefaultExecOptions(): ExecutionOptionsWithEnv { const opts = super.getDefaultExecOptions(); opts.env.ZCCCFG = path.join(path.dirname(this.compiler.exe), '../share/z88dk/lib/config'); opts.env.PATH = process.env.PATH + path.delimiter + path.dirname(this.compiler.exe); @@ -177,7 +177,7 @@ export class z88dkCompiler extends BaseCompiler { result.asm = this.postProcessObjdumpOutput(objResult.stdout); } else { logger.error(`Error executing objdump ${this.compiler.objdumper}`, objResult); - result.asm = ``; + result.asm = [{text: ``}]; } } diff --git a/lib/compilers/zigcxx.ts b/lib/compilers/zigcxx.ts index 1495586f474..0b1428b1317 100644 --- a/lib/compilers/zigcxx.ts +++ b/lib/compilers/zigcxx.ts @@ -44,7 +44,7 @@ export class ZigCXX extends ClangCompiler { Semver.lt(asSafeVer(this.compiler.semver), '0.9.0', true); } - protected override getArgumentParser(): any { + protected override getArgumentParserClass(): any { return ZigCxxParser; } diff --git a/lib/exec.ts b/lib/exec.ts index 38d4efee262..c76033c9309 100644 --- a/lib/exec.ts +++ b/lib/exec.ts @@ -608,7 +608,9 @@ async function executeNone(command: string, args: string[], options: ExecutionOp return await executeDirect(command, args, options); } -const executeDispatchTable = { +type DispatchFunction = (command: string, args: string[], options: ExecutionOptions) => Promise; + +const executeDispatchTable: Record = { none: executeNone, firejail: executeFirejail, nsjail: (command: string, args: string[], options: ExecutionOptions) => diff --git a/lib/execution/base-execution-env.ts b/lib/execution/base-execution-env.ts index 3e6b1672cdd..0d3eb13a0fa 100644 --- a/lib/execution/base-execution-env.ts +++ b/lib/execution/base-execution-env.ts @@ -28,7 +28,12 @@ import path from 'path'; import fs from 'fs-extra'; import temp from 'temp'; -import {BuildResult, ExecutionOptions, ExecutionParams} from '../../types/compilation/compilation.interfaces.js'; +import { + BuildResult, + ExecutionOptions, + ExecutionOptionsWithEnv, + ExecutionParams, +} from '../../types/compilation/compilation.interfaces.js'; import { BasicExecutionResult, ConfiguredRuntimeTool, @@ -126,7 +131,7 @@ export class LocalExecutionEnvironment implements IExecutionEnvironment { this.buildResult = await this.loadPackageWithExecutable(hash, this.dirPath); } - protected getDefaultExecOptions(params: ExecutionParams): ExecutionOptions & {env: Record} { + protected getDefaultExecOptions(params: ExecutionParams): ExecutionOptionsWithEnv { const env: Record = {}; env.PATH = ''; @@ -152,7 +157,7 @@ export class LocalExecutionEnvironment implements IExecutionEnvironment { else env.PATH = this.buildResult.defaultExecOptions.env.PATH; } - const execOptions: ExecutionOptions & {env: Record} = { + const execOptions: ExecutionOptionsWithEnv = { env, }; diff --git a/lib/handlers/compile.ts b/lib/handlers/compile.ts index 12cdfa4176f..783941ebf55 100644 --- a/lib/handlers/compile.ts +++ b/lib/handlers/compile.ts @@ -45,6 +45,7 @@ import { import {CompilerOverrideOptions} from '../../types/compilation/compiler-overrides.interfaces.js'; import {CompilerInfo, ICompiler, PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js'; import {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; +import {LanguageKey} from '../../types/languages.interfaces.js'; import {ResultLine} from '../../types/resultline/resultline.interfaces.js'; import {BaseCompiler} from '../base-compiler.js'; import {CompilationEnvironment} from '../compilation-env.js'; @@ -105,7 +106,7 @@ export type ParsedRequest = { }; export class CompileHandler implements ICompileHandler { - private compilersById: Record> = {}; + private compilersById: Partial>> = {}; private readonly compilerEnv: CompilationEnvironment; private readonly textBanner: string; private readonly proxy: Server; @@ -304,15 +305,15 @@ export class CompileHandler implements ICompileHandler { this.compilerEnv.setPossibleToolchains(toolchains); } - compilerAliasMatch(compiler, compilerId): boolean { + compilerAliasMatch(compiler: BaseCompiler, compilerId: string): boolean { return compiler.compiler.alias && compiler.compiler.alias.includes(compilerId); } - compilerIdOrAliasMatch(compiler, compilerId): boolean { + compilerIdOrAliasMatch(compiler: BaseCompiler, compilerId: string): boolean { return compiler.compiler.id === compilerId || this.compilerAliasMatch(compiler, compilerId); } - findCompiler(langId, compilerId): BaseCompiler | undefined { + findCompiler(langId: string, compilerId: string): BaseCompiler | undefined { if (!compilerId) return; const langCompilers: Record | undefined = this.compilersById[langId]; @@ -407,7 +408,7 @@ export class CompileHandler implements ICompileHandler { filters = compiler.getDefaultFilters(); _.each(filters, (value, item) => { - filters[item] = textRequest[item] === 'true'; + filters[item] = textRequest[item as keyof CompileRequestTextBody] === 'true'; }); backendOptions.filterAnsi = textRequest.filterAnsi === 'true'; @@ -431,7 +432,7 @@ export class CompileHandler implements ICompileHandler { }); // Remove a filter. ?removeFilter=intel _.each((query.removeFilters || '').split(','), filter => { - if (filter) delete filters[filter]; + if (filter) delete filters[filter as keyof ParseFiltersAndOutputOptions]; }); // Ask for asm not to be returned backendOptions.skipAsm = query.skipAsm === 'true'; @@ -576,7 +577,7 @@ export class CompileHandler implements ICompileHandler { const {source, options, backendOptions, filters, bypassCache, tools, executeParameters, libraries} = parsedRequest; - let files; + let files: FiledataPair[] = []; if (req.body.files) files = req.body.files; if (source === undefined || Object.keys(req.body).length === 0) { diff --git a/lib/handlers/route-api.ts b/lib/handlers/route-api.ts index 00452194620..a39d3c45e19 100644 --- a/lib/handlers/route-api.ts +++ b/lib/handlers/route-api.ts @@ -26,6 +26,7 @@ import express from 'express'; import {AppDefaultArguments, CompilerExplorerOptions} from '../../app.js'; import {isString} from '../../shared/common-utils.js'; +import {Language} from '../../types/languages.interfaces.js'; import {assert, unwrap} from '../assert.js'; import {ClientStateGoldenifier, ClientStateNormalizer} from '../clientstate-normalizer.js'; import {ClientState} from '../clientstate.js'; @@ -189,10 +190,15 @@ export class RouteAPI { compiler.id = req.query.compiler; compiler.options = req.query.compiler_flags || ''; - this.renderClientState(state, undefined, req, res); + this.renderClientState(state, null, req, res); } - renderClientState(clientstate: ClientState, metadata, req: express.Request, res: express.Response) { + renderClientState( + clientstate: ClientState, + metadata: ShortLinkMetaData | null, + req: express.Request, + res: express.Response, + ) { const config = this.getGoldenLayoutFromClientState(clientstate); this.renderGoldenLayout(config, metadata, req, res); @@ -231,15 +237,15 @@ export class RouteAPI { return line.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>'); } - filterCode(req: express.Request, code: string, lang) { + filterCode(req: express.Request, code: string, lang: Language) { let lines = code.split('\n'); if (lang.previewFilter !== null) { - lines = lines.filter(line => !lang.previewFilter.test(line)); + lines = lines.filter(line => !lang.previewFilter || !lang.previewFilter.test(line)); } return lines.map(line => this.escapeLine(req, line)).join('\n'); } - getMetaDataFromLink(req: express.Request, link: ExpandedShortLink | null, config) { + getMetaDataFromLink(req: express.Request, link: ExpandedShortLink | null, config: any) { const metadata: ShortLinkMetaData = { ogTitle: 'Compiler Explorer', }; @@ -255,7 +261,7 @@ export class RouteAPI { } if (!metadata.ogDescription) { - let lang; + let lang: Language | undefined; let source = ''; const sources = utils.glGetMainContents(config.content); diff --git a/lib/llvm-ast.ts b/lib/llvm-ast.ts index c716839e995..e9e461887ea 100644 --- a/lib/llvm-ast.ts +++ b/lib/llvm-ast.ts @@ -116,7 +116,7 @@ export class LlvmAstParser { } } - processAst(result: CompilationResult) { + processAst(result: CompilationResult): ResultLine[] { const output = result.stdout; // Top level decls start with |- or `- diff --git a/lib/utils.ts b/lib/utils.ts index d79bd3a0558..acf956e6513 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -36,6 +36,7 @@ import _ from 'underscore'; import type {CacheableValue} from '../types/cache.interfaces.js'; import {BasicExecutionResult, UnprocessedExecResult} from '../types/execution/execution.interfaces.js'; +import {LanguageKey} from '../types/languages.interfaces.js'; import type {ResultLine} from '../types/resultline/resultline.interfaces.js'; const tabsRe = /\t/g; @@ -331,7 +332,7 @@ interface glEditorMainContent { // Editor content source: string; // Editor syntax language - language: string; + language: LanguageKey; } interface glCompilerMainContent { @@ -357,7 +358,7 @@ export function glGetMainContents(content: ItemConfigType[] = []): glContents { if (component.componentName === 'codeEditor') { contents.editors.push({ source: component.componentState.source, - language: component.componentState.lang, + language: component.componentState.lang as LanguageKey, }); } else if (component.componentName === 'compiler') { contents.compilers.push({ diff --git a/lib/win-utils.ts b/lib/win-utils.ts index 222517f62bd..cde5b01a8d6 100644 --- a/lib/win-utils.ts +++ b/lib/win-utils.ts @@ -26,7 +26,7 @@ import path from 'path'; import * as fs from 'fs-extra'; -import {ExecutionOptions} from '../types/compilation/compilation.interfaces.js'; +import {ExecutionOptionsWithEnv} from '../types/compilation/compilation.interfaces.js'; import {logger} from './logger.js'; import * as utils from './utils.js'; @@ -36,10 +36,10 @@ export class WinUtils { protected objdumper: string; protected exec: any; protected alreadyDone: string[]; - protected execOptions: ExecutionOptions & {env: Record}; + protected execOptions: ExecutionOptionsWithEnv; protected skippable: string[]; - constructor(exec, objdumper: string, execOptions: ExecutionOptions & {env: Record}) { + constructor(exec, objdumper: string, execOptions: ExecutionOptionsWithEnv) { this.exec = exec; this.objdumper = objdumper; this.execOptions = execOptions; @@ -98,7 +98,7 @@ export async function copyNeededDlls( executableFilename: string, execFunction, objdumper: string, - execoptions: ExecutionOptions & {env: Record}, + execoptions: ExecutionOptionsWithEnv, ): Promise { const winutils = new WinUtils(execFunction, objdumper, execoptions); const dlls = await winutils.get_dlls_used(executableFilename); diff --git a/test/base-compiler-tests.ts b/test/base-compiler-tests.ts index 8cdeab36d84..7bb9cb5512b 100644 --- a/test/base-compiler-tests.ts +++ b/test/base-compiler-tests.ts @@ -100,7 +100,7 @@ describe('Basic compiler invariants', () => { const newConfig: Partial = {...info, explicitVersion: '123'}; const forcedVersionCompiler = new BaseCompiler(newConfig as CompilerInfo, ce); const result = await forcedVersionCompiler.getVersion(); - expect(result.stdout).toEqual(['123']); + expect(result && result.stdout).toEqual('123'); }); }); diff --git a/test/handlers/compile-tests.ts b/test/handlers/compile-tests.ts index ebf3458bfae..703b62ef53e 100644 --- a/test/handlers/compile-tests.ts +++ b/test/handlers/compile-tests.ts @@ -223,6 +223,7 @@ describe('Compiler tests', () => { code: 0, input: { backendOptions: {}, + files: [], filters: {}, options: [], source: 'I am a program', diff --git a/types/compilation/compilation.interfaces.ts b/types/compilation/compilation.interfaces.ts index 0d3493f1b91..4ac69efa80e 100644 --- a/types/compilation/compilation.interfaces.ts +++ b/types/compilation/compilation.interfaces.ts @@ -58,6 +58,11 @@ export type CompileChildLibraries = { version: string; }; +export type LibsAndOptions = { + libraries: CompileChildLibraries[]; + options: string[]; +}; + export type GccDumpFlags = { gimpleFe: boolean; address: boolean; @@ -72,6 +77,15 @@ export type GccDumpFlags = { all: boolean; }; +export type GccDumpOptions = { + opened: boolean; + pass?: GccDumpViewSelectedPass; + treeDump?: boolean; + rtlDump?: boolean; + ipaDump?: boolean; + dumpFlags?: GccDumpFlags; +}; + export type CompilationRequestOptions = { userArguments: string; compilerOptions: { @@ -79,14 +93,7 @@ export type CompilationRequestOptions = { skipAsm?: boolean; producePp?: PPOptions | null; produceAst?: boolean; - produceGccDump?: { - opened: boolean; - pass?: GccDumpViewSelectedPass; - treeDump?: boolean; - rtlDump?: boolean; - ipaDump?: boolean; - dumpFlags?: GccDumpFlags; - }; + produceGccDump?: GccDumpOptions; produceStackUsageInfo?: boolean; produceOptInfo?: boolean; produceCfg?: {asm: boolean; ir: boolean} | false; @@ -229,6 +236,8 @@ export type ExecutionOptions = { killChild?: () => void; }; +export type ExecutionOptionsWithEnv = ExecutionOptions & {env: Record}; + export type BuildResult = CompilationResult & { downloads: BuildEnvDownloadInfo[]; executableFilename: string; @@ -282,7 +291,7 @@ export type CompilationCacheKey = { options: ExecutionOptions; }; -export type CacheKey = { +export type SingleFileCacheKey = { compiler: any; source: string; options: string[]; @@ -293,12 +302,14 @@ export type CacheKey = { files: any[]; }; -export type CmakeCacheKey = CacheKey & { +export type CmakeCacheKey = Omit & { compiler: CompilerInfo; - files: []; + files: FiledataPair[]; api: string; }; +export type CacheKey = SingleFileCacheKey | CmakeCacheKey; + export type FiledataPair = { filename: string; contents: string; diff --git a/types/compiler.interfaces.ts b/types/compiler.interfaces.ts index eac6cf88f69..bc21dc09403 100644 --- a/types/compiler.interfaces.ts +++ b/types/compiler.interfaces.ts @@ -22,7 +22,12 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. -import {BypassCache, CompileChildLibraries} from './compilation/compilation.interfaces.js'; +import { + BypassCache, + CompilationResult, + CompileChildLibraries, + FiledataPair, +} from './compilation/compilation.interfaces.js'; import {AllCompilerOverrideOptions} from './compilation/compiler-overrides.interfaces.js'; import {ICompilerArguments} from './compiler-arguments.interfaces.js'; import {PossibleRuntimeTools} from './execution/execution.interfaces.js'; @@ -172,9 +177,9 @@ export interface ICompiler { tools, executeParameters, libraries: CompileChildLibraries[], - files, + files: FiledataPair[], ); - cmake(files, key, bypassCache: BypassCache); + cmake(files: FiledataPair[], key, bypassCache: BypassCache): Promise; initialise(mtime: Date, clientOptions, isPrediscovered: boolean); getInfo(): CompilerInfo; }