This commit is contained in:
Andrew Eisenberg
2021-08-09 11:37:06 -07:00
parent 47cfd760cf
commit f3f429af7c
12 changed files with 145 additions and 32 deletions
Generated
+34 -10
View File
@@ -273,6 +273,7 @@ function resolveFunction(partialCodeql, methodName, defaultImplementation) {
*/
function setCodeQL(partialCodeql) {
cachedCodeQL = {
getVersion: resolveFunction(partialCodeql, "getVersion", () => Promise.resolve("0.0.0")),
getPath: resolveFunction(partialCodeql, "getPath", () => "/tmp/dummy-path"),
printVersion: resolveFunction(partialCodeql, "printVersion"),
getTracerEnv: resolveFunction(partialCodeql, "getTracerEnv"),
@@ -306,12 +307,28 @@ function getCachedCodeQL() {
}
exports.getCachedCodeQL = getCachedCodeQL;
function getCodeQLForCmd(cmd) {
let version;
return {
async getVersion() {
if (!version) {
await this.printVersion();
}
return version;
},
getPath() {
return cmd;
},
async printVersion() {
await runTool(cmd, ["version", "--format=json"]);
const output = await runTool(cmd, ["version", "--format=json"]);
try {
version = JSON.parse(output).version;
if (!version) {
throw new Error("Missing version");
}
}
catch (e) {
throw new Error(`Unexpected output from codeql version: ${e}`);
}
},
async getTracerEnv(databasePath) {
// Write tracer-env.js to a temp location.
@@ -498,22 +515,22 @@ function getCodeQLForCmd(cmd) {
* downloaded. The check to determine what the latest version is is done
* each time this package is requested.
*/
async packDownload(packs) {
async packDownload(packsOrSuites, extraSearchPath) {
const codeqlArgs = [
"pack",
"download",
"--format=json",
...getExtraOptionsFromEnv(["pack", "download"]),
...packs.map(packWithVersionToString),
...packsOrSuites,
];
if (extraSearchPath) {
codeqlArgs.push("--additional-packs", extraSearchPath);
}
const output = await runTool(cmd, codeqlArgs);
try {
const parsedOutput = JSON.parse(output);
if (Array.isArray(parsedOutput.packs) &&
// TODO PackDownloadOutput will not include the version if it is not specified
// in the input. The version is always the latest version available.
// It should be added to the output, but this requires a CLI change
parsedOutput.packs.every((p) => p.name /* && p.version */)) {
parsedOutput.packs.every((p) => p.name && p.version)) {
return parsedOutput;
}
else {
@@ -544,9 +561,6 @@ function getCodeQLForCmd(cmd) {
},
};
}
function packWithVersionToString(pack) {
return pack.version ? `${pack.packName}@${pack.version}` : pack.packName;
}
/**
* Gets the options for `path` of `options` as an array of extra option strings.
*/
@@ -593,6 +607,16 @@ function getExtraOptions(options, paths, pathInfo) {
return all.concat(specific);
}
exports.getExtraOptions = getExtraOptions;
// TODO verify that this is the correct version.
const CODEQL_MIN_VERSION_DOWNLOAD_PACKS_FROM_SUITES = ">=2.6.0";
/**
* Determines if this codeql supports introspecting query suites to look for packages
* to download.
*/
async function supportsDownloadPacksFromSuites(codeQL) {
return semver.satisfies(await codeQL.getVersion(), CODEQL_MIN_VERSION_DOWNLOAD_PACKS_FROM_SUITES);
}
exports.supportsDownloadPacksFromSuites = supportsDownloadPacksFromSuites;
/*
* A constant defining the maximum number of characters we will keep from
* the programs stderr for logging. This serves two purposes: