databaseRunQueries(): add optimizeForLastQueryRun parameter

This commit is contained in:
Chuan-kai Lin 2023-02-15 08:45:13 -08:00
parent 3095a09bb0
commit 8242edb8ed
9 changed files with 47 additions and 11 deletions

View file

@ -392,7 +392,8 @@ export async function runQueries(
databasePath,
searchPath,
querySuitePath,
queryFlags
queryFlags,
false
);
logger.debug(`BQRS results produced for ${language} (queries: ${type})"`);
@ -424,7 +425,8 @@ export async function runQueries(
databasePath,
undefined,
querySuitePath,
queryFlags
queryFlags,
false
);
return querySuitePath;

View file

@ -148,12 +148,19 @@ export interface CodeQL {
): Promise<void>;
/**
* Run 'codeql database run-queries'.
*
* @param optimizeForLastQueryRun Whether to apply additional optimization for
* the last database query run in the action.
* It is always safe to set it to false.
* It should be set to true only for the very
* last databaseRunQueries() call.
*/
databaseRunQueries(
databasePath: string,
extraSearchPath: string | undefined,
querySuitePath: string | undefined,
flags: string[]
flags: string[],
optimizeForLastQueryRun: boolean
): Promise<void>;
/**
* Run 'codeql database interpret-results'.
@ -788,7 +795,8 @@ export async function getCodeQLForCmd(
databasePath: string,
extraSearchPath: string | undefined,
querySuitePath: string | undefined,
flags: string[]
flags: string[],
optimizeForLastQueryRun: boolean
): Promise<void> {
const codeqlArgs = [
"database",
@ -799,6 +807,12 @@ export async function getCodeQLForCmd(
"-v",
...getExtraOptionsFromEnv(["database", "run-queries"]),
];
if (
optimizeForLastQueryRun &&
(await util.supportExpectDiscardedCache(this))
) {
codeqlArgs.push("--expect-discarded-cache");
}
if (extraSearchPath !== undefined) {
codeqlArgs.push("--additional-packs", extraSearchPath);
}

View file

@ -571,6 +571,15 @@ export function isGoodVersion(versionSpec: string) {
return !BROKEN_VERSIONS.includes(versionSpec);
}
/**
* Checks whether the CodeQL CLI supports the `--expect-discarded-cache` command-line flag.
*/
export async function supportExpectDiscardedCache(
codeQL: CodeQL
): Promise<boolean> {
return codeQlVersionAbove(codeQL, "2.12.1");
}
export const ML_POWERED_JS_QUERIES_PACK_NAME =
"codeql/javascript-experimental-atm-queries";