Skip to content

Commit

Permalink
tsification - migrating to a new env
Browse files Browse the repository at this point in the history
  • Loading branch information
OfekShilon committed Sep 21, 2024
1 parent 1ea5d97 commit f9266e5
Show file tree
Hide file tree
Showing 52 changed files with 309 additions and 219 deletions.
6 changes: 6 additions & 0 deletions app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,23 @@ import url from 'url';

import * as Sentry from '@sentry/node';
import bodyParser from 'body-parser';
// @ts-ignore
import compression from 'compression';
import express from 'express';
import fs from 'fs-extra';
// @ts-ignore
import morgan from 'morgan';
import nopt from 'nopt';
import PromClient from 'prom-client';
// @ts-ignore
import responseTime from 'response-time';
import sanitize from 'sanitize-filename';
// @ts-ignore
import sFavicon from 'serve-favicon';
// @ts-ignore
import systemdSocket from 'systemd-socket';
import _ from 'underscore';
// @ts-ignore
import urljoin from 'url-join';

import * as aws from './lib/aws.js';
Expand Down
64 changes: 30 additions & 34 deletions lib/base-compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1432,7 +1432,7 @@ export class BaseCompiler implements ICompiler {
}

async processOptPipeline(
output,
output: CompilationResult,
filters: ParseFiltersAndOutputOptions,
optPipelineOptions: OptPipelineBackendOptions,
debugPatched?: boolean,
Expand All @@ -1444,39 +1444,39 @@ export class BaseCompiler implements ICompiler {
);
}

