Set optimizeForLastQueryRun on last run
This commit is contained in:
parent
08d1f21d4f
commit
0e4e857bab
3 changed files with 28 additions and 17 deletions
21
lib/analyze.js
generated
21
lib/analyze.js
generated
|
|
@ -132,6 +132,7 @@ async function runQueries(sarifFolder, memoryFlag, addSnippetsFlag, threadsFlag,
|
|||
const queries = config.queries[language];
|
||||
const queryFilters = validateQueryFilters(config.originalUserInput["query-filters"]);
|
||||
const packsWithVersion = config.packs[language] || [];
|
||||
const isLastLanguage = language === config.languages[config.languages.length - 1];
|
||||
try {
|
||||
if (await util.useCodeScanningConfigInCli(codeql, featureEnablement)) {
|
||||
// If we are using the code scanning config in the CLI,
|
||||
|
|
@ -141,7 +142,7 @@ async function runQueries(sarifFolder, memoryFlag, addSnippetsFlag, threadsFlag,
|
|||
// another to interpret the results.
|
||||
logger.startGroup(`Running queries for ${language}`);
|
||||
const startTimeBuiltIn = new Date().getTime();
|
||||
await runQueryGroup(language, "all", undefined, undefined);
|
||||
await runQueryGroup(language, "all", undefined, undefined, isLastLanguage);
|
||||
// TODO should not be using `builtin` here. We should be using `all` instead.
|
||||
// The status report does not support `all` yet.
|
||||
statusReport[`analyze_builtin_queries_${language}_duration_ms`] =
|
||||
|
|
@ -175,18 +176,22 @@ async function runQueries(sarifFolder, memoryFlag, addSnippetsFlag, threadsFlag,
|
|||
const querySuitePaths = [];
|
||||
if (queries.builtin.length > 0) {
|
||||
const startTimeBuiltIn = new Date().getTime();
|
||||
querySuitePaths.push((await runQueryGroup(language, "builtin", createQuerySuiteContents(queries.builtin, queryFilters), undefined)));
|
||||
querySuitePaths.push((await runQueryGroup(language, "builtin", createQuerySuiteContents(queries.builtin, queryFilters), undefined, isLastLanguage &&
|
||||
customQueryIndices.length === 0 &&
|
||||
packsWithVersion.length === 0)));
|
||||
statusReport[`analyze_builtin_queries_${language}_duration_ms`] =
|
||||
new Date().getTime() - startTimeBuiltIn;
|
||||
}
|
||||
const startTimeCustom = new Date().getTime();
|
||||
let ranCustom = false;
|
||||
for (const i of customQueryIndices) {
|
||||
querySuitePaths.push((await runQueryGroup(language, `custom-${i}`, createQuerySuiteContents(queries.custom[i].queries, queryFilters), queries.custom[i].searchPath)));
|
||||
querySuitePaths.push((await runQueryGroup(language, `custom-${i}`, createQuerySuiteContents(queries.custom[i].queries, queryFilters), queries.custom[i].searchPath, isLastLanguage &&
|
||||
i === customQueryIndices[customQueryIndices.length - 1] &&
|
||||
packsWithVersion.length === 0)));
|
||||
ranCustom = true;
|
||||
}
|
||||
if (packsWithVersion.length > 0) {
|
||||
querySuitePaths.push(await runQueryPacks(language, "packs", packsWithVersion, queryFilters));
|
||||
querySuitePaths.push(await runQueryPacks(language, "packs", packsWithVersion, queryFilters, isLastLanguage));
|
||||
ranCustom = true;
|
||||
}
|
||||
if (ranCustom) {
|
||||
|
|
@ -223,7 +228,7 @@ async function runQueries(sarifFolder, memoryFlag, addSnippetsFlag, threadsFlag,
|
|||
const databasePath = util.getCodeQLDatabasePath(config, language);
|
||||
return await codeql.databasePrintBaseline(databasePath);
|
||||
}
|
||||
async function runQueryGroup(language, type, querySuiteContents, searchPath) {
|
||||
async function runQueryGroup(language, type, querySuiteContents, searchPath, optimizeForLastQueryRun) {
|
||||
const databasePath = util.getCodeQLDatabasePath(config, language);
|
||||
// Pass the queries to codeql using a file instead of using the command
|
||||
// line to avoid command line length restrictions, particularly on windows.
|
||||
|
|
@ -234,11 +239,11 @@ async function runQueries(sarifFolder, memoryFlag, addSnippetsFlag, threadsFlag,
|
|||
fs.writeFileSync(querySuitePath, querySuiteContents);
|
||||
logger.debug(`Query suite file for ${language}-${type}...\n${querySuiteContents}`);
|
||||
}
|
||||
await codeql.databaseRunQueries(databasePath, searchPath, querySuitePath, queryFlags, false);
|
||||
await codeql.databaseRunQueries(databasePath, searchPath, querySuitePath, queryFlags, optimizeForLastQueryRun);
|
||||
logger.debug(`BQRS results produced for ${language} (queries: ${type})"`);
|
||||
return querySuitePath;
|
||||
}
|
||||
async function runQueryPacks(language, type, packs, queryFilters) {
|
||||
async function runQueryPacks(language, type, packs, queryFilters, optimizeForLastQueryRun) {
|
||||
const databasePath = util.getCodeQLDatabasePath(config, language);
|
||||
for (const pack of packs) {
|
||||
logger.debug(`Running query pack for ${language}-${type}: ${pack}`);
|
||||
|
|
@ -248,7 +253,7 @@ async function runQueries(sarifFolder, memoryFlag, addSnippetsFlag, threadsFlag,
|
|||
const querySuitePath = `${databasePath}-queries-${type}.qls`;
|
||||
fs.writeFileSync(querySuitePath, yaml.dump(querySuite));
|
||||
logger.debug(`BQRS results produced for ${language} (queries: ${type})"`);
|
||||
await codeql.databaseRunQueries(databasePath, undefined, querySuitePath, queryFlags, false);
|
||||
await codeql.databaseRunQueries(databasePath, undefined, querySuitePath, queryFlags, optimizeForLastQueryRun);
|
||||
return querySuitePath;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -232,7 +232,7 @@ export async function runQueries(
|
|||
// another to interpret the results.
|
||||
logger.startGroup(`Running queries for ${language}`);
|
||||
const startTimeBuiltIn = new Date().getTime();
|
||||
await runQueryGroup(language, "all", undefined, undefined);
|
||||
await runQueryGroup(language, "all", undefined, undefined, true);
|
||||
// TODO should not be using `builtin` here. We should be using `all` instead.
|
||||
// The status report does not support `all` yet.
|
||||
statusReport[`analyze_builtin_queries_${language}_duration_ms`] =
|
||||
|
|
@ -284,7 +284,8 @@ export async function runQueries(
|
|||
language,
|
||||
"builtin",
|
||||
createQuerySuiteContents(queries.builtin, queryFilters),
|
||||
undefined
|
||||
undefined,
|
||||
customQueryIndices.length === 0 && packsWithVersion.length === 0
|
||||
)) as string
|
||||
);
|
||||
statusReport[`analyze_builtin_queries_${language}_duration_ms`] =
|
||||
|
|
@ -298,7 +299,9 @@ export async function runQueries(
|
|||
language,
|
||||
`custom-${i}`,
|
||||
createQuerySuiteContents(queries.custom[i].queries, queryFilters),
|
||||
queries.custom[i].searchPath
|
||||
queries.custom[i].searchPath,
|
||||
i === customQueryIndices[customQueryIndices.length - 1] &&
|
||||
packsWithVersion.length === 0
|
||||
)) as string
|
||||
);
|
||||
ranCustom = true;
|
||||
|
|
@ -309,7 +312,8 @@ export async function runQueries(
|
|||
language,
|
||||
"packs",
|
||||
packsWithVersion,
|
||||
queryFilters
|
||||
queryFilters,
|
||||
true
|
||||
)
|
||||
);
|
||||
ranCustom = true;
|
||||
|
|
@ -376,7 +380,8 @@ export async function runQueries(
|
|||
language: Language,
|
||||
type: string,
|
||||
querySuiteContents: string | undefined,
|
||||
searchPath: string | undefined
|
||||
searchPath: string | undefined,
|
||||
optimizeForLastQueryRun: boolean
|
||||
): Promise<string | undefined> {
|
||||
const databasePath = util.getCodeQLDatabasePath(config, language);
|
||||
// Pass the queries to codeql using a file instead of using the command
|
||||
|
|
@ -395,7 +400,7 @@ export async function runQueries(
|
|||
searchPath,
|
||||
querySuitePath,
|
||||
queryFlags,
|
||||
false
|
||||
optimizeForLastQueryRun
|
||||
);
|
||||
|
||||
logger.debug(`BQRS results produced for ${language} (queries: ${type})"`);
|
||||
|
|
@ -405,7 +410,8 @@ export async function runQueries(
|
|||
language: Language,
|
||||
type: string,
|
||||
packs: string[],
|
||||
queryFilters: configUtils.QueryFilter[]
|
||||
queryFilters: configUtils.QueryFilter[],
|
||||
optimizeForLastQueryRun: boolean
|
||||
): Promise<string> {
|
||||
const databasePath = util.getCodeQLDatabasePath(config, language);
|
||||
|
||||
|
|
@ -428,7 +434,7 @@ export async function runQueries(
|
|||
undefined,
|
||||
querySuitePath,
|
||||
queryFlags,
|
||||
false
|
||||
optimizeForLastQueryRun
|
||||
);
|
||||
|
||||
return querySuitePath;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue