Autobuild using CodeQL CLI

This commit is contained in:
Henry Mercer
2023-03-28 17:16:14 +01:00
parent bc0ed6a6c3
commit 43d8ea1026
15 changed files with 174 additions and 79 deletions
Generated
+31 -13
View File
@@ -179,7 +179,7 @@ function setCodeQL(partialCodeql) {
getTracerEnv: resolveFunction(partialCodeql, "getTracerEnv"),
databaseInit: resolveFunction(partialCodeql, "databaseInit"),
databaseInitCluster: resolveFunction(partialCodeql, "databaseInitCluster"),
runAutobuild: resolveFunction(partialCodeql, "runAutobuild"),
runAutobuildScript: resolveFunction(partialCodeql, "runAutobuildScript"),
extractScannedLanguage: resolveFunction(partialCodeql, "extractScannedLanguage"),
finalizeDatabase: resolveFunction(partialCodeql, "finalizeDatabase"),
resolveLanguages: resolveFunction(partialCodeql, "resolveLanguages"),
@@ -193,6 +193,7 @@ function setCodeQL(partialCodeql) {
databasePrintBaseline: resolveFunction(partialCodeql, "databasePrintBaseline"),
databaseExportDiagnostics: resolveFunction(partialCodeql, "databaseExportDiagnostics"),
diagnosticsExport: resolveFunction(partialCodeql, "diagnosticsExport"),
databaseAutobuild: resolveFunction(partialCodeql, "databaseAutobuild"),
};
return cachedCodeQL;
}
@@ -354,22 +355,12 @@ async function getCodeQLForCmd(cmd, checkVersion) {
...getExtraOptionsFromEnv(["database", "init"]),
], { stdin: externalRepositoryToken });
},
async runAutobuild(language) {
async runAutobuildScript(language) {
const cmdName = process.platform === "win32" ? "autobuild.cmd" : "autobuild.sh";
// The autobuilder for Swift is located in the experimental/ directory.
const possibleExperimentalDir = language === languages_1.Language.swift ? "experimental" : "";
const autobuildCmd = path.join(path.dirname(cmd), possibleExperimentalDir, language, "tools", cmdName);
// Update JAVA_TOOL_OPTIONS to contain '-Dhttp.keepAlive=false'
// This is because of an issue with Azure pipelines timing out connections after 4 minutes
// and Maven not properly handling closed connections
// Otherwise long build processes will timeout when pulling down Java packages
// https://developercommunity.visualstudio.com/content/problem/292284/maven-hosted-agent-connection-timeout.html
const javaToolOptions = process.env["JAVA_TOOL_OPTIONS"] || "";
process.env["JAVA_TOOL_OPTIONS"] = [
...javaToolOptions.split(/\s+/),
"-Dhttp.keepAlive=false",
"-Dmaven.wagon.http.pool=false",
].join(" ");
updateEnvForAutobuild();
// On macOS, System Integrity Protection (SIP) typically interferes with
// CodeQL build tracing of protected binaries.
// The usual workaround is to prefix `$CODEQL_RUNNER` to build commands:
@@ -656,6 +647,20 @@ async function getCodeQLForCmd(cmd, checkVersion) {
}
await new toolrunner.ToolRunner(cmd, args).exec();
},
async databaseAutobuild(databasePath, workingDirectory) {
const args = [
"database",
"autobuild",
"--db-cluster",
databasePath,
...getExtraOptionsFromEnv(["database", "autobuild"]),
];
if (workingDirectory !== undefined) {
args.push("--working-dir", workingDirectory);
}
updateEnvForAutobuild();
await new toolrunner.ToolRunner(cmd, args).exec();
},
};
// To ensure that status reports include the CodeQL CLI version wherever
// possible, we want to call getVersion(), which populates the version value
@@ -856,4 +861,17 @@ async function enrichEnvironment(codeql) {
}
}
exports.enrichEnvironment = enrichEnvironment;
function updateEnvForAutobuild() {
// Update JAVA_TOOL_OPTIONS to contain '-Dhttp.keepAlive=false'
// This is because of an issue with Azure pipelines timing out connections after 4 minutes
// and Maven not properly handling closed connections
// Otherwise long build processes will timeout when pulling down Java packages
// https://developercommunity.visualstudio.com/content/problem/292284/maven-hosted-agent-connection-timeout.html
const javaToolOptions = process.env["JAVA_TOOL_OPTIONS"] || "";
process.env["JAVA_TOOL_OPTIONS"] = [
...javaToolOptions.split(/\s+/),
"-Dhttp.keepAlive=false",
"-Dmaven.wagon.http.pool=false",
].join(" ");
}
//# sourceMappingURL=codeql.js.map