getRustMacroExpansionOutputFilename(inputFilename) {
getRustMacroExpansionOutputFilename(inputFilename: string) {
return utils.changeExtension(inputFilename, '.expanded.rs');
}

getRustHirOutputFilename(inputFilename) {
getRustHirOutputFilename(inputFilename: string) {
return utils.changeExtension(inputFilename, '.hir');
}

getRustMirOutputFilename(outputFilename) {
getRustMirOutputFilename(outputFilename: string) {
return utils.changeExtension(outputFilename, '.mir');
}

getHaskellCoreOutputFilename(inputFilename) {
getHaskellCoreOutputFilename(inputFilename: string) {
return utils.changeExtension(inputFilename, '.dump-simpl');
}

getHaskellStgOutputFilename(inputFilename) {
getHaskellStgOutputFilename(inputFilename: string) {
return utils.changeExtension(inputFilename, '.dump-stg-final');
}

getHaskellCmmOutputFilename(inputFilename) {
getHaskellCmmOutputFilename(inputFilename: string) {
return utils.changeExtension(inputFilename, '.dump-cmm');
}

// Currently called for getting macro expansion and HIR.
// It returns the content of the output file created after using -Z unpretty=<unprettyOpt>.
// The outputFriendlyName is a free form string used in case of error.
async generateRustUnprettyOutput(
inputFilename,
inputFilename: string,
options,
unprettyOpt,
outputFilename,
outputFriendlyName,
outputFilename: string,
outputFriendlyName: string,
): Promise<ResultLine[]> {
const execOptions = this.getDefaultExecOptions();

Expand All @@ -1497,17 +1497,17 @@ export class BaseCompiler implements ICompiler {
return [{text: 'Internal error; unable to open output path'}];
}

async generateRustMacroExpansion(inputFilename, options): Promise<ResultLine[]> {
async generateRustMacroExpansion(inputFilename: string, options: string[]): Promise<ResultLine[]> {
const macroExpPath = this.getRustMacroExpansionOutputFilename(inputFilename);
return this.generateRustUnprettyOutput(inputFilename, options, 'expanded', macroExpPath, 'Macro Expansion');
}

async generateRustHir(inputFilename, options): Promise<ResultLine[]> {
async generateRustHir(inputFilename: string, options: string[]): Promise<ResultLine[]> {
const hirPath = this.getRustHirOutputFilename(inputFilename);
return this.generateRustUnprettyOutput(inputFilename, options, 'hir-tree', hirPath, 'HIR');
}

async processRustMirOutput(outputFilename, output): Promise<ResultLine[]> {
async processRustMirOutput(outputFilename: string, output: CompilationResult): Promise<ResultLine[]> {
const mirPath = this.getRustMirOutputFilename(outputFilename);
if (output.code !== 0) {
return [{text: 'Failed to run compiler to get Rust MIR'}];
Expand All @@ -1521,7 +1521,7 @@ export class BaseCompiler implements ICompiler {
return [{text: 'Internal error; unable to open output path'}];
}

async processHaskellExtraOutput(outpath, output): Promise<ResultLine[]> {
async processHaskellExtraOutput(outpath: string, output: CompilationResult): Promise<ResultLine[]> {
if (output.code !== 0) {
return [{text: 'Failed to run compiler to get Haskell Core'}];
}
Expand All @@ -1547,7 +1547,7 @@ export class BaseCompiler implements ICompiler {
return utils.changeExtension(inputFilename, '.ll');
}

getOutputFilename(dirPath: string, outputFilebase: string, key?: any): string {
getOutputFilename(dirPath: string, outputFilebase: string, key?: CacheKey): string {
let filename;
if (key && key.backendOptions && key.backendOptions.customOutputFilename) {
filename = key.backendOptions.customOutputFilename;
Expand All @@ -1562,11 +1562,11 @@ export class BaseCompiler implements ICompiler {
}
}

getExecutableFilename(dirPath: string, outputFilebase: string, key?) {
getExecutableFilename(dirPath: string, outputFilebase: string, key?: CacheKey) {
return this.getOutputFilename(dirPath, outputFilebase, key);
}

async processGnatDebugOutput(inputFilename, result) {
async processGnatDebugOutput(inputFilename: string, result: CompilationResult) {
const contentDebugExpanded: ResultLine[] = [];
const contentDebugTree: ResultLine[] = [];
const keep_stdout: ResultLine[] = [];
Expand Down Expand Up @@ -1645,7 +1645,7 @@ export class BaseCompiler implements ICompiler {
* `command_prefix`: command prefix to be used in case this dump is to be
* created using a targeted option (eg. -fdump-rtl-expand)
*/
fromInternalGccDumpName(internalDumpName, selectedPasses) {
fromInternalGccDumpName(internalDumpName: string, selectedPasses: string[]) {
if (!selectedPasses) selectedPasses = ['ipa', 'tree', 'rtl'];

const internalNameRe = new RegExp('^\\s*(' + selectedPasses.join('|') + ')-([\\w_-]+).*ON$');
Expand Down Expand Up @@ -1770,7 +1770,7 @@ export class BaseCompiler implements ICompiler {
};
}

protected async writeAllFilesCMake(dirPath, source, files, filters: ParseFiltersAndOutputOptions) {
protected async writeAllFilesCMake(dirPath: string, source: string, files, filters: ParseFiltersAndOutputOptions) {
if (!source) throw new Error('File CMakeLists.txt has no content or file is missing');

const inputFilename = path.join(dirPath, 'CMakeLists.txt');
Expand Down Expand Up @@ -1920,7 +1920,7 @@ export class BaseCompiler implements ICompiler {
async runExecutable(
executable: string,
executeParameters: ExecutableExecutionOptions,
homeDir,
homeDir: string,
): Promise<BasicExecutionResult> {
const execOptionsCopy: ExecutableExecutionOptions = JSON.parse(
JSON.stringify(executeParameters),
Expand Down Expand Up @@ -2072,7 +2072,7 @@ export class BaseCompiler implements ICompiler {
return cacheKey;
}

getCompilationInfo(key: CompilationCacheKey, result: CompilationResult, customBuildPath?: string): CompilationInfo {
getCompilationInfo(key: CacheKey, result: CompilationResult, customBuildPath?: string): CompilationInfo {
return {
outputFilename: this.getOutputFilename(customBuildPath || result.dirPath || '', this.outputFilebase, key),
executableFilename: this.getExecutableFilename(
Expand All @@ -2083,14 +2083,10 @@ export class BaseCompiler implements ICompiler {
asmParser: this.asm,
...key,
...result,
};
} as any as CompilationInfo;
}

getCompilationInfo2(
key: CompilationCacheKey,
result: CustomInputForTool,
customBuildPath?: string,
): CompilationInfo2 {
getCompilationInfo2(key: CacheKey, result: CustomInputForTool, customBuildPath?: string): CompilationInfo2 {
return {
executableFilename: this.getExecutableFilename(
customBuildPath || result.dirPath || '',
Expand All @@ -2100,7 +2096,7 @@ export class BaseCompiler implements ICompiler {
asmParser: this.asm,
...key,
...result,
};
} as any as CompilationInfo2;
}

tryAutodetectLibraries(libsAndOptions) {
Expand Down Expand Up @@ -2155,12 +2151,12 @@ export class BaseCompiler implements ICompiler {
}

async doCompilation(
inputFilename,
dirPath,
inputFilename: string,
dirPath: string,
key,
options,
filters,
backendOptions,
options: string[],
filters: ParseFiltersAndOutputOptions,
backendOptions: Record<string, any>,
libraries: CompileChildLibraries[],
tools,
) {
Expand All @@ -2170,7 +2166,7 @@ export class BaseCompiler implements ICompiler {

const overrides = this.sanitizeCompilerOverrides(backendOptions.overrides || []);

const downloads = await this.setupBuildEnvironment(key, dirPath, filters.binary || filters.binaryObject);
const downloads = await this.setupBuildEnvironment(key, dirPath, !!filters.binary || !!filters.binaryObject);

options = _.compact(
this.prepareArguments(
Expand Down
6 changes: 3 additions & 3 deletions lib/buildenvsetup/ceconan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export class BuildEnvSetupCeConanDirect extends BuildEnvSetupBase {
};
}

async findMatchingHash(buildProperties, possibleBuilds) {
async findMatchingHash(buildProperties: ConanBuildProperties, possibleBuilds) {
return _.findKey(possibleBuilds, elem => {
return _.all(buildProperties, (val, key) => {
if ((key === 'compiler' || key === 'compiler.version') && elem.settings[key] === 'cshared') {
Expand All @@ -255,7 +255,7 @@ export class BuildEnvSetupCeConanDirect extends BuildEnvSetupBase {
const allDownloads: Promise<BuildEnvDownloadInfo>[] = [];
const allLibraryBuilds: any = [];

_.each(libraryDetails, (details, libId) => {
_.each(libraryDetails, (details: VersionInfo, libId: string) => {
if (details.packagedheaders || this.hasBinariesToLink(details)) {
const lookupname = details.lookupname || libId;
const lookupversion = details.lookupversion || details.version;
Expand Down Expand Up @@ -306,7 +306,7 @@ export class BuildEnvSetupCeConanDirect extends BuildEnvSetupBase {

if (this.onlyonstaticliblink && !binary) return [];

const librariesToDownload = _.pick(libraryDetails, details => {
const librariesToDownload = _.pick(libraryDetails, (details: VersionInfo) => {
return this.shouldDownloadPackage(details);
}) as Record<string, VersionInfo>;

Expand Down
28 changes: 19 additions & 9 deletions lib/buildenvsetup/cliconan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ import path from 'path';
import fs from 'fs-extra';
import _ from 'underscore';

import {CacheKey} from '../../types/compilation/compilation.interfaces.js';
import {CompilerInfo} from '../../types/compiler.interfaces.js';
import {CompilationEnvironment} from '../compilation-env.js';
import * as exec from '../exec.js';
import {logger} from '../logger.js';
import {VersionInfo} from '../options-handler.js';

import {BuildEnvSetupBase} from './base.js';
import type {BuildEnvDownloadInfo} from './buildenv.interfaces.js';
Expand All @@ -42,24 +46,30 @@ export class BuildEnvSetupCliConan extends BuildEnvSetupBase {
return 'cliconan';
}

constructor(compilerInfo, env) {
constructor(compilerInfo: CompilerInfo, env: CompilationEnvironment) {
super(compilerInfo, env);

this.exe = compilerInfo.buildenvsetup.props('exe', 'conan');
this.remote = compilerInfo.buildenvsetup.props('remote', false);
this.onlyonstaticliblink = compilerInfo.buildenvsetup.props('onlyonstaticliblink', true);
this.exe = compilerInfo.buildenvsetup!.props('exe', 'conan');
this.remote = compilerInfo.buildenvsetup!.props('remote', false);
this.onlyonstaticliblink = compilerInfo.buildenvsetup!.props('onlyonstaticliblink', true);
}

override async setup(key, dirPath, libraryDetails, binary): Promise<BuildEnvDownloadInfo[]> {
override async setup(
key: CacheKey,
dirPath: string,
libraryDetails: Record<string, VersionInfo>,
binary: boolean,
): Promise<BuildEnvDownloadInfo[]> {
if (this.onlyonstaticliblink && !binary) return [];

const librariesToDownload = libraryDetails.filter(details => this.shouldDownloadPackage(details));
const librariesToDownload = libraryDetails.filter((details: VersionInfo) =>
this.shouldDownloadPackage(details),
);

await this.prepareConanRequest(librariesToDownload, dirPath);
return this.installLibrariesViaConan(key, dirPath);
}

async prepareConanRequest(libraryDetails, dirPath) {
async prepareConanRequest(libraryDetails: Record<string, VersionInfo>, dirPath: string) {
let data = '[requires]\n';

_.each(libraryDetails, (details, libId) => {
Expand All @@ -77,7 +87,7 @@ export class BuildEnvSetupCliConan extends BuildEnvSetupBase {
return fs.writeFile(path.join(dirPath, 'conanfile.txt'), data);
}

async installLibrariesViaConan(key, dirPath) {
async installLibrariesViaConan(key: CacheKey, dirPath: string): Promise<BuildEnvDownloadInfo[]> {
const arch = this.getTarget(key);
const libcxx = this.getLibcxx(key);
const stdver = '';
Expand Down
2 changes: 2 additions & 0 deletions lib/cache/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {Buffer} from 'buffer';

import {Counter} from 'prom-client';

import type {CacheableValue, GetResult} from '../../types/cache.interfaces.js';
Expand Down
2 changes: 2 additions & 0 deletions lib/cache/in-memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {Buffer} from 'buffer';

import {LRUCache} from 'lru-cache';

import type {GetResult} from '../../types/cache.interfaces.js';
Expand Down
2 changes: 2 additions & 0 deletions lib/cache/multi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {Buffer} from 'buffer';

import type {GetResult} from '../../types/cache.interfaces.js';
import {unwrap} from '../assert.js';

Expand Down
1 change: 1 addition & 0 deletions lib/cache/on-disk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {Buffer} from 'buffer';
import crypto from 'crypto';
import path from 'path';

Expand Down
2 changes: 2 additions & 0 deletions lib/cache/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {Buffer} from 'buffer';

import {StorageClass} from '@aws-sdk/client-s3';

import type {GetResult} from '../../types/cache.interfaces.js';
Expand Down
2 changes: 1 addition & 1 deletion lib/compiler-finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ export class CompilerFinder {
},
externalparser: {
id: props('externalparser', ''),
props: (name, def) => {
props: (name: string, def: any) => {
return props(`externalparser.${name}`, def);
},
},
Expand Down
4 changes: 2 additions & 2 deletions lib/compilers/argument-parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class BaseParser {
}

static getExamplesRoot(): string {
return props.get('builtin', 'sourcePath', './examples/');
return props.get('builtin', 'sourcePath', './examples/') as string;
}

static getDefaultExampleFilename() {
Expand Down Expand Up @@ -422,7 +422,7 @@ export class ClangParser extends BaseParser {
return this.extractPossibleTargets(utils.splitLines(result.stdout));
}

static override async getOptions(compiler, helpArg, populate = true, isolate = false) {
static override async getOptions(compiler, helpArg: string, populate = true, isolate = false) {
const optionFinderWithDesc = /^ {2}?(--?[\d#+,<=>A-Z[\]a-z|-]*\s?[\d+,<=>A-Z[\]a-z|-]*)\s+([A-Z].*)/;
const optionFinderWithoutDesc = /^ {2}?(--?[\d#+,<=>[\]a-z|-]*\s?[\d+,<=>[\]a-z|-]*)/i;
const execOptions = {...compiler.getDefaultExecOptions()};
Expand Down
Loading

0 comments on commit f9266e5

Please sign in to comment.