reformat code and allow negative values for threads
This commit is contained in:
parent
bcb5b28954
commit
31996935e6
8 changed files with 37 additions and 27 deletions
|
|
@ -19,7 +19,7 @@ import * as util from './util';
|
|||
*
|
||||
* Format is a map from language to an array of path suffixes of .ql files.
|
||||
*/
|
||||
const DISABLED_BUILTIN_QUERIES: { [language: string]: string[]; } = {
|
||||
const DISABLED_BUILTIN_QUERIES: {[language: string]: string[]} = {
|
||||
'csharp': [
|
||||
'ql/src/Security Features/CWE-937/VulnerablePackage.ql',
|
||||
'ql/src/Security Features/CWE-451/MissingXFrameOptions.ql',
|
||||
|
|
@ -75,14 +75,14 @@ async function finalizeDatabaseCreation(codeqlCmd: string, databaseFolder: strin
|
|||
interface ResolveQueriesOutput {
|
||||
byLanguage: {
|
||||
[language: string]: {
|
||||
[queryPath: string]: {};
|
||||
};
|
||||
[queryPath: string]: {}
|
||||
}
|
||||
};
|
||||
noDeclaredLanguage: {
|
||||
[queryPath: string]: {};
|
||||
[queryPath: string]: {}
|
||||
};
|
||||
multipleDeclaredLanguages: {
|
||||
[queryPath: string]: {};
|
||||
[queryPath: string]: {}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -98,11 +98,11 @@ async function runResolveQueries(codeqlCmd: string, queries: string[]): Promise<
|
|||
|
||||
await exec.exec(
|
||||
codeqlCmd, [
|
||||
'resolve',
|
||||
'queries',
|
||||
...queries,
|
||||
'--format=bylanguage'
|
||||
],
|
||||
'resolve',
|
||||
'queries',
|
||||
...queries,
|
||||
'--format=bylanguage'
|
||||
],
|
||||
options);
|
||||
|
||||
return JSON.parse(output);
|
||||
|
|
|
|||
|
|
@ -42,7 +42,8 @@ test('getThreadsFlag() should return the correct --threads flag', t => {
|
|||
const tests = {
|
||||
"0": "--threads=0",
|
||||
"1": "--threads=1",
|
||||
[`${numCpus + 1}`]: `--threads=${numCpus}`
|
||||
[`${numCpus + 1}`]: `--threads=${numCpus}`,
|
||||
[`${-numCpus - 1}`]: `--threads=${-numCpus}`
|
||||
};
|
||||
|
||||
for (const [input, expectedFlag] of Object.entries(tests)) {
|
||||
|
|
@ -55,7 +56,7 @@ test('getThreadsFlag() should return the correct --threads flag', t => {
|
|||
});
|
||||
|
||||
test('getThreadsFlag() throws if the ram input is < 0 or NaN', t => {
|
||||
for (const input of ["-1", "hello!"]) {
|
||||
for (const input of ["hello!"]) {
|
||||
process.env['INPUT_THREADS'] = input;
|
||||
t.throws(util.getThreadsFlag);
|
||||
}
|
||||
|
|
|
|||
14
src/util.ts
14
src/util.ts
|
|
@ -395,8 +395,8 @@ export async function withTmpDir<T>(body: (tmpDir: string) => Promise<T>): Promi
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the value specified for the `ram` input. If no value was specified, the
|
||||
* total available memory will be used minus 256 MB.
|
||||
* Get the codeql `--ram` flag as configured by the `ram` input. If no value was
|
||||
* specified, the total available memory will be used minus 256 MB.
|
||||
*
|
||||
* @returns string
|
||||
*/
|
||||
|
|
@ -418,8 +418,8 @@ export function getMemoryFlag(): string {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the value specified for the `threads` input. The value defaults to 1.
|
||||
* The value will be capped to the number of available CPUs.
|
||||
* Get the codeql `--threads` value specified for the `threads` input. The value
|
||||
* defaults to 1. The value will be capped to the number of available CPUs.
|
||||
*
|
||||
* @returns string
|
||||
*/
|
||||
|
|
@ -428,13 +428,17 @@ export function getThreadsFlag(): string {
|
|||
const numThreadsString = core.getInput("threads");
|
||||
if (numThreadsString) {
|
||||
numThreads = Number(numThreadsString);
|
||||
if (Number.isNaN(numThreads) || numThreads < 0) {
|
||||
if (Number.isNaN(numThreads)) {
|
||||
throw new Error(`Invalid threads setting "${numThreadsString}", specified.`);
|
||||
}
|
||||
const maxThreads = os.cpus().length;
|
||||
if (numThreads > maxThreads) {
|
||||
numThreads = maxThreads;
|
||||
}
|
||||
const minThreads = -maxThreads;
|
||||
if (numThreads < minThreads) {
|
||||
numThreads = minThreads;
|
||||
}
|
||||
}
|
||||
return `--threads=${numThreads}`;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue