diff --git a/app.ts b/app.ts index 5cefba0c0..f0b90e074 100755 --- a/app.ts +++ b/app.ts @@ -33,14 +33,16 @@ import bodyParser from 'body-parser'; import compression from 'compression'; import express from 'express'; import fs from 'fs-extra'; -// @ts-expect-warning +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-ignore import morgan from 'morgan'; import nopt from 'nopt'; import PromClient from 'prom-client'; import responseTime from 'response-time'; import sanitize from 'sanitize-filename'; import sFavicon from 'serve-favicon'; -// @ts-expect-warning +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-ignore import systemdSocket from 'systemd-socket'; import _ from 'underscore'; import urljoin from 'url-join'; @@ -50,7 +52,6 @@ import * as normalizer from './lib/clientstate-normalizer.js'; import {CompilationEnvironment} from './lib/compilation-env.js'; import {CompilationQueue} from './lib/compilation-queue.js'; import {CompilerFinder} from './lib/compiler-finder.js'; -// import { policy as csp } from './lib/csp.js'; import {startWineInit} from './lib/exec.js'; import {CompileHandler} from './lib/handlers/compile.js'; import * as healthCheck from './lib/handlers/health-check.js'; diff --git a/lib/base-compiler.ts b/lib/base-compiler.ts index 73f471bcf..f307b1dba 100644 --- a/lib/base-compiler.ts +++ b/lib/base-compiler.ts @@ -34,6 +34,7 @@ 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 { + ActiveTool, BuildResult, BuildStep, BypassCache, @@ -78,7 +79,7 @@ import type {ResultLine} from '../types/resultline/resultline.interfaces.js'; import {type ToolResult, type ToolTypeKey} from '../types/tool.interfaces.js'; import {moveArtifactsIntoResult} from './artifact-utils.js'; -import {unwrap} from './assert.js'; +import {assert, unwrap} from './assert.js'; import type {BuildEnvDownloadInfo} from './buildenvsetup/buildenv.interfaces.js'; import {BuildEnvSetupBase, getBuildEnvTypeByKey} from './buildenvsetup/index.js'; import * as cfg from './cfg/cfg.js'; @@ -1734,7 +1735,7 @@ export class BaseCompiler implements ICompiler { return await this.postProcess(asmResult, outputFilename, filters); } - runToolsOfType(tools, type: ToolTypeKey, compilationInfo: CompilationInfo): Promise[] { + runToolsOfType(tools: ActiveTool[], type: ToolTypeKey, compilationInfo: CompilationInfo): Promise[] { const tooling: Promise[] = []; if (tools) { for (const tool of tools) { @@ -2120,7 +2121,7 @@ export class BaseCompiler implements ICompiler { options: string[], backendOptions: Record, filters: ParseFiltersAndOutputOptions, - tools, + tools: ActiveTool[], libraries: CompileChildLibraries[], files: FiledataPair[], ): CacheKey { @@ -2242,7 +2243,7 @@ export class BaseCompiler implements ICompiler { filters: ParseFiltersAndOutputOptions, backendOptions: Record, libraries: CompileChildLibraries[], - tools, + tools: ActiveTool[], ) { const inputFilenameSafe = this.filename(inputFilename); @@ -2423,7 +2424,7 @@ export class BaseCompiler implements ICompiler { } } - async doBuildstep(command, args, execParams) { + async doBuildstep(command: string, args: string[], execParams: ExecutionOptions) { const result = await this.exec(command, args, execParams); return this.processExecutionResult(result); } @@ -2440,7 +2441,13 @@ export class BaseCompiler implements ICompiler { }; } - async doBuildstepAndAddToResult(result, name, command, args, execParams): Promise { + async doBuildstepAndAddToResult( + result, + name: string, + command: string, + args: string[], + execParams: ExecutionOptions, + ): Promise { const stepResult: BuildStep = { ...(await this.doBuildstep(command, args, execParams)), compilationOptions: args, @@ -2602,10 +2609,13 @@ export class BaseCompiler implements ICompiler { const useNinja = this.env.ceProps('useninja'); const fullArgs: string[] = useNinja ? ['-GNinja'].concat(partArgs) : partArgs; + const cmd = this.env.ceProps('cmake') as string; + assert(cmd, 'No cmake command found'); + const cmakeStepResult = await this.doBuildstepAndAddToResult( fullResult, 'cmake', - this.env.ceProps('cmake'), + cmd, fullArgs, makeExecParams, ); @@ -2627,7 +2637,7 @@ export class BaseCompiler implements ICompiler { const makeStepResult = await this.doBuildstepAndAddToResult( fullResult, 'build', - this.env.ceProps('cmake'), + cmd, ['--build', '.'], execParams, ); @@ -2751,7 +2761,7 @@ export class BaseCompiler implements ICompiler { backendOptions: Record, filters: ParseFiltersAndOutputOptions, bypassCache: BypassCache, - tools, + tools: ActiveTool[], executeParameters: ExecutionParams, libraries: CompileChildLibraries[], files: FiledataPair[], @@ -2879,7 +2889,7 @@ export class BaseCompiler implements ICompiler { doExecute: boolean, key: CacheKey, executeOptions: ExecutableExecutionOptions, - tools, + tools: ActiveTool[], backendOptions: Record, filters: ParseFiltersAndOutputOptions, options: string[], diff --git a/lib/buildenvsetup/base.ts b/lib/buildenvsetup/base.ts index aec95268c..0667ea272 100644 --- a/lib/buildenvsetup/base.ts +++ b/lib/buildenvsetup/base.ts @@ -26,7 +26,7 @@ import path from 'path'; import _ from 'underscore'; -import {CacheKey, ExecutionOptionsWithEnv} from '../../types/compilation/compilation.interfaces.js'; +import {Arch, CacheKey, ExecutionOptionsWithEnv} from '../../types/compilation/compilation.interfaces.js'; import {CompilerInfo} from '../../types/compiler.interfaces.js'; import {UnprocessedExecResult} from '../../types/execution/execution.interfaces.js'; import {CompilationEnvironment} from '../compilation-env.js'; @@ -73,9 +73,9 @@ export class BuildEnvSetupBase { }); } - async hasSupportForArch(execCompilerCached: ExecCompilerCachedFunc, arch: string): Promise { + async hasSupportForArch(execCompilerCached: ExecCompilerCachedFunc, arch: Arch): Promise { let result: any; - let searchFor = arch; + let searchFor = arch as string; if (this.compiler.exe.includes('icpx')) { return arch === 'x86' || arch === 'x86_64'; } else if (this.compiler.exe.includes('circle')) { diff --git a/lib/cache/s3.ts b/lib/cache/s3.ts index 4eadf4a61..9f153ee1c 100644 --- a/lib/cache/s3.ts +++ b/lib/cache/s3.ts @@ -34,7 +34,7 @@ import {SentryCapture} from '../sentry.js'; import {BaseCache} from './base.js'; -function messageFor(e) { +function messageFor(e: any) { return e.message || e.toString(); } @@ -42,9 +42,15 @@ export class S3Cache extends BaseCache { private readonly s3: S3Bucket; readonly path: string; readonly region: string; - private readonly onError: (Error, string) => void; + private readonly onError: (Error: any, msg: string) => void; - constructor(cacheName: string, bucket: string, path: string, region: string, onError?: (Error, string) => void) { + constructor( + cacheName: string, + bucket: string, + path: string, + region: string, + onError?: (Error: any, msg: string) => void, + ) { super(cacheName, `S3Cache(s3://${bucket}/${path} in ${region})`, 's3'); this.path = path; this.region = region; diff --git a/lib/compilers/assembly.ts b/lib/compilers/assembly.ts index 68bb1b26d..b6aaa601e 100644 --- a/lib/compilers/assembly.ts +++ b/lib/compilers/assembly.ts @@ -27,7 +27,13 @@ import path from 'path'; import _ from 'underscore'; -import type {BuildResult, CacheKey, CompilationResult} from '../../types/compilation/compilation.interfaces.js'; +import type { + Arch, + BuildResult, + BuildStep, + 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'; @@ -84,13 +90,13 @@ export class AssemblyCompiler extends BaseCompiler { return await this.doBuildstepAndAddToResult( fullResult, 'readelf', - this.env.ceProps('readelf'), + this.env.ceProps('readelf') as string, ['-h', objectFilename], execOptions, ); } - async getArchitecture(fullResult: BuildResult, objectFilename: string) { + async getArchitecture(fullResult: BuildResult, objectFilename: string): Promise { const result = await this.runReadelf(fullResult, objectFilename); const output = result.stdout.map(line => line.text).join('\n'); if (output.includes('ELF32') && output.includes('80386')) { @@ -102,10 +108,10 @@ export class AssemblyCompiler extends BaseCompiler { return 'x86_64'; } - return false; + return null; } - async runLinker(fullResult, inputArch, objectFilename, outputFilename) { + async runLinker(fullResult: BuildResult, inputArch: Arch, objectFilename: string, outputFilename: string) { const execOptions = this.getDefaultExecOptions(); execOptions.customCwd = path.dirname(objectFilename); @@ -115,17 +121,23 @@ export class AssemblyCompiler extends BaseCompiler { } else if (inputArch === 'x86_64') { // default target } else { - const result = { + const result: BuildStep = { code: -1, step: 'ld', stderr: [{text: 'Invalid architecture for linking and execution'}], + okToCache: false, + filenameTransform: (fn: string) => fn, + stdout: [], + execTime: '', + timedOut: false, + compilationOptions: [], }; - fullResult.buildsteps.push(result); + fullResult.buildsteps!.push(result); return result; } options.push(objectFilename); - return this.doBuildstepAndAddToResult(fullResult, 'ld', this.env.ceProps('ld'), options, execOptions); + return this.doBuildstepAndAddToResult(fullResult, 'ld', this.env.ceProps('ld') as string, options, execOptions); } override getExecutableFilename(dirPath: string) { diff --git a/lib/compilers/cc65.ts b/lib/compilers/cc65.ts index 8191a724c..5b96ed6aa 100644 --- a/lib/compilers/cc65.ts +++ b/lib/compilers/cc65.ts @@ -27,7 +27,11 @@ import path from 'path'; import fs from 'fs-extra'; import _ from 'underscore'; -import type {CompilationResult, CompileChildLibraries} from '../../types/compilation/compilation.interfaces.js'; +import type { + CompilationResult, + CompileChildLibraries, + ExecutionOptions, +} 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'; @@ -139,10 +143,16 @@ export class Cc65Compiler extends BaseCompiler { return res; } - override async doBuildstepAndAddToResult(result: CompilationResult, name, command, args, execParams) { + override async doBuildstepAndAddToResult( + result: CompilationResult, + name: string, + command: string, + args: string[], + execParams: ExecutionOptions, + ) { const stepResult = await super.doBuildstepAndAddToResult(result, name, command, args, execParams); if (name === 'build') { - const mapFile = path.join(execParams.customCwd, 'map.txt'); + const mapFile = path.join(execParams.customCwd!, 'map.txt'); if (await utils.fileExists(mapFile)) { const file_buffer = await fs.readFile(mapFile); stepResult.stderr = stepResult.stderr.concat(utils.parseOutput(file_buffer.toString())); diff --git a/lib/compilers/clang.ts b/lib/compilers/clang.ts index 3ed5c8de5..6ce4d76c7 100644 --- a/lib/compilers/clang.ts +++ b/lib/compilers/clang.ts @@ -28,6 +28,7 @@ import path from 'path'; import _ from 'underscore'; import type { + ActiveTool, BuildResult, BypassCache, CacheKey, @@ -191,7 +192,7 @@ export class ClangCompiler extends BaseCompiler { doExecute: boolean, key: CacheKey, executeParameters: ExecutableExecutionOptions, - tools, + tools: ActiveTool[], backendOptions: Record, filters: ParseFiltersAndOutputOptions, options: string[], @@ -256,7 +257,7 @@ export class ClangCompiler extends BaseCompiler { return devices; } - override async extractDeviceCode(result, filters, compilationInfo: CompilationInfo) { + override async extractDeviceCode(result, filters: ParseFiltersAndOutputOptions, compilationInfo: CompilationInfo) { const split = await this.splitDeviceCode(result.asm); if (!split) return result; diff --git a/lib/compilers/llvm-mos.ts b/lib/compilers/llvm-mos.ts index 736e2c5e0..35b5fda00 100644 --- a/lib/compilers/llvm-mos.ts +++ b/lib/compilers/llvm-mos.ts @@ -59,11 +59,11 @@ export class LLVMMOSCompiler extends ClangCompiler { } override async objdump( - outputFilename, + outputFilename: string, result: CompilationResult, maxSize: number, - intelAsm, - demangle, + intelAsm: boolean, + demangle: boolean, staticReloc: boolean, dynamicReloc: boolean, filters: ParseFiltersAndOutputOptions, diff --git a/lib/compilers/nvcc.ts b/lib/compilers/nvcc.ts index 3d8c3aedc..5cfe15328 100644 --- a/lib/compilers/nvcc.ts +++ b/lib/compilers/nvcc.ts @@ -134,7 +134,11 @@ export class NvccCompiler extends BaseCompiler { return Promise.all([asmPromise, optPromise, '']); } - override async extractDeviceCode(result: CompilationResult, filters, compilationInfo: CompilationInfo) { + override async extractDeviceCode( + result: CompilationResult, + filters: ParseFiltersAndOutputOptions, + 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 dfdb13d73..d36366785 100644 --- a/lib/compilers/nvcpp.ts +++ b/lib/compilers/nvcpp.ts @@ -27,6 +27,7 @@ import path from 'path'; import {CompilationInfo, CompilationResult} from '../../types/compilation/compilation.interfaces.js'; import {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js'; +import {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; import {unwrap} from '../assert.js'; import {BaseCompiler} from '../base-compiler.js'; import {CompilationEnvironment} from '../compilation-env.js'; @@ -53,7 +54,7 @@ export class NvcppCompiler extends BaseCompiler { this.compiler.supportsDeviceAsmView = true; } - async nvdisasm(result, outputFilename: string, maxOutput: number) { + async nvdisasm(outputFilename: string, maxOutput: number) { const disasmResult = await this.exec(unwrap(this.compiler.nvdisasm), ['-c', '-g', '-hex', outputFilename], { maxOutput, customCwd: path.dirname(outputFilename), @@ -89,7 +90,11 @@ export class NvcppCompiler extends BaseCompiler { return false; } - override async extractDeviceCode(result: CompilationResult, filters, compilationInfo: CompilationInfo) { + override async extractDeviceCode( + result: CompilationResult, + filters: ParseFiltersAndOutputOptions, + compilationInfo: CompilationInfo, + ) { const {dirPath} = result; const {demangle} = filters; const devices = {...result.devices}; @@ -109,7 +114,7 @@ export class NvcppCompiler extends BaseCompiler { const {asm} = type === 'PTX' ? {asm: await fs.readFile(path.join(dirPath, name), 'utf8')} - : await this.nvdisasm(result, path.join(dirPath, name), maxSize); + : await this.nvdisasm(path.join(dirPath, name), maxSize); const archAndCode = name.split('.').slice(1, -1).join(', ') || ''; const nameAndArch = type + (archAndCode ? ` (${archAndCode.toLowerCase()})` : ''); Object.assign(devices, { diff --git a/types/compilation/compilation.interfaces.ts b/types/compilation/compilation.interfaces.ts index 3f6eb7875..0afb684c6 100644 --- a/types/compilation/compilation.interfaces.ts +++ b/types/compilation/compilation.interfaces.ts @@ -252,6 +252,8 @@ export type BuildResult = CompilationResult & { code: number; }; +export type Arch = 'x86' | 'x86_64' | null; + export type BuildStep = BasicExecutionResult & { compilationOptions: string[]; step: string; diff --git a/types/compiler.interfaces.ts b/types/compiler.interfaces.ts index 6765bad38..810f6fe8d 100644 --- a/types/compiler.interfaces.ts +++ b/types/compiler.interfaces.ts @@ -23,6 +23,7 @@ // POSSIBILITY OF SUCH DAMAGE. import { + ActiveTool, BypassCache, CompilationResult, CompileChildLibraries, @@ -177,7 +178,7 @@ export interface ICompiler { backendOptions: Record, filters: ParseFiltersAndOutputOptions, bypassCache: BypassCache, - tools, + tools: ActiveTool[], executeParameters: ExecutionParams, libraries: CompileChildLibraries[], files: FiledataPair[],