databaseRunQueries(): accept a list of flags

This refactoring commit changes databaseRunQueries() to accept a list of
flags instead of separate memory and threads flags.
This commit is contained in:
Chuan-kai Lin 2023-02-14 11:53:52 -08:00
parent e00cd12e3e
commit 3095a09bb0
6 changed files with 13 additions and 17 deletions

5
lib/analyze.js generated
View file

@ -126,6 +126,7 @@ async function finalizeDatabaseCreation(config, threadsFlag, memoryFlag, logger)
async function runQueries(sarifFolder, memoryFlag, addSnippetsFlag, threadsFlag, automationDetailsId, config, logger, featureEnablement) { async function runQueries(sarifFolder, memoryFlag, addSnippetsFlag, threadsFlag, automationDetailsId, config, logger, featureEnablement) {
const statusReport = {}; const statusReport = {};
const codeql = await (0, codeql_1.getCodeQL)(config.codeQLCmd); const codeql = await (0, codeql_1.getCodeQL)(config.codeQLCmd);
const queryFlags = [memoryFlag, threadsFlag];
await util.logCodeScanningConfigInCli(codeql, featureEnablement, logger); await util.logCodeScanningConfigInCli(codeql, featureEnablement, logger);
for (const language of config.languages) { for (const language of config.languages) {
const queries = config.queries[language]; const queries = config.queries[language];
@ -229,7 +230,7 @@ async function runQueries(sarifFolder, memoryFlag, addSnippetsFlag, threadsFlag,
fs.writeFileSync(querySuitePath, querySuiteContents); fs.writeFileSync(querySuitePath, querySuiteContents);
logger.debug(`Query suite file for ${language}-${type}...\n${querySuiteContents}`); logger.debug(`Query suite file for ${language}-${type}...\n${querySuiteContents}`);
} }
await codeql.databaseRunQueries(databasePath, searchPath, querySuitePath, memoryFlag, threadsFlag); await codeql.databaseRunQueries(databasePath, searchPath, querySuitePath, queryFlags);
logger.debug(`BQRS results produced for ${language} (queries: ${type})"`); logger.debug(`BQRS results produced for ${language} (queries: ${type})"`);
return querySuitePath; return querySuitePath;
} }
@ -243,7 +244,7 @@ async function runQueries(sarifFolder, memoryFlag, addSnippetsFlag, threadsFlag,
const querySuitePath = `${databasePath}-queries-${type}.qls`; const querySuitePath = `${databasePath}-queries-${type}.qls`;
fs.writeFileSync(querySuitePath, yaml.dump(querySuite)); fs.writeFileSync(querySuitePath, yaml.dump(querySuite));
logger.debug(`BQRS results produced for ${language} (queries: ${type})"`); logger.debug(`BQRS results produced for ${language} (queries: ${type})"`);
await codeql.databaseRunQueries(databasePath, undefined, querySuitePath, memoryFlag, threadsFlag); await codeql.databaseRunQueries(databasePath, undefined, querySuitePath, queryFlags);
return querySuitePath; return querySuitePath;
} }
} }

File diff suppressed because one or more lines are too long

5
lib/codeql.js generated
View file

@ -472,12 +472,11 @@ async function getCodeQLForCmd(cmd, checkVersion) {
throw new Error(`Unexpected output from codeql resolve queries: ${e}`); throw new Error(`Unexpected output from codeql resolve queries: ${e}`);
} }
}, },
async databaseRunQueries(databasePath, extraSearchPath, querySuitePath, memoryFlag, threadsFlag) { async databaseRunQueries(databasePath, extraSearchPath, querySuitePath, flags) {
const codeqlArgs = [ const codeqlArgs = [
"database", "database",
"run-queries", "run-queries",
memoryFlag, ...flags,
threadsFlag,
databasePath, databasePath,
"--min-disk-free=1024", "--min-disk-free=1024",
"-v", "-v",

File diff suppressed because one or more lines are too long

View file

@ -212,6 +212,7 @@ export async function runQueries(
const statusReport: QueriesStatusReport = {}; const statusReport: QueriesStatusReport = {};
const codeql = await getCodeQL(config.codeQLCmd); const codeql = await getCodeQL(config.codeQLCmd);
const queryFlags = [memoryFlag, threadsFlag];
await util.logCodeScanningConfigInCli(codeql, featureEnablement, logger); await util.logCodeScanningConfigInCli(codeql, featureEnablement, logger);
@ -391,8 +392,7 @@ export async function runQueries(
databasePath, databasePath,
searchPath, searchPath,
querySuitePath, querySuitePath,
memoryFlag, queryFlags
threadsFlag
); );
logger.debug(`BQRS results produced for ${language} (queries: ${type})"`); logger.debug(`BQRS results produced for ${language} (queries: ${type})"`);
@ -424,8 +424,7 @@ export async function runQueries(
databasePath, databasePath,
undefined, undefined,
querySuitePath, querySuitePath,
memoryFlag, queryFlags
threadsFlag
); );
return querySuitePath; return querySuitePath;

View file

@ -153,8 +153,7 @@ export interface CodeQL {
databasePath: string, databasePath: string,
extraSearchPath: string | undefined, extraSearchPath: string | undefined,
querySuitePath: string | undefined, querySuitePath: string | undefined,
memoryFlag: string, flags: string[]
threadsFlag: string
): Promise<void>; ): Promise<void>;
/** /**
* Run 'codeql database interpret-results'. * Run 'codeql database interpret-results'.
@ -789,14 +788,12 @@ export async function getCodeQLForCmd(
databasePath: string, databasePath: string,
extraSearchPath: string | undefined, extraSearchPath: string | undefined,
querySuitePath: string | undefined, querySuitePath: string | undefined,
memoryFlag: string, flags: string[]
threadsFlag: string
): Promise<void> { ): Promise<void> {
const codeqlArgs = [ const codeqlArgs = [
"database", "database",
"run-queries", "run-queries",
memoryFlag, ...flags,
threadsFlag,
databasePath, databasePath,
"--min-disk-free=1024", // Try to leave at least 1GB free "--min-disk-free=1024", // Try to leave at least 1GB free
"-v", "-v",