spec: use SPEC interface

This commit is contained in:
2024-06-18 02:02:20 +08:00
parent 4925db51a9
commit 8094248810

40
spec.ts
View File

@@ -1,4 +1,7 @@
import * as path from 'path';
import * as fs from "fs";
import { promisify } from "util";
import { SW_AUTOVEC } from "./environment";
export interface SPECBench {
objectNames: string[];
@@ -356,3 +359,40 @@ export function setenv(specdir: string): void {
process.env.SPEC = specdir;
process.env.PATH = `${path.join(specdir, 'bin')}${path.delimiter}${process.env.PATH}`;
}
export interface SPEC {
newConfig: (name: string, content: string) => Promise<void>;
benchpath: (bench: SPECBench) => string;
exepath: (bench: SPECBench) => string;
buildpath: (bench: SPECBench) => string;
setenv: () => void;
}
export function mkSPEC(specRoot: string): SPEC {
return {
newConfig: async (name: string, content: string) => {
await writeFile(path.join(specRoot, "config", name), content);
},
benchpath: bench => benchpath(specRoot, bench),
exepath: bench => exepath(specRoot, bench),
buildpath: bench => buildpath(specRoot, bench),
setenv: () => setenv(specRoot),
};
}
export const defaultSPEC = mkSPEC(path.join(SW_AUTOVEC, "spec2017"));
const specTemplate = fs.readFileSync("assets/specTemplate.cfg").toString("utf-8");
const writeFile = promisify(fs.writeFile);
interface ConfigOptions {
gccdir: string;
optimize: string;
}
export function renderConfig(options: ConfigOptions) {
return `# Rendered from TypeScript, do not edit!\n\n\n` + specTemplate
.replace("@@GCCDIR@@", options.gccdir)
.replace("@@OPTIMIZE@@", options.optimize);
}