MCPcopy
hub / github.com/compiler-explorer/compiler-explorer / runCompiler

Method runCompiler

lib/compilers/nix.ts:36–66  ·  view source on GitHub ↗
(
        compiler: string,
        options: string[],
        inputFilename: string,
        execOptions: ExecutionOptions & {env: Record<string, string>},
    )

Source from the content-addressed store, hash-verified

34 }
35
36 override async runCompiler(
37 compiler: string,
38 options: string[],
39 inputFilename: string,
40 execOptions: ExecutionOptions & {env: Record<string, string>},
41 ) {
42 if (!execOptions) {
43 execOptions = this.getDefaultExecOptions();
44 }
45
46 execOptions.customCwd = path.dirname(inputFilename);
47 const dirPath = path.dirname(inputFilename);
48 if (!execOptions.customCwd) {
49 execOptions.customCwd = dirPath;
50 }
51
52 const compilerExecResult = await super.runCompiler(compiler, options, inputFilename, execOptions);
53 if (compilerExecResult.stdout.length > 0) {
54 const outputFilename = this.getOutputFilename(dirPath, this.outputFilebase);
55 const outputText = compilerExecResult.stdout.map(line => line.text).join('\n');
56
57 if (options.includes('--json')) {
58 // Parse and pretty-print if --json is passed
59 await fs.writeFile(outputFilename, JSON.stringify(JSON.parse(outputText), null, 2));
60 } else {
61 // Otherwise, write raw output (Should call nixfmt probably)
62 await fs.writeFile(outputFilename, outputText);
63 }
64 }
65 return compilerExecResult;
66 }
67
68 override optionsForFilter(): any[] {
69 return [];

Callers

nothing calls this directly

Calls 3

getOutputFilenameMethod · 0.65
getDefaultExecOptionsMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected