Skip to content

Commit

Permalink
databaseRunQueries(): add optimizeForLastQueryRun parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
cklin committed Feb 15, 2023
1 parent 3095a09 commit 8242edb
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lib/analyze.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/analyze.js.map

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion lib/codeql.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/codeql.js.map

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion lib/util.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/util.js.map

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions src/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,8 @@ export async function runQueries(
databasePath,
searchPath,
querySuitePath,
queryFlags
queryFlags,
false
);

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

return querySuitePath;
Expand Down
18 changes: 16 additions & 2 deletions src/codeql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'.
Expand Down Expand Up @@ -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",
Expand All @@ -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);
}
Expand Down
9 changes: 9 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down

0 comments on commit 8242edb

Please sign in to comment.