Use resolve extractor when finding autobuild scripts

This commit is contained in:
Henry Mercer
2023-05-16 11:18:16 +01:00
parent 5489416722
commit e422b64793
3 changed files with 60 additions and 64 deletions

View File

@@ -196,6 +196,8 @@ export interface CodeQL {
config: Config,
features: FeatureEnablement
): Promise<void>;
/** Get the location of an extractor for the specified language. */
resolveExtractor(language: Language): Promise<string>;
}
export interface ResolveLanguagesOutput {
@@ -418,6 +420,7 @@ export function setCodeQL(partialCodeql: Partial<CodeQL>): CodeQL {
"databaseExportDiagnostics"
),
diagnosticsExport: resolveFunction(partialCodeql, "diagnosticsExport"),
resolveExtractor: resolveFunction(partialCodeql, "resolveExtractor"),
};
return cachedCodeQL;
}
@@ -547,17 +550,10 @@ export async function getCodeQLForCmd(
);
},
async runAutobuild(language: Language) {
const cmdName =
process.platform === "win32" ? "autobuild.cmd" : "autobuild.sh";
// The autobuilder for Swift is located in the experimental/ directory.
const possibleExperimentalDir =
language === Language.swift ? "experimental" : "";
const autobuildCmd = path.join(
path.dirname(cmd),
possibleExperimentalDir,
language,
await this.resolveExtractor(language),
"tools",
cmdName
process.platform === "win32" ? "autobuild.cmd" : "autobuild.sh"
);
// Update JAVA_TOOL_OPTIONS to contain '-Dhttp.keepAlive=false'
@@ -590,37 +586,11 @@ export async function getCodeQLForCmd(
},
async extractScannedLanguage(config: Config, language: Language) {
const databasePath = util.getCodeQLDatabasePath(config, language);
// Get extractor location
//
// Request it using `format=json` so we don't need to strip the trailing new line generated by
// the CLI.
let extractorPath = "";
await new toolrunner.ToolRunner(
cmd,
[
"resolve",
"extractor",
"--format=json",
`--language=${language}`,
...getExtraOptionsFromEnv(["resolve", "extractor"]),
],
{
silent: true,
listeners: {
stdout: (data) => {
extractorPath += data.toString();
},
stderr: (data) => {
process.stderr.write(data);
},
},
}
).exec();
// Set trace command
const ext = process.platform === "win32" ? ".cmd" : ".sh";
const traceCommand = path.resolve(
JSON.parse(extractorPath) as string,
await this.resolveExtractor(language),
"tools",
`autobuild${ext}`
);
@@ -954,6 +924,33 @@ export async function getCodeQLForCmd(
}
await new toolrunner.ToolRunner(cmd, args).exec();
},
async resolveExtractor(language: Language): Promise<string> {
// Request it using `format=json` so we don't need to strip the trailing new line generated by
// the CLI.
let extractorPath = "";
await new toolrunner.ToolRunner(
cmd,
[
"resolve",
"extractor",
"--format=json",
`--language=${language}`,
...getExtraOptionsFromEnv(["resolve", "extractor"]),
],
{
silent: true,
listeners: {
stdout: (data) => {
extractorPath += data.toString();
},
stderr: (data) => {
process.stderr.write(data);
},
},
}
).exec();
return JSON.parse(extractorPath);
},
};
// To ensure that status reports include the CodeQL CLI version wherever
// possible, we want to call getVersion(), which populates the version value