Merge branch 'main' into language_parsing
This commit is contained in:
Коммит
574b5dc4e9
|
@ -225,6 +225,7 @@ function getCodeQLForCmd(cmd) {
|
|||
'trace-command',
|
||||
databasePath,
|
||||
...compilerSpecArg,
|
||||
...getExtraOptionsFromEnv(['database', 'trace-command']),
|
||||
process.execPath,
|
||||
path.resolve(__dirname, 'tracer-env.js'),
|
||||
envFile
|
||||
|
@ -238,6 +239,7 @@ function getCodeQLForCmd(cmd) {
|
|||
databasePath,
|
||||
'--language=' + language,
|
||||
'--source-root=' + sourceRoot,
|
||||
...getExtraOptionsFromEnv(['database', 'init']),
|
||||
]);
|
||||
},
|
||||
runAutobuild: async function (language) {
|
||||
|
@ -259,7 +261,8 @@ function getCodeQLForCmd(cmd) {
|
|||
'resolve',
|
||||
'extractor',
|
||||
'--format=json',
|
||||
'--language=' + language
|
||||
'--language=' + language,
|
||||
...getExtraOptionsFromEnv(['resolve', 'extractor']),
|
||||
], {
|
||||
silent: true,
|
||||
listeners: {
|
||||
|
@ -274,6 +277,7 @@ function getCodeQLForCmd(cmd) {
|
|||
await exec.exec(cmd, [
|
||||
'database',
|
||||
'trace-command',
|
||||
...getExtraOptionsFromEnv(['database', 'trace-command']),
|
||||
databasePath,
|
||||
'--',
|
||||
traceCommand
|
||||
|
@ -283,6 +287,7 @@ function getCodeQLForCmd(cmd) {
|
|||
await exec.exec(cmd, [
|
||||
'database',
|
||||
'finalize',
|
||||
...getExtraOptionsFromEnv(['database', 'finalize']),
|
||||
databasePath
|
||||
]);
|
||||
},
|
||||
|
@ -291,7 +296,8 @@ function getCodeQLForCmd(cmd) {
|
|||
'resolve',
|
||||
'queries',
|
||||
...queries,
|
||||
'--format=bylanguage'
|
||||
'--format=bylanguage',
|
||||
...getExtraOptionsFromEnv(['resolve', 'queries'])
|
||||
];
|
||||
if (extraSearchPath !== undefined) {
|
||||
codeqlArgs.push('--search-path', extraSearchPath);
|
||||
|
@ -316,9 +322,54 @@ function getCodeQLForCmd(cmd) {
|
|||
'--format=sarif-latest',
|
||||
'--output=' + sarifFile,
|
||||
'--no-sarif-add-snippets',
|
||||
...getExtraOptionsFromEnv(['database', 'analyze']),
|
||||
querySuite
|
||||
]);
|
||||
}
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Gets the options for `path` of `options` as an array of extra option strings.
|
||||
*/
|
||||
function getExtraOptionsFromEnv(path) {
|
||||
let options = util.getExtraOptionsEnvParam();
|
||||
return getExtraOptions(options, path, []);
|
||||
}
|
||||
/**
|
||||
* Gets the options for `path` of `options` as an array of extra option strings.
|
||||
*
|
||||
* - the special terminal step name '*' in `options` matches all path steps
|
||||
* - throws an exception if this conversion is impossible.
|
||||
*/
|
||||
function getExtraOptions(options, path, pathInfo) {
|
||||
var _a, _b, _c;
|
||||
/**
|
||||
* Gets `options` as an array of extra option strings.
|
||||
*
|
||||
* - throws an exception mentioning `pathInfo` if this conversion is impossible.
|
||||
*/
|
||||
function asExtraOptions(options, pathInfo) {
|
||||
if (options === undefined) {
|
||||
return [];
|
||||
}
|
||||
if (!Array.isArray(options)) {
|
||||
const msg = `The extra options for '${pathInfo.join('.')}' ('${JSON.stringify(options)}') are not in an array.`;
|
||||
throw new Error(msg);
|
||||
}
|
||||
return options.map(o => {
|
||||
const t = typeof o;
|
||||
if (t !== 'string' && t !== 'number' && t !== 'boolean') {
|
||||
const msg = `The extra option for '${pathInfo.join('.')}' ('${JSON.stringify(o)}') is not a primitive value.`;
|
||||
throw new Error(msg);
|
||||
}
|
||||
return o + '';
|
||||
});
|
||||
}
|
||||
let all = asExtraOptions((_a = options) === null || _a === void 0 ? void 0 : _a['*'], pathInfo.concat('*'));
|
||||
let specific = path.length === 0 ?
|
||||
asExtraOptions(options, pathInfo) :
|
||||
getExtraOptions((_b = options) === null || _b === void 0 ? void 0 : _b[path[0]], (_c = path) === null || _c === void 0 ? void 0 : _c.slice(1), pathInfo.concat(path[0]));
|
||||
return all.concat(specific);
|
||||
}
|
||||
exports.getExtraOptions = getExtraOptions;
|
||||
//# sourceMappingURL=codeql.js.map
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -57,4 +57,26 @@ ava_1.default('parse codeql bundle url version', t => {
|
|||
}
|
||||
}
|
||||
});
|
||||
ava_1.default('getExtraOptions works for explicit paths', t => {
|
||||
t.deepEqual(codeql.getExtraOptions({}, ['foo'], []), []);
|
||||
t.deepEqual(codeql.getExtraOptions({ foo: [42] }, ['foo'], []), ['42']);
|
||||
t.deepEqual(codeql.getExtraOptions({ foo: { bar: [42] } }, ['foo', 'bar'], []), ['42']);
|
||||
});
|
||||
ava_1.default('getExtraOptions works for wildcards', t => {
|
||||
t.deepEqual(codeql.getExtraOptions({ '*': [42] }, ['foo'], []), ['42']);
|
||||
});
|
||||
ava_1.default('getExtraOptions works for wildcards and explicit paths', t => {
|
||||
let o1 = { '*': [42], foo: [87] };
|
||||
t.deepEqual(codeql.getExtraOptions(o1, ['foo'], []), ['42', '87']);
|
||||
let o2 = { '*': [42], foo: [87] };
|
||||
t.deepEqual(codeql.getExtraOptions(o2, ['foo', 'bar'], []), ['42']);
|
||||
let o3 = { '*': [42], foo: { '*': [87], bar: [99] } };
|
||||
let p = ['foo', 'bar'];
|
||||
t.deepEqual(codeql.getExtraOptions(o3, p, []), ['42', '87', '99']);
|
||||
});
|
||||
ava_1.default('getExtraOptions throws for bad content', t => {
|
||||
t.throws(() => codeql.getExtraOptions({ '*': 42 }, ['foo'], []));
|
||||
t.throws(() => codeql.getExtraOptions({ foo: 87 }, ['foo'], []));
|
||||
t.throws(() => codeql.getExtraOptions({ '*': [42], foo: { '*': 87, bar: [99] } }, ['foo', 'bar'], []));
|
||||
});
|
||||
//# sourceMappingURL=codeql.test.js.map
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"codeql.test.js","sourceRoot":"","sources":["../src/codeql.test.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+DAAiD;AACjD,8CAAuB;AACvB,gDAAwB;AACxB,2CAA6B;AAE7B,iDAAmC;AACnC,mDA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KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IAE/D,CAAC,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,eAAe,CAAC,EAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,EAAC,EAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AACtG,CAAC,CAAC,CAAC"}
|
|
@ -45,6 +45,25 @@ function getRequiredEnvParam(paramName) {
|
|||
return value;
|
||||
}
|
||||
exports.getRequiredEnvParam = getRequiredEnvParam;
|
||||
/**
|
||||
* Get the extra options for the codeql commands.
|
||||
*/
|
||||
function getExtraOptionsEnvParam() {
|
||||
const varName = 'CODEQL_ACTION_EXTRA_OPTIONS';
|
||||
const raw = process.env[varName];
|
||||
if (raw === undefined || raw.length === 0) {
|
||||
return {};
|
||||
}
|
||||
try {
|
||||
return JSON.parse(raw);
|
||||
}
|
||||
catch (e) {
|
||||
throw new Error(varName +
|
||||
' environment variable is set, but does not contain valid JSON: ' +
|
||||
e.message);
|
||||
}
|
||||
}
|
||||
exports.getExtraOptionsEnvParam = getExtraOptionsEnvParam;
|
||||
function isLocalRun() {
|
||||
return !!process.env.CODEQL_LOCAL_RUN
|
||||
&& process.env.CODEQL_LOCAL_RUN !== 'false'
|
||||
|
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -92,4 +92,25 @@ ava_1.default('prepareEnvironment() when a local run', t => {
|
|||
t.deepEqual(process.env.GITHUB_JOB, 'UNKNOWN-JOB');
|
||||
process.env.CODEQL_LOCAL_RUN = origLocalRun;
|
||||
});
|
||||
ava_1.default('getExtraOptionsEnvParam() succeeds on valid JSON with invalid options (for now)', t => {
|
||||
const origExtraOptions = process.env.CODEQL_ACTION_EXTRA_OPTIONS;
|
||||
const options = { foo: 42 };
|
||||
process.env.CODEQL_ACTION_EXTRA_OPTIONS = JSON.stringify(options);
|
||||
t.deepEqual(util.getExtraOptionsEnvParam(), options);
|
||||
process.env.CODEQL_ACTION_EXTRA_OPTIONS = origExtraOptions;
|
||||
});
|
||||
ava_1.default('getExtraOptionsEnvParam() succeeds on valid options', t => {
|
||||
const origExtraOptions = process.env.CODEQL_ACTION_EXTRA_OPTIONS;
|
||||
const options = { database: { init: ["--debug"] } };
|
||||
process.env.CODEQL_ACTION_EXTRA_OPTIONS =
|
||||
JSON.stringify(options);
|
||||
t.deepEqual(util.getExtraOptionsEnvParam(), options);
|
||||
process.env.CODEQL_ACTION_EXTRA_OPTIONS = origExtraOptions;
|
||||
});
|
||||
ava_1.default('getExtraOptionsEnvParam() fails on invalid JSON', t => {
|
||||
const origExtraOptions = process.env.CODEQL_ACTION_EXTRA_OPTIONS;
|
||||
process.env.CODEQL_ACTION_EXTRA_OPTIONS = "{{invalid-json}}";
|
||||
t.throws(util.getExtraOptionsEnvParam);
|
||||
process.env.CODEQL_ACTION_EXTRA_OPTIONS = origExtraOptions;
|
||||
});
|
||||
//# sourceMappingURL=util.test.js.map
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"util.test.js","sourceRoot":"","sources":["../src/util.test.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8CAAuB;AACvB,uCAAyB;AACzB,uCAAyB;AAEzB,mDAA2C;AAC3C,6CAA+B;AAE/B,0BAAU,CAAC,aAAI,CAAC,CAAC;AAEjB,aAAI,CAAC,cAAc,EAAE,CAAC,CAAC,EAAE;IACvB,MAAM,KAAK,GAAG,EAAE,CAAC,YAAY,CAAC,SAAS,GAAG,mCAAmC,EAAE,MAAM,CAAC,CAAC;IACvF,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAC3C,CAAC,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC,+BAA+B,EAAE,QAAQ,CAAC,CAAC,CAAC;AACtE,CAAC,CAAC,CAAC;AAE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AAgB,GAAG,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC;IAEjE,OAAO,CAAC,GAAG,CAAC,2BAA2B,GAAG,kBAAkB,CAAC;IAC7D,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;IAEvC,OAAO,CAAC,GAAG,CAAC,2BAA2B,GAAG,gBAAgB,CAAC;AAC7D,CAAC,CAAC,CAAC"}
|
|
@ -63,3 +63,35 @@ test('parse codeql bundle url version', t => {
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('getExtraOptions works for explicit paths', t => {
|
||||
t.deepEqual(codeql.getExtraOptions({}, ['foo'], []), []);
|
||||
|
||||
t.deepEqual(codeql.getExtraOptions({foo: [42]}, ['foo'], []), ['42']);
|
||||
|
||||
t.deepEqual(codeql.getExtraOptions({foo: {bar: [42]}}, ['foo', 'bar'], []), ['42']);
|
||||
});
|
||||
|
||||
test('getExtraOptions works for wildcards', t => {
|
||||
t.deepEqual(codeql.getExtraOptions({'*': [42]}, ['foo'], []), ['42']);
|
||||
});
|
||||
|
||||
test('getExtraOptions works for wildcards and explicit paths', t => {
|
||||
let o1 = {'*': [42], foo: [87]};
|
||||
t.deepEqual(codeql.getExtraOptions(o1, ['foo'], []), ['42', '87']);
|
||||
|
||||
let o2 = {'*': [42], foo: [87]};
|
||||
t.deepEqual(codeql.getExtraOptions(o2, ['foo', 'bar'], []), ['42']);
|
||||
|
||||
let o3 = {'*': [42], foo: { '*': [87], bar: [99]}};
|
||||
let p = ['foo', 'bar'];
|
||||
t.deepEqual(codeql.getExtraOptions(o3, p, []), ['42', '87', '99']);
|
||||
});
|
||||
|
||||
test('getExtraOptions throws for bad content', t => {
|
||||
t.throws(() => codeql.getExtraOptions({'*': 42}, ['foo'], []));
|
||||
|
||||
t.throws(() => codeql.getExtraOptions({foo: 87}, ['foo'], []));
|
||||
|
||||
t.throws(() => codeql.getExtraOptions({'*': [42], foo: { '*': 87, bar: [99]}}, ['foo', 'bar'], []));
|
||||
});
|
||||
|
|
|
@ -15,6 +15,27 @@ import * as defaults from './defaults.json'; // Referenced from codeql-action-sy
|
|||
import { Language } from './languages';
|
||||
import * as util from './util';
|
||||
|
||||
type Options = (string|number|boolean)[];
|
||||
|
||||
/**
|
||||
* Extra command line options for the codeql commands.
|
||||
*/
|
||||
interface ExtraOptions {
|
||||
'*'?: Options;
|
||||
database?: {
|
||||
'*'?: Options,
|
||||
init?: Options,
|
||||
'trace-command'?: Options,
|
||||
analyze?: Options,
|
||||
finalize?: Options
|
||||
};
|
||||
resolve?: {
|
||||
'*'?: Options,
|
||||
extractor?: Options,
|
||||
queries?: Options
|
||||
};
|
||||
}
|
||||
|
||||
export interface CodeQL {
|
||||
/**
|
||||
* Get the directory where the CodeQL executable is located.
|
||||
|
@ -287,6 +308,7 @@ function getCodeQLForCmd(cmd: string): CodeQL {
|
|||
'trace-command',
|
||||
databasePath,
|
||||
...compilerSpecArg,
|
||||
...getExtraOptionsFromEnv(['database', 'trace-command']),
|
||||
process.execPath,
|
||||
path.resolve(__dirname, 'tracer-env.js'),
|
||||
envFile
|
||||
|
@ -300,6 +322,7 @@ function getCodeQLForCmd(cmd: string): CodeQL {
|
|||
databasePath,
|
||||
'--language=' + language,
|
||||
'--source-root=' + sourceRoot,
|
||||
...getExtraOptionsFromEnv(['database', 'init']),
|
||||
]);
|
||||
},
|
||||
runAutobuild: async function(language: Language) {
|
||||
|
@ -325,7 +348,8 @@ function getCodeQLForCmd(cmd: string): CodeQL {
|
|||
'resolve',
|
||||
'extractor',
|
||||
'--format=json',
|
||||
'--language=' + language
|
||||
'--language=' + language,
|
||||
...getExtraOptionsFromEnv(['resolve', 'extractor']),
|
||||
],
|
||||
{
|
||||
silent: true,
|
||||
|
@ -343,6 +367,7 @@ function getCodeQLForCmd(cmd: string): CodeQL {
|
|||
await exec.exec(cmd, [
|
||||
'database',
|
||||
'trace-command',
|
||||
...getExtraOptionsFromEnv(['database', 'trace-command']),
|
||||
databasePath,
|
||||
'--',
|
||||
traceCommand
|
||||
|
@ -352,6 +377,7 @@ function getCodeQLForCmd(cmd: string): CodeQL {
|
|||
await exec.exec(cmd, [
|
||||
'database',
|
||||
'finalize',
|
||||
...getExtraOptionsFromEnv(['database', 'finalize']),
|
||||
databasePath
|
||||
]);
|
||||
},
|
||||
|
@ -360,7 +386,8 @@ function getCodeQLForCmd(cmd: string): CodeQL {
|
|||
'resolve',
|
||||
'queries',
|
||||
...queries,
|
||||
'--format=bylanguage'
|
||||
'--format=bylanguage',
|
||||
...getExtraOptionsFromEnv(['resolve', 'queries'])
|
||||
];
|
||||
if (extraSearchPath !== undefined) {
|
||||
codeqlArgs.push('--search-path', extraSearchPath);
|
||||
|
@ -386,8 +413,58 @@ function getCodeQLForCmd(cmd: string): CodeQL {
|
|||
'--format=sarif-latest',
|
||||
'--output=' + sarifFile,
|
||||
'--no-sarif-add-snippets',
|
||||
...getExtraOptionsFromEnv(['database', 'analyze']),
|
||||
querySuite
|
||||
]);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the options for `path` of `options` as an array of extra option strings.
|
||||
*/
|
||||
function getExtraOptionsFromEnv(path: string[]) {
|
||||
let options: ExtraOptions = util.getExtraOptionsEnvParam();
|
||||
return getExtraOptions(options, path, []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the options for `path` of `options` as an array of extra option strings.
|
||||
*
|
||||
* - the special terminal step name '*' in `options` matches all path steps
|
||||
* - throws an exception if this conversion is impossible.
|
||||
*/
|
||||
export /* exported for testing */ function getExtraOptions(
|
||||
options: any,
|
||||
path: string[],
|
||||
pathInfo: string[]): string[] {
|
||||
/**
|
||||
* Gets `options` as an array of extra option strings.
|
||||
*
|
||||
* - throws an exception mentioning `pathInfo` if this conversion is impossible.
|
||||
*/
|
||||
function asExtraOptions(options: any, pathInfo: string[]): string[] {
|
||||
if (options === undefined) {
|
||||
return [];
|
||||
}
|
||||
if (!Array.isArray(options)) {
|
||||
const msg =
|
||||
`The extra options for '${pathInfo.join('.')}' ('${JSON.stringify(options)}') are not in an array.`;
|
||||
throw new Error(msg);
|
||||
}
|
||||
return options.map(o => {
|
||||
const t = typeof o;
|
||||
if (t !== 'string' && t !== 'number' && t !== 'boolean') {
|
||||
const msg =
|
||||
`The extra option for '${pathInfo.join('.')}' ('${JSON.stringify(o)}') is not a primitive value.`;
|
||||
throw new Error(msg);
|
||||
}
|
||||
return o + '';
|
||||
});
|
||||
}
|
||||
let all = asExtraOptions(options?.['*'], pathInfo.concat('*'));
|
||||
let specific = path.length === 0 ?
|
||||
asExtraOptions(options, pathInfo) :
|
||||
getExtraOptions(options?.[path[0]], path?.slice(1), pathInfo.concat(path[0]));
|
||||
return all.concat(specific);
|
||||
}
|
||||
|
|
|
@ -116,3 +116,37 @@ test('prepareEnvironment() when a local run', t => {
|
|||
|
||||
process.env.CODEQL_LOCAL_RUN = origLocalRun;
|
||||
});
|
||||
|
||||
test('getExtraOptionsEnvParam() succeeds on valid JSON with invalid options (for now)', t => {
|
||||
const origExtraOptions = process.env.CODEQL_ACTION_EXTRA_OPTIONS;
|
||||
|
||||
const options = {foo: 42};
|
||||
|
||||
process.env.CODEQL_ACTION_EXTRA_OPTIONS = JSON.stringify(options);
|
||||
|
||||
t.deepEqual(util.getExtraOptionsEnvParam(), <any>options);
|
||||
|
||||
process.env.CODEQL_ACTION_EXTRA_OPTIONS = origExtraOptions;
|
||||
});
|
||||
|
||||
|
||||
test('getExtraOptionsEnvParam() succeeds on valid options', t => {
|
||||
const origExtraOptions = process.env.CODEQL_ACTION_EXTRA_OPTIONS;
|
||||
|
||||
const options = { database: { init: ["--debug"] } };
|
||||
process.env.CODEQL_ACTION_EXTRA_OPTIONS =
|
||||
JSON.stringify(options);
|
||||
|
||||
t.deepEqual(util.getExtraOptionsEnvParam(), options);
|
||||
|
||||
process.env.CODEQL_ACTION_EXTRA_OPTIONS = origExtraOptions;
|
||||
});
|
||||
|
||||
test('getExtraOptionsEnvParam() fails on invalid JSON', t => {
|
||||
const origExtraOptions = process.env.CODEQL_ACTION_EXTRA_OPTIONS;
|
||||
|
||||
process.env.CODEQL_ACTION_EXTRA_OPTIONS = "{{invalid-json}}";
|
||||
t.throws(util.getExtraOptionsEnvParam);
|
||||
|
||||
process.env.CODEQL_ACTION_EXTRA_OPTIONS = origExtraOptions;
|
||||
});
|
||||
|
|
20
src/util.ts
20
src/util.ts
|
@ -39,6 +39,26 @@ export function getRequiredEnvParam(paramName: string): string {
|
|||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the extra options for the codeql commands.
|
||||
*/
|
||||
export function getExtraOptionsEnvParam(): object {
|
||||
const varName = 'CODEQL_ACTION_EXTRA_OPTIONS';
|
||||
const raw = process.env[varName];
|
||||
if (raw === undefined || raw.length === 0) {
|
||||
return {};
|
||||
}
|
||||
try {
|
||||
return JSON.parse(raw);
|
||||
} catch (e) {
|
||||
throw new Error(
|
||||
varName +
|
||||
' environment variable is set, but does not contain valid JSON: ' +
|
||||
e.message
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function isLocalRun(): boolean {
|
||||
return !!process.env.CODEQL_LOCAL_RUN
|
||||
&& process.env.CODEQL_LOCAL_RUN !== 'false'
|
||||
|
|
Загрузка…
Ссылка в новой задаче