Finish ts work on tools, some extra ts fixes

This commit is contained in:
Ofek Shilon
2024-10-25 23:57:30 +03:00
parent 429f02b231
commit 7b627cf4cf
12 changed files with 92 additions and 40 deletions
+4 -3
View File
@@ -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';
+20 -10
View File
@@ -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<ToolResult>[] {
runToolsOfType(tools: ActiveTool[], type: ToolTypeKey, compilationInfo: CompilationInfo): Promise<ToolResult>[] {
const tooling: Promise<ToolResult>[] = [];
if (tools) {
for (const tool of tools) {
@@ -2120,7 +2121,7 @@ export class BaseCompiler implements ICompiler {
options: string[],
backendOptions: Record<string, any>,
filters: ParseFiltersAndOutputOptions,
tools,
tools: ActiveTool[],
libraries: CompileChildLibraries[],
files: FiledataPair[],
): CacheKey {
@@ -2242,7 +2243,7 @@ export class BaseCompiler implements ICompiler {
filters: ParseFiltersAndOutputOptions,
backendOptions: Record<string, any>,
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<BuildStep> {
async doBuildstepAndAddToResult(
result,
name: string,
command: string,
args: string[],
execParams: ExecutionOptions,
): Promise<BuildStep> {
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<string, any>,
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<string, any>,
filters: ParseFiltersAndOutputOptions,
options: string[],
+3 -3
View File
@@ -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<boolean> {
async hasSupportForArch(execCompilerCached: ExecCompilerCachedFunc, arch: Arch): Promise<boolean> {
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')) {
+9 -3
View File
@@ -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;
+20 -8
View File
@@ -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<Arch> {
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) {
+13 -3
View File
@@ -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()));
+3 -2
View File
@@ -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<string, any>,
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;
+3 -3
View File
@@ -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,
+5 -1
View File
@@ -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};
+8 -3
View File
@@ -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, {
@@ -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;
+2 -1
View File
@@ -23,6 +23,7 @@
// POSSIBILITY OF SUCH DAMAGE.
import {
ActiveTool,
BypassCache,
CompilationResult,
CompileChildLibraries,
@@ -177,7 +178,7 @@ export interface ICompiler {
backendOptions: Record<string, any>,
filters: ParseFiltersAndOutputOptions,
bypassCache: BypassCache,
tools,
tools: ActiveTool[],
executeParameters: ExecutionParams,
libraries: CompileChildLibraries[],
files: FiledataPair[],