Merge branch 'main' into nickfyson/error_wrapper
# Conflicts: # lib/codeql.js # lib/codeql.js.map # src/codeql.ts
This commit is contained in:
commit
3cd41279f2
3466 changed files with 8685 additions and 446173 deletions
18
.github/workflows/cli.yml
vendored
18
.github/workflows/cli.yml
vendored
|
|
@ -1,18 +0,0 @@
|
|||
name: "CodeScanning CLI"
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
# Build the CLI
|
||||
- name: Build CLI
|
||||
run: npm run build-cli
|
||||
|
||||
# Upload an empty SARIF file
|
||||
- name: Upload with CLI
|
||||
run: node cli/code-scanning-cli.js upload --sarif-file src/testdata/empty-sarif.sarif --repository $GITHUB_REPOSITORY --commit $GITHUB_SHA --ref $GITHUB_REF --github-url $GITHUB_API_URL --github-auth ${{ github.token }}
|
||||
9
.github/workflows/pr-checks.yml
vendored
9
.github/workflows/pr-checks.yml
vendored
|
|
@ -24,6 +24,8 @@ jobs:
|
|||
>&2 echo "Failed: Repo should be clean before testing!"
|
||||
exit 1
|
||||
fi
|
||||
# Wipe the lib directory incase there are extra unnecessary files in there
|
||||
rm -rf lib
|
||||
# Generate the JavaScript files
|
||||
npm run-script build
|
||||
# Check that repo is still clean
|
||||
|
|
@ -63,9 +65,12 @@ jobs:
|
|||
echo "Success: node_modules are up to date"
|
||||
|
||||
npm-test:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest,macos-latest]
|
||||
runs-on: ${{ matrix.os }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: npm run-script test
|
||||
run: npm run-script test
|
||||
run: npm run-script test
|
||||
|
|
|
|||
26
.github/workflows/runner.yml
vendored
Normal file
26
.github/workflows/runner.yml
vendored
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
name: "CodeQL runner"
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Build runner
|
||||
run: |
|
||||
cd runner
|
||||
npm install
|
||||
npm run build-runner
|
||||
|
||||
- name: Upload with runner
|
||||
run: |
|
||||
runner/dist/codeql-runner-linux upload \
|
||||
--sarif-file src/testdata/empty-sarif.sarif \
|
||||
--repository $GITHUB_REPOSITORY \
|
||||
--commit $GITHUB_SHA \
|
||||
--ref $GITHUB_REF \
|
||||
--github-url $GITHUB_SERVER_URL \
|
||||
--github-auth ${{ github.token }}
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -1,2 +1,2 @@
|
|||
/cli/
|
||||
|
||||
/runner/dist/
|
||||
/runner/node_modules/
|
||||
|
|
|
|||
|
|
@ -49,6 +49,10 @@ Running locally will generate the CodeQL database and run all the queries, but i
|
|||
|
||||
As well as the unit tests (see _Common tasks_ above), there are integration tests, defined in `.github/workflows/integration-testing.yml`. These are run by a CI check. Depending on the change you’re making, you may want to add a test to this file or extend an existing one.
|
||||
|
||||
### Building the CodeQL runner
|
||||
|
||||
Navigate to the `runner` directory and run `npm install` to install dependencies needed only for compiling the CodeQL runner. Run `npm run build-runner` to output files to the `runner/dist` directory.
|
||||
|
||||
## Submitting a pull request
|
||||
|
||||
1. [Fork][fork] and clone the repository
|
||||
|
|
|
|||
|
|
@ -29,4 +29,4 @@ inputs:
|
|||
default: ${{ toJson(matrix) }}
|
||||
runs:
|
||||
using: 'node12'
|
||||
main: '../lib/finalize-db.js'
|
||||
main: '../lib/analyze-action.js'
|
||||
|
|
|
|||
|
|
@ -8,4 +8,4 @@ inputs:
|
|||
default: ${{ toJson(matrix) }}
|
||||
runs:
|
||||
using: 'node12'
|
||||
main: '../lib/autobuild.js'
|
||||
main: '../lib/autobuild-action.js'
|
||||
|
|
@ -16,6 +16,9 @@ inputs:
|
|||
config-file:
|
||||
description: Path of the config file to use
|
||||
required: false
|
||||
queries:
|
||||
description: Comma-separated list of additional queries to run. By default, this overrides the same setting in a configuration file
|
||||
required: false
|
||||
runs:
|
||||
using: 'node12'
|
||||
main: '../lib/setup-tracer.js'
|
||||
main: '../lib/init-action.js'
|
||||
|
|
|
|||
32
lib/analysis-paths.js
generated
32
lib/analysis-paths.js
generated
|
|
@ -1,13 +1,5 @@
|
|||
"use strict";
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(require("@actions/core"));
|
||||
function isInterpretedLanguage(language) {
|
||||
return language === 'javascript' || language === 'python';
|
||||
}
|
||||
|
|
@ -23,6 +15,16 @@ function buildIncludeExcludeEnvVar(paths) {
|
|||
}
|
||||
return paths.join('\n');
|
||||
}
|
||||
function printPathFiltersWarning(config, logger) {
|
||||
// Index include/exclude/filters only work in javascript and python.
|
||||
// If any other languages are detected/configured then show a warning.
|
||||
if ((config.paths.length !== 0 ||
|
||||
config.pathsIgnore.length !== 0) &&
|
||||
!config.languages.every(isInterpretedLanguage)) {
|
||||
logger.warning('The "paths"/"paths-ignore" fields of the config only have effect for Javascript and Python');
|
||||
}
|
||||
}
|
||||
exports.printPathFiltersWarning = printPathFiltersWarning;
|
||||
function includeAndExcludeAnalysisPaths(config) {
|
||||
// The 'LGTM_INDEX_INCLUDE' and 'LGTM_INDEX_EXCLUDE' environment variables
|
||||
// control which files/directories are traversed when scanning.
|
||||
|
|
@ -32,10 +34,10 @@ function includeAndExcludeAnalysisPaths(config) {
|
|||
// traverse the entire file tree to determine which files are matched.
|
||||
// Any paths containing "*" are not included in these.
|
||||
if (config.paths.length !== 0) {
|
||||
core.exportVariable('LGTM_INDEX_INCLUDE', buildIncludeExcludeEnvVar(config.paths));
|
||||
process.env['LGTM_INDEX_INCLUDE'] = buildIncludeExcludeEnvVar(config.paths);
|
||||
}
|
||||
if (config.pathsIgnore.length !== 0) {
|
||||
core.exportVariable('LGTM_INDEX_EXCLUDE', buildIncludeExcludeEnvVar(config.pathsIgnore));
|
||||
process.env['LGTM_INDEX_EXCLUDE'] = buildIncludeExcludeEnvVar(config.pathsIgnore);
|
||||
}
|
||||
// The 'LGTM_INDEX_FILTERS' environment variable controls which files are
|
||||
// extracted or ignored. It does not control which directories are traversed.
|
||||
|
|
@ -44,15 +46,7 @@ function includeAndExcludeAnalysisPaths(config) {
|
|||
filters.push(...config.paths.map(p => 'include:' + p));
|
||||
filters.push(...config.pathsIgnore.map(p => 'exclude:' + p));
|
||||
if (filters.length !== 0) {
|
||||
core.exportVariable('LGTM_INDEX_FILTERS', filters.join('\n'));
|
||||
}
|
||||
// Index include/exclude/filters only work in javascript and python.
|
||||
// If any other languages are detected/configured then show a warning.
|
||||
if ((config.paths.length !== 0 ||
|
||||
config.pathsIgnore.length !== 0 ||
|
||||
filters.length !== 0) &&
|
||||
!config.languages.every(isInterpretedLanguage)) {
|
||||
core.warning('The "paths"/"paths-ignore" fields of the config only have effect for Javascript and Python');
|
||||
process.env['LGTM_INDEX_FILTERS'] = filters.join('\n');
|
||||
}
|
||||
}
|
||||
exports.includeAndExcludeAnalysisPaths = includeAndExcludeAnalysisPaths;
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"analysis-paths.js","sourceRoot":"","sources":["../src/analysis-paths.ts"],"names":[],"mappings":";;;;;;;;;AAAA,oDAAsC;AAItC,SAAS,qBAAqB,CAAC,QAAQ;IACrC,OAAO,QAAQ,KAAK,YAAY,IAAI,QAAQ,KAAK,QAAQ,CAAC;AAC5D,CAAC;AAED,6FAA6F;AAChF,QAAA,+BAA+B,GAAG,eAAe,CAAC;AAE/D,uFAAuF;AACvF,SAAS,yBAAyB,CAAC,KAAe;IAChD,iCAAi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lib/analyze-action.js
generated
Normal file
53
lib/analyze-action.js
generated
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
"use strict";
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const analyze_1 = require("./analyze");
|
||||
const config_utils_1 = require("./config-utils");
|
||||
const logging_1 = require("./logging");
|
||||
const repository_1 = require("./repository");
|
||||
const util = __importStar(require("./util"));
|
||||
async function sendStatusReport(startedAt, stats, error) {
|
||||
var _a, _b, _c;
|
||||
const status = ((_a = stats) === null || _a === void 0 ? void 0 : _a.analyze_failure_language) !== undefined || error !== undefined ? 'failure' : 'success';
|
||||
const statusReportBase = await util.createStatusReportBase('finish', status, startedAt, (_b = error) === null || _b === void 0 ? void 0 : _b.message, (_c = error) === null || _c === void 0 ? void 0 : _c.stack);
|
||||
const statusReport = {
|
||||
...statusReportBase,
|
||||
...(stats || {}),
|
||||
};
|
||||
await util.sendStatusReport(statusReport);
|
||||
}
|
||||
async function run() {
|
||||
const startedAt = new Date();
|
||||
let stats = undefined;
|
||||
try {
|
||||
util.prepareLocalRunEnvironment();
|
||||
if (!await util.sendStatusReport(await util.createStatusReportBase('finish', 'starting', startedAt), true)) {
|
||||
return;
|
||||
}
|
||||
const logger = logging_1.getActionsLogger();
|
||||
const config = await config_utils_1.getConfig(util.getRequiredEnvParam('RUNNER_TEMP'), logger);
|
||||
if (config === undefined) {
|
||||
throw new Error("Config file could not be found at expected location. Has the 'init' action been called?");
|
||||
}
|
||||
stats = await analyze_1.runAnalyze(repository_1.parseRepositoryNwo(util.getRequiredEnvParam('GITHUB_REPOSITORY')), await util.getCommitOid(), util.getRef(), await util.getAnalysisKey(), util.getRequiredEnvParam('GITHUB_WORKFLOW'), util.getWorkflowRunID(), core.getInput('checkout_path'), core.getInput('matrix'), core.getInput('token'), util.getRequiredEnvParam('GITHUB_SERVER_URL'), core.getInput('upload') === 'true', 'actions', core.getInput('output'), util.getMemoryFlag(core.getInput('ram')), util.getThreadsFlag(core.getInput('threads'), logger), config, logger);
|
||||
}
|
||||
catch (error) {
|
||||
core.setFailed(error.message);
|
||||
console.log(error);
|
||||
await sendStatusReport(startedAt, stats, error);
|
||||
return;
|
||||
}
|
||||
await sendStatusReport(startedAt, stats);
|
||||
}
|
||||
run().catch(e => {
|
||||
core.setFailed("analyze action failed: " + e);
|
||||
console.log(e);
|
||||
});
|
||||
//# sourceMappingURL=analyze-action.js.map
|
||||
1
lib/analyze-action.js.map
Normal file
1
lib/analyze-action.js.map
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"analyze-action.js","sourceRoot":"","sources":["../src/analyze-action.ts"],"names":[],"mappings":";;;;;;;;;AAAA,oDAAsC;AAEtC,uCAA6D;AAC7D,iDAA2C;AAC3C,uCAA6C;AAC7C,6CAAkD;AAClD,6CAA+B;AAI/B,KAAK,UAAU,gBAAgB,CAC7B,SAAe,EACf,KAAuC,EACvC,KAAa;;IAEb,MAAM,MAAM,GAAG,OAAA,KAAK,0CAAE,wBAAwB,MAAK,SAAS,IAAI,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;IAC5G,MAAM,gBAAgB,GAAG,MAAM,IAAI,CAAC,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,QAAE,KAAK,0CAAE,OAAO,QAAE,KAAK,0CAAE,KAAK,CAAC,CAAC;IACtH,MAAM,YAAY,GAAuB;QACvC,GAAG,gBAAgB;QACnB,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC;KACjB,CAAC;IACF,MAAM,IAAI,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC;AAC5C,CAAC;AA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CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC,EACrD,MAAM,EACN,MAAM,CAAC,CAAC;KAEX;IAAC,OAAO,KAAK,EAAE;QACd,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC9B,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACnB,MAAM,gBAAgB,CAAC,SAAS,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;QAChD,OAAO;KACR;IAED,MAAM,gBAAgB,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;AAC3C,CAAC;AAED,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;IACd,IAAI,CAAC,SAAS,CAAC,yBAAyB,GAAG,CAAC,CAAC,CAAC;IAC9C,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AACjB,CAAC,CAAC,CAAC"}
|
||||
87
lib/analyze.js
generated
Normal file
87
lib/analyze.js
generated
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
"use strict";
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fs = __importStar(require("fs"));
|
||||
const path = __importStar(require("path"));
|
||||
const analysisPaths = __importStar(require("./analysis-paths"));
|
||||
const codeql_1 = require("./codeql");
|
||||
const languages_1 = require("./languages");
|
||||
const sharedEnv = __importStar(require("./shared-environment"));
|
||||
const upload_lib = __importStar(require("./upload-lib"));
|
||||
const util = __importStar(require("./util"));
|
||||
async function createdDBForScannedLanguages(config, logger) {
|
||||
// Insert the LGTM_INDEX_X env vars at this point so they are set when
|
||||
// we extract any scanned languages.
|
||||
analysisPaths.includeAndExcludeAnalysisPaths(config);
|
||||
const codeql = codeql_1.getCodeQL(config.codeQLCmd);
|
||||
for (const language of config.languages) {
|
||||
if (languages_1.isScannedLanguage(language)) {
|
||||
logger.startGroup('Extracting ' + language);
|
||||
await codeql.extractScannedLanguage(util.getCodeQLDatabasePath(config.tempDir, language), language);
|
||||
logger.endGroup();
|
||||
}
|
||||
}
|
||||
}
|
||||
async function finalizeDatabaseCreation(config, logger) {
|
||||
await createdDBForScannedLanguages(config, logger);
|
||||
const codeql = codeql_1.getCodeQL(config.codeQLCmd);
|
||||
for (const language of config.languages) {
|
||||
logger.startGroup('Finalizing ' + language);
|
||||
await codeql.finalizeDatabase(util.getCodeQLDatabasePath(config.tempDir, language));
|
||||
logger.endGroup();
|
||||
}
|
||||
}
|
||||
// Runs queries and creates sarif files in the given folder
|
||||
async function runQueries(sarifFolder, memoryFlag, threadsFlag, config, logger) {
|
||||
const codeql = codeql_1.getCodeQL(config.codeQLCmd);
|
||||
for (let language of config.languages) {
|
||||
logger.startGroup('Analyzing ' + language);
|
||||
const queries = config.queries[language] || [];
|
||||
if (queries.length === 0) {
|
||||
throw new Error('Unable to analyse ' + language + ' as no queries were selected for this language');
|
||||
}
|
||||
try {
|
||||
const databasePath = util.getCodeQLDatabasePath(config.tempDir, language);
|
||||
// Pass the queries to codeql using a file instead of using the command
|
||||
// line to avoid command line length restrictions, particularly on windows.
|
||||
const querySuite = databasePath + '-queries.qls';
|
||||
const querySuiteContents = queries.map(q => '- query: ' + q).join('\n');
|
||||
fs.writeFileSync(querySuite, querySuiteContents);
|
||||
logger.debug('Query suite file for ' + language + '...\n' + querySuiteContents);
|
||||
const sarifFile = path.join(sarifFolder, language + '.sarif');
|
||||
await codeql.databaseAnalyze(databasePath, sarifFile, querySuite, memoryFlag, threadsFlag);
|
||||
logger.debug('SARIF results for database ' + language + ' created at "' + sarifFile + '"');
|
||||
logger.endGroup();
|
||||
}
|
||||
catch (e) {
|
||||
// For now the fields about query performance are not populated
|
||||
return {
|
||||
analyze_failure_language: language,
|
||||
};
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
async function runAnalyze(repositoryNwo, commitOid, ref, analysisKey, analysisName, workflowRunID, checkoutPath, environment, githubAuth, githubUrl, doUpload, mode, outputDir, memoryFlag, threadsFlag, config, logger) {
|
||||
// Delete the tracer config env var to avoid tracing ourselves
|
||||
delete process.env[sharedEnv.ODASA_TRACER_CONFIGURATION];
|
||||
fs.mkdirSync(outputDir, { recursive: true });
|
||||
logger.info('Finalizing database creation');
|
||||
await finalizeDatabaseCreation(config, logger);
|
||||
logger.info('Analyzing database');
|
||||
const queriesStats = await runQueries(outputDir, memoryFlag, threadsFlag, config, logger);
|
||||
if (!doUpload) {
|
||||
logger.info('Not uploading results');
|
||||
return { ...queriesStats };
|
||||
}
|
||||
const uploadStats = await upload_lib.upload(outputDir, repositoryNwo, commitOid, ref, analysisKey, analysisName, workflowRunID, checkoutPath, environment, githubAuth, githubUrl, mode, logger);
|
||||
return { ...queriesStats, ...uploadStats };
|
||||
}
|
||||
exports.runAnalyze = runAnalyze;
|
||||
//# sourceMappingURL=analyze.js.map
|
||||
1
lib/analyze.js.map
Normal file
1
lib/analyze.js.map
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"analyze.js","sourceRoot":"","sources":["../src/analyze.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uCAAyB;AACzB,2CAA6B;AAE7B,gEAAkD;AAClD,qCAAqC;AAErC,2CAAgD;AAGhD,gEAAkD;AAClD,yDAA2C;AAC3C,6CAA+B;AAiC/B,KAAK,UAAU,4BAA4B,CACzC,MAA0B,EAC1B,MAAc;IAEd,sEAAsE;IACtE,oCAAoC;IACpC,aAAa,CAAC,8BAA8B,CAAC,MAAM,CAAC,CAAC;IAErD,MAAM,MAAM,GAAG,kBAAS,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IAC3C,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,SAAS,EAAE;QACvC,IAAI,6BAAiB,CAA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O,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,0BAA0B,CAAC,CAAC;IAEzD,EAAE,CAAC,SAAS,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAE7C,MAAM,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;IAC5C,MAAM,wBAAwB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAE/C,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;IAClC,MAAM,YAAY,GAAG,MAAM,UAAU,CAAC,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAE1F,IAAI,CAAC,QAAQ,EAAE;QACb,MAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;QACrC,OAAO,EAAE,GAAG,YAAY,EAAE,CAAC;KAC5B;IAED,MAAM,WAAW,GAAG,MAAM,UAAU,CAAC,MAAM,CACzC,SAAS,EACT,aAAa,EACb,SAAS,EACT,GAAG,EACH,WAAW,EACX,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,WAAW,EACX,UAAU,EACV,SAAS,EACT,IAAI,EACJ,MAAM,CAAC,CAAC;IAEV,OAAO,EAAE,GAAG,YAAY,EAAE,GAAG,WAAW,EAAE,CAAC;AAC7C,CAAC;AAnDD,gCAmDC"}
|
||||
27
lib/api-client.js
generated
27
lib/api-client.js
generated
|
|
@ -13,34 +13,35 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||
const core = __importStar(require("@actions/core"));
|
||||
const github = __importStar(require("@actions/github"));
|
||||
const console_log_level_1 = __importDefault(require("console-log-level"));
|
||||
const path = __importStar(require("path"));
|
||||
const util_1 = require("./util");
|
||||
exports.getApiClient = function (githubAuth, githubApiUrl, allowLocalRun = false) {
|
||||
exports.getApiClient = function (githubAuth, githubUrl, allowLocalRun = false) {
|
||||
if (util_1.isLocalRun() && !allowLocalRun) {
|
||||
throw new Error('Invalid API call in local run');
|
||||
}
|
||||
return new github.GitHub({
|
||||
auth: parseAuth(githubAuth),
|
||||
baseUrl: githubApiUrl,
|
||||
auth: githubAuth,
|
||||
baseUrl: getApiUrl(githubUrl),
|
||||
userAgent: "CodeQL Action",
|
||||
log: console_log_level_1.default({ level: "debug" })
|
||||
});
|
||||
};
|
||||
// Parses the user input as either a single token,
|
||||
// or a username and password / PAT.
|
||||
function parseAuth(auth) {
|
||||
// Check if it's a username:password pair
|
||||
const c = auth.indexOf(':');
|
||||
if (c !== -1) {
|
||||
return 'basic ' + Buffer.from(auth).toString('base64');
|
||||
function getApiUrl(githubUrl) {
|
||||
const url = new URL(githubUrl);
|
||||
// If we detect this is trying to be to github.com
|
||||
// then return with a fixed canonical URL.
|
||||
if (url.hostname === 'github.com' || url.hostname === 'api.github.com') {
|
||||
return 'https://api.github.com';
|
||||
}
|
||||
// Otherwise use the token as it is
|
||||
return auth;
|
||||
// Add the /api/v3 API prefix
|
||||
url.pathname = path.join(url.pathname, 'api', 'v3');
|
||||
return url.toString();
|
||||
}
|
||||
// Temporary function to aid in the transition to running on and off of github actions.
|
||||
// Once all code has been coverted this function should be removed or made canonical
|
||||
// and called only from the action entrypoints.
|
||||
function getActionsApiClient(allowLocalRun = false) {
|
||||
return exports.getApiClient(core.getInput('token'), util_1.getRequiredEnvParam('GITHUB_API_URL'), allowLocalRun);
|
||||
return exports.getApiClient(core.getInput('token'), util_1.getRequiredEnvParam('GITHUB_SERVER_URL'), allowLocalRun);
|
||||
}
|
||||
exports.getActionsApiClient = getActionsApiClient;
|
||||
//# sourceMappingURL=api-client.js.map
|
||||
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"api-client.js","sourceRoot":"","sources":["../src/api-client.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAsC;AACtC,wDAA0C;AAC1C,0EAAgD;AAEhD,iCAAyD;AAE5C,QAAA,YAAY,GAAG,UAAS,UAAkB,EAAE,YAAoB,EAAE,aAAa,GAAG,KAAK;IAClG,I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C,CAAC;KAClD;IACD,OAAO,IAAI,MAAM,CAAC,MAAM,CACtB;QACE,IAAI,EAAE,UAAU;QAChB,OAAO,EAAE,SAAS,CAAC,SAAS,CAAC;QAC7B,SAAS,EAAE,eAAe;QAC1B,GAAG,EAAE,2BAAe,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;KACzC,CAAC,CAAC;AACP,CAAC,CAAC;AAEF,SAAS,SAAS,CAAC,SAAiB;IAClC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC;IAE/B,kDAAkD;IAClD,0CAA0C;IAC1C,IAAI,GAAG,CAAC,QAAQ,KAAK,YAAY,IAAI,GAAG,CAAC,QAAQ,KAAK,gBAAgB,EAAE;QACtE,OAAO,wBAAwB,CAAC;KACjC;IAED,6BAA6B;IAC7B,GAAG,CAAC,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IACpD,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;AACxB,CAAC;AAED,uFAAuF;AACvF,oFAAoF;AACpF,+CAA+C;AAC/C,SAAgB,mBAAmB,CAAC,aAAa,GAAG,KAAK;IACvD,OAAO,oBAAY,CACjB,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EACtB,0BAAmB,CAAC,mBAAmB,CAAC,EACxC,aAAa,CAAC,CAAC;AACnB,CAAC;AALD,kDAKC"}
|
||||
56
lib/autobuild-action.js
generated
Normal file
56
lib/autobuild-action.js
generated
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
"use strict";
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const autobuild_1 = require("./autobuild");
|
||||
const config_utils = __importStar(require("./config-utils"));
|
||||
const logging_1 = require("./logging");
|
||||
const util = __importStar(require("./util"));
|
||||
async function sendCompletedStatusReport(startedAt, allLanguages, failingLanguage, cause) {
|
||||
var _a, _b;
|
||||
const status = failingLanguage !== undefined || cause !== undefined ? 'failure' : 'success';
|
||||
const statusReportBase = await util.createStatusReportBase('autobuild', status, startedAt, (_a = cause) === null || _a === void 0 ? void 0 : _a.message, (_b = cause) === null || _b === void 0 ? void 0 : _b.stack);
|
||||
const statusReport = {
|
||||
...statusReportBase,
|
||||
autobuild_languages: allLanguages.join(','),
|
||||
autobuild_failure: failingLanguage,
|
||||
};
|
||||
await util.sendStatusReport(statusReport);
|
||||
}
|
||||
async function run() {
|
||||
const logger = logging_1.getActionsLogger();
|
||||
const startedAt = new Date();
|
||||
let language = undefined;
|
||||
try {
|
||||
util.prepareLocalRunEnvironment();
|
||||
if (!await util.sendStatusReport(await util.createStatusReportBase('autobuild', 'starting', startedAt), true)) {
|
||||
return;
|
||||
}
|
||||
const config = await config_utils.getConfig(util.getRequiredEnvParam('RUNNER_TEMP'), logger);
|
||||
if (config === undefined) {
|
||||
throw new Error("Config file could not be found at expected location. Has the 'init' action been called?");
|
||||
}
|
||||
language = autobuild_1.determineAutobuildLanguage(config, logger);
|
||||
if (language !== undefined) {
|
||||
await autobuild_1.runAutobuild(language, config, logger);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
core.setFailed("We were unable to automatically build your code. Please replace the call to the autobuild action with your custom build steps. " + error.message);
|
||||
console.log(error);
|
||||
await sendCompletedStatusReport(startedAt, language ? [language] : [], language, error);
|
||||
return;
|
||||
}
|
||||
await sendCompletedStatusReport(startedAt, language ? [language] : []);
|
||||
}
|
||||
run().catch(e => {
|
||||
core.setFailed("autobuild action failed. " + e);
|
||||
console.log(e);
|
||||
});
|
||||
//# sourceMappingURL=autobuild-action.js.map
|
||||
1
lib/autobuild-action.js.map
Normal file
1
lib/autobuild-action.js.map
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"autobuild-action.js","sourceRoot":"","sources":["../src/autobuild-action.ts"],"names":[],"mappings":";;;;;;;;;AAAA,oDAAsC;AAEtC,2CAAuE;AACvE,6DAA+C;AAE/C,uCAA6C;AAC7C,6CAA+B;AAS/B,KAAK,UAAU,yBAAyB,CACtC,SAAe,EACf,YAAsB,EACtB,eAAwB,EACxB,KAAa;;IAEb,MAAM,MAAM,GAAG,eAAe,KAAK,SAAS,IAAI,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;IAC5F,MAAM,gBAAgB,GAAG,MAAM,IAAI,CAAC,sBAAsB,CACxD,WAAW,EACX,MAAM,EACN,SAAS,QACT,KAAK,0CAAE,OAAO,QACd,KAAK,0CAAE,KAAK,CAAC,CAAC;IAChB,MAAM,YAAY,GAA0B;QAC1C,GAAG,gBAAgB;QACnB,mBAAmB,EAAE,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC;QAC3C,iBAAiB,EAAE,eAAe;KACnC,CAAC;IACF,MAAM,IAAI,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC;AAC5C,CAAC;AAED,KAAK,UAAU,GAAG;IAChB,MAAM,MAAM,GAAG,0BAAgB,EAAE,CAAC;IAClC,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;IAC7B,IAAI,QAAQ,GAAyB,SAAS,CAAC;IAC/C,IAAI;QACF,IAAI,CAAC,0BAA0B,EAAE,CAAC;QAClC,IAAI,CAAC,MAAM,IAAI,CAAC,gBAAgB,CAAC,MAAM,IAAI,CAAC,sBAAsB,CAAC,WAAW,EAAE,UAAU,EAAE,SAAS,CAAC,EAAE,IAAI,CAAC,EAAE;YAC7G,OAAO;SACR;QAED,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,SAAS,CAAC,IAAI,CAAC,mBAAmB,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC,CAAC;QAC7F,IAAI,MAAM,KAAK,SAAS,EAAE;YACxB,MAAM,IAAI,KAAK,CAAC,yFAAyF,CAAC,CAAC;SAC5G;QACD,QAAQ,GAAG,sCAA0B,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACtD,IAAI,QAAQ,KAAK,SAAS,EAAE;YAC1B,MAAM,wBAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;SAC9C;KAEF;IAAC,OAAO,KAAK,EAAE;QACd,IAAI,CAAC,SAAS,CAAC,kIAAkI,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC;QACnK,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACnB,MAAM,yBAAyB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;QACxF,OAAO;KACR;IAED,MAAM,yBAAyB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AACzE,CAAC;AAED,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;IACd,IAAI,CAAC,SAAS,CAAC,4BAA4B,GAAG,CAAC,CAAC,CAAC;IACjD,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AACjB,CAAC,CAAC,CAAC"}
|
||||
80
lib/autobuild.js
generated
80
lib/autobuild.js
generated
|
|
@ -1,66 +1,30 @@
|
|||
"use strict";
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const codeql_1 = require("./codeql");
|
||||
const config_utils = __importStar(require("./config-utils"));
|
||||
const languages_1 = require("./languages");
|
||||
const util = __importStar(require("./util"));
|
||||
async function sendCompletedStatusReport(startedAt, allLanguages, failingLanguage, cause) {
|
||||
var _a, _b;
|
||||
const status = failingLanguage !== undefined || cause !== undefined ? 'failure' : 'success';
|
||||
const statusReportBase = await util.createStatusReportBase('autobuild', status, startedAt, (_a = cause) === null || _a === void 0 ? void 0 : _a.message, (_b = cause) === null || _b === void 0 ? void 0 : _b.stack);
|
||||
const statusReport = {
|
||||
...statusReportBase,
|
||||
autobuild_languages: allLanguages.join(','),
|
||||
autobuild_failure: failingLanguage,
|
||||
};
|
||||
await util.sendStatusReport(statusReport);
|
||||
}
|
||||
async function run() {
|
||||
const startedAt = new Date();
|
||||
let language;
|
||||
try {
|
||||
util.prepareLocalRunEnvironment();
|
||||
if (!await util.sendStatusReport(await util.createStatusReportBase('autobuild', 'starting', startedAt), true)) {
|
||||
return;
|
||||
}
|
||||
const config = await config_utils.getConfig(util.getRequiredEnvParam('RUNNER_TEMP'));
|
||||
// Attempt to find a language to autobuild
|
||||
// We want pick the dominant language in the repo from the ones we're able to build
|
||||
// The languages are sorted in order specified by user or by lines of code if we got
|
||||
// them from the GitHub API, so try to build the first language on the list.
|
||||
const autobuildLanguages = config.languages.filter(languages_1.isTracedLanguage);
|
||||
language = autobuildLanguages[0];
|
||||
if (!language) {
|
||||
core.info("None of the languages in this project require extra build steps");
|
||||
return;
|
||||
}
|
||||
core.debug(`Detected dominant traced language: ${language}`);
|
||||
if (autobuildLanguages.length > 1) {
|
||||
core.warning(`We will only automatically build ${language} code. If you wish to scan ${autobuildLanguages.slice(1).join(' and ')}, you must replace this block with custom build steps.`);
|
||||
}
|
||||
core.startGroup(`Attempting to automatically build ${language} code`);
|
||||
const codeQL = codeql_1.getCodeQL(config.codeQLCmd);
|
||||
await codeQL.runAutobuild(language);
|
||||
core.endGroup();
|
||||
function determineAutobuildLanguage(config, logger) {
|
||||
// Attempt to find a language to autobuild
|
||||
// We want pick the dominant language in the repo from the ones we're able to build
|
||||
// The languages are sorted in order specified by user or by lines of code if we got
|
||||
// them from the GitHub API, so try to build the first language on the list.
|
||||
const autobuildLanguages = config.languages.filter(languages_1.isTracedLanguage);
|
||||
const language = autobuildLanguages[0];
|
||||
if (!language) {
|
||||
logger.info("None of the languages in this project require extra build steps");
|
||||
return undefined;
|
||||
}
|
||||
catch (error) {
|
||||
core.setFailed("We were unable to automatically build your code. Please replace the call to the autobuild action with your custom build steps. " + error.message);
|
||||
console.log(error);
|
||||
await sendCompletedStatusReport(startedAt, [language], language, error);
|
||||
return;
|
||||
logger.debug(`Detected dominant traced language: ${language}`);
|
||||
if (autobuildLanguages.length > 1) {
|
||||
logger.warning(`We will only automatically build ${language} code. If you wish to scan ${autobuildLanguages.slice(1).join(' and ')}, you must replace this call with custom build steps.`);
|
||||
}
|
||||
await sendCompletedStatusReport(startedAt, [language]);
|
||||
return language;
|
||||
}
|
||||
run().catch(e => {
|
||||
core.setFailed("autobuild action failed. " + e);
|
||||
console.log(e);
|
||||
});
|
||||
exports.determineAutobuildLanguage = determineAutobuildLanguage;
|
||||
async function runAutobuild(language, config, logger) {
|
||||
logger.startGroup(`Attempting to automatically build ${language} code`);
|
||||
const codeQL = codeql_1.getCodeQL(config.codeQLCmd);
|
||||
await codeQL.runAutobuild(language);
|
||||
logger.endGroup();
|
||||
}
|
||||
exports.runAutobuild = runAutobuild;
|
||||
//# sourceMappingURL=autobuild.js.map
|
||||
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"autobuild.js","sourceRoot":"","sources":["../src/autobuild.ts"],"names":[],"mappings":";;;;;;;;;AAAA,oDAAsC;AAEtC,qCAAqC;AACrC,6DAA+C;AAC/C,2CAA+C;AAC/C,6CAA+B;AAS/B,KAAK,UAAU,yBAAyB,CACtC,SAAe,EACf,YAAsB,EACtB,eAAwB,EACxB,KAAa;;IAEb,MAAM,MAA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,4BAAgB,CAAC,CAAC;IACrE,MAAM,QAAQ,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAAC;IAEvC,IAAI,CAAC,QAAQ,EAAE;QACb,MAAM,CAAC,IAAI,CAAC,iEAAiE,CAAC,CAAC;QAC/E,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,CAAC,KAAK,CAAC,sCAAsC,QAAQ,EAAE,CAAC,CAAC;IAE/D,IAAI,kBAAkB,CAAC,MAAM,GAAG,CAAC,EAAE;QACjC,MAAM,CAAC,OAAO,CAAC,oCAAoC,QAAQ,8BAA8B,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,uDAAuD,CAAC,CAAC;KAC5L;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC;AAxBD,gEAwBC;AAEM,KAAK,UAAU,YAAY,CAChC,QAAkB,EAClB,MAA2B,EAC3B,MAAc;IAEd,MAAM,CAAC,UAAU,CAAC,qCAAqC,QAAQ,OAAO,CAAC,CAAC;IACxE,MAAM,MAAM,GAAG,kBAAS,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IAC3C,MAAM,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;IACpC,MAAM,CAAC,QAAQ,EAAE,CAAC;AACpB,CAAC;AATD,oCASC"}
|
||||
57
lib/cli.js
generated
57
lib/cli.js
generated
|
|
@ -1,57 +0,0 @@
|
|||
"use strict";
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const commander_1 = require("commander");
|
||||
const path = __importStar(require("path"));
|
||||
const logging_1 = require("./logging");
|
||||
const repository_1 = require("./repository");
|
||||
const upload_lib = __importStar(require("./upload-lib"));
|
||||
const program = new commander_1.Command();
|
||||
program.version('0.0.1');
|
||||
function parseGithubApiUrl(inputUrl) {
|
||||
try {
|
||||
const url = new URL(inputUrl);
|
||||
// If we detect this is trying to be to github.com
|
||||
// then return with a fixed canonical URL.
|
||||
if (url.hostname === 'github.com' || url.hostname === 'api.github.com') {
|
||||
return 'https://api.github.com';
|
||||
}
|
||||
// Add the API path if it's not already present.
|
||||
if (url.pathname.indexOf('/api/v3') === -1) {
|
||||
url.pathname = path.join(url.pathname, 'api', 'v3');
|
||||
}
|
||||
return url.toString();
|
||||
}
|
||||
catch (e) {
|
||||
throw new Error(`"${inputUrl}" is not a valid URL`);
|
||||
}
|
||||
}
|
||||
const logger = logging_1.getCLILogger();
|
||||
program
|
||||
.command('upload')
|
||||
.description('Uploads a SARIF file, or all SARIF files from a directory, to code scanning')
|
||||
.requiredOption('--sarif-file <file>', 'SARIF file to upload; can also be a directory for uploading multiple')
|
||||
.requiredOption('--repository <repository>', 'Repository name')
|
||||
.requiredOption('--commit <commit>', 'SHA of commit that was analyzed')
|
||||
.requiredOption('--ref <ref>', 'Name of ref that was analyzed')
|
||||
.requiredOption('--github-url <url>', 'URL of GitHub instance')
|
||||
.requiredOption('--github-auth <auth>', 'GitHub Apps token, or of the form "username:token" if using a personal access token')
|
||||
.option('--checkout-path <path>', 'Checkout path (default: current working directory)')
|
||||
.action(async (cmd) => {
|
||||
try {
|
||||
await upload_lib.upload(cmd.sarifFile, repository_1.parseRepositoryNwo(cmd.repository), cmd.commit, cmd.ref, undefined, undefined, undefined, cmd.checkoutPath || process.cwd(), undefined, cmd.githubAuth, parseGithubApiUrl(cmd.githubUrl), 'cli', logger);
|
||||
}
|
||||
catch (e) {
|
||||
logger.error('Upload failed');
|
||||
logger.error(e);
|
||||
process.exitCode = 1;
|
||||
}
|
||||
});
|
||||
program.parse(process.argv);
|
||||
//# sourceMappingURL=cli.js.map
|
||||
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"cli.js","sourceRoot":"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,qFAAqF,CAAC;KAC7H,MAAM,CAAC,wBAAwB,EAAE,oDAAoD,CAAC;KACtF,MAAM,CAAC,KAAK,EAAE,GAAe,EAAE,EAAE;IAChC,IAAI;QACF,MAAM,UAAU,CAAC,MAAM,CACrB,GAAG,CAAC,SAAS,EACb,+BAAkB,CAAC,GAAG,CAAC,UAAU,CAAC,EAClC,GAAG,CAAC,MAAM,EACV,GAAG,CAAC,GAAG,EACP,SAAS,EACT,SAAS,EACT,SAAS,EACT,GAAG,CAAC,YAAY,IAAI,OAAO,CAAC,GAAG,EAAE,EACjC,SAAS,EACT,GAAG,CAAC,UAAU,EACd,iBAAiB,CAAC,GAAG,CAAC,SAAS,CAAC,EAChC,KAAK,EACL,MAAM,CAAC,CAAC;KACX;IAAC,OAAO,CAAC,EAAE;QACV,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;QAC9B,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAChB,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;KACtB;AACH,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
||||
124
lib/codeql.js
generated
124
lib/codeql.js
generated
|
|
@ -10,8 +10,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const exec = __importStar(require("@actions/exec"));
|
||||
const toolrunnner = __importStar(require("@actions/exec/lib/toolrunner"));
|
||||
const http = __importStar(require("@actions/http-client"));
|
||||
const toolcache = __importStar(require("@actions/tool-cache"));
|
||||
const fs = __importStar(require("fs"));
|
||||
|
|
@ -33,7 +32,10 @@ let cachedCodeQL = undefined;
|
|||
const CODEQL_BUNDLE_VERSION = defaults.bundleVersion;
|
||||
const CODEQL_BUNDLE_NAME = "codeql-bundle.tar.gz";
|
||||
const CODEQL_DEFAULT_ACTION_REPOSITORY = "github/codeql-action";
|
||||
function getCodeQLActionRepository() {
|
||||
function getCodeQLActionRepository(mode) {
|
||||
if (mode !== 'actions') {
|
||||
return CODEQL_DEFAULT_ACTION_REPOSITORY;
|
||||
}
|
||||
// Actions do not know their own repository name,
|
||||
// so we currently use this hack to find the name based on where our files are.
|
||||
// This can be removed once the change to the runner in https://github.com/actions/runner/pull/585 is deployed.
|
||||
|
|
@ -48,15 +50,15 @@ function getCodeQLActionRepository() {
|
|||
const relativeScriptPathParts = relativeScriptPath.split(path.sep);
|
||||
return relativeScriptPathParts[0] + "/" + relativeScriptPathParts[1];
|
||||
}
|
||||
async function getCodeQLBundleDownloadURL() {
|
||||
const codeQLActionRepository = getCodeQLActionRepository();
|
||||
async function getCodeQLBundleDownloadURL(githubAuth, githubUrl, mode, logger) {
|
||||
const codeQLActionRepository = getCodeQLActionRepository(mode);
|
||||
const potentialDownloadSources = [
|
||||
// This GitHub instance, and this Action.
|
||||
[util.getInstanceAPIURL(), codeQLActionRepository],
|
||||
[githubUrl, codeQLActionRepository],
|
||||
// This GitHub instance, and the canonical Action.
|
||||
[util.getInstanceAPIURL(), CODEQL_DEFAULT_ACTION_REPOSITORY],
|
||||
[githubUrl, CODEQL_DEFAULT_ACTION_REPOSITORY],
|
||||
// GitHub.com, and the canonical Action.
|
||||
[util.GITHUB_DOTCOM_API_URL, CODEQL_DEFAULT_ACTION_REPOSITORY],
|
||||
[util.GITHUB_DOTCOM_URL, CODEQL_DEFAULT_ACTION_REPOSITORY],
|
||||
];
|
||||
// We now filter out any duplicates.
|
||||
// Duplicates will happen either because the GitHub instance is GitHub.com, or because the Action is not a fork.
|
||||
|
|
@ -64,71 +66,74 @@ async function getCodeQLBundleDownloadURL() {
|
|||
for (let downloadSource of uniqueDownloadSources) {
|
||||
let [apiURL, repository] = downloadSource;
|
||||
// If we've reached the final case, short-circuit the API check since we know the bundle exists and is public.
|
||||
if (apiURL === util.GITHUB_DOTCOM_API_URL && repository === CODEQL_DEFAULT_ACTION_REPOSITORY) {
|
||||
if (apiURL === util.GITHUB_DOTCOM_URL && repository === CODEQL_DEFAULT_ACTION_REPOSITORY) {
|
||||
break;
|
||||
}
|
||||
let [repositoryOwner, repositoryName] = repository.split("/");
|
||||
try {
|
||||
const release = await api.getActionsApiClient().repos.getReleaseByTag({
|
||||
const release = await api.getApiClient(githubAuth, githubUrl).repos.getReleaseByTag({
|
||||
owner: repositoryOwner,
|
||||
repo: repositoryName,
|
||||
tag: CODEQL_BUNDLE_VERSION
|
||||
});
|
||||
for (let asset of release.data.assets) {
|
||||
if (asset.name === CODEQL_BUNDLE_NAME) {
|
||||
core.info(`Found CodeQL bundle in ${downloadSource[1]} on ${downloadSource[0]} with URL ${asset.url}.`);
|
||||
logger.info(`Found CodeQL bundle in ${downloadSource[1]} on ${downloadSource[0]} with URL ${asset.url}.`);
|
||||
return asset.url;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
core.info(`Looked for CodeQL bundle in ${downloadSource[1]} on ${downloadSource[0]} but got error ${e}.`);
|
||||
logger.info(`Looked for CodeQL bundle in ${downloadSource[1]} on ${downloadSource[0]} but got error ${e}.`);
|
||||
}
|
||||
}
|
||||
return `https://github.com/${CODEQL_DEFAULT_ACTION_REPOSITORY}/releases/download/${CODEQL_BUNDLE_VERSION}/${CODEQL_BUNDLE_NAME}`;
|
||||
}
|
||||
// We have to download CodeQL manually because the toolcache doesn't support Accept headers.
|
||||
// This can be removed once https://github.com/actions/toolkit/pull/530 is merged and released.
|
||||
async function toolcacheDownloadTool(url, headers) {
|
||||
async function toolcacheDownloadTool(url, headers, tempDir, logger) {
|
||||
const client = new http.HttpClient('CodeQL Action');
|
||||
const dest = path.join(util.getRequiredEnvParam('RUNNER_TEMP'), v4_1.default());
|
||||
const dest = path.join(tempDir, v4_1.default());
|
||||
const response = await client.get(url, headers);
|
||||
if (response.message.statusCode !== 200) {
|
||||
const err = new toolcache.HTTPError(response.message.statusCode);
|
||||
core.info(`Failed to download from "${url}". Code(${response.message.statusCode}) Message(${response.message.statusMessage})`);
|
||||
throw err;
|
||||
logger.info(`Failed to download from "${url}". Code(${response.message.statusCode}) Message(${response.message.statusMessage})`);
|
||||
throw new Error(`Unexpected HTTP response: ${response.message.statusCode}`);
|
||||
}
|
||||
const pipeline = globalutil.promisify(stream.pipeline);
|
||||
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
||||
await pipeline(response.message, fs.createWriteStream(dest));
|
||||
return dest;
|
||||
}
|
||||
async function setupCodeQL() {
|
||||
async function setupCodeQL(codeqlURL, githubAuth, githubUrl, tempDir, toolsDir, mode, logger) {
|
||||
// Setting these two env vars makes the toolcache code safe to use outside,
|
||||
// of actions but this is obviously not a great thing we're doing and it would
|
||||
// be better to write our own implementation to use outside of actions.
|
||||
process.env['RUNNER_TEMP'] = tempDir;
|
||||
process.env['RUNNER_TOOL_CACHE'] = toolsDir;
|
||||
try {
|
||||
let codeqlURL = core.getInput('tools');
|
||||
const codeqlURLVersion = getCodeQLURLVersion(codeqlURL || `/${CODEQL_BUNDLE_VERSION}/`);
|
||||
const codeqlURLVersion = getCodeQLURLVersion(codeqlURL || `/${CODEQL_BUNDLE_VERSION}/`, logger);
|
||||
let codeqlFolder = toolcache.find('CodeQL', codeqlURLVersion);
|
||||
if (codeqlFolder) {
|
||||
core.debug(`CodeQL found in cache ${codeqlFolder}`);
|
||||
logger.debug(`CodeQL found in cache ${codeqlFolder}`);
|
||||
}
|
||||
else {
|
||||
if (!codeqlURL) {
|
||||
codeqlURL = await getCodeQLBundleDownloadURL();
|
||||
codeqlURL = await getCodeQLBundleDownloadURL(githubAuth, githubUrl, mode, logger);
|
||||
}
|
||||
const headers = { accept: 'application/octet-stream' };
|
||||
// We only want to provide an authorization header if we are downloading
|
||||
// from the same GitHub instance the Action is running on.
|
||||
// This avoids leaking Enterprise tokens to dotcom.
|
||||
if (codeqlURL.startsWith(util.getInstanceAPIURL() + "/")) {
|
||||
core.debug('Downloading CodeQL bundle with token.');
|
||||
let token = core.getInput('token', { required: true });
|
||||
headers.authorization = `token ${token}`;
|
||||
if (codeqlURL.startsWith(githubUrl + "/")) {
|
||||
logger.debug('Downloading CodeQL bundle with token.');
|
||||
headers.authorization = `token ${githubAuth}`;
|
||||
}
|
||||
else {
|
||||
core.debug('Downloading CodeQL bundle without token.');
|
||||
logger.debug('Downloading CodeQL bundle without token.');
|
||||
}
|
||||
let codeqlPath = await toolcacheDownloadTool(codeqlURL, headers);
|
||||
core.debug(`CodeQL bundle download to ${codeqlPath} complete.`);
|
||||
logger.info(`Downloading CodeQL tools from ${codeqlURL}. This may take a while.`);
|
||||
let codeqlPath = await toolcacheDownloadTool(codeqlURL, headers, tempDir, logger);
|
||||
logger.debug(`CodeQL bundle download to ${codeqlPath} complete.`);
|
||||
const codeqlExtracted = await toolcache.extractTar(codeqlPath);
|
||||
codeqlFolder = await toolcache.cacheDir(codeqlExtracted, 'CodeQL', codeqlURLVersion);
|
||||
}
|
||||
|
|
@ -143,19 +148,19 @@ async function setupCodeQL() {
|
|||
return cachedCodeQL;
|
||||
}
|
||||
catch (e) {
|
||||
core.error(e);
|
||||
logger.error(e);
|
||||
throw new Error("Unable to download and extract CodeQL CLI");
|
||||
}
|
||||
}
|
||||
exports.setupCodeQL = setupCodeQL;
|
||||
function getCodeQLURLVersion(url) {
|
||||
function getCodeQLURLVersion(url, logger) {
|
||||
const match = url.match(/\/codeql-bundle-(.*)\//);
|
||||
if (match === null || match.length < 2) {
|
||||
throw new Error(`Malformed tools url: ${url}. Version could not be inferred`);
|
||||
}
|
||||
let version = match[1];
|
||||
if (!semver.valid(version)) {
|
||||
core.debug(`Bundle version ${version} is not in SemVer format. Will treat it as pre-release 0.0.0-${version}.`);
|
||||
logger.debug(`Bundle version ${version} is not in SemVer format. Will treat it as pre-release 0.0.0-${version}.`);
|
||||
version = '0.0.0-' + version;
|
||||
}
|
||||
const s = semver.clean(version);
|
||||
|
|
@ -228,35 +233,48 @@ function getCodeQLForCmd(cmd) {
|
|||
return cmd;
|
||||
},
|
||||
printVersion: async function () {
|
||||
await exec.exec(cmd, [
|
||||
await new toolrunnner.ToolRunner(cmd, [
|
||||
'version',
|
||||
'--format=json'
|
||||
]);
|
||||
]).exec();
|
||||
},
|
||||
getTracerEnv: async function (databasePath, compilerSpec) {
|
||||
let envFile = path.resolve(databasePath, 'working', 'env.tmp');
|
||||
const compilerSpecArg = compilerSpec ? ["--compiler-spec=" + compilerSpec] : [];
|
||||
await exec.exec(cmd, [
|
||||
getTracerEnv: async function (databasePath) {
|
||||
// Write tracer-env.js to a temp location.
|
||||
const tracerEnvJs = path.resolve(databasePath, 'working', 'tracer-env.js');
|
||||
fs.mkdirSync(path.dirname(tracerEnvJs), { recursive: true });
|
||||
fs.writeFileSync(tracerEnvJs, `
|
||||
const fs = require('fs');
|
||||
const env = {};
|
||||
for (let entry of Object.entries(process.env)) {
|
||||
const key = entry[0];
|
||||
const value = entry[1];
|
||||
if (typeof value !== 'undefined' && key !== '_' && !key.startsWith('JAVA_MAIN_CLASS_')) {
|
||||
env[key] = value;
|
||||
}
|
||||
}
|
||||
process.stdout.write(process.argv[2]);
|
||||
fs.writeFileSync(process.argv[2], JSON.stringify(env), 'utf-8');`);
|
||||
const envFile = path.resolve(databasePath, 'working', 'env.tmp');
|
||||
await new toolrunnner.ToolRunner(cmd, [
|
||||
'database',
|
||||
'trace-command',
|
||||
databasePath,
|
||||
...compilerSpecArg,
|
||||
...getExtraOptionsFromEnv(['database', 'trace-command']),
|
||||
process.execPath,
|
||||
path.resolve(__dirname, 'tracer-env.js'),
|
||||
tracerEnvJs,
|
||||
envFile
|
||||
]);
|
||||
]).exec();
|
||||
return JSON.parse(fs.readFileSync(envFile, 'utf-8'));
|
||||
},
|
||||
databaseInit: async function (databasePath, language, sourceRoot) {
|
||||
await exec.exec(cmd, [
|
||||
await new toolrunnner.ToolRunner(cmd, [
|
||||
'database',
|
||||
'init',
|
||||
databasePath,
|
||||
'--language=' + language,
|
||||
'--source-root=' + sourceRoot,
|
||||
...getExtraOptionsFromEnv(['database', 'init']),
|
||||
]);
|
||||
]).exec();
|
||||
},
|
||||
runAutobuild: async function (language) {
|
||||
const cmdName = process.platform === 'win32' ? 'autobuild.cmd' : 'autobuild.sh';
|
||||
|
|
@ -268,12 +286,12 @@ function getCodeQLForCmd(cmd) {
|
|||
// https://developercommunity.visualstudio.com/content/problem/292284/maven-hosted-agent-connection-timeout.html
|
||||
let javaToolOptions = process.env['JAVA_TOOL_OPTIONS'] || "";
|
||||
process.env['JAVA_TOOL_OPTIONS'] = [...javaToolOptions.split(/\s+/), '-Dhttp.keepAlive=false', '-Dmaven.wagon.http.pool=false'].join(' ');
|
||||
await exec.exec(autobuildCmd);
|
||||
await new toolrunnner.ToolRunner(autobuildCmd).exec();
|
||||
},
|
||||
extractScannedLanguage: async function (databasePath, language) {
|
||||
// Get extractor location
|
||||
let extractorPath = '';
|
||||
await exec.exec(cmd, [
|
||||
await new toolrunnner.ToolRunner(cmd, [
|
||||
'resolve',
|
||||
'extractor',
|
||||
'--format=json',
|
||||
|
|
@ -285,7 +303,7 @@ function getCodeQLForCmd(cmd) {
|
|||
stdout: (data) => { extractorPath += data.toString(); },
|
||||
stderr: (data) => { process.stderr.write(data); }
|
||||
}
|
||||
});
|
||||
}).exec();
|
||||
// Set trace command
|
||||
const ext = process.platform === 'win32' ? '.cmd' : '.sh';
|
||||
const traceCommand = path.resolve(JSON.parse(extractorPath), 'tools', 'autobuild' + ext);
|
||||
|
|
@ -319,28 +337,28 @@ function getCodeQLForCmd(cmd) {
|
|||
codeqlArgs.push('--search-path', extraSearchPath);
|
||||
}
|
||||
let output = '';
|
||||
await exec.exec(cmd, codeqlArgs, {
|
||||
await new toolrunnner.ToolRunner(cmd, codeqlArgs, {
|
||||
listeners: {
|
||||
stdout: (data) => {
|
||||
output += data.toString();
|
||||
}
|
||||
}
|
||||
});
|
||||
}).exec();
|
||||
return JSON.parse(output);
|
||||
},
|
||||
databaseAnalyze: async function (databasePath, sarifFile, querySuite) {
|
||||
await exec.exec(cmd, [
|
||||
databaseAnalyze: async function (databasePath, sarifFile, querySuite, memoryFlag, threadsFlag) {
|
||||
await new toolrunnner.ToolRunner(cmd, [
|
||||
'database',
|
||||
'analyze',
|
||||
util.getMemoryFlag(),
|
||||
util.getThreadsFlag(),
|
||||
memoryFlag,
|
||||
threadsFlag,
|
||||
databasePath,
|
||||
'--format=sarif-latest',
|
||||
'--output=' + sarifFile,
|
||||
'--no-sarif-add-snippets',
|
||||
...getExtraOptionsFromEnv(['database', 'analyze']),
|
||||
querySuite
|
||||
]);
|
||||
]).exec();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
9
lib/codeql.test.js
generated
9
lib/codeql.test.js
generated
|
|
@ -15,22 +15,19 @@ const ava_1 = __importDefault(require("ava"));
|
|||
const nock_1 = __importDefault(require("nock"));
|
||||
const path = __importStar(require("path"));
|
||||
const codeql = __importStar(require("./codeql"));
|
||||
const logging_1 = require("./logging");
|
||||
const testing_utils_1 = require("./testing-utils");
|
||||
const util = __importStar(require("./util"));
|
||||
testing_utils_1.setupTests(ava_1.default);
|
||||
ava_1.default('download codeql bundle cache', async (t) => {
|
||||
await util.withTmpDir(async (tmpDir) => {
|
||||
process.env['GITHUB_WORKSPACE'] = tmpDir;
|
||||
process.env['RUNNER_TEMP'] = path.join(tmpDir, 'temp');
|
||||
process.env['RUNNER_TOOL_CACHE'] = path.join(tmpDir, 'cache');
|
||||
const versions = ['20200601', '20200610'];
|
||||
for (let i = 0; i < versions.length; i++) {
|
||||
const version = versions[i];
|
||||
nock_1.default('https://example.com')
|
||||
.get(`/download/codeql-bundle-${version}/codeql-bundle.tar.gz`)
|
||||
.replyWithFile(200, path.join(__dirname, `/../src/testdata/codeql-bundle.tar.gz`));
|
||||
process.env['INPUT_TOOLS'] = `https://example.com/download/codeql-bundle-${version}/codeql-bundle.tar.gz`;
|
||||
await codeql.setupCodeQL();
|
||||
await codeql.setupCodeQL(`https://example.com/download/codeql-bundle-${version}/codeql-bundle.tar.gz`, 'token', 'https://github.example.com', tmpDir, tmpDir, 'runner', logging_1.getRunnerLogger(true));
|
||||
t.assert(toolcache.find('CodeQL', `0.0.0-${version}`));
|
||||
}
|
||||
const cachedVersions = toolcache.findAllVersions('CodeQL');
|
||||
|
|
@ -49,7 +46,7 @@ ava_1.default('parse codeql bundle url version', t => {
|
|||
for (const [version, expectedVersion] of Object.entries(tests)) {
|
||||
const url = `https://github.com/.../codeql-bundle-${version}/...`;
|
||||
try {
|
||||
const parsedVersion = codeql.getCodeQLURLVersion(url);
|
||||
const parsedVersion = codeql.getCodeQLURLVersion(url, logging_1.getRunnerLogger(true));
|
||||
t.deepEqual(parsedVersion, expectedVersion);
|
||||
}
|
||||
catch (e) {
|
||||
|
|
|
|||
|
|
@ -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,mDAA2C;AAC3C,6CAA+B;AAE/B,0BAAU,CAAC,aAAI,CAAC,CAAC;AAEjB,aAAI,CAAC,8BAA8B,EAAE,KAAK,EAAC,CAAC,EAAC,EAAE;IAE7C,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,EAAC,MAAM,EAAC,EAAE;QAEnC,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,GAAG,MAAM,CAAC;QAEzC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACvD,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAE9D,MAAM,QAAQ,GAAG,CAAC,UAAU,EAAE,UA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AC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACvB,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,eAAe,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;AACrE,CAAC,CAAC,CAAC;AAEH,aAAI,CAAC,wCAAwC,EAAE,CAAC,CAAC,EAAE;IACjD,CAAC,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,eAAe,CAAC,EAAC,GAAG,EAAE,EAAE,EAAC,EAAE,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IAE/D,CAAC,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,eAAe,CAAC,EAAC,GAAG,EAAE,EAAE,EAAC,EAAE,CAAC,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"}
|
||||
182
lib/config-utils.js
generated
182
lib/config-utils.js
generated
|
|
@ -7,14 +7,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const fs = __importStar(require("fs"));
|
||||
const yaml = __importStar(require("js-yaml"));
|
||||
const path = __importStar(require("path"));
|
||||
const api = __importStar(require("./api-client"));
|
||||
const externalQueries = __importStar(require("./external-queries"));
|
||||
const languages_1 = require("./languages");
|
||||
const util = __importStar(require("./util"));
|
||||
// Property names from the user-supplied config file.
|
||||
const NAME_PROPERTY = 'name';
|
||||
const DISABLE_DEFAULT_QUERIES_PROPERTY = 'disable-default-queries';
|
||||
|
|
@ -89,7 +87,7 @@ const builtinSuites = ['security-extended', 'security-and-quality'];
|
|||
* Determine the set of queries associated with suiteName's suites and add them to resultMap.
|
||||
* Throws an error if suiteName is not a valid builtin suite.
|
||||
*/
|
||||
async function addBuiltinSuiteQueries(configFile, languages, codeQL, resultMap, suiteName) {
|
||||
async function addBuiltinSuiteQueries(languages, codeQL, resultMap, suiteName, configFile) {
|
||||
const suite = builtinSuites.find((suite) => suite === suiteName);
|
||||
if (!suite) {
|
||||
throw new Error(getQueryUsesInvalid(configFile, suiteName));
|
||||
|
|
@ -100,11 +98,10 @@ async function addBuiltinSuiteQueries(configFile, languages, codeQL, resultMap,
|
|||
/**
|
||||
* Retrieve the set of queries at localQueryPath and add them to resultMap.
|
||||
*/
|
||||
async function addLocalQueries(configFile, codeQL, resultMap, localQueryPath) {
|
||||
async function addLocalQueries(codeQL, resultMap, localQueryPath, checkoutPath, configFile) {
|
||||
// Resolve the local path against the workspace so that when this is
|
||||
// passed to codeql it resolves to exactly the path we expect it to resolve to.
|
||||
const workspacePath = fs.realpathSync(util.getRequiredEnvParam('GITHUB_WORKSPACE'));
|
||||
let absoluteQueryPath = path.join(workspacePath, localQueryPath);
|
||||
let absoluteQueryPath = path.join(checkoutPath, localQueryPath);
|
||||
// Check the file exists
|
||||
if (!fs.existsSync(absoluteQueryPath)) {
|
||||
throw new Error(getLocalPathDoesNotExist(configFile, localQueryPath));
|
||||
|
|
@ -112,17 +109,15 @@ async function addLocalQueries(configFile, codeQL, resultMap, localQueryPath) {
|
|||
// Call this after checking file exists, because it'll fail if file doesn't exist
|
||||
absoluteQueryPath = fs.realpathSync(absoluteQueryPath);
|
||||
// Check the local path doesn't jump outside the repo using '..' or symlinks
|
||||
if (!(absoluteQueryPath + path.sep).startsWith(workspacePath + path.sep)) {
|
||||
if (!(absoluteQueryPath + path.sep).startsWith(fs.realpathSync(checkoutPath) + path.sep)) {
|
||||
throw new Error(getLocalPathOutsideOfRepository(configFile, localQueryPath));
|
||||
}
|
||||
// Get the root of the current repo to use when resolving query dependencies
|
||||
const rootOfRepo = util.getRequiredEnvParam('GITHUB_WORKSPACE');
|
||||
await runResolveQueries(codeQL, resultMap, [absoluteQueryPath], rootOfRepo, true);
|
||||
await runResolveQueries(codeQL, resultMap, [absoluteQueryPath], checkoutPath, true);
|
||||
}
|
||||
/**
|
||||
* Retrieve the set of queries at the referenced remote repo and add them to resultMap.
|
||||
*/
|
||||
async function addRemoteQueries(configFile, codeQL, resultMap, queryUses, tempDir) {
|
||||
async function addRemoteQueries(codeQL, resultMap, queryUses, tempDir, githubUrl, logger, configFile) {
|
||||
let tok = queryUses.split('@');
|
||||
if (tok.length !== 2) {
|
||||
throw new Error(getQueryUsesInvalid(configFile, queryUses));
|
||||
|
|
@ -141,11 +136,11 @@ async function addRemoteQueries(configFile, codeQL, resultMap, queryUses, tempDi
|
|||
}
|
||||
const nwo = tok[0] + '/' + tok[1];
|
||||
// Checkout the external repository
|
||||
const rootOfRepo = await externalQueries.checkoutExternalRepository(nwo, ref, tempDir);
|
||||
const checkoutPath = await externalQueries.checkoutExternalRepository(nwo, ref, githubUrl, tempDir, logger);
|
||||
const queryPath = tok.length > 2
|
||||
? path.join(rootOfRepo, tok.slice(2).join('/'))
|
||||
: rootOfRepo;
|
||||
await runResolveQueries(codeQL, resultMap, [queryPath], rootOfRepo, true);
|
||||
? path.join(checkoutPath, tok.slice(2).join('/'))
|
||||
: checkoutPath;
|
||||
await runResolveQueries(codeQL, resultMap, [queryPath], checkoutPath, true);
|
||||
}
|
||||
/**
|
||||
* Parse a query 'uses' field to a discrete set of query files and update resultMap.
|
||||
|
|
@ -155,23 +150,23 @@ async function addRemoteQueries(configFile, codeQL, resultMap, queryUses, tempDi
|
|||
* local paths starting with './', or references to remote repos, or
|
||||
* a finite set of hardcoded terms for builtin suites.
|
||||
*/
|
||||
async function parseQueryUses(configFile, languages, codeQL, resultMap, queryUses, tempDir) {
|
||||
async function parseQueryUses(languages, codeQL, resultMap, queryUses, tempDir, checkoutPath, githubUrl, logger, configFile) {
|
||||
queryUses = queryUses.trim();
|
||||
if (queryUses === "") {
|
||||
throw new Error(getQueryUsesInvalid(configFile));
|
||||
}
|
||||
// Check for the local path case before we start trying to parse the repository name
|
||||
if (queryUses.startsWith("./")) {
|
||||
await addLocalQueries(configFile, codeQL, resultMap, queryUses.slice(2));
|
||||
await addLocalQueries(codeQL, resultMap, queryUses.slice(2), checkoutPath, configFile);
|
||||
return;
|
||||
}
|
||||
// Check for one of the builtin suites
|
||||
if (queryUses.indexOf('/') === -1 && queryUses.indexOf('@') === -1) {
|
||||
await addBuiltinSuiteQueries(configFile, languages, codeQL, resultMap, queryUses);
|
||||
await addBuiltinSuiteQueries(languages, codeQL, resultMap, queryUses, configFile);
|
||||
return;
|
||||
}
|
||||
// Otherwise, must be a reference to another repo
|
||||
await addRemoteQueries(configFile, codeQL, resultMap, queryUses, tempDir);
|
||||
await addRemoteQueries(codeQL, resultMap, queryUses, tempDir, githubUrl, logger, configFile);
|
||||
}
|
||||
// Regex validating stars in paths or paths-ignore entries.
|
||||
// The intention is to only allow ** to appear when immediately
|
||||
|
|
@ -182,7 +177,7 @@ const pathStarsRegex = /.*(?:\*\*[^/].*|\*\*$|[^/]\*\*.*)/;
|
|||
const filterPatternCharactersRegex = /.*[\?\+\[\]!].*/;
|
||||
// Checks that a paths of paths-ignore entry is valid, possibly modifying it
|
||||
// to make it valid, or if not possible then throws an error.
|
||||
function validateAndSanitisePath(originalPath, propertyName, configFile) {
|
||||
function validateAndSanitisePath(originalPath, propertyName, configFile, logger) {
|
||||
// Take a copy so we don't modify the original path, so we can still construct error messages
|
||||
let path = originalPath;
|
||||
// All paths are relative to the src root, so strip off leading slashes.
|
||||
|
|
@ -206,7 +201,7 @@ function validateAndSanitisePath(originalPath, propertyName, configFile) {
|
|||
// Check for other regex characters that we don't support.
|
||||
// Output a warning so the user knows, but otherwise continue normally.
|
||||
if (path.match(filterPatternCharactersRegex)) {
|
||||
core.warning(getConfigFilePropertyError(configFile, propertyName, '"' + originalPath + '" contains an unsupported character. ' +
|
||||
logger.warning(getConfigFilePropertyError(configFile, propertyName, '"' + originalPath + '" contains an unsupported character. ' +
|
||||
'The filter pattern characters ?, +, [, ], ! are not supported and will be matched literally.'));
|
||||
}
|
||||
// Ban any uses of backslash for now.
|
||||
|
|
@ -219,6 +214,8 @@ function validateAndSanitisePath(originalPath, propertyName, configFile) {
|
|||
return path;
|
||||
}
|
||||
exports.validateAndSanitisePath = validateAndSanitisePath;
|
||||
// An undefined configFile in some of these functions indicates that
|
||||
// the property was in a workflow file, not a config file
|
||||
function getNameInvalid(configFile) {
|
||||
return getConfigFilePropertyError(configFile, NAME_PROPERTY, 'must be a non-empty string');
|
||||
}
|
||||
|
|
@ -276,7 +273,12 @@ function getConfigFileDirectoryGivenMessage(configFile) {
|
|||
}
|
||||
exports.getConfigFileDirectoryGivenMessage = getConfigFileDirectoryGivenMessage;
|
||||
function getConfigFilePropertyError(configFile, property, error) {
|
||||
return 'The configuration file "' + configFile + '" is invalid: property "' + property + '" ' + error;
|
||||
if (configFile === undefined) {
|
||||
return 'The workflow property "' + property + '" is invalid: ' + error;
|
||||
}
|
||||
else {
|
||||
return 'The configuration file "' + configFile + '" is invalid: property "' + property + '" ' + error;
|
||||
}
|
||||
}
|
||||
function getNoLanguagesError() {
|
||||
return "Did not detect any languages to analyze. " +
|
||||
|
|
@ -290,34 +292,25 @@ exports.getUnknownLanguagesError = getUnknownLanguagesError;
|
|||
/**
|
||||
* Gets the set of languages in the current repository
|
||||
*/
|
||||
async function getLanguagesInRepo() {
|
||||
var _a;
|
||||
let repo_nwo = (_a = process.env['GITHUB_REPOSITORY']) === null || _a === void 0 ? void 0 : _a.split("/");
|
||||
if (repo_nwo) {
|
||||
let owner = repo_nwo[0];
|
||||
let repo = repo_nwo[1];
|
||||
core.debug(`GitHub repo ${owner} ${repo}`);
|
||||
const response = await api.getActionsApiClient(true).repos.listLanguages({
|
||||
owner,
|
||||
repo
|
||||
});
|
||||
core.debug("Languages API response: " + JSON.stringify(response));
|
||||
// The GitHub API is going to return languages in order of popularity,
|
||||
// When we pick a language to autobuild we want to pick the most popular traced language
|
||||
// Since sets in javascript maintain insertion order, using a set here and then splatting it
|
||||
// into an array gives us an array of languages ordered by popularity
|
||||
let languages = new Set();
|
||||
for (let lang of Object.keys(response.data)) {
|
||||
let parsedLang = languages_1.parseLanguage(lang);
|
||||
if (parsedLang !== undefined) {
|
||||
languages.add(parsedLang);
|
||||
}
|
||||
async function getLanguagesInRepo(repository, githubAuth, githubUrl, logger) {
|
||||
logger.debug(`GitHub repo ${repository.owner} ${repository.repo}`);
|
||||
const response = await api.getApiClient(githubAuth, githubUrl, true).repos.listLanguages({
|
||||
owner: repository.owner,
|
||||
repo: repository.repo
|
||||
});
|
||||
logger.debug("Languages API response: " + JSON.stringify(response));
|
||||
// The GitHub API is going to return languages in order of popularity,
|
||||
// When we pick a language to autobuild we want to pick the most popular traced language
|
||||
// Since sets in javascript maintain insertion order, using a set here and then splatting it
|
||||
// into an array gives us an array of languages ordered by popularity
|
||||
let languages = new Set();
|
||||
for (let lang of Object.keys(response.data)) {
|
||||
let parsedLang = languages_1.parseLanguage(lang);
|
||||
if (parsedLang !== undefined) {
|
||||
languages.add(parsedLang);
|
||||
}
|
||||
return [...languages];
|
||||
}
|
||||
else {
|
||||
return [];
|
||||
}
|
||||
return [...languages];
|
||||
}
|
||||
/**
|
||||
* Get the languages to analyse.
|
||||
|
|
@ -329,17 +322,17 @@ async function getLanguagesInRepo() {
|
|||
* If no languages could be detected from either the workflow or the repository
|
||||
* then throw an error.
|
||||
*/
|
||||
async function getLanguages() {
|
||||
async function getLanguages(languagesInput, repository, githubAuth, githubUrl, logger) {
|
||||
// Obtain from action input 'languages' if set
|
||||
let languages = core.getInput('languages', { required: false })
|
||||
let languages = (languagesInput || "")
|
||||
.split(',')
|
||||
.map(x => x.trim())
|
||||
.filter(x => x.length > 0);
|
||||
core.info("Languages from configuration: " + JSON.stringify(languages));
|
||||
logger.info("Languages from configuration: " + JSON.stringify(languages));
|
||||
if (languages.length === 0) {
|
||||
// Obtain languages as all languages in the repo that can be analysed
|
||||
languages = await getLanguagesInRepo();
|
||||
core.info("Automatically detected languages: " + JSON.stringify(languages));
|
||||
languages = await getLanguagesInRepo(repository, githubAuth, githubUrl, logger);
|
||||
logger.info("Automatically detected languages: " + JSON.stringify(languages));
|
||||
}
|
||||
// If the languages parameter was not given and no languages were
|
||||
// detected then fail here as this is a workflow configuration error.
|
||||
|
|
@ -363,13 +356,25 @@ async function getLanguages() {
|
|||
}
|
||||
return parsedLanguages;
|
||||
}
|
||||
/**
|
||||
* Returns true if queries were provided in the workflow file
|
||||
* (and thus added), otherwise false
|
||||
*/
|
||||
async function addQueriesFromWorkflow(codeQL, queriesInput, languages, resultMap, tempDir, checkoutPath, githubUrl, logger) {
|
||||
for (const query of queriesInput.split(',')) {
|
||||
await parseQueryUses(languages, codeQL, resultMap, query, tempDir, checkoutPath, githubUrl, logger);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get the default config for when the user has not supplied one.
|
||||
*/
|
||||
async function getDefaultConfig(tempDir, toolCacheDir, codeQL) {
|
||||
const languages = await getLanguages();
|
||||
async function getDefaultConfig(languagesInput, queriesInput, repository, tempDir, toolCacheDir, codeQL, checkoutPath, githubAuth, githubUrl, logger) {
|
||||
const languages = await getLanguages(languagesInput, repository, githubAuth, githubUrl, logger);
|
||||
const queries = {};
|
||||
await addDefaultQueries(codeQL, languages, queries);
|
||||
if (queriesInput) {
|
||||
await addQueriesFromWorkflow(codeQL, queriesInput, languages, queries, tempDir, checkoutPath, githubUrl, logger);
|
||||
}
|
||||
return {
|
||||
languages: languages,
|
||||
queries: queries,
|
||||
|
|
@ -385,16 +390,15 @@ exports.getDefaultConfig = getDefaultConfig;
|
|||
/**
|
||||
* Load the config from the given file.
|
||||
*/
|
||||
async function loadConfig(configFile, tempDir, toolCacheDir, codeQL) {
|
||||
async function loadConfig(languagesInput, queriesInput, configFile, repository, tempDir, toolCacheDir, codeQL, checkoutPath, githubAuth, githubUrl, logger) {
|
||||
let parsedYAML;
|
||||
if (isLocal(configFile)) {
|
||||
// Treat the config file as relative to the workspace
|
||||
const workspacePath = util.getRequiredEnvParam('GITHUB_WORKSPACE');
|
||||
configFile = path.resolve(workspacePath, configFile);
|
||||
parsedYAML = getLocalConfig(configFile, workspacePath);
|
||||
configFile = path.resolve(checkoutPath, configFile);
|
||||
parsedYAML = getLocalConfig(configFile, checkoutPath);
|
||||
}
|
||||
else {
|
||||
parsedYAML = await getRemoteConfig(configFile);
|
||||
parsedYAML = await getRemoteConfig(configFile, githubAuth, githubUrl);
|
||||
}
|
||||
// Validate that the 'name' property is syntactically correct,
|
||||
// even though we don't use the value yet.
|
||||
|
|
@ -406,7 +410,7 @@ async function loadConfig(configFile, tempDir, toolCacheDir, codeQL) {
|
|||
throw new Error(getNameInvalid(configFile));
|
||||
}
|
||||
}
|
||||
const languages = await getLanguages();
|
||||
const languages = await getLanguages(languagesInput, repository, githubAuth, githubUrl, logger);
|
||||
const queries = {};
|
||||
const pathsIgnore = [];
|
||||
const paths = [];
|
||||
|
|
@ -420,7 +424,12 @@ async function loadConfig(configFile, tempDir, toolCacheDir, codeQL) {
|
|||
if (!disableDefaultQueries) {
|
||||
await addDefaultQueries(codeQL, languages, queries);
|
||||
}
|
||||
if (QUERIES_PROPERTY in parsedYAML) {
|
||||
// If queries were provided using `with` in the action configuration,
|
||||
// they should take precedence over the queries in the config file
|
||||
if (queriesInput) {
|
||||
await addQueriesFromWorkflow(codeQL, queriesInput, languages, queries, tempDir, checkoutPath, githubUrl, logger);
|
||||
}
|
||||
else if (QUERIES_PROPERTY in parsedYAML) {
|
||||
if (!(parsedYAML[QUERIES_PROPERTY] instanceof Array)) {
|
||||
throw new Error(getQueriesInvalid(configFile));
|
||||
}
|
||||
|
|
@ -428,7 +437,7 @@ async function loadConfig(configFile, tempDir, toolCacheDir, codeQL) {
|
|||
if (!(QUERIES_USES_PROPERTY in query) || typeof query[QUERIES_USES_PROPERTY] !== "string") {
|
||||
throw new Error(getQueryUsesInvalid(configFile));
|
||||
}
|
||||
await parseQueryUses(configFile, languages, codeQL, queries, query[QUERIES_USES_PROPERTY], tempDir);
|
||||
await parseQueryUses(languages, codeQL, queries, query[QUERIES_USES_PROPERTY], tempDir, checkoutPath, githubUrl, logger, configFile);
|
||||
}
|
||||
}
|
||||
if (PATHS_IGNORE_PROPERTY in parsedYAML) {
|
||||
|
|
@ -439,7 +448,7 @@ async function loadConfig(configFile, tempDir, toolCacheDir, codeQL) {
|
|||
if (typeof path !== "string" || path === '') {
|
||||
throw new Error(getPathsIgnoreInvalid(configFile));
|
||||
}
|
||||
pathsIgnore.push(validateAndSanitisePath(path, PATHS_IGNORE_PROPERTY, configFile));
|
||||
pathsIgnore.push(validateAndSanitisePath(path, PATHS_IGNORE_PROPERTY, configFile, logger));
|
||||
});
|
||||
}
|
||||
if (PATHS_PROPERTY in parsedYAML) {
|
||||
|
|
@ -450,7 +459,7 @@ async function loadConfig(configFile, tempDir, toolCacheDir, codeQL) {
|
|||
if (typeof path !== "string" || path === '') {
|
||||
throw new Error(getPathsInvalid(configFile));
|
||||
}
|
||||
paths.push(validateAndSanitisePath(path, PATHS_PROPERTY, configFile));
|
||||
paths.push(validateAndSanitisePath(path, PATHS_PROPERTY, configFile, logger));
|
||||
});
|
||||
}
|
||||
// The list of queries should not be empty for any language. If it is then
|
||||
|
|
@ -478,19 +487,18 @@ async function loadConfig(configFile, tempDir, toolCacheDir, codeQL) {
|
|||
* This will parse the config from the user input if present, or generate
|
||||
* a default config. The parsed config is then stored to a known location.
|
||||
*/
|
||||
async function initConfig(tempDir, toolCacheDir, codeQL) {
|
||||
const configFile = core.getInput('config-file');
|
||||
async function initConfig(languagesInput, queriesInput, configFile, repository, tempDir, toolCacheDir, codeQL, checkoutPath, githubAuth, githubUrl, logger) {
|
||||
let config;
|
||||
// If no config file was provided create an empty one
|
||||
if (configFile === '') {
|
||||
core.debug('No configuration file was provided');
|
||||
config = await getDefaultConfig(tempDir, toolCacheDir, codeQL);
|
||||
if (!configFile) {
|
||||
logger.debug('No configuration file was provided');
|
||||
config = await getDefaultConfig(languagesInput, queriesInput, repository, tempDir, toolCacheDir, codeQL, checkoutPath, githubAuth, githubUrl, logger);
|
||||
}
|
||||
else {
|
||||
config = await loadConfig(configFile, tempDir, toolCacheDir, codeQL);
|
||||
config = await loadConfig(languagesInput, queriesInput, configFile, repository, tempDir, toolCacheDir, codeQL, checkoutPath, githubAuth, githubUrl, logger);
|
||||
}
|
||||
// Save the config so we can easily access it again in the future
|
||||
await saveConfig(config);
|
||||
await saveConfig(config, logger);
|
||||
return config;
|
||||
}
|
||||
exports.initConfig = initConfig;
|
||||
|
|
@ -501,9 +509,9 @@ function isLocal(configPath) {
|
|||
}
|
||||
return (configPath.indexOf("@") === -1);
|
||||
}
|
||||
function getLocalConfig(configFile, workspacePath) {
|
||||
function getLocalConfig(configFile, checkoutPath) {
|
||||
// Error if the config file is now outside of the workspace
|
||||
if (!(configFile + path.sep).startsWith(workspacePath + path.sep)) {
|
||||
if (!(configFile + path.sep).startsWith(checkoutPath + path.sep)) {
|
||||
throw new Error(getConfigFileOutsideWorkspaceErrorMessage(configFile));
|
||||
}
|
||||
// Error if the file does not exist
|
||||
|
|
@ -512,7 +520,7 @@ function getLocalConfig(configFile, workspacePath) {
|
|||
}
|
||||
return yaml.safeLoad(fs.readFileSync(configFile, 'utf8'));
|
||||
}
|
||||
async function getRemoteConfig(configFile) {
|
||||
async function getRemoteConfig(configFile, githubAuth, githubUrl) {
|
||||
// retrieve the various parts of the config location, and ensure they're present
|
||||
const format = new RegExp('(?<owner>[^/]+)/(?<repo>[^/]+)/(?<path>[^@]+)@(?<ref>.*)');
|
||||
const pieces = format.exec(configFile);
|
||||
|
|
@ -520,7 +528,7 @@ async function getRemoteConfig(configFile) {
|
|||
if (pieces === null || pieces.groups === undefined || pieces.length < 5) {
|
||||
throw new Error(getConfigFileRepoFormatInvalidMessage(configFile));
|
||||
}
|
||||
const response = await api.getActionsApiClient(true).repos.getContents({
|
||||
const response = await api.getApiClient(githubAuth, githubUrl, true).repos.getContents({
|
||||
owner: pieces.groups.owner,
|
||||
repo: pieces.groups.repo,
|
||||
path: pieces.groups.path,
|
||||
|
|
@ -548,30 +556,26 @@ exports.getPathToParsedConfigFile = getPathToParsedConfigFile;
|
|||
/**
|
||||
* Store the given config to the path returned from getPathToParsedConfigFile.
|
||||
*/
|
||||
async function saveConfig(config) {
|
||||
async function saveConfig(config, logger) {
|
||||
const configString = JSON.stringify(config);
|
||||
const configFile = getPathToParsedConfigFile(config.tempDir);
|
||||
fs.mkdirSync(path.dirname(configFile), { recursive: true });
|
||||
fs.writeFileSync(configFile, configString, 'utf8');
|
||||
core.debug('Saved config:');
|
||||
core.debug(configString);
|
||||
logger.debug('Saved config:');
|
||||
logger.debug(configString);
|
||||
}
|
||||
/**
|
||||
* Get the config.
|
||||
*
|
||||
* If this is the first time in a workflow that this is being called then
|
||||
* this will parse the config from the user input. The parsed config is then
|
||||
* stored to a known location. On the second and further calls, this will
|
||||
* return the contents of the parsed config from the known location.
|
||||
* Get the config that has been saved to the given temp dir.
|
||||
* If the config could not be found then returns undefined.
|
||||
*/
|
||||
async function getConfig(tempDir) {
|
||||
async function getConfig(tempDir, logger) {
|
||||
const configFile = getPathToParsedConfigFile(tempDir);
|
||||
if (!fs.existsSync(configFile)) {
|
||||
throw new Error("Config file could not be found at expected location. Has the 'init' action been called?");
|
||||
return undefined;
|
||||
}
|
||||
const configString = fs.readFileSync(configFile, 'utf8');
|
||||
core.debug('Loaded config:');
|
||||
core.debug(configString);
|
||||
logger.debug('Loaded config:');
|
||||
logger.debug(configString);
|
||||
return JSON.parse(configString);
|
||||
}
|
||||
exports.getConfig = getConfig;
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
275
lib/config-utils.test.js
generated
275
lib/config-utils.test.js
generated
|
|
@ -19,20 +19,10 @@ const api = __importStar(require("./api-client"));
|
|||
const codeql_1 = require("./codeql");
|
||||
const configUtils = __importStar(require("./config-utils"));
|
||||
const languages_1 = require("./languages");
|
||||
const logging_1 = require("./logging");
|
||||
const testing_utils_1 = require("./testing-utils");
|
||||
const util = __importStar(require("./util"));
|
||||
testing_utils_1.setupTests(ava_1.default);
|
||||
function setInput(name, value) {
|
||||
// Transformation copied from
|
||||
// https://github.com/actions/toolkit/blob/05e39f551d33e1688f61b209ab5cdd335198f1b8/packages/core/src/core.ts#L69
|
||||
const envVar = `INPUT_${name.replace(/ /g, '_').toUpperCase()}`;
|
||||
if (value !== undefined) {
|
||||
process.env[envVar] = value;
|
||||
}
|
||||
else {
|
||||
delete process.env[envVar];
|
||||
}
|
||||
}
|
||||
function mockGetContents(content) {
|
||||
// Passing an auth token is required, so we just use a dummy value
|
||||
let client = new github.GitHub('123');
|
||||
|
|
@ -57,10 +47,8 @@ function mockListLanguages(languages) {
|
|||
}
|
||||
ava_1.default("load empty config", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
process.env['RUNNER_TEMP'] = tmpDir;
|
||||
process.env['GITHUB_WORKSPACE'] = tmpDir;
|
||||
setInput('config-file', undefined);
|
||||
setInput('languages', 'javascript,python');
|
||||
const logger = logging_1.getRunnerLogger(true);
|
||||
const languages = 'javascript,python';
|
||||
const codeQL = codeql_1.setCodeQL({
|
||||
resolveQueries: async function () {
|
||||
return {
|
||||
|
|
@ -70,16 +58,13 @@ ava_1.default("load empty config", async (t) => {
|
|||
};
|
||||
},
|
||||
});
|
||||
const config = await configUtils.initConfig(tmpDir, tmpDir, codeQL);
|
||||
t.deepEqual(config, await configUtils.getDefaultConfig(tmpDir, tmpDir, codeQL));
|
||||
const config = await configUtils.initConfig(languages, undefined, undefined, { owner: 'github', repo: 'example ' }, tmpDir, tmpDir, codeQL, tmpDir, 'token', 'https://github.example.com', logger);
|
||||
t.deepEqual(config, await configUtils.getDefaultConfig(languages, undefined, { owner: 'github', repo: 'example ' }, tmpDir, tmpDir, codeQL, tmpDir, 'token', 'https://github.example.com', logger));
|
||||
});
|
||||
});
|
||||
ava_1.default("loading config saves config", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
process.env['RUNNER_TEMP'] = tmpDir;
|
||||
process.env['GITHUB_WORKSPACE'] = tmpDir;
|
||||
setInput('config-file', undefined);
|
||||
setInput('languages', 'javascript,python');
|
||||
const logger = logging_1.getRunnerLogger(true);
|
||||
const codeQL = codeql_1.setCodeQL({
|
||||
resolveQueries: async function () {
|
||||
return {
|
||||
|
|
@ -91,23 +76,20 @@ ava_1.default("loading config saves config", async (t) => {
|
|||
});
|
||||
// Sanity check the saved config file does not already exist
|
||||
t.false(fs.existsSync(configUtils.getPathToParsedConfigFile(tmpDir)));
|
||||
// Sanity check that getConfig throws before we have called initConfig
|
||||
await t.throwsAsync(() => configUtils.getConfig(tmpDir));
|
||||
const config1 = await configUtils.initConfig(tmpDir, tmpDir, codeQL);
|
||||
// Sanity check that getConfig returns undefined before we have called initConfig
|
||||
t.deepEqual(await configUtils.getConfig(tmpDir, logger), undefined);
|
||||
const config1 = await configUtils.initConfig('javascript,python', undefined, undefined, { owner: 'github', repo: 'example ' }, tmpDir, tmpDir, codeQL, tmpDir, 'token', 'https://github.example.com', logger);
|
||||
// The saved config file should now exist
|
||||
t.true(fs.existsSync(configUtils.getPathToParsedConfigFile(tmpDir)));
|
||||
// And that same newly-initialised config should now be returned by getConfig
|
||||
const config2 = await configUtils.getConfig(tmpDir);
|
||||
const config2 = await configUtils.getConfig(tmpDir, logger);
|
||||
t.deepEqual(config1, config2);
|
||||
});
|
||||
});
|
||||
ava_1.default("load input outside of workspace", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
process.env['RUNNER_TEMP'] = tmpDir;
|
||||
process.env['GITHUB_WORKSPACE'] = tmpDir;
|
||||
setInput('config-file', '../input');
|
||||
try {
|
||||
await configUtils.initConfig(tmpDir, tmpDir, codeql_1.getCachedCodeQL());
|
||||
await configUtils.initConfig(undefined, undefined, '../input', { owner: 'github', repo: 'example ' }, tmpDir, tmpDir, codeql_1.getCachedCodeQL(), tmpDir, 'token', 'https://github.example.com', logging_1.getRunnerLogger(true));
|
||||
throw new Error('initConfig did not throw error');
|
||||
}
|
||||
catch (err) {
|
||||
|
|
@ -117,12 +99,10 @@ ava_1.default("load input outside of workspace", async (t) => {
|
|||
});
|
||||
ava_1.default("load non-local input with invalid repo syntax", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
process.env['RUNNER_TEMP'] = tmpDir;
|
||||
process.env['GITHUB_WORKSPACE'] = tmpDir;
|
||||
// no filename given, just a repo
|
||||
setInput('config-file', 'octo-org/codeql-config@main');
|
||||
const configFile = 'octo-org/codeql-config@main';
|
||||
try {
|
||||
await configUtils.initConfig(tmpDir, tmpDir, codeql_1.getCachedCodeQL());
|
||||
await configUtils.initConfig(undefined, undefined, configFile, { owner: 'github', repo: 'example ' }, tmpDir, tmpDir, codeql_1.getCachedCodeQL(), tmpDir, 'token', 'https://github.example.com', logging_1.getRunnerLogger(true));
|
||||
throw new Error('initConfig did not throw error');
|
||||
}
|
||||
catch (err) {
|
||||
|
|
@ -132,13 +112,11 @@ ava_1.default("load non-local input with invalid repo syntax", async (t) => {
|
|||
});
|
||||
ava_1.default("load non-existent input", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
process.env['RUNNER_TEMP'] = tmpDir;
|
||||
process.env['GITHUB_WORKSPACE'] = tmpDir;
|
||||
t.false(fs.existsSync(path.join(tmpDir, 'input')));
|
||||
setInput('config-file', 'input');
|
||||
setInput('languages', 'javascript');
|
||||
const languages = 'javascript';
|
||||
const configFile = 'input';
|
||||
t.false(fs.existsSync(path.join(tmpDir, configFile)));
|
||||
try {
|
||||
await configUtils.initConfig(tmpDir, tmpDir, codeql_1.getCachedCodeQL());
|
||||
await configUtils.initConfig(languages, undefined, configFile, { owner: 'github', repo: 'example ' }, tmpDir, tmpDir, codeql_1.getCachedCodeQL(), tmpDir, 'token', 'https://github.example.com', logging_1.getRunnerLogger(true));
|
||||
throw new Error('initConfig did not throw error');
|
||||
}
|
||||
catch (err) {
|
||||
|
|
@ -148,8 +126,6 @@ ava_1.default("load non-existent input", async (t) => {
|
|||
});
|
||||
ava_1.default("load non-empty input", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
process.env['RUNNER_TEMP'] = tmpDir;
|
||||
process.env['GITHUB_WORKSPACE'] = tmpDir;
|
||||
const codeQL = codeql_1.setCodeQL({
|
||||
resolveQueries: async function () {
|
||||
return {
|
||||
|
|
@ -193,18 +169,16 @@ ava_1.default("load non-empty input", async (t) => {
|
|||
toolCacheDir: tmpDir,
|
||||
codeQLCmd: codeQL.getPath(),
|
||||
};
|
||||
fs.writeFileSync(path.join(tmpDir, 'input'), inputFileContents, 'utf8');
|
||||
setInput('config-file', 'input');
|
||||
setInput('languages', 'javascript');
|
||||
const actualConfig = await configUtils.initConfig(tmpDir, tmpDir, codeQL);
|
||||
const languages = 'javascript';
|
||||
const configFile = 'input';
|
||||
fs.writeFileSync(path.join(tmpDir, configFile), inputFileContents, 'utf8');
|
||||
const actualConfig = await configUtils.initConfig(languages, undefined, configFile, { owner: 'github', repo: 'example ' }, tmpDir, tmpDir, codeQL, tmpDir, 'token', 'https://github.example.com', logging_1.getRunnerLogger(true));
|
||||
// Should exactly equal the object we constructed earlier
|
||||
t.deepEqual(actualConfig, expectedConfig);
|
||||
});
|
||||
});
|
||||
ava_1.default("default queries are used", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
process.env['RUNNER_TEMP'] = tmpDir;
|
||||
process.env['GITHUB_WORKSPACE'] = tmpDir;
|
||||
// Check that the default behaviour is to add the default queries.
|
||||
// In this case if a config file is specified but does not include
|
||||
// the disable-default-queries field.
|
||||
|
|
@ -232,20 +206,169 @@ ava_1.default("default queries are used", async (t) => {
|
|||
paths:
|
||||
- foo`;
|
||||
fs.mkdirSync(path.join(tmpDir, 'foo'));
|
||||
fs.writeFileSync(path.join(tmpDir, 'input'), inputFileContents, 'utf8');
|
||||
setInput('config-file', 'input');
|
||||
setInput('languages', 'javascript');
|
||||
await configUtils.initConfig(tmpDir, tmpDir, codeQL);
|
||||
const languages = 'javascript';
|
||||
const configFile = 'input';
|
||||
fs.writeFileSync(path.join(tmpDir, configFile), inputFileContents, 'utf8');
|
||||
await configUtils.initConfig(languages, undefined, configFile, { owner: 'github', repo: 'example ' }, tmpDir, tmpDir, codeQL, tmpDir, 'token', 'https://github.example.com', logging_1.getRunnerLogger(true));
|
||||
// Check resolve queries was called correctly
|
||||
t.deepEqual(resolveQueriesArgs.length, 1);
|
||||
t.deepEqual(resolveQueriesArgs[0].queries, ['javascript-code-scanning.qls']);
|
||||
t.deepEqual(resolveQueriesArgs[0].extraSearchPath, undefined);
|
||||
});
|
||||
});
|
||||
ava_1.default("Queries can be specified in config file", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
const inputFileContents = `
|
||||
name: my config
|
||||
queries:
|
||||
- uses: ./foo`;
|
||||
const configFile = path.join(tmpDir, 'input');
|
||||
fs.writeFileSync(configFile, inputFileContents, 'utf8');
|
||||
fs.mkdirSync(path.join(tmpDir, 'foo'));
|
||||
const resolveQueriesArgs = [];
|
||||
const codeQL = codeql_1.setCodeQL({
|
||||
resolveQueries: async function (queries, extraSearchPath) {
|
||||
resolveQueriesArgs.push({ queries, extraSearchPath });
|
||||
// Return what we're given, just in the right format for a resolved query
|
||||
// This way we can test by seeing which returned items are in the final
|
||||
// configuration.
|
||||
const dummyResolvedQueries = {};
|
||||
queries.forEach(q => { dummyResolvedQueries[q] = {}; });
|
||||
return {
|
||||
byLanguage: {
|
||||
'javascript': dummyResolvedQueries,
|
||||
},
|
||||
noDeclaredLanguage: {},
|
||||
multipleDeclaredLanguages: {},
|
||||
};
|
||||
},
|
||||
});
|
||||
const languages = 'javascript';
|
||||
const config = await configUtils.initConfig(languages, undefined, configFile, { owner: 'github', repo: 'example ' }, tmpDir, tmpDir, codeQL, tmpDir, 'token', 'https://github.example.com', logging_1.getRunnerLogger(true));
|
||||
// Check resolveQueries was called correctly
|
||||
// It'll be called once for the default queries
|
||||
// and once for `./foo` from the config file.
|
||||
t.deepEqual(resolveQueriesArgs.length, 2);
|
||||
t.deepEqual(resolveQueriesArgs[1].queries.length, 1);
|
||||
t.regex(resolveQueriesArgs[1].queries[0], /.*\/foo$/);
|
||||
// Now check that the end result contains the default queries and the query from config
|
||||
t.deepEqual(config.queries['javascript'].length, 2);
|
||||
t.regex(config.queries['javascript'][0], /javascript-code-scanning.qls$/);
|
||||
t.regex(config.queries['javascript'][1], /.*\/foo$/);
|
||||
});
|
||||
});
|
||||
ava_1.default("Queries from config file can be overridden in workflow file", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
const inputFileContents = `
|
||||
name: my config
|
||||
queries:
|
||||
- uses: ./foo`;
|
||||
const configFile = path.join(tmpDir, 'input');
|
||||
fs.writeFileSync(configFile, inputFileContents, 'utf8');
|
||||
// This config item should take precedence over the config file but shouldn't affect the default queries.
|
||||
const queries = './override';
|
||||
fs.mkdirSync(path.join(tmpDir, 'foo'));
|
||||
fs.mkdirSync(path.join(tmpDir, 'override'));
|
||||
const resolveQueriesArgs = [];
|
||||
const codeQL = codeql_1.setCodeQL({
|
||||
resolveQueries: async function (queries, extraSearchPath) {
|
||||
resolveQueriesArgs.push({ queries, extraSearchPath });
|
||||
// Return what we're given, just in the right format for a resolved query
|
||||
// This way we can test overriding by seeing which returned items are in
|
||||
// the final configuration.
|
||||
const dummyResolvedQueries = {};
|
||||
queries.forEach(q => { dummyResolvedQueries[q] = {}; });
|
||||
return {
|
||||
byLanguage: {
|
||||
'javascript': dummyResolvedQueries,
|
||||
},
|
||||
noDeclaredLanguage: {},
|
||||
multipleDeclaredLanguages: {},
|
||||
};
|
||||
},
|
||||
});
|
||||
const languages = 'javascript';
|
||||
const config = await configUtils.initConfig(languages, queries, configFile, { owner: 'github', repo: 'example ' }, tmpDir, tmpDir, codeQL, tmpDir, 'token', 'https://github.example.com', logging_1.getRunnerLogger(true));
|
||||
// Check resolveQueries was called correctly
|
||||
// It'll be called once for the default queries and once for `./override`,
|
||||
// but won't be called for './foo' from the config file.
|
||||
t.deepEqual(resolveQueriesArgs.length, 2);
|
||||
t.deepEqual(resolveQueriesArgs[1].queries.length, 1);
|
||||
t.regex(resolveQueriesArgs[1].queries[0], /.*\/override$/);
|
||||
// Now check that the end result contains only the default queries and the override query
|
||||
t.deepEqual(config.queries['javascript'].length, 2);
|
||||
t.regex(config.queries['javascript'][0], /javascript-code-scanning.qls$/);
|
||||
t.regex(config.queries['javascript'][1], /.*\/override$/);
|
||||
});
|
||||
});
|
||||
ava_1.default("Multiple queries can be specified in workflow file, no config file required", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
fs.mkdirSync(path.join(tmpDir, 'override1'));
|
||||
fs.mkdirSync(path.join(tmpDir, 'override2'));
|
||||
const queries = './override1,./override2';
|
||||
const resolveQueriesArgs = [];
|
||||
const codeQL = codeql_1.setCodeQL({
|
||||
resolveQueries: async function (queries, extraSearchPath) {
|
||||
resolveQueriesArgs.push({ queries, extraSearchPath });
|
||||
// Return what we're given, just in the right format for a resolved query
|
||||
// This way we can test overriding by seeing which returned items are in
|
||||
// the final configuration.
|
||||
const dummyResolvedQueries = {};
|
||||
queries.forEach(q => { dummyResolvedQueries[q] = {}; });
|
||||
return {
|
||||
byLanguage: {
|
||||
'javascript': dummyResolvedQueries,
|
||||
},
|
||||
noDeclaredLanguage: {},
|
||||
multipleDeclaredLanguages: {},
|
||||
};
|
||||
},
|
||||
});
|
||||
const languages = 'javascript';
|
||||
const config = await configUtils.initConfig(languages, queries, undefined, { owner: 'github', repo: 'example ' }, tmpDir, tmpDir, codeQL, tmpDir, 'token', 'https://github.example.com', logging_1.getRunnerLogger(true));
|
||||
// Check resolveQueries was called correctly:
|
||||
// It'll be called once for the default queries,
|
||||
// and then once for each of the two queries from the workflow
|
||||
t.deepEqual(resolveQueriesArgs.length, 3);
|
||||
t.deepEqual(resolveQueriesArgs[1].queries.length, 1);
|
||||
t.deepEqual(resolveQueriesArgs[2].queries.length, 1);
|
||||
t.regex(resolveQueriesArgs[1].queries[0], /.*\/override1$/);
|
||||
t.regex(resolveQueriesArgs[2].queries[0], /.*\/override2$/);
|
||||
// Now check that the end result contains both the queries from the workflow, as well as the defaults
|
||||
t.deepEqual(config.queries['javascript'].length, 3);
|
||||
t.regex(config.queries['javascript'][0], /javascript-code-scanning.qls$/);
|
||||
t.regex(config.queries['javascript'][1], /.*\/override1$/);
|
||||
t.regex(config.queries['javascript'][2], /.*\/override2$/);
|
||||
});
|
||||
});
|
||||
ava_1.default("Invalid queries in workflow file handled correctly", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
const queries = 'foo/bar@v1@v3';
|
||||
const languages = 'javascript';
|
||||
// This function just needs to be type-correct; it doesn't need to do anything,
|
||||
// since we're deliberately passing in invalid data
|
||||
const codeQL = codeql_1.setCodeQL({
|
||||
resolveQueries: async function (_queries, _extraSearchPath) {
|
||||
return {
|
||||
byLanguage: {
|
||||
'javascript': {},
|
||||
},
|
||||
noDeclaredLanguage: {},
|
||||
multipleDeclaredLanguages: {},
|
||||
};
|
||||
},
|
||||
});
|
||||
try {
|
||||
await configUtils.initConfig(languages, queries, undefined, { owner: 'github', repo: 'example ' }, tmpDir, tmpDir, codeQL, tmpDir, 'token', 'https://github.example.com', logging_1.getRunnerLogger(true));
|
||||
t.fail('initConfig did not throw error');
|
||||
}
|
||||
catch (err) {
|
||||
t.deepEqual(err, new Error(configUtils.getQueryUsesInvalid(undefined, "foo/bar@v1@v3")));
|
||||
}
|
||||
});
|
||||
});
|
||||
ava_1.default("API client used when reading remote config", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
process.env['RUNNER_TEMP'] = tmpDir;
|
||||
process.env['GITHUB_WORKSPACE'] = tmpDir;
|
||||
const codeQL = codeql_1.setCodeQL({
|
||||
resolveQueries: async function () {
|
||||
return {
|
||||
|
|
@ -276,23 +399,20 @@ ava_1.default("API client used when reading remote config", async (t) => {
|
|||
};
|
||||
const spyGetContents = mockGetContents(dummyResponse);
|
||||
// Create checkout directory for remote queries repository
|
||||
fs.mkdirSync(path.join(tmpDir, 'foo/bar'), { recursive: true });
|
||||
setInput('config-file', 'octo-org/codeql-config/config.yaml@main');
|
||||
setInput('languages', 'javascript');
|
||||
await configUtils.initConfig(tmpDir, tmpDir, codeQL);
|
||||
fs.mkdirSync(path.join(tmpDir, 'foo/bar/dev'), { recursive: true });
|
||||
const configFile = 'octo-org/codeql-config/config.yaml@main';
|
||||
const languages = 'javascript';
|
||||
await configUtils.initConfig(languages, undefined, configFile, { owner: 'github', repo: 'example ' }, tmpDir, tmpDir, codeQL, tmpDir, 'token', 'https://github.example.com', logging_1.getRunnerLogger(true));
|
||||
t.assert(spyGetContents.called);
|
||||
});
|
||||
});
|
||||
ava_1.default("Remote config handles the case where a directory is provided", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
process.env['RUNNER_TEMP'] = tmpDir;
|
||||
process.env['GITHUB_WORKSPACE'] = tmpDir;
|
||||
const dummyResponse = []; // directories are returned as arrays
|
||||
mockGetContents(dummyResponse);
|
||||
const repoReference = 'octo-org/codeql-config/config.yaml@main';
|
||||
setInput('config-file', repoReference);
|
||||
try {
|
||||
await configUtils.initConfig(tmpDir, tmpDir, codeql_1.getCachedCodeQL());
|
||||
await configUtils.initConfig(undefined, undefined, repoReference, { owner: 'github', repo: 'example ' }, tmpDir, tmpDir, codeql_1.getCachedCodeQL(), tmpDir, 'token', 'https://github.example.com', logging_1.getRunnerLogger(true));
|
||||
throw new Error('initConfig did not throw error');
|
||||
}
|
||||
catch (err) {
|
||||
|
|
@ -302,16 +422,13 @@ ava_1.default("Remote config handles the case where a directory is provided", as
|
|||
});
|
||||
ava_1.default("Invalid format of remote config handled correctly", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
process.env['RUNNER_TEMP'] = tmpDir;
|
||||
process.env['GITHUB_WORKSPACE'] = tmpDir;
|
||||
const dummyResponse = {
|
||||
// note no "content" property here
|
||||
};
|
||||
mockGetContents(dummyResponse);
|
||||
const repoReference = 'octo-org/codeql-config/config.yaml@main';
|
||||
setInput('config-file', repoReference);
|
||||
try {
|
||||
await configUtils.initConfig(tmpDir, tmpDir, codeql_1.getCachedCodeQL());
|
||||
await configUtils.initConfig(undefined, undefined, repoReference, { owner: 'github', repo: 'example ' }, tmpDir, tmpDir, codeql_1.getCachedCodeQL(), tmpDir, 'token', 'https://github.example.com', logging_1.getRunnerLogger(true));
|
||||
throw new Error('initConfig did not throw error');
|
||||
}
|
||||
catch (err) {
|
||||
|
|
@ -321,11 +438,9 @@ ava_1.default("Invalid format of remote config handled correctly", async (t) =>
|
|||
});
|
||||
ava_1.default("No detected languages", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
process.env['RUNNER_TEMP'] = tmpDir;
|
||||
process.env['GITHUB_WORKSPACE'] = tmpDir;
|
||||
mockListLanguages([]);
|
||||
try {
|
||||
await configUtils.initConfig(tmpDir, tmpDir, codeql_1.getCachedCodeQL());
|
||||
await configUtils.initConfig(undefined, undefined, undefined, { owner: 'github', repo: 'example ' }, tmpDir, tmpDir, codeql_1.getCachedCodeQL(), tmpDir, 'token', 'https://github.example.com', logging_1.getRunnerLogger(true));
|
||||
throw new Error('initConfig did not throw error');
|
||||
}
|
||||
catch (err) {
|
||||
|
|
@ -335,11 +450,9 @@ ava_1.default("No detected languages", async (t) => {
|
|||
});
|
||||
ava_1.default("Unknown languages", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
process.env['RUNNER_TEMP'] = tmpDir;
|
||||
process.env['GITHUB_WORKSPACE'] = tmpDir;
|
||||
setInput('languages', 'ruby,english');
|
||||
const languages = 'ruby,english';
|
||||
try {
|
||||
await configUtils.initConfig(tmpDir, tmpDir, codeql_1.getCachedCodeQL());
|
||||
await configUtils.initConfig(languages, undefined, undefined, { owner: 'github', repo: 'example ' }, tmpDir, tmpDir, codeql_1.getCachedCodeQL(), tmpDir, 'token', 'https://github.example.com', logging_1.getRunnerLogger(true));
|
||||
throw new Error('initConfig did not throw error');
|
||||
}
|
||||
catch (err) {
|
||||
|
|
@ -350,8 +463,6 @@ ava_1.default("Unknown languages", async (t) => {
|
|||
function doInvalidInputTest(testName, inputFileContents, expectedErrorMessageGenerator) {
|
||||
ava_1.default("load invalid input - " + testName, async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
process.env['RUNNER_TEMP'] = tmpDir;
|
||||
process.env['GITHUB_WORKSPACE'] = tmpDir;
|
||||
const codeQL = codeql_1.setCodeQL({
|
||||
resolveQueries: async function () {
|
||||
return {
|
||||
|
|
@ -361,12 +472,12 @@ function doInvalidInputTest(testName, inputFileContents, expectedErrorMessageGen
|
|||
};
|
||||
},
|
||||
});
|
||||
const inputFile = path.join(tmpDir, 'input');
|
||||
const languages = 'javascript';
|
||||
const configFile = 'input';
|
||||
const inputFile = path.join(tmpDir, configFile);
|
||||
fs.writeFileSync(inputFile, inputFileContents, 'utf8');
|
||||
setInput('config-file', 'input');
|
||||
setInput('languages', 'javascript');
|
||||
try {
|
||||
await configUtils.initConfig(tmpDir, tmpDir, codeQL);
|
||||
await configUtils.initConfig(languages, undefined, configFile, { owner: 'github', repo: 'example ' }, tmpDir, tmpDir, codeQL, tmpDir, 'token', 'https://github.example.com', logging_1.getRunnerLogger(true));
|
||||
throw new Error('initConfig did not throw error');
|
||||
}
|
||||
catch (err) {
|
||||
|
|
@ -426,10 +537,10 @@ ava_1.default('path validations', t => {
|
|||
const propertyName = 'paths';
|
||||
const configFile = './.github/codeql/config.yml';
|
||||
for (const path of validPaths) {
|
||||
t.truthy(configUtils.validateAndSanitisePath(path, propertyName, configFile));
|
||||
t.truthy(configUtils.validateAndSanitisePath(path, propertyName, configFile, logging_1.getRunnerLogger(true)));
|
||||
}
|
||||
for (const path of invalidPaths) {
|
||||
t.throws(() => configUtils.validateAndSanitisePath(path, propertyName, configFile));
|
||||
t.throws(() => configUtils.validateAndSanitisePath(path, propertyName, configFile, logging_1.getRunnerLogger(true)));
|
||||
}
|
||||
});
|
||||
ava_1.default('path sanitisation', t => {
|
||||
|
|
@ -437,8 +548,8 @@ ava_1.default('path sanitisation', t => {
|
|||
const propertyName = 'paths';
|
||||
const configFile = './.github/codeql/config.yml';
|
||||
// Valid paths are not modified
|
||||
t.deepEqual(configUtils.validateAndSanitisePath('foo/bar', propertyName, configFile), 'foo/bar');
|
||||
t.deepEqual(configUtils.validateAndSanitisePath('foo/bar', propertyName, configFile, logging_1.getRunnerLogger(true)), 'foo/bar');
|
||||
// Trailing stars are stripped
|
||||
t.deepEqual(configUtils.validateAndSanitisePath('foo/**', propertyName, configFile), 'foo/');
|
||||
t.deepEqual(configUtils.validateAndSanitisePath('foo/**', propertyName, configFile, logging_1.getRunnerLogger(true)), 'foo/');
|
||||
});
|
||||
//# sourceMappingURL=config-utils.test.js.map
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -1,3 +1,3 @@
|
|||
{
|
||||
"bundleVersion": "codeql-bundle-20200630"
|
||||
"bundleVersion": "codeql-bundle-20200826"
|
||||
}
|
||||
|
|
|
|||
6
lib/exec-wrapper.js
generated
6
lib/exec-wrapper.js
generated
|
|
@ -7,7 +7,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const exec = __importStar(require("@actions/exec"));
|
||||
const toolrunnner = __importStar(require("@actions/exec/lib/toolrunner"));
|
||||
/**
|
||||
* Wrapper for exec.exec which checks for specific return code and/or regex matches in console output.
|
||||
* Output will be streamed to the live console as well as captured for subsequent processing.
|
||||
|
|
@ -50,11 +50,11 @@ async function execErrorCatcher(commandLine, args, matchers, options) {
|
|||
// we capture the original return code or error so that if no match is found we can duplicate the behavior
|
||||
let returnState;
|
||||
try {
|
||||
returnState = await exec.exec(commandLine, args, {
|
||||
returnState = await new toolrunnner.ToolRunner(commandLine, args, {
|
||||
...options,
|
||||
listeners: listeners,
|
||||
ignoreReturnCode: true,
|
||||
});
|
||||
}).exec();
|
||||
}
|
||||
catch (e) {
|
||||
returnState = e;
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"exec-wrapper.js","sourceRoot":"","sources":["../src/exec-wrapper.ts"],"names":[],"mappings":";;;;;;;;;AAAA,oDAAsC;AAKtC;;;;;;;;;;GAUG;AACI,KAAK,UAAU,gBAAgB,CAAC,WAAmB,EAAE,IAAe,EACpC,QAAyB,EACzB,OAAwB;;IAE7D,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,MAAM,GAAG,EAAE,CAAC;IAEhB,IAAI,SAAS,GAAG;QACd,MAAM,EAAE,CAAC,IAAY,EAAE,EAAE;;YACvB,MAAM,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC1B,IAAI,aAAA,OAAO,0CAAE,SAAS,0CAAE,MAAM,MAAK,SAAS,EAAE;gBAC5C,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;aAChC;iBAAM;gBACL,2FAA2F;gBAC3F,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;aAC5B;QAEH,CAAC;QACD,MAAM,EAAE,CAAC,IAAY,EAAE,EAAE;;YACvB,MAAM,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAC1B,IAAI,aAAA,OAAO,0CAAE,SAAS,0CAAE,MAAM,MAAK,SAAS,EAAE;gBAC5C,OAAO,CAAC,SAAS,CAAC,MAAM,CA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M,CAAC,UAAU,EAAE,KAAK,EAAE,OAAO,CAAC,IAAI,QAAQ,EAAE;YACnD,IAAI,UAAU,KAAK,WAAW,IAAI,KAAK,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAG;gBACtF,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;aAC1B;SACF;KACF;IAED,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE;QACnC,qFAAqF;QACrF,UAAI,OAAO,0CAAE,gBAAgB,EAAE;YAC7B,OAAO,WAAW,CAAC;SACpB;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,iBAAiB,WAAW,4BAA4B,WAAW,EAAE,CAAC,CAAC;SACxF;KACF;SAAM;QACL,MAAM,WAAW,CAAC;KACnB;AACH,CAAC;AAlED,4CAkEC"}
|
||||
51
lib/exec-wrapper.test.js
generated
51
lib/exec-wrapper.test.js
generated
|
|
@ -11,54 +11,55 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const exec = __importStar(require("@actions/exec"));
|
||||
const toolrunnner = __importStar(require("@actions/exec/lib/toolrunner"));
|
||||
const ava_1 = __importDefault(require("ava"));
|
||||
const exec_wrapper_1 = require("./exec-wrapper");
|
||||
const testing_utils_1 = require("./testing-utils");
|
||||
testing_utils_1.setupTests(ava_1.default);
|
||||
ava_1.default('matchers are never applied if non-error exit', async (t) => {
|
||||
const testCommand = buildDummyCommand("foo bar\\nblort qux", "foo bar\\nblort qux", '', 0);
|
||||
const testArgs = buildDummyArgs("foo bar\\nblort qux", "foo bar\\nblort qux", '', 0);
|
||||
const matchers = [[123, new RegExp("foo bar"), 'error!!!']];
|
||||
t.deepEqual(await exec.exec(testCommand), 0);
|
||||
t.deepEqual(await exec_wrapper_1.execErrorCatcher(testCommand, [], matchers), 0);
|
||||
t.deepEqual(await exec.exec('node', testArgs), 0);
|
||||
t.deepEqual(await exec_wrapper_1.execErrorCatcher('node', testArgs, matchers), 0);
|
||||
});
|
||||
ava_1.default('regex matchers are applied to stdout for non-zero exit code', async (t) => {
|
||||
const testCommand = buildDummyCommand("foo bar\\nblort qux", '', '', 1);
|
||||
const testArgs = buildDummyArgs("foo bar\\nblort qux", '', '', 1);
|
||||
const matchers = [[123, new RegExp("foo bar"), '🦄']];
|
||||
await t.throwsAsync(exec.exec(testCommand), { instanceOf: Error, message: 'The process \'node\' failed with exit code 1' });
|
||||
await t.throwsAsync(exec_wrapper_1.execErrorCatcher(testCommand, [], matchers), { instanceOf: Error, message: '🦄' });
|
||||
await t.throwsAsync(exec.exec('node', testArgs), { instanceOf: Error, message: 'The process \'node\' failed with exit code 1' });
|
||||
await t.throwsAsync(exec_wrapper_1.execErrorCatcher('node', testArgs, matchers), { instanceOf: Error, message: '🦄' });
|
||||
});
|
||||
ava_1.default('regex matchers are applied to stderr for non-zero exit code', async (t) => {
|
||||
const testCommand = buildDummyCommand("non matching string", 'foo bar\\nblort qux', '', 1);
|
||||
const testArgs = buildDummyArgs("non matching string", 'foo bar\\nblort qux', '', 1);
|
||||
const matchers = [[123, new RegExp("foo bar"), '🦄']];
|
||||
await t.throwsAsync(exec.exec(testCommand), { instanceOf: Error, message: 'The process \'node\' failed with exit code 1' });
|
||||
await t.throwsAsync(exec_wrapper_1.execErrorCatcher(testCommand, [], matchers), { instanceOf: Error, message: '🦄' });
|
||||
await t.throwsAsync(exec.exec('node', testArgs), { instanceOf: Error, message: 'The process \'node\' failed with exit code 1' });
|
||||
await t.throwsAsync(exec_wrapper_1.execErrorCatcher('node', testArgs, matchers), { instanceOf: Error, message: '🦄' });
|
||||
});
|
||||
ava_1.default('matcher returns correct error message when multiple matchers defined', async (t) => {
|
||||
const testCommand = buildDummyCommand("non matching string", 'foo bar\\nblort qux', '', 1);
|
||||
const testArgs = buildDummyArgs("non matching string", 'foo bar\\nblort qux', '', 1);
|
||||
const matchers = [[456, new RegExp("lorem ipsum"), '😩'],
|
||||
[123, new RegExp("foo bar"), '🦄'],
|
||||
[789, new RegExp("blah blah"), '🤦♂️']];
|
||||
await t.throwsAsync(exec.exec(testCommand), { instanceOf: Error, message: 'The process \'node\' failed with exit code 1' });
|
||||
await t.throwsAsync(exec_wrapper_1.execErrorCatcher(testCommand, [], matchers), { instanceOf: Error, message: '🦄' });
|
||||
await t.throwsAsync(exec.exec('node', testArgs), { instanceOf: Error, message: 'The process \'node\' failed with exit code 1' });
|
||||
await t.throwsAsync(exec_wrapper_1.execErrorCatcher('node', testArgs, matchers), { instanceOf: Error, message: '🦄' });
|
||||
});
|
||||
ava_1.default('matcher returns first match to regex when multiple matches', async (t) => {
|
||||
const testCommand = buildDummyCommand("non matching string", 'foo bar\\nblort qux', '', 1);
|
||||
const testArgs = buildDummyArgs("non matching string", 'foo bar\\nblort qux', '', 1);
|
||||
const matchers = [[123, new RegExp("foo bar"), '🦄'],
|
||||
[789, new RegExp("blah blah"), '🤦♂️'],
|
||||
[987, new RegExp("foo bar"), '🚫']];
|
||||
await t.throwsAsync(exec.exec(testCommand), { instanceOf: Error, message: 'The process \'node\' failed with exit code 1' });
|
||||
await t.throwsAsync(exec_wrapper_1.execErrorCatcher(testCommand, [], matchers), { instanceOf: Error, message: '🦄' });
|
||||
await t.throwsAsync(exec.exec('node', testArgs), { instanceOf: Error, message: 'The process \'node\' failed with exit code 1' });
|
||||
await t.throwsAsync(exec_wrapper_1.execErrorCatcher('node', testArgs, matchers), { instanceOf: Error, message: '🦄' });
|
||||
});
|
||||
ava_1.default('exit code matchers are applied', async (t) => {
|
||||
const testCommand = buildDummyCommand("non matching string", 'foo bar\\nblort qux', '', 123);
|
||||
const testArgs = buildDummyArgs("non matching string", 'foo bar\\nblort qux', '', 123);
|
||||
const matchers = [[123, new RegExp("this will not match"), '🦄']];
|
||||
await t.throwsAsync(exec.exec(testCommand), { instanceOf: Error, message: 'The process \'node\' failed with exit code 123' });
|
||||
await t.throwsAsync(exec_wrapper_1.execErrorCatcher(testCommand, [], matchers), { instanceOf: Error, message: '🦄' });
|
||||
await t.throwsAsync(exec.exec('node', testArgs), { instanceOf: Error, message: 'The process \'node\' failed with exit code 123' });
|
||||
await t.throwsAsync(exec_wrapper_1.execErrorCatcher('node', testArgs, matchers), { instanceOf: Error, message: '🦄' });
|
||||
});
|
||||
ava_1.default('execErrorCatcher respects the ignoreReturnValue option', async (t) => {
|
||||
const testCommand = buildDummyCommand("standard output", 'error output', '', 199);
|
||||
await t.throwsAsync(exec_wrapper_1.execErrorCatcher(testCommand, [], [], { ignoreReturnCode: false }), { instanceOf: Error });
|
||||
t.deepEqual(await exec_wrapper_1.execErrorCatcher(testCommand, [], [], { ignoreReturnCode: true }), 199);
|
||||
const testArgs = buildDummyArgs("standard output", 'error output', '', 199);
|
||||
await t.throwsAsync(exec_wrapper_1.execErrorCatcher('node', testArgs, [], { ignoreReturnCode: false }), { instanceOf: Error });
|
||||
t.deepEqual(await exec_wrapper_1.execErrorCatcher('node', testArgs, [], { ignoreReturnCode: true }), 199);
|
||||
});
|
||||
ava_1.default('execErrorCatcher preserves behavior of provided listeners', async (t) => {
|
||||
let stdoutExpected = 'standard output';
|
||||
|
|
@ -73,12 +74,12 @@ ava_1.default('execErrorCatcher preserves behavior of provided listeners', async
|
|||
stderrActual += data.toString();
|
||||
}
|
||||
};
|
||||
const testCommand = buildDummyCommand(stdoutExpected, stderrExpected, '', 0);
|
||||
t.deepEqual(await exec_wrapper_1.execErrorCatcher(testCommand, [], [], { listeners: listeners }), 0);
|
||||
const testArgs = buildDummyArgs(stdoutExpected, stderrExpected, '', 0);
|
||||
t.deepEqual(await exec_wrapper_1.execErrorCatcher('node', testArgs, [], { listeners: listeners }), 0);
|
||||
t.deepEqual(stdoutActual, stdoutExpected + "\n");
|
||||
t.deepEqual(stderrActual, stderrExpected + "\n");
|
||||
});
|
||||
function buildDummyCommand(stdoutContents, stderrContents, desiredErrorMessage, desiredExitCode) {
|
||||
function buildDummyArgs(stdoutContents, stderrContents, desiredErrorMessage, desiredExitCode) {
|
||||
let command = '';
|
||||
if (stdoutContents)
|
||||
command += 'console.log(\\"' + stdoutContents + '\\");';
|
||||
|
|
@ -90,6 +91,6 @@ function buildDummyCommand(stdoutContents, stderrContents, desiredErrorMessage,
|
|||
command += 'throw new Error(\\"' + desiredErrorMessage + '\\");';
|
||||
if (desiredExitCode)
|
||||
command += 'process.exitCode = ' + desiredExitCode + ';';
|
||||
return 'node -e "' + command + '"';
|
||||
return toolrunnner.argStringToArray('-e "' + command + '"');
|
||||
}
|
||||
//# sourceMappingURL=exec-wrapper.test.js.map
|
||||
File diff suppressed because one or more lines are too long
21
lib/external-queries.js
generated
21
lib/external-queries.js
generated
|
|
@ -7,24 +7,27 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const exec = __importStar(require("@actions/exec"));
|
||||
const toolrunnner = __importStar(require("@actions/exec/lib/toolrunner"));
|
||||
const fs = __importStar(require("fs"));
|
||||
const path = __importStar(require("path"));
|
||||
/**
|
||||
* Check out repository at the given ref, and return the directory of the checkout.
|
||||
*/
|
||||
async function checkoutExternalRepository(repository, ref, tempDir) {
|
||||
core.info('Checking out ' + repository);
|
||||
const checkoutLocation = path.join(tempDir, repository);
|
||||
async function checkoutExternalRepository(repository, ref, githubUrl, tempDir, logger) {
|
||||
logger.info('Checking out ' + repository);
|
||||
const checkoutLocation = path.join(tempDir, repository, ref);
|
||||
if (!checkoutLocation.startsWith(tempDir)) {
|
||||
// this still permits locations that mess with sibling repositories in `tempDir`, but that is acceptable
|
||||
throw new Error(`'${repository}@${ref}' is not a valid repository and reference.`);
|
||||
}
|
||||
if (!fs.existsSync(checkoutLocation)) {
|
||||
const repoURL = 'https://github.com/' + repository + '.git';
|
||||
await exec.exec('git', ['clone', repoURL, checkoutLocation]);
|
||||
await exec.exec('git', [
|
||||
const repoURL = githubUrl + '/' + repository + '.git';
|
||||
await new toolrunnner.ToolRunner('git', ['clone', repoURL, checkoutLocation]).exec();
|
||||
await new toolrunnner.ToolRunner('git', [
|
||||
'--work-tree=' + checkoutLocation,
|
||||
'--git-dir=' + checkoutLocation + '/.git',
|
||||
'checkout', ref,
|
||||
]);
|
||||
]).exec();
|
||||
}
|
||||
return checkoutLocation;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"external-queries.js","sourceRoot":"","sources":["../src/external-queries.ts"],"names":[],"mappings":";;;;;;;;;AAAA,oDAAsC;AACtC,oDAAsC;AACtC,uCAAyB;AACzB,2CAA6B;AAE7B;;GAEG;AACI,KAAK,UAAU,0BAA0B,CAAC,UAAkB,EAAE,GAAW,EAAE,OAAe;IAC/F,IAAI,CAAC,IAAI,CAAC,eAAe,GAAG,UAAU,CAAC,CAAC;IAExC,MAAM,gBAAgB,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IACxD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,gBAAgB,CAAC,EAAE;QACpC,MAAM,OAAO,GAAG,qBAAqB,GAAG,UAAU,GAAG,MAAM,CAAC;QAC5D,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC;QAC7D,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE;YACrB,cAAc,GAAG,gBAAgB;YACjC,YAAY,GAAG,gBAAgB,GAAG,OAAO;YACzC,UAAU,EAAE,GAAG;SAChB,CAAC,CAAC;KACJ;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAfD,gEAeC"}
|
||||
{"version":3,"file":"external-queries.js","sourceRoot":"","sources":["../src/external-queries.ts"],"names":[],"mappings":";;;;;;;;;AAAA,0EAA4D;AAC5D,uCAAyB;AACzB,2CAA6B;AAI7B;;GAEG;AACI,KAAK,UAAU,0BAA0B,CAC9C,UAAkB,EAClB,GAAW,EACX,SAAiB,EACjB,OAAe,EACf,MAAc;IAEd,MAAM,CAAC,IAAI,CAAC,eAAe,GAAG,UAAU,CAAC,CAAC;IAE1C,MAAM,gBAAgB,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC;IAE7D,IAAI,CAAC,gBAAgB,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE;QACzC,wGAAwG;QACxG,MAAM,IAAI,KAAK,CAAC,IAAI,UAAU,IAAI,GAAG,4CAA4C,CAAC,CAAC;KACpF;IAED,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,gBAAgB,CAAC,EAAE;QACpC,MAAM,OAAO,GAAG,SAAS,GAAG,GAAG,GAAG,UAAU,GAAG,MAAM,CAAC;QACtD,MAAM,IAAI,WAAW,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QACrF,MAAM,IAAI,WAAW,CAAC,UAAU,CAAC,KAAK,EAAE;YACtC,cAAc,GAAG,gBAAgB;YACjC,YAAY,GAAG,gBAAgB,GAAG,OAAO;YACzC,UAAU,EAAE,GAAG;SAChB,CAAC,CAAC,IAAI,EAAE,CAAC;KACX;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AA3BD,gEA2BC"}
|
||||
6
lib/external-queries.test.js
generated
6
lib/external-queries.test.js
generated
|
|
@ -14,14 +14,16 @@ const ava_1 = __importDefault(require("ava"));
|
|||
const fs = __importStar(require("fs"));
|
||||
const path = __importStar(require("path"));
|
||||
const externalQueries = __importStar(require("./external-queries"));
|
||||
const logging_1 = require("./logging");
|
||||
const testing_utils_1 = require("./testing-utils");
|
||||
const util = __importStar(require("./util"));
|
||||
testing_utils_1.setupTests(ava_1.default);
|
||||
ava_1.default("checkoutExternalQueries", async (t) => {
|
||||
await util.withTmpDir(async (tmpDir) => {
|
||||
await externalQueries.checkoutExternalRepository("github/codeql-go", "df4c6869212341b601005567381944ed90906b6b", tmpDir);
|
||||
const ref = "df4c6869212341b601005567381944ed90906b6b";
|
||||
await externalQueries.checkoutExternalRepository("github/codeql-go", ref, 'https://github.com', tmpDir, logging_1.getRunnerLogger(true));
|
||||
// COPYRIGHT file existed in df4c6869212341b601005567381944ed90906b6b but not in the default branch
|
||||
t.true(fs.existsSync(path.join(tmpDir, "github", "codeql-go", "COPYRIGHT")));
|
||||
t.true(fs.existsSync(path.join(tmpDir, "github", "codeql-go", ref, "COPYRIGHT")));
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=external-queries.test.js.map
|
||||
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"external-queries.test.js","sourceRoot":"","sources":["../src/external-queries.test.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8CAAuB;AACvB,uCAAyB;AACzB,2CAA6B;AAE7B,oEAAsD;AACtD,mDAA2C;AAC3C,6CAA+B;AAE/B,0BAAU,CAAC,aAAI,CAAC,CAAC;AAEjB,aAAI,CAAC,yBAAyB,EAAE,KAAK,EAAC,CAAC,EAAC,EAAE;IACxC,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,EAAC,MAAM,EAAC,EAAE;QACnC,MAAM,eAAe,CAAC,0BAA0B,CAC9C,kBAAkB,EAClB,0CAA0C,EAC1C,MAAM,CAAC,CAAC;QAEV,mGAAmG;QACnG,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IAC/E,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
||||
{"version":3,"file":"external-queries.test.js","sourceRoot":"","sources":["../src/external-queries.test.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8CAAuB;AACvB,uCAAyB;AACzB,2CAA6B;AAE7B,oEAAsD;AACtD,uCAA4C;AAC5C,mDAA2C;AAC3C,6CAA+B;AAE/B,0BAAU,CAAC,aAAI,CAAC,CAAC;AAEjB,aAAI,CAAC,yBAAyB,EAAE,KAAK,EAAC,CAAC,EAAC,EAAE;IACxC,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,EAAC,MAAM,EAAC,EAAE;QACnC,MAAM,GAAG,GAAG,0CAA0C,CAAC;QACvD,MAAM,eAAe,CAAC,0BAA0B,CAC9C,kBAAkB,EAClB,GAAG,EACH,oBAAoB,EACpB,MAAM,EACN,yBAAe,CAAC,IAAI,CAAC,CAAC,CAAC;QAEzB,mGAAmG;QACnG,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;IACpF,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
||||
116
lib/finalize-db.js
generated
116
lib/finalize-db.js
generated
|
|
@ -1,116 +0,0 @@
|
|||
"use strict";
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const fs = __importStar(require("fs"));
|
||||
const path = __importStar(require("path"));
|
||||
const codeql_1 = require("./codeql");
|
||||
const configUtils = __importStar(require("./config-utils"));
|
||||
const languages_1 = require("./languages");
|
||||
const logging_1 = require("./logging");
|
||||
const repository_1 = require("./repository");
|
||||
const sharedEnv = __importStar(require("./shared-environment"));
|
||||
const upload_lib = __importStar(require("./upload-lib"));
|
||||
const util = __importStar(require("./util"));
|
||||
async function sendStatusReport(startedAt, queriesStats, uploadStats, error) {
|
||||
var _a, _b, _c;
|
||||
const status = ((_a = queriesStats) === null || _a === void 0 ? void 0 : _a.analyze_failure_language) !== undefined || error !== undefined ? 'failure' : 'success';
|
||||
const statusReportBase = await util.createStatusReportBase('finish', status, startedAt, (_b = error) === null || _b === void 0 ? void 0 : _b.message, (_c = error) === null || _c === void 0 ? void 0 : _c.stack);
|
||||
const statusReport = {
|
||||
...statusReportBase,
|
||||
...(queriesStats || {}),
|
||||
...(uploadStats || {}),
|
||||
};
|
||||
await util.sendStatusReport(statusReport);
|
||||
}
|
||||
async function createdDBForScannedLanguages(databaseFolder, config) {
|
||||
const codeql = codeql_1.getCodeQL(config.codeQLCmd);
|
||||
for (const language of config.languages) {
|
||||
if (languages_1.isScannedLanguage(language)) {
|
||||
core.startGroup('Extracting ' + language);
|
||||
await codeql.extractScannedLanguage(path.join(databaseFolder, language), language);
|
||||
core.endGroup();
|
||||
}
|
||||
}
|
||||
}
|
||||
async function finalizeDatabaseCreation(databaseFolder, config) {
|
||||
await createdDBForScannedLanguages(databaseFolder, config);
|
||||
const codeql = codeql_1.getCodeQL(config.codeQLCmd);
|
||||
for (const language of config.languages) {
|
||||
core.startGroup('Finalizing ' + language);
|
||||
await codeql.finalizeDatabase(path.join(databaseFolder, language));
|
||||
core.endGroup();
|
||||
}
|
||||
}
|
||||
// Runs queries and creates sarif files in the given folder
|
||||
async function runQueries(databaseFolder, sarifFolder, config) {
|
||||
const codeql = codeql_1.getCodeQL(config.codeQLCmd);
|
||||
for (let language of fs.readdirSync(databaseFolder)) {
|
||||
core.startGroup('Analyzing ' + language);
|
||||
const queries = config.queries[language] || [];
|
||||
if (queries.length === 0) {
|
||||
throw new Error('Unable to analyse ' + language + ' as no queries were selected for this language');
|
||||
}
|
||||
try {
|
||||
// Pass the queries to codeql using a file instead of using the command
|
||||
// line to avoid command line length restrictions, particularly on windows.
|
||||
const querySuite = path.join(databaseFolder, language + '-queries.qls');
|
||||
const querySuiteContents = queries.map(q => '- query: ' + q).join('\n');
|
||||
fs.writeFileSync(querySuite, querySuiteContents);
|
||||
core.debug('Query suite file for ' + language + '...\n' + querySuiteContents);
|
||||
const sarifFile = path.join(sarifFolder, language + '.sarif');
|
||||
await codeql.databaseAnalyze(path.join(databaseFolder, language), sarifFile, querySuite);
|
||||
core.debug('SARIF results for database ' + language + ' created at "' + sarifFile + '"');
|
||||
core.endGroup();
|
||||
}
|
||||
catch (e) {
|
||||
// For now the fields about query performance are not populated
|
||||
return {
|
||||
analyze_failure_language: language,
|
||||
};
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
async function run() {
|
||||
const startedAt = new Date();
|
||||
let queriesStats = undefined;
|
||||
let uploadStats = undefined;
|
||||
try {
|
||||
util.prepareLocalRunEnvironment();
|
||||
if (!await util.sendStatusReport(await util.createStatusReportBase('finish', 'starting', startedAt), true)) {
|
||||
return;
|
||||
}
|
||||
const config = await configUtils.getConfig(util.getRequiredEnvParam('RUNNER_TEMP'));
|
||||
core.exportVariable(sharedEnv.ODASA_TRACER_CONFIGURATION, '');
|
||||
delete process.env[sharedEnv.ODASA_TRACER_CONFIGURATION];
|
||||
const databaseFolder = util.getCodeQLDatabasesDir(config.tempDir);
|
||||
const sarifFolder = core.getInput('output');
|
||||
fs.mkdirSync(sarifFolder, { recursive: true });
|
||||
core.info('Finalizing database creation');
|
||||
await finalizeDatabaseCreation(databaseFolder, config);
|
||||
core.info('Analyzing database');
|
||||
queriesStats = await runQueries(databaseFolder, sarifFolder, config);
|
||||
if ('true' === core.getInput('upload')) {
|
||||
uploadStats = await upload_lib.upload(sarifFolder, repository_1.parseRepositoryNwo(util.getRequiredEnvParam('GITHUB_REPOSITORY')), await util.getCommitOid(), util.getRef(), await util.getAnalysisKey(), util.getRequiredEnvParam('GITHUB_WORKFLOW'), util.getWorkflowRunID(), core.getInput('checkout_path'), core.getInput('matrix'), core.getInput('token'), util.getRequiredEnvParam('GITHUB_API_URL'), 'actions', logging_1.getActionsLogger());
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
core.setFailed(error.message);
|
||||
console.log(error);
|
||||
await sendStatusReport(startedAt, queriesStats, uploadStats, error);
|
||||
return;
|
||||
}
|
||||
await sendStatusReport(startedAt, queriesStats, uploadStats);
|
||||
}
|
||||
run().catch(e => {
|
||||
core.setFailed("analyze action failed: " + e);
|
||||
console.log(e);
|
||||
});
|
||||
//# sourceMappingURL=finalize-db.js.map
|
||||
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"finalize-db.js","sourceRoot":"","sources":["../src/finalize-db.ts"],"names":[],"mappings":";;;;;;;;;AAAA,oDAAsC;AACtC,uCAAyB;AACzB,2CAA6B;AAE7B,qCAAqC;AACrC,4DAA8C;AAC9C,2CAAgD;AAChD,uCAA6C;AAC7C,6CAAkD;AAClD,gEAAkD;AAClD,yDAA2C;AAC3C,6CAA+B;AAiC/B,KAAK,UAAU,gBAAgB,CAC7B,SAAe,EACf,YAA6C,EAC7C,WAAsD,EACtD,KAAa;;IAEb,MAAM,MAAM,GAAG,OAAA,YAAY,0CAAE,wBAAwB,MAAK,SAAS,IAAI,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;IACnH,MAAM,gBAAgB,GAAG,MAAM,IAAI,CAAC,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,QAAE,KAAK,0CAAE,OAAO,QAAE,KAAK,0CAAE,KAAK,CAAC,CAAC;IACtH,MAAM,YAAY,GAAuB;QACvC,GAAG,gBAAgB;QACnB,GAAG,CAAC,YAAY,IAAI,EAAE,CAAC;QACvB,GAAG,CAAC,WAAW,IAAI,EAAE,CAAC;KACvB,CAAC;IACF,MAAM,IAAI,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC;AAC5C,CAAC;AAED,KAAK,UAAU,4BAA4B,CAAC,cAAsB,EAAE,MAA0B;IAC5F,MAAM,MAAM,GAAG,kBAAS,CAAC,MAAM,CAA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AAQ,CAAC,eAAe,CAAC,EAC9B,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EACvB,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,EACtB,IAAI,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,EAC1C,SAAS,EACT,0BAAgB,EAAE,CAAC,CAAC;SACvB;KAEF;IAAC,OAAO,KAAK,EAAE;QACd,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC9B,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACnB,MAAM,gBAAgB,CAAC,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;QACpE,OAAO;KACR;IAED,MAAM,gBAAgB,CAAC,SAAS,EAAE,YAAY,EAAE,WAAW,CAAC,CAAC;AAC/D,CAAC;AAED,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;IACd,IAAI,CAAC,SAAS,CAAC,yBAAyB,GAAG,CAAC,CAAC,CAAC;IAC9C,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AACjB,CAAC,CAAC,CAAC"}
|
||||
2
lib/finalize-db.test.js
generated
2
lib/finalize-db.test.js
generated
|
|
@ -1,2 +0,0 @@
|
|||
"use strict";
|
||||
//# sourceMappingURL=finalize-db.test.js.map
|
||||
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"finalize-db.test.js","sourceRoot":"","sources":["../src/finalize-db.test.ts"],"names":[],"mappings":""}
|
||||
8
lib/fingerprints.js
generated
8
lib/fingerprints.js
generated
|
|
@ -156,7 +156,7 @@ function locationUpdateCallback(result, location, logger) {
|
|||
// the source file so we can hash it.
|
||||
// If possible returns a absolute file path for the source file,
|
||||
// or if not possible then returns undefined.
|
||||
function resolveUriToFile(location, artifacts, logger) {
|
||||
function resolveUriToFile(location, artifacts, checkoutPath, logger) {
|
||||
// This may be referencing an artifact
|
||||
if (!location.uri && location.index !== undefined) {
|
||||
if (typeof location.index !== 'number' ||
|
||||
|
|
@ -184,7 +184,7 @@ function resolveUriToFile(location, artifacts, logger) {
|
|||
return undefined;
|
||||
}
|
||||
// Discard any absolute paths that aren't in the src root
|
||||
const srcRootPrefix = process.env['GITHUB_WORKSPACE'] + '/';
|
||||
const srcRootPrefix = checkoutPath + '/';
|
||||
if (uri.startsWith('/') && !uri.startsWith(srcRootPrefix)) {
|
||||
logger.debug(`Ignoring location URI "${uri}" as it is outside of the src root`);
|
||||
return undefined;
|
||||
|
|
@ -205,7 +205,7 @@ function resolveUriToFile(location, artifacts, logger) {
|
|||
exports.resolveUriToFile = resolveUriToFile;
|
||||
// Compute fingerprints for results in the given sarif file
|
||||
// and return an updated sarif file contents.
|
||||
function addFingerprints(sarifContents, logger) {
|
||||
function addFingerprints(sarifContents, checkoutPath, logger) {
|
||||
var _a, _b;
|
||||
let sarif = JSON.parse(sarifContents);
|
||||
// Gather together results for the same file and construct
|
||||
|
|
@ -221,7 +221,7 @@ function addFingerprints(sarifContents, logger) {
|
|||
logger.debug(`Unable to compute fingerprint for invalid location: ${JSON.stringify(primaryLocation)}`);
|
||||
continue;
|
||||
}
|
||||
const filepath = resolveUriToFile(primaryLocation.physicalLocation.artifactLocation, artifacts, logger);
|
||||
const filepath = resolveUriToFile(primaryLocation.physicalLocation.artifactLocation, artifacts, checkoutPath, logger);
|
||||
if (!filepath) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
11
lib/fingerprints.test.js
generated
11
lib/fingerprints.test.js
generated
|
|
@ -99,7 +99,7 @@ ava_1.default('hash', (t) => {
|
|||
function testResolveUriToFile(uri, index, artifactsURIs) {
|
||||
const location = { "uri": uri, "index": index };
|
||||
const artifacts = artifactsURIs.map(uri => ({ "location": { "uri": uri } }));
|
||||
return fingerprints.resolveUriToFile(location, artifacts, logging_1.getCLILogger());
|
||||
return fingerprints.resolveUriToFile(location, artifacts, process.cwd(), logging_1.getRunnerLogger(true));
|
||||
}
|
||||
ava_1.default('resolveUriToFile', t => {
|
||||
// The resolveUriToFile method checks that the file exists and is in the right directory
|
||||
|
|
@ -110,7 +110,6 @@ ava_1.default('resolveUriToFile', t => {
|
|||
const filepath = __filename;
|
||||
t.true(filepath.startsWith(cwd + '/'));
|
||||
const relativeFilepaht = filepath.substring(cwd.length + 1);
|
||||
process.env['GITHUB_WORKSPACE'] = cwd;
|
||||
// Absolute paths are unmodified
|
||||
t.is(testResolveUriToFile(filepath, undefined, []), filepath);
|
||||
t.is(testResolveUriToFile('file://' + filepath, undefined, []), filepath);
|
||||
|
|
@ -143,8 +142,8 @@ ava_1.default('addFingerprints', t => {
|
|||
input = JSON.stringify(JSON.parse(input));
|
||||
expected = JSON.stringify(JSON.parse(expected));
|
||||
// The URIs in the SARIF files resolve to files in the testdata directory
|
||||
process.env['GITHUB_WORKSPACE'] = path.normalize(__dirname + '/../src/testdata');
|
||||
t.deepEqual(fingerprints.addFingerprints(input, logging_1.getCLILogger()), expected);
|
||||
const checkoutPath = path.normalize(__dirname + '/../src/testdata');
|
||||
t.deepEqual(fingerprints.addFingerprints(input, checkoutPath, logging_1.getRunnerLogger(true)), expected);
|
||||
});
|
||||
ava_1.default('missingRegions', t => {
|
||||
// Run an end-to-end test on a test file
|
||||
|
|
@ -154,7 +153,7 @@ ava_1.default('missingRegions', t => {
|
|||
input = JSON.stringify(JSON.parse(input));
|
||||
expected = JSON.stringify(JSON.parse(expected));
|
||||
// The URIs in the SARIF files resolve to files in the testdata directory
|
||||
process.env['GITHUB_WORKSPACE'] = path.normalize(__dirname + '/../src/testdata');
|
||||
t.deepEqual(fingerprints.addFingerprints(input, logging_1.getCLILogger()), expected);
|
||||
const checkoutPath = path.normalize(__dirname + '/../src/testdata');
|
||||
t.deepEqual(fingerprints.addFingerprints(input, checkoutPath, logging_1.getRunnerLogger(true)), expected);
|
||||
});
|
||||
//# sourceMappingURL=fingerprints.test.js.map
|
||||
File diff suppressed because one or more lines are too long
80
lib/init-action.js
generated
Normal file
80
lib/init-action.js
generated
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
"use strict";
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const init_1 = require("./init");
|
||||
const logging_1 = require("./logging");
|
||||
const repository_1 = require("./repository");
|
||||
const util = __importStar(require("./util"));
|
||||
async function sendSuccessStatusReport(startedAt, config) {
|
||||
const statusReportBase = await util.createStatusReportBase('init', 'success', startedAt);
|
||||
const languages = config.languages.join(',');
|
||||
const workflowLanguages = core.getInput('languages', { required: false });
|
||||
const paths = (config.originalUserInput.paths || []).join(',');
|
||||
const pathsIgnore = (config.originalUserInput['paths-ignore'] || []).join(',');
|
||||
const disableDefaultQueries = config.originalUserInput['disable-default-queries'] ? languages : '';
|
||||
const queries = (config.originalUserInput.queries || []).map(q => q.uses).join(',');
|
||||
const statusReport = {
|
||||
...statusReportBase,
|
||||
languages: languages,
|
||||
workflow_languages: workflowLanguages,
|
||||
paths: paths,
|
||||
paths_ignore: pathsIgnore,
|
||||
disable_default_queries: disableDefaultQueries,
|
||||
queries: queries,
|
||||
};
|
||||
await util.sendStatusReport(statusReport);
|
||||
}
|
||||
async function run() {
|
||||
const startedAt = new Date();
|
||||
const logger = logging_1.getActionsLogger();
|
||||
let config;
|
||||
let codeql;
|
||||
try {
|
||||
util.prepareLocalRunEnvironment();
|
||||
if (!await util.sendStatusReport(await util.createStatusReportBase('init', 'starting', startedAt), true)) {
|
||||
return;
|
||||
}
|
||||
codeql = await init_1.initCodeQL(core.getInput('tools'), core.getInput('token'), util.getRequiredEnvParam('GITHUB_SERVER_URL'), util.getRequiredEnvParam('RUNNER_TEMP'), util.getRequiredEnvParam('RUNNER_TOOL_CACHE'), 'actions', logger);
|
||||
config = await init_1.initConfig(core.getInput('languages'), core.getInput('queries'), core.getInput('config-file'), repository_1.parseRepositoryNwo(util.getRequiredEnvParam('GITHUB_REPOSITORY')), util.getRequiredEnvParam('RUNNER_TEMP'), util.getRequiredEnvParam('RUNNER_TOOL_CACHE'), codeql, util.getRequiredEnvParam('GITHUB_WORKSPACE'), core.getInput('token'), util.getRequiredEnvParam('GITHUB_SERVER_URL'), logger);
|
||||
}
|
||||
catch (e) {
|
||||
core.setFailed(e.message);
|
||||
console.log(e);
|
||||
await util.sendStatusReport(await util.createStatusReportBase('init', 'aborted', startedAt, e.message));
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// Forward Go flags
|
||||
const goFlags = process.env['GOFLAGS'];
|
||||
if (goFlags) {
|
||||
core.exportVariable('GOFLAGS', goFlags);
|
||||
core.warning("Passing the GOFLAGS env parameter to the init action is deprecated. Please move this to the analyze action.");
|
||||
}
|
||||
// Setup CODEQL_RAM flag (todo improve this https://github.com/github/dsp-code-scanning/issues/935)
|
||||
const codeqlRam = process.env['CODEQL_RAM'] || '6500';
|
||||
core.exportVariable('CODEQL_RAM', codeqlRam);
|
||||
const tracerConfig = await init_1.runInit(codeql, config);
|
||||
if (tracerConfig !== undefined) {
|
||||
Object.entries(tracerConfig.env).forEach(([key, value]) => core.exportVariable(key, value));
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
core.setFailed(error.message);
|
||||
console.log(error);
|
||||
await util.sendStatusReport(await util.createStatusReportBase('init', 'failure', startedAt, error.message, error.stack));
|
||||
return;
|
||||
}
|
||||
await sendSuccessStatusReport(startedAt, config);
|
||||
}
|
||||
run().catch(e => {
|
||||
core.setFailed("init action failed: " + e);
|
||||
console.log(e);
|
||||
});
|
||||
//# sourceMappingURL=init-action.js.map
|
||||
1
lib/init-action.js.map
Normal file
1
lib/init-action.js.map
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"init-action.js","sourceRo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CAAC,OAAO,EACb,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QAChB,OAAO;KACR;IACD,MAAM,uBAAuB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;AACnD,CAAC;AAED,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;IACd,IAAI,CAAC,SAAS,CAAC,sBAAsB,GAAG,CAAC,CAAC,CAAC;IAC3C,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AACjB,CAAC,CAAC,CAAC"}
|
||||
63
lib/init.js
generated
Normal file
63
lib/init.js
generated
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
"use strict";
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const toolrunnner = __importStar(require("@actions/exec/lib/toolrunner"));
|
||||
const fs = __importStar(require("fs"));
|
||||
const path = __importStar(require("path"));
|
||||
const analysisPaths = __importStar(require("./analysis-paths"));
|
||||
const codeql_1 = require("./codeql");
|
||||
const configUtils = __importStar(require("./config-utils"));
|
||||
const tracer_config_1 = require("./tracer-config");
|
||||
const util = __importStar(require("./util"));
|
||||
async function initCodeQL(codeqlURL, githubAuth, githubUrl, tempDir, toolsDir, mode, logger) {
|
||||
logger.startGroup('Setup CodeQL tools');
|
||||
const codeql = await codeql_1.setupCodeQL(codeqlURL, githubAuth, githubUrl, tempDir, toolsDir, mode, logger);
|
||||
await codeql.printVersion();
|
||||
logger.endGroup();
|
||||
return codeql;
|
||||
}
|
||||
exports.initCodeQL = initCodeQL;
|
||||
async function initConfig(languagesInput, queriesInput, configFile, repository, tempDir, toolCacheDir, codeQL, checkoutPath, githubAuth, githubUrl, logger) {
|
||||
logger.startGroup('Load language configuration');
|
||||
const config = await configUtils.initConfig(languagesInput, queriesInput, configFile, repository, tempDir, toolCacheDir, codeQL, checkoutPath, githubAuth, githubUrl, logger);
|
||||
analysisPaths.printPathFiltersWarning(config, logger);
|
||||
logger.endGroup();
|
||||
return config;
|
||||
}
|
||||
exports.initConfig = initConfig;
|
||||
async function runInit(codeql, config) {
|
||||
const sourceRoot = path.resolve();
|
||||
fs.mkdirSync(util.getCodeQLDatabasesDir(config.tempDir), { recursive: true });
|
||||
// TODO: replace this code once CodeQL supports multi-language tracing
|
||||
for (let language of config.languages) {
|
||||
// Init language database
|
||||
await codeql.databaseInit(util.getCodeQLDatabasePath(config.tempDir, language), language, sourceRoot);
|
||||
}
|
||||
const tracerConfig = await tracer_config_1.getCombinedTracerConfig(config, codeql);
|
||||
if (tracerConfig !== undefined && process.platform === 'win32') {
|
||||
const injectTracerPath = path.join(config.tempDir, 'inject-tracer.ps1');
|
||||
fs.writeFileSync(injectTracerPath, `
|
||||
Param(
|
||||
[Parameter(Position=0)]
|
||||
[String]
|
||||
$tracer
|
||||
)
|
||||
Get-Process -Name Runner.Worker
|
||||
$process=Get-Process -Name Runner.Worker
|
||||
$id=$process.Id
|
||||
Invoke-Expression "&$tracer --inject=$id"`);
|
||||
await new toolrunnner.ToolRunner('powershell', [
|
||||
injectTracerPath,
|
||||
path.resolve(path.dirname(codeql.getPath()), 'tools', 'win64', 'tracer.exe'),
|
||||
], { env: { 'ODASA_TRACER_CONFIGURATION': tracerConfig.spec } }).exec();
|
||||
}
|
||||
return tracerConfig;
|
||||
}
|
||||
exports.runInit = runInit;
|
||||
//# sourceMappingURL=init.js.map
|
||||
1
lib/init.js.map
Normal file
1
lib/init.js.map
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"init.js","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":";;;;;;;;;AAAA,0EAA4D;AAC5D,uCAAyB;AACzB,2CAA6B;AAE7B,gEAAkD;AAClD,qCAA+C;AAC/C,4DAA8C;AA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AC;IAE9E,sEAAsE;IACtE,KAAK,IAAI,QAAQ,IAAI,MAAM,CAAC,SAAS,EAAE;QACrC,yBAAyB;QACzB,MAAM,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;KACvG;IAED,MAAM,YAAY,GAAG,MAAM,uCAAuB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnE,IAAI,YAAY,KAAK,SAAS,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE;QAC9D,MAAM,gBAAgB,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;QACxE,EAAE,CAAC,aAAa,CAAC,gBAAgB,EAAE;;;;;;;;;gDASS,CAAC,CAAC;QAE9C,MAAM,IAAI,WAAW,CAAC,UAAU,CAC9B,YAAY,EACZ;YACE,gBAAgB;YAChB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC;SAC7E,EACD,EAAE,GAAG,EAAE,EAAE,4BAA4B,EAAE,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;KACxE;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AArCD,0BAqCC"}
|
||||
6
lib/logging.js
generated
6
lib/logging.js
generated
|
|
@ -12,9 +12,9 @@ function getActionsLogger() {
|
|||
return core;
|
||||
}
|
||||
exports.getActionsLogger = getActionsLogger;
|
||||
function getCLILogger() {
|
||||
function getRunnerLogger(debugMode) {
|
||||
return {
|
||||
debug: console.debug,
|
||||
debug: debugMode ? console.debug : () => undefined,
|
||||
info: console.info,
|
||||
warning: console.warn,
|
||||
error: console.error,
|
||||
|
|
@ -22,5 +22,5 @@ function getCLILogger() {
|
|||
endGroup: () => undefined,
|
||||
};
|
||||
}
|
||||
exports.getCLILogger = getCLILogger;
|
||||
exports.getRunnerLogger = getRunnerLogger;
|
||||
//# sourceMappingURL=logging.js.map
|
||||
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"logging.js","sourceRoot":"","sources":["../src/logging.ts"],"names":[],"mappings":";;;;;;;;;AAAA,oDAAsC;AAYtC,SAAgB,gBAAgB;IAC9B,OAAO,IAAI,CAAC;AACd,CAAC;AAFD,4CAEC;AAED,SAAgB,YAAY;IAC1B,OAAO;QACL,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,OAAO,EAAE,OAAO,CAAC,IAAI;QACrB,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,UAAU,EAAE,GAAG,EAAE,CAAC,SAAS;QAC3B,QAAQ,EAAE,GAAG,EAAE,CAAC,SAAS;KAC1B,CAAC;AACJ,CAAC;AATD,oCASC"}
|
||||
{"version":3,"file":"logging.js","sourceRoot":"","sources":["../src/logging.ts"],"names":[],"mappings":";;;;;;;;;AAAA,oDAAsC;AAYtC,SAAgB,gBAAgB;IAC9B,OAAO,IAAI,CAAC;AACd,CAAC;AAFD,4CAEC;AAED,SAAgB,eAAe,CAAC,SAAkB;IAChD,OAAO;QACL,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,SAAS;QAClD,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,OAAO,EAAE,OAAO,CAAC,IAAI;QACrB,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,UAAU,EAAE,GAAG,EAAE,CAAC,SAAS;QAC3B,QAAQ,EAAE,GAAG,EAAE,CAAC,SAAS;KAC1B,CAAC;AACJ,CAAC;AATD,0CASC"}
|
||||
243
lib/runner.js
generated
Normal file
243
lib/runner.js
generated
Normal file
|
|
@ -0,0 +1,243 @@
|
|||
"use strict";
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const commander_1 = require("commander");
|
||||
const fs = __importStar(require("fs"));
|
||||
const os = __importStar(require("os"));
|
||||
const path = __importStar(require("path"));
|
||||
const analyze_1 = require("./analyze");
|
||||
const autobuild_1 = require("./autobuild");
|
||||
const codeql_1 = require("./codeql");
|
||||
const config_utils_1 = require("./config-utils");
|
||||
const init_1 = require("./init");
|
||||
const languages_1 = require("./languages");
|
||||
const logging_1 = require("./logging");
|
||||
const repository_1 = require("./repository");
|
||||
const upload_lib = __importStar(require("./upload-lib"));
|
||||
const util_1 = require("./util");
|
||||
const program = new commander_1.Command();
|
||||
program.version('0.0.1');
|
||||
function parseGithubUrl(inputUrl) {
|
||||
try {
|
||||
const url = new URL(inputUrl);
|
||||
// If we detect this is trying to be to github.com
|
||||
// then return with a fixed canonical URL.
|
||||
if (url.hostname === 'github.com' || url.hostname === 'api.github.com') {
|
||||
return 'https://github.com';
|
||||
}
|
||||
// Remove the API prefix if it's present
|
||||
if (url.pathname.indexOf('/api/v3') !== -1) {
|
||||
url.pathname = url.pathname.substring(0, url.pathname.indexOf('/api/v3'));
|
||||
}
|
||||
return url.toString();
|
||||
}
|
||||
catch (e) {
|
||||
throw new Error(`"${inputUrl}" is not a valid URL`);
|
||||
}
|
||||
}
|
||||
function getTempDir(userInput) {
|
||||
const tempDir = path.join(userInput || process.cwd(), 'codeql-runner');
|
||||
if (!fs.existsSync(tempDir)) {
|
||||
fs.mkdirSync(tempDir, { recursive: true });
|
||||
}
|
||||
return tempDir;
|
||||
}
|
||||
function getToolsDir(userInput) {
|
||||
const toolsDir = userInput || path.join(os.homedir(), 'codeql-runner-tools');
|
||||
if (!fs.existsSync(toolsDir)) {
|
||||
fs.mkdirSync(toolsDir, { recursive: true });
|
||||
}
|
||||
return toolsDir;
|
||||
}
|
||||
const codeqlEnvJsonFilename = 'codeql-env.json';
|
||||
// Imports the environment from codeqlEnvJsonFilename if not already present
|
||||
function importTracerEnvironment(config) {
|
||||
if (!('ODASA_TRACER_CONFIGURATION' in process.env)) {
|
||||
const jsonEnvFile = path.join(config.tempDir, codeqlEnvJsonFilename);
|
||||
const env = JSON.parse(fs.readFileSync(jsonEnvFile).toString('utf-8'));
|
||||
Object.keys(env).forEach(key => process.env[key] = env[key]);
|
||||
}
|
||||
}
|
||||
// Allow the user to specify refs in full refs/heads/branch format
|
||||
// or just the short branch name and prepend "refs/heads/" to it.
|
||||
function parseRef(userInput) {
|
||||
if (userInput.startsWith('refs/')) {
|
||||
return userInput;
|
||||
}
|
||||
else {
|
||||
return 'refs/heads/' + userInput;
|
||||
}
|
||||
}
|
||||
program
|
||||
.command('init')
|
||||
.description('Initializes CodeQL')
|
||||
.requiredOption('--repository <repository>', 'Repository name. (Required)')
|
||||
.requiredOption('--github-url <url>', 'URL of GitHub instance. (Required)')
|
||||
.requiredOption('--github-auth <auth>', 'GitHub Apps token or personal access token. (Required)')
|
||||
.option('--languages <languages>', 'Comma-separated list of languages to analyze. Otherwise detects and analyzes all supported languages from the repo.')
|
||||
.option('--queries <queries>', 'Comma-separated list of additional queries to run. This overrides the same setting in a configuration file.')
|
||||
.option('--config-file <file>', 'Path to config file.')
|
||||
.option('--codeql-path <path>', 'Path to a copy of the CodeQL CLI executable to use. Otherwise downloads a copy.')
|
||||
.option('--temp-dir <dir>', 'Directory to use for temporary files. Default is "./codeql-runner".')
|
||||
.option('--tools-dir <dir>', 'Directory to use for CodeQL tools and other files to store between runs. Default is a subdirectory of the home directory.')
|
||||
.option('--checkout-path <path>', 'Checkout path. Default is the current working directory.')
|
||||
.option('--debug', 'Print more verbose output', false)
|
||||
.action(async (cmd) => {
|
||||
const logger = logging_1.getRunnerLogger(cmd.debug);
|
||||
try {
|
||||
const tempDir = getTempDir(cmd.tempDir);
|
||||
const toolsDir = getToolsDir(cmd.toolsDir);
|
||||
// Wipe the temp dir
|
||||
logger.info(`Cleaning temp directory ${tempDir}`);
|
||||
fs.rmdirSync(tempDir, { recursive: true });
|
||||
fs.mkdirSync(tempDir, { recursive: true });
|
||||
let codeql;
|
||||
if (cmd.codeqlPath !== undefined) {
|
||||
codeql = codeql_1.getCodeQL(cmd.codeqlPath);
|
||||
}
|
||||
else {
|
||||
codeql = await init_1.initCodeQL(undefined, cmd.githubAuth, parseGithubUrl(cmd.githubUrl), tempDir, toolsDir, 'runner', logger);
|
||||
}
|
||||
const config = await init_1.initConfig(cmd.languages, cmd.queries, cmd.configFile, repository_1.parseRepositoryNwo(cmd.repository), tempDir, toolsDir, codeql, cmd.checkoutPath || process.cwd(), cmd.githubAuth, parseGithubUrl(cmd.githubUrl), logger);
|
||||
const tracerConfig = await init_1.runInit(codeql, config);
|
||||
if (tracerConfig === undefined) {
|
||||
return;
|
||||
}
|
||||
// Always output a json file of the env that can be consumed programatically
|
||||
const jsonEnvFile = path.join(config.tempDir, codeqlEnvJsonFilename);
|
||||
fs.writeFileSync(jsonEnvFile, JSON.stringify(tracerConfig.env));
|
||||
if (process.platform === 'win32') {
|
||||
const batEnvFile = path.join(config.tempDir, 'codeql-env.bat');
|
||||
const batEnvFileContents = Object.entries(tracerConfig.env)
|
||||
.map(([key, value]) => `Set ${key}=${value}`)
|
||||
.join('\n');
|
||||
fs.writeFileSync(batEnvFile, batEnvFileContents);
|
||||
const powershellEnvFile = path.join(config.tempDir, 'codeql-env.sh');
|
||||
const powershellEnvFileContents = Object.entries(tracerConfig.env)
|
||||
.map(([key, value]) => `$env:${key}="${value}"`)
|
||||
.join('\n');
|
||||
fs.writeFileSync(powershellEnvFile, powershellEnvFileContents);
|
||||
logger.info(`\nCodeQL environment output to "${jsonEnvFile}", "${batEnvFile}" and "${powershellEnvFile}". ` +
|
||||
`Please export these variables to future processes so the build can be traced. ` +
|
||||
`If using cmd/batch run "call ${batEnvFile}" ` +
|
||||
`or if using PowerShell run "cat ${powershellEnvFile} | Invoke-Expression".`);
|
||||
}
|
||||
else {
|
||||
// Assume that anything that's not windows is using a unix-style shell
|
||||
const shEnvFile = path.join(config.tempDir, 'codeql-env.sh');
|
||||
const shEnvFileContents = Object.entries(tracerConfig.env)
|
||||
// Some vars contain ${LIB} that we do not want to be expanded when executing this script
|
||||
.map(([key, value]) => `export ${key}="${value.replace('$', '\\$')}"`)
|
||||
.join('\n');
|
||||
fs.writeFileSync(shEnvFile, shEnvFileContents);
|
||||
logger.info(`\nCodeQL environment output to "${jsonEnvFile}" and "${shEnvFile}". ` +
|
||||
`Please export these variables to future processes so the build can be traced, ` +
|
||||
`for example by running ". ${shEnvFile}".`);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
logger.error('Init failed');
|
||||
logger.error(e);
|
||||
process.exitCode = 1;
|
||||
}
|
||||
});
|
||||
program
|
||||
.command('autobuild')
|
||||
.description('Attempts to automatically build code')
|
||||
.option('--language <language>', 'The language to build. Otherwise will detect the dominant compiled language.')
|
||||
.option('--temp-dir <dir>', 'Directory to use for temporary files. Default is "./codeql-runner".')
|
||||
.option('--debug', 'Print more verbose output', false)
|
||||
.action(async (cmd) => {
|
||||
const logger = logging_1.getRunnerLogger(cmd.debug);
|
||||
try {
|
||||
const config = await config_utils_1.getConfig(getTempDir(cmd.tempDir), logger);
|
||||
if (config === undefined) {
|
||||
throw new Error("Config file could not be found at expected location. " +
|
||||
"Was the 'init' command run with the same '--temp-dir' argument as this command.");
|
||||
}
|
||||
importTracerEnvironment(config);
|
||||
let language = undefined;
|
||||
if (cmd.language !== undefined) {
|
||||
language = languages_1.parseLanguage(cmd.language);
|
||||
if (language === undefined || !config.languages.includes(language)) {
|
||||
throw new Error(`"${cmd.language}" is not a recognised language. ` +
|
||||
`Known languages in this project are ${config.languages.join(', ')}.`);
|
||||
}
|
||||
}
|
||||
else {
|
||||
language = autobuild_1.determineAutobuildLanguage(config, logger);
|
||||
}
|
||||
if (language !== undefined) {
|
||||
await autobuild_1.runAutobuild(language, config, logger);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
logger.error('Autobuild failed');
|
||||
logger.error(e);
|
||||
process.exitCode = 1;
|
||||
}
|
||||
});
|
||||
program
|
||||
.command('analyze')
|
||||
.description('Finishes extracting code and runs CodeQL queries')
|
||||
.requiredOption('--repository <repository>', 'Repository name. (Required)')
|
||||
.requiredOption('--commit <commit>', 'SHA of commit that was analyzed. (Required)')
|
||||
.requiredOption('--ref <ref>', 'Name of ref that was analyzed. (Required)')
|
||||
.requiredOption('--github-url <url>', 'URL of GitHub instance. (Required)')
|
||||
.requiredOption('--github-auth <auth>', 'GitHub Apps token or personal access token. (Required)')
|
||||
.option('--checkout-path <path>', 'Checkout path. Default is the current working directory.')
|
||||
.option('--no-upload', 'Do not upload results after analysis.', false)
|
||||
.option('--output-dir <dir>', 'Directory to output SARIF files to. Default is in the temp directory.')
|
||||
.option('--ram <ram>', 'Amount of memory to use when running queries. Default is to use all available memory.')
|
||||
.option('--threads <threads>', 'Number of threads to use when running queries. ' +
|
||||
'Default is to use all available cores.')
|
||||
.option('--temp-dir <dir>', 'Directory to use for temporary files. Default is "./codeql-runner".')
|
||||
.option('--debug', 'Print more verbose output', false)
|
||||
.action(async (cmd) => {
|
||||
const logger = logging_1.getRunnerLogger(cmd.debug);
|
||||
try {
|
||||
const tempDir = getTempDir(cmd.tempDir);
|
||||
const outputDir = cmd.outputDir || path.join(tempDir, 'codeql-sarif');
|
||||
const config = await config_utils_1.getConfig(getTempDir(cmd.tempDir), logger);
|
||||
if (config === undefined) {
|
||||
throw new Error("Config file could not be found at expected location. " +
|
||||
"Was the 'init' command run with the same '--temp-dir' argument as this command.");
|
||||
}
|
||||
await analyze_1.runAnalyze(repository_1.parseRepositoryNwo(cmd.repository), cmd.commit, parseRef(cmd.ref), undefined, undefined, undefined, cmd.checkoutPath || process.cwd(), undefined, cmd.githubAuth, parseGithubUrl(cmd.githubUrl), cmd.upload, 'runner', outputDir, util_1.getMemoryFlag(cmd.ram), util_1.getThreadsFlag(cmd.threads, logger), config, logger);
|
||||
}
|
||||
catch (e) {
|
||||
logger.error('Analyze failed');
|
||||
logger.error(e);
|
||||
process.exitCode = 1;
|
||||
}
|
||||
});
|
||||
program
|
||||
.command('upload')
|
||||
.description('Uploads a SARIF file, or all SARIF files from a directory, to code scanning')
|
||||
.requiredOption('--sarif-file <file>', 'SARIF file to upload, or a directory containing multiple SARIF files. (Required)')
|
||||
.requiredOption('--repository <repository>', 'Repository name. (Required)')
|
||||
.requiredOption('--commit <commit>', 'SHA of commit that was analyzed. (Required)')
|
||||
.requiredOption('--ref <ref>', 'Name of ref that was analyzed. (Required)')
|
||||
.requiredOption('--github-url <url>', 'URL of GitHub instance. (Required)')
|
||||
.requiredOption('--github-auth <auth>', 'GitHub Apps token or personal access token. (Required)')
|
||||
.option('--checkout-path <path>', 'Checkout path. Default is the current working directory.')
|
||||
.option('--debug', 'Print more verbose output', false)
|
||||
.action(async (cmd) => {
|
||||
const logger = logging_1.getRunnerLogger(cmd.debug);
|
||||
try {
|
||||
await upload_lib.upload(cmd.sarifFile, repository_1.parseRepositoryNwo(cmd.repository), cmd.commit, parseRef(cmd.ref), undefined, undefined, undefined, cmd.checkoutPath || process.cwd(), undefined, cmd.githubAuth, parseGithubUrl(cmd.githubUrl), 'runner', logger);
|
||||
}
|
||||
catch (e) {
|
||||
logger.error('Upload failed');
|
||||
logger.error(e);
|
||||
process.exitCode = 1;
|
||||
}
|
||||
});
|
||||
program.parse(process.argv);
|
||||
//# sourceMappingURL=runner.js.map
|
||||
1
lib/runner.js.map
Normal file
1
lib/runner.js.map
Normal file
File diff suppressed because one or more lines are too long
76
lib/setup-tools.js
generated
76
lib/setup-tools.js
generated
|
|
@ -1,76 +0,0 @@
|
|||
"use strict";
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const toolcache = __importStar(require("@actions/tool-cache"));
|
||||
const path = __importStar(require("path"));
|
||||
const semver = __importStar(require("semver"));
|
||||
class CodeQLSetup {
|
||||
constructor(codeqlDist) {
|
||||
this.dist = codeqlDist;
|
||||
this.tools = path.join(this.dist, 'tools');
|
||||
this.cmd = path.join(codeqlDist, 'codeql');
|
||||
// TODO check process.arch ?
|
||||
if (process.platform === 'win32') {
|
||||
this.platform = 'win64';
|
||||
if (this.cmd.endsWith('codeql')) {
|
||||
this.cmd += ".exe";
|
||||
}
|
||||
}
|
||||
else if (process.platform === 'linux') {
|
||||
this.platform = 'linux64';
|
||||
}
|
||||
else if (process.platform === 'darwin') {
|
||||
this.platform = 'osx64';
|
||||
}
|
||||
else {
|
||||
throw new Error("Unsupported plaform: " + process.platform);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.CodeQLSetup = CodeQLSetup;
|
||||
async function setupCodeQL() {
|
||||
try {
|
||||
const codeqlURL = core.getInput('tools', { required: true });
|
||||
const codeqlURLVersion = getCodeQLURLVersion(codeqlURL);
|
||||
let codeqlFolder = toolcache.find('CodeQL', codeqlURLVersion);
|
||||
if (codeqlFolder) {
|
||||
core.debug(`CodeQL found in cache ${codeqlFolder}`);
|
||||
}
|
||||
else {
|
||||
const codeqlPath = await toolcache.downloadTool(codeqlURL);
|
||||
const codeqlExtracted = await toolcache.extractTar(codeqlPath);
|
||||
codeqlFolder = await toolcache.cacheDir(codeqlExtracted, 'CodeQL', codeqlURLVersion);
|
||||
}
|
||||
return new CodeQLSetup(path.join(codeqlFolder, 'codeql'));
|
||||
}
|
||||
catch (e) {
|
||||
core.error(e);
|
||||
throw new Error("Unable to download and extract CodeQL CLI");
|
||||
}
|
||||
}
|
||||
exports.setupCodeQL = setupCodeQL;
|
||||
function getCodeQLURLVersion(url) {
|
||||
const match = url.match(/\/codeql-bundle-(.*)\//);
|
||||
if (match === null || match.length < 2) {
|
||||
throw new Error(`Malformed tools url: ${url}. Version could not be inferred`);
|
||||
}
|
||||
let version = match[1];
|
||||
if (!semver.valid(version)) {
|
||||
core.debug(`Bundle version ${version} is not in SemVer format. Will treat it as pre-release 0.0.0-${version}.`);
|
||||
version = '0.0.0-' + version;
|
||||
}
|
||||
const s = semver.clean(version);
|
||||
if (!s) {
|
||||
throw new Error(`Malformed tools url ${url}. Version should be in SemVer format but have ${version} instead`);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
exports.getCodeQLURLVersion = getCodeQLURLVersion;
|
||||
//# sourceMappingURL=setup-tools.js.map
|
||||
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"setup-tools.js","sourceRoot":"","sources":["../src/setup-tools.ts"],"names":[],"mappings":";;;;;;;;;AAAA,oDAAsC;AACtC,+DAAiD;AACjD,2CAA6B;AAC7B,+CAAiC;AAEjC,MAAa,WAAW;IAMtB,YAAY,UAAkB;QAC5B,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAC3C,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;QAC3C,4BAA4B;QAC5B,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE;YAChC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;YACxB,IAAI,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;gBAC/B,IAAI,CAAC,GAAG,IAAI,MAAM,CAAC;aACpB;SACF;aAAM,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE;YACvC,IAAI,CA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CAAC;IAClD,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;QACtC,MAAM,IAAI,KAAK,CAAC,wBAAwB,GAAG,iCAAiC,CAAC,CAAC;KAC/E;IAED,IAAI,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IAEvB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE;QAC1B,IAAI,CAAC,KAAK,CAAC,kBAAkB,OAAO,gEAAgE,OAAO,GAAG,CAAC,CAAC;QAChH,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;KAC9B;IAED,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAChC,IAAI,CAAC,CAAC,EAAE;QACN,MAAM,IAAI,KAAK,CAAC,uBAAuB,GAAG,iDAAiD,OAAO,UAAU,CAAC,CAAC;KAC/G;IAED,OAAO,CAAC,CAAC;AACX,CAAC;AApBD,kDAoBC"}
|
||||
60
lib/setup-tools.test.js
generated
60
lib/setup-tools.test.js
generated
|
|
@ -1,60 +0,0 @@
|
|||
"use strict";
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const toolcache = __importStar(require("@actions/tool-cache"));
|
||||
const ava_1 = __importDefault(require("ava"));
|
||||
const nock_1 = __importDefault(require("nock"));
|
||||
const path = __importStar(require("path"));
|
||||
const setupTools = __importStar(require("./setup-tools"));
|
||||
const testing_utils_1 = require("./testing-utils");
|
||||
const util = __importStar(require("./util"));
|
||||
testing_utils_1.silenceDebugOutput(ava_1.default);
|
||||
ava_1.default('download codeql bundle cache', async (t) => {
|
||||
await util.withTmpDir(async (tmpDir) => {
|
||||
process.env['GITHUB_WORKSPACE'] = tmpDir;
|
||||
process.env['RUNNER_TEMP'] = path.join(tmpDir, 'temp');
|
||||
process.env['RUNNER_TOOL_CACHE'] = path.join(tmpDir, 'cache');
|
||||
const versions = ['20200601', '20200610'];
|
||||
for (let i = 0; i < versions.length; i++) {
|
||||
const version = versions[i];
|
||||
nock_1.default('https://example.com')
|
||||
.get(`/download/codeql-bundle-${version}/codeql-bundle.tar.gz`)
|
||||
.replyWithFile(200, path.join(__dirname, `/../src/testdata/codeql-bundle.tar.gz`));
|
||||
process.env['INPUT_TOOLS'] = `https://example.com/download/codeql-bundle-${version}/codeql-bundle.tar.gz`;
|
||||
await setupTools.setupCodeQL();
|
||||
t.assert(toolcache.find('CodeQL', `0.0.0-${version}`));
|
||||
}
|
||||
const cachedVersions = toolcache.findAllVersions('CodeQL');
|
||||
t.is(cachedVersions.length, 2);
|
||||
});
|
||||
});
|
||||
ava_1.default('parse codeql bundle url version', t => {
|
||||
const tests = {
|
||||
'20200601': '0.0.0-20200601',
|
||||
'20200601.0': '0.0.0-20200601.0',
|
||||
'20200601.0.0': '20200601.0.0',
|
||||
'1.2.3': '1.2.3',
|
||||
'1.2.3-alpha': '1.2.3-alpha',
|
||||
'1.2.3-beta.1': '1.2.3-beta.1',
|
||||
};
|
||||
for (const [version, expectedVersion] of Object.entries(tests)) {
|
||||
const url = `https://github.com/.../codeql-bundle-${version}/...`;
|
||||
try {
|
||||
const parsedVersion = setupTools.getCodeQLURLVersion(url);
|
||||
t.deepEqual(parsedVersion, expectedVersion);
|
||||
}
|
||||
catch (e) {
|
||||
t.fail(e.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=setup-tools.test.js.map
|
||||
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"setup-tools.test.js","sourceRoot":"","sources":["../src/setup-tools.test.ts"],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,eAAe,CAAC,QAAQ,CAAC,CAAC;QAE3D,CAAC,CAAC,EAAE,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,aAAI,CAAC,iCAAiC,EAAE,CAAC,CAAC,EAAE;IAE1C,MAAM,KAAK,GAAG;QACZ,UAAU,EAAE,gBAAgB;QAC5B,YAAY,EAAE,kBAAkB;QAChC,cAAc,EAAE,cAAc;QAC9B,OAAO,EAAE,OAAO;QAChB,aAAa,EAAE,aAAa;QAC5B,cAAc,EAAE,cAAc;KAC/B,CAAC;IAEF,KAAK,MAAM,CAAC,OAAO,EAAE,eAAe,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QAC9D,MAAM,GAAG,GAAG,wCAAwC,OAAO,MAAM,CAAC;QAElE,IAAI;YACF,MAAM,aAAa,GAAG,UAAU,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;YAC1D,CAAC,CAAC,SAAS,CAAC,aAAa,EAAE,eAAe,CAAC,CAAC;SAC7C;QAAC,OAAO,CAAC,EAAE;YACV,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;SACnB;KACF;AACH,CAAC,CAAC,CAAC"}
|
||||
225
lib/setup-tracer.js
generated
225
lib/setup-tracer.js
generated
|
|
@ -1,225 +0,0 @@
|
|||
"use strict";
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const exec = __importStar(require("@actions/exec"));
|
||||
const fs = __importStar(require("fs"));
|
||||
const path = __importStar(require("path"));
|
||||
const analysisPaths = __importStar(require("./analysis-paths"));
|
||||
const codeql_1 = require("./codeql");
|
||||
const configUtils = __importStar(require("./config-utils"));
|
||||
const languages_1 = require("./languages");
|
||||
const util = __importStar(require("./util"));
|
||||
const CRITICAL_TRACER_VARS = new Set(['SEMMLE_PRELOAD_libtrace',
|
||||
,
|
||||
'SEMMLE_RUNNER',
|
||||
,
|
||||
'SEMMLE_COPY_EXECUTABLES_ROOT',
|
||||
,
|
||||
'SEMMLE_DEPTRACE_SOCKET',
|
||||
,
|
||||
'SEMMLE_JAVA_TOOL_OPTIONS'
|
||||
]);
|
||||
async function tracerConfig(codeql, database, compilerSpec) {
|
||||
const env = await codeql.getTracerEnv(database, compilerSpec);
|
||||
const config = env['ODASA_TRACER_CONFIGURATION'];
|
||||
const info = { spec: config, env: {} };
|
||||
// Extract critical tracer variables from the environment
|
||||
for (let entry of Object.entries(env)) {
|
||||
const key = entry[0];
|
||||
const value = entry[1];
|
||||
// skip ODASA_TRACER_CONFIGURATION as it is handled separately
|
||||
if (key === 'ODASA_TRACER_CONFIGURATION') {
|
||||
continue;
|
||||
}
|
||||
// skip undefined values
|
||||
if (typeof value === 'undefined') {
|
||||
continue;
|
||||
}
|
||||
// Keep variables that do not exist in current environment. In addition always keep
|
||||
// critical and CODEQL_ variables
|
||||
if (typeof process.env[key] === 'undefined' || CRITICAL_TRACER_VARS.has(key) || key.startsWith('CODEQL_')) {
|
||||
info.env[key] = value;
|
||||
}
|
||||
}
|
||||
return info;
|
||||
}
|
||||
function concatTracerConfigs(tracerConfigs, config) {
|
||||
// A tracer config is a map containing additional environment variables and a tracer 'spec' file.
|
||||
// A tracer 'spec' file has the following format [log_file, number_of_blocks, blocks_text]
|
||||
// Merge the environments
|
||||
const env = {};
|
||||
let copyExecutables = false;
|
||||
let envSize = 0;
|
||||
for (const v of tracerConfigs) {
|
||||
for (let e of Object.entries(v.env)) {
|
||||
const name = e[0];
|
||||
const value = e[1];
|
||||
// skip SEMMLE_COPY_EXECUTABLES_ROOT as it is handled separately
|
||||
if (name === 'SEMMLE_COPY_EXECUTABLES_ROOT') {
|
||||
copyExecutables = true;
|
||||
}
|
||||
else if (name in env) {
|
||||
if (env[name] !== value) {
|
||||
throw Error('Incompatible values in environment parameter ' +
|
||||
name + ': ' + env[name] + ' and ' + value);
|
||||
}
|
||||
}
|
||||
else {
|
||||
env[name] = value;
|
||||
envSize += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Concatenate spec files into a new spec file
|
||||
let languages = Object.keys(tracerConfigs);
|
||||
const cppIndex = languages.indexOf('cpp');
|
||||
// Make sure cpp is the last language, if it's present since it must be concatenated last
|
||||
if (cppIndex !== -1) {
|
||||
let lastLang = languages[languages.length - 1];
|
||||
languages[languages.length - 1] = languages[cppIndex];
|
||||
languages[cppIndex] = lastLang;
|
||||
}
|
||||
let totalLines = [];
|
||||
let totalCount = 0;
|
||||
for (let lang of languages) {
|
||||
const lines = fs.readFileSync(tracerConfigs[lang].spec, 'utf8').split(/\r?\n/);
|
||||
const count = parseInt(lines[1], 10);
|
||||
totalCount += count;
|
||||
totalLines.push(...lines.slice(2));
|
||||
}
|
||||
const newLogFilePath = path.resolve(config.tempDir, 'compound-build-tracer.log');
|
||||
const spec = path.resolve(config.tempDir, 'compound-spec');
|
||||
const compoundTempFolder = path.resolve(config.tempDir, 'compound-temp');
|
||||
const newSpecContent = [newLogFilePath, totalCount.toString(10), ...totalLines];
|
||||
if (copyExecutables) {
|
||||
env['SEMMLE_COPY_EXECUTABLES_ROOT'] = compoundTempFolder;
|
||||
envSize += 1;
|
||||
}
|
||||
fs.writeFileSync(spec, newSpecContent.join('\n'));
|
||||
// Prepare the content of the compound environment file
|
||||
let buffer = Buffer.alloc(4);
|
||||
buffer.writeInt32LE(envSize, 0);
|
||||
for (let e of Object.entries(env)) {
|
||||
const key = e[0];
|
||||
const value = e[1];
|
||||
const lineBuffer = new Buffer(key + '=' + value + '\0', 'utf8');
|
||||
const sizeBuffer = Buffer.alloc(4);
|
||||
sizeBuffer.writeInt32LE(lineBuffer.length, 0);
|
||||
buffer = Buffer.concat([buffer, sizeBuffer, lineBuffer]);
|
||||
}
|
||||
// Write the compound environment
|
||||
const envPath = spec + '.environment';
|
||||
fs.writeFileSync(envPath, buffer);
|
||||
return { env, spec };
|
||||
}
|
||||
async function sendSuccessStatusReport(startedAt, config) {
|
||||
const statusReportBase = await util.createStatusReportBase('init', 'success', startedAt);
|
||||
const languages = config.languages.join(',');
|
||||
const workflowLanguages = core.getInput('languages', { required: false });
|
||||
const paths = (config.originalUserInput.paths || []).join(',');
|
||||
const pathsIgnore = (config.originalUserInput['paths-ignore'] || []).join(',');
|
||||
const disableDefaultQueries = config.originalUserInput['disable-default-queries'] ? languages : '';
|
||||
const queries = (config.originalUserInput.queries || []).map(q => q.uses).join(',');
|
||||
const statusReport = {
|
||||
...statusReportBase,
|
||||
languages: languages,
|
||||
workflow_languages: workflowLanguages,
|
||||
paths: paths,
|
||||
paths_ignore: pathsIgnore,
|
||||
disable_default_queries: disableDefaultQueries,
|
||||
queries: queries,
|
||||
};
|
||||
await util.sendStatusReport(statusReport);
|
||||
}
|
||||
async function run() {
|
||||
const startedAt = new Date();
|
||||
let config;
|
||||
let codeql;
|
||||
try {
|
||||
util.prepareLocalRunEnvironment();
|
||||
if (!await util.sendStatusReport(await util.createStatusReportBase('init', 'starting', startedAt), true)) {
|
||||
return;
|
||||
}
|
||||
core.startGroup('Setup CodeQL tools');
|
||||
codeql = await codeql_1.setupCodeQL();
|
||||
await codeql.printVersion();
|
||||
core.endGroup();
|
||||
core.startGroup('Load language configuration');
|
||||
config = await configUtils.initConfig(util.getRequiredEnvParam('RUNNER_TEMP'), util.getRequiredEnvParam('RUNNER_TOOL_CACHE'), codeql);
|
||||
analysisPaths.includeAndExcludeAnalysisPaths(config);
|
||||
core.endGroup();
|
||||
}
|
||||
catch (e) {
|
||||
core.setFailed(e.message);
|
||||
console.log(e);
|
||||
await util.sendStatusReport(await util.createStatusReportBase('init', 'aborted', startedAt, e.message));
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const sourceRoot = path.resolve();
|
||||
// Forward Go flags
|
||||
const goFlags = process.env['GOFLAGS'];
|
||||
if (goFlags) {
|
||||
core.exportVariable('GOFLAGS', goFlags);
|
||||
core.warning("Passing the GOFLAGS env parameter to the init action is deprecated. Please move this to the analyze action.");
|
||||
}
|
||||
// Setup CODEQL_RAM flag (todo improve this https://github.com/github/dsp-code-scanning/issues/935)
|
||||
const codeqlRam = process.env['CODEQL_RAM'] || '6500';
|
||||
core.exportVariable('CODEQL_RAM', codeqlRam);
|
||||
const databaseFolder = util.getCodeQLDatabasesDir(config.tempDir);
|
||||
fs.mkdirSync(databaseFolder, { recursive: true });
|
||||
let tracedLanguageConfigs = [];
|
||||
// TODO: replace this code once CodeQL supports multi-language tracing
|
||||
for (let language of config.languages) {
|
||||
const languageDatabase = path.join(databaseFolder, language);
|
||||
// Init language database
|
||||
await codeql.databaseInit(languageDatabase, language, sourceRoot);
|
||||
// TODO: add better detection of 'traced languages' instead of using a hard coded list
|
||||
if (languages_1.isTracedLanguage(language)) {
|
||||
const config = await tracerConfig(codeql, languageDatabase);
|
||||
tracedLanguageConfigs.push(config);
|
||||
}
|
||||
}
|
||||
if (tracedLanguageConfigs.length > 0) {
|
||||
const mainTracerConfig = concatTracerConfigs(tracedLanguageConfigs, config);
|
||||
if (mainTracerConfig.spec) {
|
||||
for (let entry of Object.entries(mainTracerConfig.env)) {
|
||||
core.exportVariable(entry[0], entry[1]);
|
||||
}
|
||||
core.exportVariable('ODASA_TRACER_CONFIGURATION', mainTracerConfig.spec);
|
||||
const codeQLDir = path.dirname(codeql.getPath());
|
||||
if (process.platform === 'darwin') {
|
||||
core.exportVariable('DYLD_INSERT_LIBRARIES', path.join(codeQLDir, 'tools', 'osx64', 'libtrace.dylib'));
|
||||
}
|
||||
else if (process.platform === 'win32') {
|
||||
await exec.exec('powershell', [
|
||||
path.resolve(__dirname, '..', 'src', 'inject-tracer.ps1'),
|
||||
path.resolve(codeQLDir, 'tools', 'win64', 'tracer.exe'),
|
||||
], { env: { 'ODASA_TRACER_CONFIGURATION': mainTracerConfig.spec } });
|
||||
}
|
||||
else {
|
||||
core.exportVariable('LD_PRELOAD', path.join(codeQLDir, 'tools', 'linux64', '${LIB}trace.so'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
core.setFailed(error.message);
|
||||
console.log(error);
|
||||
await util.sendStatusReport(await util.createStatusReportBase('init', 'failure', startedAt, error.message, error.stack));
|
||||
return;
|
||||
}
|
||||
await sendSuccessStatusReport(startedAt, config);
|
||||
}
|
||||
run().catch(e => {
|
||||
core.setFailed("init action failed: " + e);
|
||||
console.log(e);
|
||||
});
|
||||
//# sourceMappingURL=setup-tracer.js.map
|
||||
File diff suppressed because one or more lines are too long
22
lib/test-utils.js
generated
22
lib/test-utils.js
generated
|
|
@ -1,22 +0,0 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
function silenceDebugOutput(test) {
|
||||
const typedTest = test;
|
||||
typedTest.beforeEach(t => {
|
||||
const processStdoutWrite = process.stdout.write.bind(process.stdout);
|
||||
t.context.write = processStdoutWrite;
|
||||
process.stdout.write = (str, encoding, cb) => {
|
||||
// Core library will directly call process.stdout.write for commands
|
||||
// We don't want :: commands to be executed by the runner during tests
|
||||
if (!str.match(/^::/)) {
|
||||
processStdoutWrite(str, encoding, cb);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
});
|
||||
typedTest.afterEach(t => {
|
||||
process.stdout.write = t.context.write;
|
||||
});
|
||||
}
|
||||
exports.silenceDebugOutput = silenceDebugOutput;
|
||||
//# sourceMappingURL=test-utils.js.map
|
||||
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"test-utils.js","sourceRoot":"","sources":["../src/test-utils.ts"],"names":[],"mappings":";;AAEA,SAAgB,kBAAkB,CAAC,IAAwB;IACzD,MAAM,SAAS,GAAG,IAAmC,CAAC;IAEtD,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE;QACrB,MAAM,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QACrE,CAAC,CAAC,OAAO,CAAC,KAAK,GAAG,kBAAkB,CAAC;QACrC,OAAO,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,GAAQ,EAAE,QAAc,EAAE,EAA0B,EAAE,EAAE;YAC5E,oEAAoE;YACpE,sEAAsE;YACtE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;gBACnB,kBAAkB,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC;aACzC;YACD,OAAO,IAAI,CAAC;QAChB,CAAC,CAAC;IACN,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE;QACpB,OAAO,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;IAC3C,CAAC,CAAC,CAAC;AACL,CAAC;AAnBD,gDAmBC"}
|
||||
3
lib/testing-utils.js
generated
3
lib/testing-utils.js
generated
|
|
@ -56,9 +56,6 @@ function setupTests(test) {
|
|||
// process.env only has strings fields, so a shallow copy is fine.
|
||||
t.context.env = {};
|
||||
Object.assign(t.context.env, process.env);
|
||||
// Any test that runs code that expects to only be run on actions
|
||||
// will depend on various environment variables.
|
||||
process.env['GITHUB_API_URL'] = 'https://github.localhost/api/v3';
|
||||
});
|
||||
typedTest.afterEach.always(t => {
|
||||
// Restore stdout and stderr
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"testing-utils.js","sourceRoot":"","sources":["../src/testing-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,kDAA0B;AAE1B,iDAAmC;AAInC,SAAS,UAAU,CAAC,OAAoB;IACtC,8CAA8C;IAC9C,gCAAgC;IAChC,2EAA2E;IAC3E,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,CAAC,OAAO,CAAC,WAAW,GAAG,kBAAkB,CAAC;QAC3C,OAAO,CAAC,MAAM,CAAC,KAAK,GAAG,UAAU,CAAC,CAAC,CAAC,OAAO,CAAQ,CAAC;QAEpD,mEAAmE;QACnE,wEAAwE;QACxE,kEAAkE;QAClE,CAAC,CAAC,OAAO,CAAC,GAAG,GAAG,EAAE,CAAC;QACnB,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE;QAC7B,4BAA4B;QAC5B,0DAA0D;QAC1D,OAAO,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC;QAC7C,OAAO,CAAC,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC;QAC7C,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE;YACb,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;SAC5C;QAED,uCAAuC;QACvC,eAAK,CAAC,OAAO,EAAE,CAAC;QAEhB,oCAAoC;QACpC,OAAO,CAAC,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC;IAC9B,CAAC,CAAC,CAAC;AACL,CAAC;AAvCD,gCAuCC"}
|
||||
143
lib/tracer-config.js
generated
Normal file
143
lib/tracer-config.js
generated
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
"use strict";
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fs = __importStar(require("fs"));
|
||||
const path = __importStar(require("path"));
|
||||
const languages_1 = require("./languages");
|
||||
const util = __importStar(require("./util"));
|
||||
const CRITICAL_TRACER_VARS = new Set(['SEMMLE_PRELOAD_libtrace',
|
||||
,
|
||||
'SEMMLE_RUNNER',
|
||||
,
|
||||
'SEMMLE_COPY_EXECUTABLES_ROOT',
|
||||
,
|
||||
'SEMMLE_DEPTRACE_SOCKET',
|
||||
,
|
||||
'SEMMLE_JAVA_TOOL_OPTIONS'
|
||||
]);
|
||||
async function getTracerConfigForLanguage(codeql, config, language) {
|
||||
const env = await codeql.getTracerEnv(util.getCodeQLDatabasePath(config.tempDir, language));
|
||||
const spec = env['ODASA_TRACER_CONFIGURATION'];
|
||||
const info = { spec, env: {} };
|
||||
// Extract critical tracer variables from the environment
|
||||
for (let entry of Object.entries(env)) {
|
||||
const key = entry[0];
|
||||
const value = entry[1];
|
||||
// skip ODASA_TRACER_CONFIGURATION as it is handled separately
|
||||
if (key === 'ODASA_TRACER_CONFIGURATION') {
|
||||
continue;
|
||||
}
|
||||
// skip undefined values
|
||||
if (typeof value === 'undefined') {
|
||||
continue;
|
||||
}
|
||||
// Keep variables that do not exist in current environment. In addition always keep
|
||||
// critical and CODEQL_ variables
|
||||
if (typeof process.env[key] === 'undefined' || CRITICAL_TRACER_VARS.has(key) || key.startsWith('CODEQL_')) {
|
||||
info.env[key] = value;
|
||||
}
|
||||
}
|
||||
return info;
|
||||
}
|
||||
exports.getTracerConfigForLanguage = getTracerConfigForLanguage;
|
||||
function concatTracerConfigs(tracerConfigs, config) {
|
||||
// A tracer config is a map containing additional environment variables and a tracer 'spec' file.
|
||||
// A tracer 'spec' file has the following format [log_file, number_of_blocks, blocks_text]
|
||||
// Merge the environments
|
||||
const env = {};
|
||||
let copyExecutables = false;
|
||||
let envSize = 0;
|
||||
for (const v of Object.values(tracerConfigs)) {
|
||||
for (let e of Object.entries(v.env)) {
|
||||
const name = e[0];
|
||||
const value = e[1];
|
||||
// skip SEMMLE_COPY_EXECUTABLES_ROOT as it is handled separately
|
||||
if (name === 'SEMMLE_COPY_EXECUTABLES_ROOT') {
|
||||
copyExecutables = true;
|
||||
}
|
||||
else if (name in env) {
|
||||
if (env[name] !== value) {
|
||||
throw Error('Incompatible values in environment parameter ' +
|
||||
name + ': ' + env[name] + ' and ' + value);
|
||||
}
|
||||
}
|
||||
else {
|
||||
env[name] = value;
|
||||
envSize += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Concatenate spec files into a new spec file
|
||||
let languages = Object.keys(tracerConfigs);
|
||||
const cppIndex = languages.indexOf('cpp');
|
||||
// Make sure cpp is the last language, if it's present since it must be concatenated last
|
||||
if (cppIndex !== -1) {
|
||||
let lastLang = languages[languages.length - 1];
|
||||
languages[languages.length - 1] = languages[cppIndex];
|
||||
languages[cppIndex] = lastLang;
|
||||
}
|
||||
let totalLines = [];
|
||||
let totalCount = 0;
|
||||
for (let lang of languages) {
|
||||
const lines = fs.readFileSync(tracerConfigs[lang].spec, 'utf8').split(/\r?\n/);
|
||||
const count = parseInt(lines[1], 10);
|
||||
totalCount += count;
|
||||
totalLines.push(...lines.slice(2));
|
||||
}
|
||||
const newLogFilePath = path.resolve(config.tempDir, 'compound-build-tracer.log');
|
||||
const spec = path.resolve(config.tempDir, 'compound-spec');
|
||||
const compoundTempFolder = path.resolve(config.tempDir, 'compound-temp');
|
||||
const newSpecContent = [newLogFilePath, totalCount.toString(10), ...totalLines];
|
||||
if (copyExecutables) {
|
||||
env['SEMMLE_COPY_EXECUTABLES_ROOT'] = compoundTempFolder;
|
||||
envSize += 1;
|
||||
}
|
||||
fs.writeFileSync(spec, newSpecContent.join('\n'));
|
||||
// Prepare the content of the compound environment file
|
||||
let buffer = Buffer.alloc(4);
|
||||
buffer.writeInt32LE(envSize, 0);
|
||||
for (let e of Object.entries(env)) {
|
||||
const key = e[0];
|
||||
const value = e[1];
|
||||
const lineBuffer = new Buffer(key + '=' + value + '\0', 'utf8');
|
||||
const sizeBuffer = Buffer.alloc(4);
|
||||
sizeBuffer.writeInt32LE(lineBuffer.length, 0);
|
||||
buffer = Buffer.concat([buffer, sizeBuffer, lineBuffer]);
|
||||
}
|
||||
// Write the compound environment
|
||||
const envPath = spec + '.environment';
|
||||
fs.writeFileSync(envPath, buffer);
|
||||
return { env, spec };
|
||||
}
|
||||
exports.concatTracerConfigs = concatTracerConfigs;
|
||||
async function getCombinedTracerConfig(config, codeql) {
|
||||
// Abort if there are no traced languages as there's nothing to do
|
||||
const tracedLanguages = config.languages.filter(languages_1.isTracedLanguage);
|
||||
if (tracedLanguages.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
// Get all the tracer configs and combine them together
|
||||
const tracedLanguageConfigs = {};
|
||||
for (const language of tracedLanguages) {
|
||||
tracedLanguageConfigs[language] = await getTracerConfigForLanguage(codeql, config, language);
|
||||
}
|
||||
const mainTracerConfig = concatTracerConfigs(tracedLanguageConfigs, config);
|
||||
// Add a couple more variables
|
||||
mainTracerConfig.env['ODASA_TRACER_CONFIGURATION'] = mainTracerConfig.spec;
|
||||
const codeQLDir = path.dirname(codeql.getPath());
|
||||
if (process.platform === 'darwin') {
|
||||
mainTracerConfig.env['DYLD_INSERT_LIBRARIES'] = path.join(codeQLDir, 'tools', 'osx64', 'libtrace.dylib');
|
||||
}
|
||||
else if (process.platform !== 'win32') {
|
||||
mainTracerConfig.env['LD_PRELOAD'] = path.join(codeQLDir, 'tools', 'linux64', '${LIB}trace.so');
|
||||
}
|
||||
return mainTracerConfig;
|
||||
}
|
||||
exports.getCombinedTracerConfig = getCombinedTracerConfig;
|
||||
//# sourceMappingURL=tracer-config.js.map
|
||||
1
lib/tracer-config.js.map
Normal file
1
lib/tracer-config.js.map
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"tracer-config.js","sourceRoot":"","sources":["../src/tracer-config.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uCAAyB;AACzB,2CAA6B;AAI7B,2CAAyD;AACzD,6CAA+B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BAA8B;IAC9B,gBAAgB,CAAC,GAAG,CAAC,4BAA4B,CAAC,GAAG,gBAAgB,CAAC,IAAI,CAAC;IAC3E,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;IACjD,IAAI,OAAO,CAAC,QAAQ,KAAK,QAAQ,EAAE;QACjC,gBAAgB,CAAC,GAAG,CAAC,uBAAuB,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,gBAAgB,CAAC,CAAC;KAC1G;SAAM,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE;QACvC,gBAAgB,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,gBAAgB,CAAC,CAAC;KACjG;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AA3BD,0DA2BC"}
|
||||
278
lib/tracer-config.test.js
generated
Normal file
278
lib/tracer-config.test.js
generated
Normal file
|
|
@ -0,0 +1,278 @@
|
|||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const ava_1 = __importDefault(require("ava"));
|
||||
const fs = __importStar(require("fs"));
|
||||
const path = __importStar(require("path"));
|
||||
const codeql_1 = require("./codeql");
|
||||
const languages_1 = require("./languages");
|
||||
const testing_utils_1 = require("./testing-utils");
|
||||
const tracer_config_1 = require("./tracer-config");
|
||||
const util = __importStar(require("./util"));
|
||||
testing_utils_1.setupTests(ava_1.default);
|
||||
function getTestConfig(tmpDir) {
|
||||
return {
|
||||
languages: [languages_1.Language.java],
|
||||
queries: {},
|
||||
pathsIgnore: [],
|
||||
paths: [],
|
||||
originalUserInput: {},
|
||||
tempDir: tmpDir,
|
||||
toolCacheDir: tmpDir,
|
||||
codeQLCmd: '',
|
||||
};
|
||||
}
|
||||
// A very minimal setup
|
||||
ava_1.default('getTracerConfigForLanguage - minimal setup', async (t) => {
|
||||
await util.withTmpDir(async (tmpDir) => {
|
||||
const config = getTestConfig(tmpDir);
|
||||
const codeQL = codeql_1.setCodeQL({
|
||||
getTracerEnv: async function () {
|
||||
return {
|
||||
'ODASA_TRACER_CONFIGURATION': 'abc',
|
||||
'foo': 'bar'
|
||||
};
|
||||
},
|
||||
});
|
||||
const result = await tracer_config_1.getTracerConfigForLanguage(codeQL, config, languages_1.Language.javascript);
|
||||
t.deepEqual(result, { spec: 'abc', env: { 'foo': 'bar' } });
|
||||
});
|
||||
});
|
||||
// Existing vars should not be overwritten, unless they are critical or prefixed with CODEQL_
|
||||
ava_1.default('getTracerConfigForLanguage - existing / critical vars', async (t) => {
|
||||
await util.withTmpDir(async (tmpDir) => {
|
||||
const config = getTestConfig(tmpDir);
|
||||
// Set up some variables in the environment
|
||||
process.env['foo'] = 'abc';
|
||||
process.env['SEMMLE_PRELOAD_libtrace'] = 'abc';
|
||||
process.env['SEMMLE_RUNNER'] = 'abc';
|
||||
process.env['SEMMLE_COPY_EXECUTABLES_ROOT'] = 'abc';
|
||||
process.env['SEMMLE_DEPTRACE_SOCKET'] = 'abc';
|
||||
process.env['SEMMLE_JAVA_TOOL_OPTIONS'] = 'abc';
|
||||
process.env['SEMMLE_DEPTRACE_SOCKET'] = 'abc';
|
||||
process.env['CODEQL_VAR'] = 'abc';
|
||||
// Now CodeQL returns all these variables, and one more, with different values
|
||||
const codeQL = codeql_1.setCodeQL({
|
||||
getTracerEnv: async function () {
|
||||
return {
|
||||
'ODASA_TRACER_CONFIGURATION': 'abc',
|
||||
'foo': 'bar',
|
||||
'baz': 'qux',
|
||||
'SEMMLE_PRELOAD_libtrace': 'SEMMLE_PRELOAD_libtrace',
|
||||
'SEMMLE_RUNNER': 'SEMMLE_RUNNER',
|
||||
'SEMMLE_COPY_EXECUTABLES_ROOT': 'SEMMLE_COPY_EXECUTABLES_ROOT',
|
||||
'SEMMLE_DEPTRACE_SOCKET': 'SEMMLE_DEPTRACE_SOCKET',
|
||||
'SEMMLE_JAVA_TOOL_OPTIONS': 'SEMMLE_JAVA_TOOL_OPTIONS',
|
||||
'CODEQL_VAR': 'CODEQL_VAR',
|
||||
};
|
||||
},
|
||||
});
|
||||
const result = await tracer_config_1.getTracerConfigForLanguage(codeQL, config, languages_1.Language.javascript);
|
||||
t.deepEqual(result, {
|
||||
spec: 'abc',
|
||||
env: {
|
||||
// Should contain all variables except 'foo', because that already existed in the
|
||||
// environment with a different value, and is not deemed a "critical" variable.
|
||||
'baz': 'qux',
|
||||
'SEMMLE_PRELOAD_libtrace': 'SEMMLE_PRELOAD_libtrace',
|
||||
'SEMMLE_RUNNER': 'SEMMLE_RUNNER',
|
||||
'SEMMLE_COPY_EXECUTABLES_ROOT': 'SEMMLE_COPY_EXECUTABLES_ROOT',
|
||||
'SEMMLE_DEPTRACE_SOCKET': 'SEMMLE_DEPTRACE_SOCKET',
|
||||
'SEMMLE_JAVA_TOOL_OPTIONS': 'SEMMLE_JAVA_TOOL_OPTIONS',
|
||||
'CODEQL_VAR': 'CODEQL_VAR',
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
ava_1.default('concatTracerConfigs - minimal configs correctly combined', async (t) => {
|
||||
await util.withTmpDir(async (tmpDir) => {
|
||||
const config = getTestConfig(tmpDir);
|
||||
const spec1 = path.join(tmpDir, 'spec1');
|
||||
fs.writeFileSync(spec1, 'foo.log\n2\nabc\ndef');
|
||||
const tc1 = {
|
||||
spec: spec1,
|
||||
env: {
|
||||
'a': 'a',
|
||||
'b': 'b',
|
||||
}
|
||||
};
|
||||
const spec2 = path.join(tmpDir, 'spec2');
|
||||
fs.writeFileSync(spec2, 'foo.log\n1\nghi');
|
||||
const tc2 = {
|
||||
spec: spec2,
|
||||
env: {
|
||||
'c': 'c',
|
||||
}
|
||||
};
|
||||
const result = tracer_config_1.concatTracerConfigs({ 'javascript': tc1, 'python': tc2 }, config);
|
||||
t.deepEqual(result, {
|
||||
spec: path.join(tmpDir, 'compound-spec'),
|
||||
env: {
|
||||
'a': 'a',
|
||||
'b': 'b',
|
||||
'c': 'c',
|
||||
}
|
||||
});
|
||||
t.true(fs.existsSync(result.spec));
|
||||
t.deepEqual(fs.readFileSync(result.spec, 'utf8'), path.join(tmpDir, 'compound-build-tracer.log') + '\n3\nabc\ndef\nghi');
|
||||
});
|
||||
});
|
||||
ava_1.default('concatTracerConfigs - conflicting env vars', async (t) => {
|
||||
await util.withTmpDir(async (tmpDir) => {
|
||||
const config = getTestConfig(tmpDir);
|
||||
const spec = path.join(tmpDir, 'spec');
|
||||
fs.writeFileSync(spec, 'foo.log\n0');
|
||||
// Ok if env vars have the same name and the same value
|
||||
t.deepEqual(tracer_config_1.concatTracerConfigs({
|
||||
'javascript': { spec: spec, env: { 'a': 'a', 'b': 'b' } },
|
||||
'python': { spec: spec, env: { 'b': 'b', 'c': 'c' } },
|
||||
}, config).env, {
|
||||
'a': 'a',
|
||||
'b': 'b',
|
||||
'c': 'c',
|
||||
});
|
||||
// Throws if env vars have same name but different values
|
||||
const e = t.throws(() => tracer_config_1.concatTracerConfigs({
|
||||
'javascript': { spec: spec, env: { 'a': 'a', 'b': 'b' } },
|
||||
'python': { spec: spec, env: { 'b': 'c' } },
|
||||
}, config));
|
||||
t.deepEqual(e.message, 'Incompatible values in environment parameter b: b and c');
|
||||
});
|
||||
});
|
||||
ava_1.default('concatTracerConfigs - cpp spec lines come last if present', async (t) => {
|
||||
await util.withTmpDir(async (tmpDir) => {
|
||||
const config = getTestConfig(tmpDir);
|
||||
const spec1 = path.join(tmpDir, 'spec1');
|
||||
fs.writeFileSync(spec1, 'foo.log\n2\nabc\ndef');
|
||||
const tc1 = {
|
||||
spec: spec1,
|
||||
env: {
|
||||
'a': 'a',
|
||||
'b': 'b',
|
||||
}
|
||||
};
|
||||
const spec2 = path.join(tmpDir, 'spec2');
|
||||
fs.writeFileSync(spec2, 'foo.log\n1\nghi');
|
||||
const tc2 = {
|
||||
spec: spec2,
|
||||
env: {
|
||||
'c': 'c',
|
||||
}
|
||||
};
|
||||
const result = tracer_config_1.concatTracerConfigs({ 'cpp': tc1, 'python': tc2 }, config);
|
||||
t.deepEqual(result, {
|
||||
spec: path.join(tmpDir, 'compound-spec'),
|
||||
env: {
|
||||
'a': 'a',
|
||||
'b': 'b',
|
||||
'c': 'c',
|
||||
}
|
||||
});
|
||||
t.true(fs.existsSync(result.spec));
|
||||
t.deepEqual(fs.readFileSync(result.spec, 'utf8'), path.join(tmpDir, 'compound-build-tracer.log') + '\n3\nghi\nabc\ndef');
|
||||
});
|
||||
});
|
||||
ava_1.default('concatTracerConfigs - SEMMLE_COPY_EXECUTABLES_ROOT is updated to point to compound spec', async (t) => {
|
||||
await util.withTmpDir(async (tmpDir) => {
|
||||
const config = getTestConfig(tmpDir);
|
||||
const spec = path.join(tmpDir, 'spec');
|
||||
fs.writeFileSync(spec, 'foo.log\n0');
|
||||
const result = tracer_config_1.concatTracerConfigs({
|
||||
'javascript': { spec: spec, env: { 'a': 'a', 'b': 'b' } },
|
||||
'python': { spec: spec, env: { 'SEMMLE_COPY_EXECUTABLES_ROOT': 'foo' } },
|
||||
}, config);
|
||||
t.deepEqual(result.env, {
|
||||
'a': 'a',
|
||||
'b': 'b',
|
||||
'SEMMLE_COPY_EXECUTABLES_ROOT': path.join(tmpDir, 'compound-temp')
|
||||
});
|
||||
});
|
||||
});
|
||||
ava_1.default('concatTracerConfigs - compound environment file is created correctly', async (t) => {
|
||||
await util.withTmpDir(async (tmpDir) => {
|
||||
const config = getTestConfig(tmpDir);
|
||||
const spec1 = path.join(tmpDir, 'spec1');
|
||||
fs.writeFileSync(spec1, 'foo.log\n2\nabc\ndef');
|
||||
const tc1 = {
|
||||
spec: spec1,
|
||||
env: {
|
||||
'a': 'a',
|
||||
}
|
||||
};
|
||||
const spec2 = path.join(tmpDir, 'spec2');
|
||||
fs.writeFileSync(spec2, 'foo.log\n1\nghi');
|
||||
const tc2 = {
|
||||
spec: spec2,
|
||||
env: {
|
||||
'foo': 'bar_baz',
|
||||
}
|
||||
};
|
||||
const result = tracer_config_1.concatTracerConfigs({ 'javascript': tc1, 'python': tc2 }, config);
|
||||
const envPath = result.spec + '.environment';
|
||||
t.true(fs.existsSync(envPath));
|
||||
const buffer = fs.readFileSync(envPath);
|
||||
// Contents is binary data
|
||||
t.deepEqual(buffer.length, 28);
|
||||
t.deepEqual(buffer.readInt32LE(0), 2); // number of env vars
|
||||
t.deepEqual(buffer.readInt32LE(4), 4); // length of env var definition
|
||||
t.deepEqual(buffer.toString('utf8', 8, 12), 'a=a\0'); // [key]=[value]\0
|
||||
t.deepEqual(buffer.readInt32LE(12), 12); // length of env var definition
|
||||
t.deepEqual(buffer.toString('utf8', 16, 28), 'foo=bar_baz\0'); // [key]=[value]\0
|
||||
});
|
||||
});
|
||||
ava_1.default('getCombinedTracerConfig - return undefined when no languages are traced languages', async (t) => {
|
||||
await util.withTmpDir(async (tmpDir) => {
|
||||
const config = getTestConfig(tmpDir);
|
||||
// No traced languages
|
||||
config.languages = [languages_1.Language.javascript, languages_1.Language.python];
|
||||
const codeQL = codeql_1.setCodeQL({
|
||||
getTracerEnv: async function () {
|
||||
return {
|
||||
'ODASA_TRACER_CONFIGURATION': 'abc',
|
||||
'foo': 'bar'
|
||||
};
|
||||
},
|
||||
});
|
||||
t.deepEqual(await tracer_config_1.getCombinedTracerConfig(config, codeQL), undefined);
|
||||
});
|
||||
});
|
||||
ava_1.default('getCombinedTracerConfig - valid spec file', async (t) => {
|
||||
await util.withTmpDir(async (tmpDir) => {
|
||||
const config = getTestConfig(tmpDir);
|
||||
const spec = path.join(tmpDir, 'spec');
|
||||
fs.writeFileSync(spec, 'foo.log\n2\nabc\ndef');
|
||||
const codeQL = codeql_1.setCodeQL({
|
||||
getTracerEnv: async function () {
|
||||
return {
|
||||
'ODASA_TRACER_CONFIGURATION': spec,
|
||||
'foo': 'bar',
|
||||
};
|
||||
},
|
||||
});
|
||||
const result = await tracer_config_1.getCombinedTracerConfig(config, codeQL);
|
||||
const expectedEnv = {
|
||||
'foo': 'bar',
|
||||
'ODASA_TRACER_CONFIGURATION': result.spec,
|
||||
};
|
||||
if (process.platform === 'darwin') {
|
||||
expectedEnv['DYLD_INSERT_LIBRARIES'] = path.join(path.dirname(codeQL.getPath()), 'tools', 'osx64', 'libtrace.dylib');
|
||||
}
|
||||
else if (process.platform !== 'win32') {
|
||||
expectedEnv['LD_PRELOAD'] = path.join(path.dirname(codeQL.getPath()), 'tools', 'linux64', '${LIB}trace.so');
|
||||
}
|
||||
t.deepEqual(result, {
|
||||
spec: path.join(tmpDir, 'compound-spec'),
|
||||
env: expectedEnv,
|
||||
});
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=tracer-config.test.js.map
|
||||
1
lib/tracer-config.test.js.map
Normal file
1
lib/tracer-config.test.js.map
Normal file
File diff suppressed because one or more lines are too long
21
lib/tracer-env.js
generated
21
lib/tracer-env.js
generated
|
|
@ -1,21 +0,0 @@
|
|||
"use strict";
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fs = __importStar(require("fs"));
|
||||
const env = {};
|
||||
for (let entry of Object.entries(process.env)) {
|
||||
const key = entry[0];
|
||||
const value = entry[1];
|
||||
if (typeof value !== 'undefined' && key !== '_' && !key.startsWith('JAVA_MAIN_CLASS_')) {
|
||||
env[key] = value;
|
||||
}
|
||||
}
|
||||
process.stdout.write(process.argv[2]);
|
||||
fs.writeFileSync(process.argv[2], JSON.stringify(env), 'utf-8');
|
||||
//# sourceMappingURL=tracer-env.js.map
|
||||
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"tracer-env.js","sourceRoot":"","sources":["../src/tracer-env.ts"],"names":[],"mappings":";;;;;;;;;AAAA,uCAAyB;AAEzB,MAAM,GAAG,GAAG,EAAE,CAAC;AACf,KAAK,IAAI,KAAK,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;IAC7C,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IACrB,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IACvB,IAAI,OAAO,KAAK,KAAK,WAAW,IAAI,GAAG,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,kBAAkB,CAAC,EAAE;QACtF,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;KAClB;CACF;AACD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AACtC,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC"}
|
||||
16
lib/upload-lib.js
generated
16
lib/upload-lib.js
generated
|
|
@ -43,7 +43,7 @@ function combineSarifFiles(sarifFiles) {
|
|||
exports.combineSarifFiles = combineSarifFiles;
|
||||
// Upload the given payload.
|
||||
// If the request fails then this will retry a small number of times.
|
||||
async function uploadPayload(payload, repositoryNwo, githubAuth, githubApiUrl, mode, logger) {
|
||||
async function uploadPayload(payload, repositoryNwo, githubAuth, githubUrl, mode, logger) {
|
||||
logger.info('Uploading results');
|
||||
// If in test mode we don't want to upload the results
|
||||
const testMode = process.env['TEST_MODE'] === 'true' || false;
|
||||
|
|
@ -55,7 +55,7 @@ async function uploadPayload(payload, repositoryNwo, githubAuth, githubApiUrl, m
|
|||
// We don't want to backoff too much to avoid wasting action
|
||||
// minutes, but just waiting a little bit could maybe help.
|
||||
const backoffPeriods = [1, 5, 15];
|
||||
const client = api.getApiClient(githubAuth, githubApiUrl);
|
||||
const client = api.getApiClient(githubAuth, githubUrl);
|
||||
for (let attempt = 0; attempt <= backoffPeriods.length; attempt++) {
|
||||
const reqURL = mode === 'actions'
|
||||
? 'PUT /repos/:owner/:repo/code-scanning/analysis'
|
||||
|
|
@ -100,7 +100,7 @@ async function uploadPayload(payload, repositoryNwo, githubAuth, githubApiUrl, m
|
|||
// Uploads a single sarif file or a directory of sarif files
|
||||
// depending on what the path happens to refer to.
|
||||
// Returns true iff the upload occurred and succeeded
|
||||
async function upload(sarifPath, repositoryNwo, commitOid, ref, analysisKey, analysisName, workflowRunID, checkoutPath, environment, githubAuth, githubApiUrl, mode, logger) {
|
||||
async function upload(sarifPath, repositoryNwo, commitOid, ref, analysisKey, analysisName, workflowRunID, checkoutPath, environment, githubAuth, githubUrl, mode, logger) {
|
||||
const sarifFiles = [];
|
||||
if (!fs.existsSync(sarifPath)) {
|
||||
throw new Error(`Path does not exist: ${sarifPath}`);
|
||||
|
|
@ -117,7 +117,7 @@ async function upload(sarifPath, repositoryNwo, commitOid, ref, analysisKey, ana
|
|||
else {
|
||||
sarifFiles.push(sarifPath);
|
||||
}
|
||||
return await uploadFiles(sarifFiles, repositoryNwo, commitOid, ref, analysisKey, analysisName, workflowRunID, checkoutPath, environment, githubAuth, githubApiUrl, mode, logger);
|
||||
return await uploadFiles(sarifFiles, repositoryNwo, commitOid, ref, analysisKey, analysisName, workflowRunID, checkoutPath, environment, githubAuth, githubUrl, mode, logger);
|
||||
}
|
||||
exports.upload = upload;
|
||||
// Counts the number of results in the given SARIF file
|
||||
|
|
@ -151,10 +151,10 @@ function validateSarifFileSchema(sarifFilePath, logger) {
|
|||
exports.validateSarifFileSchema = validateSarifFileSchema;
|
||||
// Uploads the given set of sarif files.
|
||||
// Returns true iff the upload occurred and succeeded
|
||||
async function uploadFiles(sarifFiles, repositoryNwo, commitOid, ref, analysisKey, analysisName, workflowRunID, checkoutPath, environment, githubAuth, githubApiUrl, mode, logger) {
|
||||
async function uploadFiles(sarifFiles, repositoryNwo, commitOid, ref, analysisKey, analysisName, workflowRunID, checkoutPath, environment, githubAuth, githubUrl, mode, logger) {
|
||||
logger.info("Uploading sarif files: " + JSON.stringify(sarifFiles));
|
||||
if (mode === 'actions') {
|
||||
// This check only works on actions as env vars don't persist between calls to the CLI
|
||||
// This check only works on actions as env vars don't persist between calls to the runner
|
||||
const sentinelEnvVar = "CODEQL_UPLOAD_SARIF";
|
||||
if (process.env[sentinelEnvVar]) {
|
||||
throw new Error("Aborting upload: only one run of the codeql/analyze or codeql/upload-sarif actions is allowed per job");
|
||||
|
|
@ -166,7 +166,7 @@ async function uploadFiles(sarifFiles, repositoryNwo, commitOid, ref, analysisKe
|
|||
validateSarifFileSchema(file, logger);
|
||||
}
|
||||
let sarifPayload = combineSarifFiles(sarifFiles);
|
||||
sarifPayload = fingerprints.addFingerprints(sarifPayload, logger);
|
||||
sarifPayload = fingerprints.addFingerprints(sarifPayload, checkoutPath, logger);
|
||||
const zipped_sarif = zlib_1.default.gzipSync(sarifPayload).toString('base64');
|
||||
let checkoutURI = file_url_1.default(checkoutPath);
|
||||
const toolNames = util.getToolNames(sarifPayload);
|
||||
|
|
@ -202,7 +202,7 @@ async function uploadFiles(sarifFiles, repositoryNwo, commitOid, ref, analysisKe
|
|||
const numResultInSarif = countResultsInSarif(sarifPayload);
|
||||
logger.debug("Number of results in upload: " + numResultInSarif);
|
||||
// Make the upload
|
||||
await uploadPayload(payload, repositoryNwo, githubAuth, githubApiUrl, mode, logger);
|
||||
await uploadPayload(payload, repositoryNwo, githubAuth, githubUrl, mode, logger);
|
||||
return {
|
||||
raw_upload_size_bytes: rawUploadSizeBytes,
|
||||
zipped_upload_size_bytes: zippedUploadSizeBytes,
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
4
lib/upload-lib.test.js
generated
4
lib/upload-lib.test.js
generated
|
|
@ -17,10 +17,10 @@ const uploadLib = __importStar(require("./upload-lib"));
|
|||
testing_utils_1.setupTests(ava_1.default);
|
||||
ava_1.default('validateSarifFileSchema - valid', t => {
|
||||
const inputFile = __dirname + '/../src/testdata/valid-sarif.sarif';
|
||||
t.notThrows(() => uploadLib.validateSarifFileSchema(inputFile, logging_1.getCLILogger()));
|
||||
t.notThrows(() => uploadLib.validateSarifFileSchema(inputFile, logging_1.getRunnerLogger(true)));
|
||||
});
|
||||
ava_1.default('validateSarifFileSchema - invalid', t => {
|
||||
const inputFile = __dirname + '/../src/testdata/invalid-sarif.sarif';
|
||||
t.throws(() => uploadLib.validateSarifFileSchema(inputFile, logging_1.getCLILogger()));
|
||||
t.throws(() => uploadLib.validateSarifFileSchema(inputFile, logging_1.getRunnerLogger(true)));
|
||||
});
|
||||
//# sourceMappingURL=upload-lib.test.js.map
|
||||
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"upload-lib.test.js","sourceRoot":"","sources":["../src/upload-lib.test.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8CAAuB;AAEvB,uCAAyC;AACzC,mDAA2C;AAC3C,wDAA0C;AAE1C,0BAAU,CAAC,aAAI,CAAC,CAAC;AAEjB,aAAI,CAAC,iCAAiC,EAAE,CAAC,CAAC,EAAE;IAC1C,MAAM,SAAS,GAAG,SAAS,GAAG,oCAAoC,CAAC;IACnE,CAAC,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,uBAAuB,CAAC,SAAS,EAAE,sBAAY,EAAE,CAAC,CAAC,CAAC;AAClF,CAAC,CAAC,CAAC;AAEH,aAAI,CAAC,mCAAmC,EAAE,CAAC,CAAC,EAAE;IAC5C,MAAM,SAAS,GAAG,SAAS,GAAG,sCAAsC,CAAC;IACrE,CAAC,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,uBAAuB,CAAC,SAAS,EAAE,sBAAY,EAAE,CAAC,CAAC,CAAC;AAC/E,CAAC,CAAC,CAAC"}
|
||||
{"version":3,"file":"upload-lib.test.js","sourceRoot":"","sources":["../src/upload-lib.test.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8CAAuB;AAEvB,uCAA4C;AAC5C,mDAA2C;AAC3C,wDAA0C;AAE1C,0BAAU,CAAC,aAAI,CAAC,CAAC;AAEjB,aAAI,CAAC,iCAAiC,EAAE,CAAC,CAAC,EAAE;IAC1C,MAAM,SAAS,GAAG,SAAS,GAAG,oCAAoC,CAAC;IACnE,CAAC,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,uBAAuB,CAAC,SAAS,EAAE,yBAAe,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACzF,CAAC,CAAC,CAAC;AAEH,aAAI,CAAC,mCAAmC,EAAE,CAAC,CAAC,EAAE;IAC5C,MAAM,SAAS,GAAG,SAAS,GAAG,sCAAsC,CAAC;IACrE,CAAC,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,uBAAuB,CAAC,SAAS,EAAE,yBAAe,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACtF,CAAC,CAAC,CAAC"}
|
||||
4
lib/upload-sarif.js → lib/upload-sarif-action.js
generated
4
lib/upload-sarif.js → lib/upload-sarif-action.js
generated
|
|
@ -26,7 +26,7 @@ async function run() {
|
|||
return;
|
||||
}
|
||||
try {
|
||||
const uploadStats = await upload_lib.upload(core.getInput('sarif_file'), repository_1.parseRepositoryNwo(util.getRequiredEnvParam('GITHUB_REPOSITORY')), await util.getCommitOid(), util.getRef(), await util.getAnalysisKey(), util.getRequiredEnvParam('GITHUB_WORKFLOW'), util.getWorkflowRunID(), core.getInput('checkout_path'), core.getInput('matrix'), core.getInput('token'), util.getRequiredEnvParam('GITHUB_API_URL'), 'actions', logging_1.getActionsLogger());
|
||||
const uploadStats = await upload_lib.upload(core.getInput('sarif_file'), repository_1.parseRepositoryNwo(util.getRequiredEnvParam('GITHUB_REPOSITORY')), await util.getCommitOid(), util.getRef(), await util.getAnalysisKey(), util.getRequiredEnvParam('GITHUB_WORKFLOW'), util.getWorkflowRunID(), core.getInput('checkout_path'), core.getInput('matrix'), core.getInput('token'), util.getRequiredEnvParam('GITHUB_SERVER_URL'), 'actions', logging_1.getActionsLogger());
|
||||
await sendSuccessStatusReport(startedAt, uploadStats);
|
||||
}
|
||||
catch (error) {
|
||||
|
|
@ -40,4 +40,4 @@ run().catch(e => {
|
|||
core.setFailed("codeql/upload-sarif action failed: " + e);
|
||||
console.log(e);
|
||||
});
|
||||
//# sourceMappingURL=upload-sarif.js.map
|
||||
//# sourceMappingURL=upload-sarif-action.js.map
|
||||
1
lib/upload-sarif-action.js.map
Normal file
1
lib/upload-sarif-action.js.map
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"upload-sarif-action.js","sourceRoot":"","sources":["../src/upload-sarif-action.ts"],"names":[],"mappings":";;;;;;;;;AAAA,oDAAsC;AAEtC,uCAA6C;AAC7C,6CAAkD;AAClD,yDAA2C;AAC3C,6CAA+B;AAI/B,KAAK,UAAU,uBAAuB,CAAC,SAAe,EAAE,WAA0C;IAChG,MAAM,gBAAgB,GAAG,MAAM,IAAI,CAAC,sBAAsB,CAAC,cAAc,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;IACjG,MAAM,YAAY,GAA4B;QAC5C,GAAG,gBAAgB;QACnB,GAAI,WAAW;KAChB,CAAC;IACF,MAAM,IAAI,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC;AAC5C,CAAC;AAED,KAAK,UAAU,GAAG;IAChB,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;IAC7B,IAAI,CAAC,MAAM,IAAI,CAAC,gBAAgB,CAAC,MAAM,IAAI,CAAC,sB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mBAAmB,CAAC,gBAAgB,CAAC,EAC1C,SAAS,EACT,0BAAgB,EAAE,CAAC,CAAC;QACtB,MAAM,uBAAuB,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;KAEvD;IAAC,OAAO,KAAK,EAAE;QACd,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC9B,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACnB,MAAM,IAAI,CAAC,gBAAgB,CAAC,MAAM,IAAI,CAAC,sBAAsB,CAC3D,cAAc,EACd,SAAS,EACT,SAAS,EACT,KAAK,CAAC,OAAO,EACb,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QAChB,OAAO;KACR;AACH,CAAC;AAED,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;IACd,IAAI,CAAC,SAAS,CAAC,qCAAqC,GAAG,CAAC,CAAC,CAAC;IAC1D,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AACjB,CAAC,CAAC,CAAC"}
|
||||
56
lib/util.js
generated
56
lib/util.js
generated
|
|
@ -8,31 +8,16 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const exec = __importStar(require("@actions/exec"));
|
||||
const toolrunnner = __importStar(require("@actions/exec/lib/toolrunner"));
|
||||
const fs = __importStar(require("fs"));
|
||||
const os = __importStar(require("os"));
|
||||
const path = __importStar(require("path"));
|
||||
const api = __importStar(require("./api-client"));
|
||||
const sharedEnv = __importStar(require("./shared-environment"));
|
||||
/**
|
||||
* The API URL for github.com.
|
||||
* The URL for github.com.
|
||||
*/
|
||||
exports.GITHUB_DOTCOM_API_URL = "https://api.github.com";
|
||||
/**
|
||||
* Get the API URL for the GitHub instance we are connected to.
|
||||
* May be for github.com or for an enterprise instance.
|
||||
*/
|
||||
function getInstanceAPIURL() {
|
||||
return process.env["GITHUB_API_URL"] || exports.GITHUB_DOTCOM_API_URL;
|
||||
}
|
||||
exports.getInstanceAPIURL = getInstanceAPIURL;
|
||||
/**
|
||||
* Are we running against a GitHub Enterpise instance, as opposed to github.com.
|
||||
*/
|
||||
function isEnterprise() {
|
||||
return getInstanceAPIURL() !== exports.GITHUB_DOTCOM_API_URL;
|
||||
}
|
||||
exports.isEnterprise = isEnterprise;
|
||||
exports.GITHUB_DOTCOM_URL = "https://github.com";
|
||||
/**
|
||||
* Get an environment parameter, but throw an error if it is not set.
|
||||
*/
|
||||
|
|
@ -96,13 +81,13 @@ async function getCommitOid() {
|
|||
// reported on the merge commit.
|
||||
try {
|
||||
let commitOid = '';
|
||||
await exec.exec('git', ['rev-parse', 'HEAD'], {
|
||||
await new toolrunnner.ToolRunner('git', ['rev-parse', 'HEAD'], {
|
||||
silent: true,
|
||||
listeners: {
|
||||
stdout: (data) => { commitOid += data.toString(); },
|
||||
stderr: (data) => { process.stderr.write(data); }
|
||||
}
|
||||
});
|
||||
}).exec();
|
||||
return commitOid.trim();
|
||||
}
|
||||
catch (e) {
|
||||
|
|
@ -245,7 +230,7 @@ exports.createStatusReportBase = createStatusReportBase;
|
|||
* Returns whether sending the status report was successful of not.
|
||||
*/
|
||||
async function sendStatusReport(statusReport, ignoreFailures) {
|
||||
if (isEnterprise()) {
|
||||
if (getRequiredEnvParam("GITHUB_SERVER_URL") !== exports.GITHUB_DOTCOM_URL) {
|
||||
core.debug("Not sending status report to GitHub Enterprise");
|
||||
return true;
|
||||
}
|
||||
|
|
@ -319,13 +304,12 @@ exports.withTmpDir = withTmpDir;
|
|||
*
|
||||
* @returns string
|
||||
*/
|
||||
function getMemoryFlag() {
|
||||
function getMemoryFlag(userInput) {
|
||||
let memoryToUseMegaBytes;
|
||||
const memoryToUseString = core.getInput("ram");
|
||||
if (memoryToUseString) {
|
||||
memoryToUseMegaBytes = Number(memoryToUseString);
|
||||
if (userInput) {
|
||||
memoryToUseMegaBytes = Number(userInput);
|
||||
if (Number.isNaN(memoryToUseMegaBytes) || memoryToUseMegaBytes <= 0) {
|
||||
throw new Error("Invalid RAM setting \"" + memoryToUseString + "\", specified.");
|
||||
throw new Error("Invalid RAM setting \"" + userInput + "\", specified.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
@ -345,22 +329,21 @@ exports.getMemoryFlag = getMemoryFlag;
|
|||
*
|
||||
* @returns string
|
||||
*/
|
||||
function getThreadsFlag() {
|
||||
function getThreadsFlag(userInput, logger) {
|
||||
let numThreads;
|
||||
const numThreadsString = core.getInput("threads");
|
||||
const maxThreads = os.cpus().length;
|
||||
if (numThreadsString) {
|
||||
numThreads = Number(numThreadsString);
|
||||
if (userInput) {
|
||||
numThreads = Number(userInput);
|
||||
if (Number.isNaN(numThreads)) {
|
||||
throw new Error(`Invalid threads setting "${numThreadsString}", specified.`);
|
||||
throw new Error(`Invalid threads setting "${userInput}", specified.`);
|
||||
}
|
||||
if (numThreads > maxThreads) {
|
||||
core.info(`Clamping desired number of threads (${numThreads}) to max available (${maxThreads}).`);
|
||||
logger.info(`Clamping desired number of threads (${numThreads}) to max available (${maxThreads}).`);
|
||||
numThreads = maxThreads;
|
||||
}
|
||||
const minThreads = -maxThreads;
|
||||
if (numThreads < minThreads) {
|
||||
core.info(`Clamping desired number of free threads (${numThreads}) to max available (${minThreads}).`);
|
||||
logger.info(`Clamping desired number of free threads (${numThreads}) to max available (${minThreads}).`);
|
||||
numThreads = minThreads;
|
||||
}
|
||||
}
|
||||
|
|
@ -378,4 +361,11 @@ function getCodeQLDatabasesDir(tempDir) {
|
|||
return path.resolve(tempDir, 'codeql_databases');
|
||||
}
|
||||
exports.getCodeQLDatabasesDir = getCodeQLDatabasesDir;
|
||||
/**
|
||||
* Get the path where the CodeQL database for the given language lives.
|
||||
*/
|
||||
function getCodeQLDatabasePath(tempDir, language) {
|
||||
return path.resolve(getCodeQLDatabasesDir(tempDir), language);
|
||||
}
|
||||
exports.getCodeQLDatabasePath = getCodeQLDatabasePath;
|
||||
//# sourceMappingURL=util.js.map
|
||||
File diff suppressed because one or more lines are too long
13
lib/util.test.js
generated
13
lib/util.test.js
generated
|
|
@ -13,6 +13,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||
const ava_1 = __importDefault(require("ava"));
|
||||
const fs = __importStar(require("fs"));
|
||||
const os = __importStar(require("os"));
|
||||
const logging_1 = require("./logging");
|
||||
const testing_utils_1 = require("./testing-utils");
|
||||
const util = __importStar(require("./util"));
|
||||
testing_utils_1.setupTests(ava_1.default);
|
||||
|
|
@ -28,15 +29,13 @@ ava_1.default('getMemoryFlag() should return the correct --ram flag', t => {
|
|||
"512": "--ram=512",
|
||||
};
|
||||
for (const [input, expectedFlag] of Object.entries(tests)) {
|
||||
process.env['INPUT_RAM'] = input;
|
||||
const flag = util.getMemoryFlag();
|
||||
const flag = util.getMemoryFlag(input);
|
||||
t.deepEqual(flag, expectedFlag);
|
||||
}
|
||||
});
|
||||
ava_1.default('getMemoryFlag() throws if the ram input is < 0 or NaN', t => {
|
||||
for (const input of ["-1", "hello!"]) {
|
||||
process.env['INPUT_RAM'] = input;
|
||||
t.throws(util.getMemoryFlag);
|
||||
t.throws(() => util.getMemoryFlag(input));
|
||||
}
|
||||
});
|
||||
ava_1.default('getThreadsFlag() should return the correct --threads flag', t => {
|
||||
|
|
@ -48,14 +47,12 @@ ava_1.default('getThreadsFlag() should return the correct --threads flag', t =>
|
|||
[`${-numCpus - 1}`]: `--threads=${-numCpus}`
|
||||
};
|
||||
for (const [input, expectedFlag] of Object.entries(tests)) {
|
||||
process.env['INPUT_THREADS'] = input;
|
||||
const flag = util.getThreadsFlag();
|
||||
const flag = util.getThreadsFlag(input, logging_1.getRunnerLogger(true));
|
||||
t.deepEqual(flag, expectedFlag);
|
||||
}
|
||||
});
|
||||
ava_1.default('getThreadsFlag() throws if the threads input is not an integer', t => {
|
||||
process.env['INPUT_THREADS'] = "hello!";
|
||||
t.throws(util.getThreadsFlag);
|
||||
t.throws(() => util.getThreadsFlag("hello!", logging_1.getRunnerLogger(true)));
|
||||
});
|
||||
ava_1.default('getRef() throws on the empty string', t => {
|
||||
process.env["GITHUB_REF"] = "";
|
||||
|
|
|
|||
|
|
@ -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;AAEH,aAAI,CAAC,sDAAsD,EAAE,CAAC,CAAC,EAAE;IAE/D,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC;IAE3D,MAAM,KAAK,GAAG;QACZ,EAAE,EAAE,SAAS,QAAQ,GAAG,GAAG,EAAE;QAC7B,KAAK,EAAE,WAAW;KACnB,CAAC;IAEF,KAAK,MAAM,CAAC,KAAK,EAAE,YAAY,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QAEzD,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,KAAK,CAAC;QAEjC,MAAM,IAAI,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;QAClC,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;KACjC;AACH,CA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2BAA2B,GAAG,gBAAgB,CAAC;AAC7D,CAAC,CAAC,CAAC;AAGH,aAAI,CAAC,qDAAqD,EAAE,CAAC,CAAC,EAAE;IAC9D,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC;IAEjE,MAAM,OAAO,GAAG,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC;IACpD,OAAO,CAAC,GAAG,CAAC,2BAA2B;QACrC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IAE1B,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,uBAAuB,EAAE,EAAE,OAAO,CAAC,CAAC;IAErD,OAAO,CAAC,GAAG,CAAC,2BAA2B,GAAG,gBAAgB,CAAC;AAC7D,CAAC,CAAC,CAAC;AAEH,aAAI,CAAC,iDAAiD,EAAE,CAAC,CAAC,EAAE;IAC1D,MAAM,gBAAgB,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"}
|
||||
1
node_modules/.bin/atob
generated
vendored
1
node_modules/.bin/atob
generated
vendored
|
|
@ -1 +0,0 @@
|
|||
../atob/bin/atob.js
|
||||
1
node_modules/.bin/errno
generated
vendored
1
node_modules/.bin/errno
generated
vendored
|
|
@ -1 +0,0 @@
|
|||
../errno/cli.js
|
||||
1
node_modules/.bin/json5
generated
vendored
1
node_modules/.bin/json5
generated
vendored
|
|
@ -1 +0,0 @@
|
|||
../json5/lib/cli.js
|
||||
1
node_modules/.bin/miller-rabin
generated
vendored
1
node_modules/.bin/miller-rabin
generated
vendored
|
|
@ -1 +0,0 @@
|
|||
../miller-rabin/bin/miller-rabin
|
||||
1
node_modules/.bin/sha.js
generated
vendored
1
node_modules/.bin/sha.js
generated
vendored
|
|
@ -1 +0,0 @@
|
|||
../sha.js/bin.js
|
||||
1
node_modules/.bin/terser
generated
vendored
1
node_modules/.bin/terser
generated
vendored
|
|
@ -1 +0,0 @@
|
|||
../terser/bin/terser
|
||||
1
node_modules/.bin/webpack
generated
vendored
1
node_modules/.bin/webpack
generated
vendored
|
|
@ -1 +0,0 @@
|
|||
../webpack/bin/webpack.js
|
||||
1
node_modules/.bin/webpack-cli
generated
vendored
1
node_modules/.bin/webpack-cli
generated
vendored
|
|
@ -1 +0,0 @@
|
|||
../webpack-cli/bin/cli.js
|
||||
21
node_modules/@webassemblyjs/ast/LICENSE
generated
vendored
21
node_modules/@webassemblyjs/ast/LICENSE
generated
vendored
|
|
@ -1,21 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2018 Sven Sauleau <sven@sauleau.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
167
node_modules/@webassemblyjs/ast/README.md
generated
vendored
167
node_modules/@webassemblyjs/ast/README.md
generated
vendored
|
|
@ -1,167 +0,0 @@
|
|||
# @webassemblyjs/ast
|
||||
|
||||
> AST utils for webassemblyjs
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
yarn add @webassemblyjs/ast
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Traverse
|
||||
|
||||
```js
|
||||
import { traverse } from "@webassemblyjs/ast";
|
||||
|
||||
traverse(ast, {
|
||||
Module(path) {
|
||||
console.log(path.node);
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
### Instruction signatures
|
||||
|
||||
```js
|
||||
import { signatures } from "@webassemblyjs/ast";
|
||||
|
||||
console.log(signatures);
|
||||
```
|
||||
|
||||
### Path methods
|
||||
|
||||
- `findParent: NodeLocator`
|
||||
- `replaceWith: Node => void`
|
||||
- `remove: () => void`
|
||||
- `insertBefore: Node => void`
|
||||
- `insertAfter: Node => void`
|
||||
- `stop: () => void`
|
||||
|
||||
### AST utils
|
||||
|
||||
- function `module(id, fields, metadata)`
|
||||
- function `moduleMetadata(sections, functionNames, localNames)`
|
||||
- function `moduleNameMetadata(value)`
|
||||
- function `functionNameMetadata(value, index)`
|
||||
- function `localNameMetadata(value, localIndex, functionIndex)`
|
||||
- function `binaryModule(id, blob)`
|
||||
- function `quoteModule(id, string)`
|
||||
- function `sectionMetadata(section, startOffset, size, vectorOfSize)`
|
||||
- function `loopInstruction(label, resulttype, instr)`
|
||||
- function `instruction(id, args, namedArgs)`
|
||||
- function `objectInstruction(id, object, args, namedArgs)`
|
||||
- function `ifInstruction(testLabel, test, result, consequent, alternate)`
|
||||
- function `stringLiteral(value)`
|
||||
- function `numberLiteralFromRaw(value, raw)`
|
||||
- function `longNumberLiteral(value, raw)`
|
||||
- function `floatLiteral(value, nan, inf, raw)`
|
||||
- function `elem(table, offset, funcs)`
|
||||
- function `indexInFuncSection(index)`
|
||||
- function `valtypeLiteral(name)`
|
||||
- function `typeInstruction(id, functype)`
|
||||
- function `start(index)`
|
||||
- function `globalType(valtype, mutability)`
|
||||
- function `leadingComment(value)`
|
||||
- function `blockComment(value)`
|
||||
- function `data(memoryIndex, offset, init)`
|
||||
- function `global(globalType, init, name)`
|
||||
- function `table(elementType, limits, name, elements)`
|
||||
- function `memory(limits, id)`
|
||||
- function `funcImportDescr(id, signature)`
|
||||
- function `moduleImport(module, name, descr)`
|
||||
- function `moduleExportDescr(exportType, id)`
|
||||
- function `moduleExport(name, descr)`
|
||||
- function `limit(min, max)`
|
||||
- function `signature(params, results)`
|
||||
- function `program(body)`
|
||||
- function `identifier(value, raw)`
|
||||
- function `blockInstruction(label, instr, result)`
|
||||
- function `callInstruction(index, instrArgs)`
|
||||
- function `callIndirectInstruction(signature, intrs)`
|
||||
- function `byteArray(values)`
|
||||
- function `func(name, signature, body, isExternal, metadata)`
|
||||
- Constant`isModule`
|
||||
- Constant`isModuleMetadata`
|
||||
- Constant`isModuleNameMetadata`
|
||||
- Constant`isFunctionNameMetadata`
|
||||
- Constant`isLocalNameMetadata`
|
||||
- Constant`isBinaryModule`
|
||||
- Constant`isQuoteModule`
|
||||
- Constant`isSectionMetadata`
|
||||
- Constant`isLoopInstruction`
|
||||
- Constant`isInstruction`
|
||||
- Constant`isObjectInstruction`
|
||||
- Constant`isIfInstruction`
|
||||
- Constant`isStringLiteral`
|
||||
- Constant`isNumberLiteral`
|
||||
- Constant`isLongNumberLiteral`
|
||||
- Constant`isFloatLiteral`
|
||||
- Constant`isElem`
|
||||
- Constant`isIndexInFuncSection`
|
||||
- Constant`isValtypeLiteral`
|
||||
- Constant`isTypeInstruction`
|
||||
- Constant`isStart`
|
||||
- Constant`isGlobalType`
|
||||
- Constant`isLeadingComment`
|
||||
- Constant`isBlockComment`
|
||||
- Constant`isData`
|
||||
- Constant`isGlobal`
|
||||
- Constant`isTable`
|
||||
- Constant`isMemory`
|
||||
- Constant`isFuncImportDescr`
|
||||
- Constant`isModuleImport`
|
||||
- Constant`isModuleExportDescr`
|
||||
- Constant`isModuleExport`
|
||||
- Constant`isLimit`
|
||||
- Constant`isSignature`
|
||||
- Constant`isProgram`
|
||||
- Constant`isIdentifier`
|
||||
- Constant`isBlockInstruction`
|
||||
- Constant`isCallInstruction`
|
||||
- Constant`isCallIndirectInstruction`
|
||||
- Constant`isByteArray`
|
||||
- Constant`isFunc`
|
||||
- Constant`assertModule`
|
||||
- Constant`assertModuleMetadata`
|
||||
- Constant`assertModuleNameMetadata`
|
||||
- Constant`assertFunctionNameMetadata`
|
||||
- Constant`assertLocalNameMetadata`
|
||||
- Constant`assertBinaryModule`
|
||||
- Constant`assertQuoteModule`
|
||||
- Constant`assertSectionMetadata`
|
||||
- Constant`assertLoopInstruction`
|
||||
- Constant`assertInstruction`
|
||||
- Constant`assertObjectInstruction`
|
||||
- Constant`assertIfInstruction`
|
||||
- Constant`assertStringLiteral`
|
||||
- Constant`assertNumberLiteral`
|
||||
- Constant`assertLongNumberLiteral`
|
||||
- Constant`assertFloatLiteral`
|
||||
- Constant`assertElem`
|
||||
- Constant`assertIndexInFuncSection`
|
||||
- Constant`assertValtypeLiteral`
|
||||
- Constant`assertTypeInstruction`
|
||||
- Constant`assertStart`
|
||||
- Constant`assertGlobalType`
|
||||
- Constant`assertLeadingComment`
|
||||
- Constant`assertBlockComment`
|
||||
- Constant`assertData`
|
||||
- Constant`assertGlobal`
|
||||
- Constant`assertTable`
|
||||
- Constant`assertMemory`
|
||||
- Constant`assertFuncImportDescr`
|
||||
- Constant`assertModuleImport`
|
||||
- Constant`assertModuleExportDescr`
|
||||
- Constant`assertModuleExport`
|
||||
- Constant`assertLimit`
|
||||
- Constant`assertSignature`
|
||||
- Constant`assertProgram`
|
||||
- Constant`assertIdentifier`
|
||||
- Constant`assertBlockInstruction`
|
||||
- Constant`assertCallInstruction`
|
||||
- Constant`assertCallIndirectInstruction`
|
||||
- Constant`assertByteArray`
|
||||
- Constant`assertFunc`
|
||||
|
||||
10
node_modules/@webassemblyjs/ast/esm/clone.js
generated
vendored
10
node_modules/@webassemblyjs/ast/esm/clone.js
generated
vendored
|
|
@ -1,10 +0,0 @@
|
|||
export function cloneNode(n) {
|
||||
// $FlowIgnore
|
||||
var newObj = {};
|
||||
|
||||
for (var k in n) {
|
||||
newObj[k] = n[k];
|
||||
}
|
||||
|
||||
return newObj;
|
||||
}
|
||||
663
node_modules/@webassemblyjs/ast/esm/definitions.js
generated
vendored
663
node_modules/@webassemblyjs/ast/esm/definitions.js
generated
vendored
|
|
@ -1,663 +0,0 @@
|
|||
var definitions = {};
|
||||
|
||||
function defineType(typeName, metadata) {
|
||||
definitions[typeName] = metadata;
|
||||
}
|
||||
|
||||
defineType("Module", {
|
||||
spec: {
|
||||
wasm: "https://webassembly.github.io/spec/core/binary/modules.html#binary-module",
|
||||
wat: "https://webassembly.github.io/spec/core/text/modules.html#text-module"
|
||||
},
|
||||
doc: "A module consists of a sequence of sections (termed fields in the text format).",
|
||||
unionType: ["Node"],
|
||||
fields: {
|
||||
id: {
|
||||
maybe: true,
|
||||
type: "string"
|
||||
},
|
||||
fields: {
|
||||
array: true,
|
||||
type: "Node"
|
||||
},
|
||||
metadata: {
|
||||
optional: true,
|
||||
type: "ModuleMetadata"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("ModuleMetadata", {
|
||||
unionType: ["Node"],
|
||||
fields: {
|
||||
sections: {
|
||||
array: true,
|
||||
type: "SectionMetadata"
|
||||
},
|
||||
functionNames: {
|
||||
optional: true,
|
||||
array: true,
|
||||
type: "FunctionNameMetadata"
|
||||
},
|
||||
localNames: {
|
||||
optional: true,
|
||||
array: true,
|
||||
type: "ModuleMetadata"
|
||||
},
|
||||
producers: {
|
||||
optional: true,
|
||||
array: true,
|
||||
type: "ProducersSectionMetadata"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("ModuleNameMetadata", {
|
||||
unionType: ["Node"],
|
||||
fields: {
|
||||
value: {
|
||||
type: "string"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("FunctionNameMetadata", {
|
||||
unionType: ["Node"],
|
||||
fields: {
|
||||
value: {
|
||||
type: "string"
|
||||
},
|
||||
index: {
|
||||
type: "number"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("LocalNameMetadata", {
|
||||
unionType: ["Node"],
|
||||
fields: {
|
||||
value: {
|
||||
type: "string"
|
||||
},
|
||||
localIndex: {
|
||||
type: "number"
|
||||
},
|
||||
functionIndex: {
|
||||
type: "number"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("BinaryModule", {
|
||||
unionType: ["Node"],
|
||||
fields: {
|
||||
id: {
|
||||
maybe: true,
|
||||
type: "string"
|
||||
},
|
||||
blob: {
|
||||
array: true,
|
||||
type: "string"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("QuoteModule", {
|
||||
unionType: ["Node"],
|
||||
fields: {
|
||||
id: {
|
||||
maybe: true,
|
||||
type: "string"
|
||||
},
|
||||
string: {
|
||||
array: true,
|
||||
type: "string"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("SectionMetadata", {
|
||||
unionType: ["Node"],
|
||||
fields: {
|
||||
section: {
|
||||
type: "SectionName"
|
||||
},
|
||||
startOffset: {
|
||||
type: "number"
|
||||
},
|
||||
size: {
|
||||
type: "NumberLiteral"
|
||||
},
|
||||
vectorOfSize: {
|
||||
comment: "Size of the vector in the section (if any)",
|
||||
type: "NumberLiteral"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("ProducersSectionMetadata", {
|
||||
unionType: ["Node"],
|
||||
fields: {
|
||||
producers: {
|
||||
array: true,
|
||||
type: "ProducerMetadata"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("ProducerMetadata", {
|
||||
unionType: ["Node"],
|
||||
fields: {
|
||||
language: {
|
||||
type: "ProducerMetadataVersionedName",
|
||||
array: true
|
||||
},
|
||||
processedBy: {
|
||||
type: "ProducerMetadataVersionedName",
|
||||
array: true
|
||||
},
|
||||
sdk: {
|
||||
type: "ProducerMetadataVersionedName",
|
||||
array: true
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("ProducerMetadataVersionedName", {
|
||||
unionType: ["Node"],
|
||||
fields: {
|
||||
name: {
|
||||
type: "string"
|
||||
},
|
||||
version: {
|
||||
type: "string"
|
||||
}
|
||||
}
|
||||
});
|
||||
/*
|
||||
Instructions
|
||||
*/
|
||||
|
||||
defineType("LoopInstruction", {
|
||||
unionType: ["Node", "Block", "Instruction"],
|
||||
fields: {
|
||||
id: {
|
||||
constant: true,
|
||||
type: "string",
|
||||
value: "loop"
|
||||
},
|
||||
label: {
|
||||
maybe: true,
|
||||
type: "Identifier"
|
||||
},
|
||||
resulttype: {
|
||||
maybe: true,
|
||||
type: "Valtype"
|
||||
},
|
||||
instr: {
|
||||
array: true,
|
||||
type: "Instruction"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("Instr", {
|
||||
unionType: ["Node", "Expression", "Instruction"],
|
||||
fields: {
|
||||
id: {
|
||||
type: "string"
|
||||
},
|
||||
object: {
|
||||
optional: true,
|
||||
type: "Valtype"
|
||||
},
|
||||
args: {
|
||||
array: true,
|
||||
type: "Expression"
|
||||
},
|
||||
namedArgs: {
|
||||
optional: true,
|
||||
type: "Object"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("IfInstruction", {
|
||||
unionType: ["Node", "Instruction"],
|
||||
fields: {
|
||||
id: {
|
||||
constant: true,
|
||||
type: "string",
|
||||
value: "if"
|
||||
},
|
||||
testLabel: {
|
||||
comment: "only for WAST",
|
||||
type: "Identifier"
|
||||
},
|
||||
test: {
|
||||
array: true,
|
||||
type: "Instruction"
|
||||
},
|
||||
result: {
|
||||
maybe: true,
|
||||
type: "Valtype"
|
||||
},
|
||||
consequent: {
|
||||
array: true,
|
||||
type: "Instruction"
|
||||
},
|
||||
alternate: {
|
||||
array: true,
|
||||
type: "Instruction"
|
||||
}
|
||||
}
|
||||
});
|
||||
/*
|
||||
Concrete value types
|
||||
*/
|
||||
|
||||
defineType("StringLiteral", {
|
||||
unionType: ["Node", "Expression"],
|
||||
fields: {
|
||||
value: {
|
||||
type: "string"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("NumberLiteral", {
|
||||
unionType: ["Node", "NumericLiteral", "Expression"],
|
||||
fields: {
|
||||
value: {
|
||||
type: "number"
|
||||
},
|
||||
raw: {
|
||||
type: "string"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("LongNumberLiteral", {
|
||||
unionType: ["Node", "NumericLiteral", "Expression"],
|
||||
fields: {
|
||||
value: {
|
||||
type: "LongNumber"
|
||||
},
|
||||
raw: {
|
||||
type: "string"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("FloatLiteral", {
|
||||
unionType: ["Node", "NumericLiteral", "Expression"],
|
||||
fields: {
|
||||
value: {
|
||||
type: "number"
|
||||
},
|
||||
nan: {
|
||||
optional: true,
|
||||
type: "boolean"
|
||||
},
|
||||
inf: {
|
||||
optional: true,
|
||||
type: "boolean"
|
||||
},
|
||||
raw: {
|
||||
type: "string"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("Elem", {
|
||||
unionType: ["Node"],
|
||||
fields: {
|
||||
table: {
|
||||
type: "Index"
|
||||
},
|
||||
offset: {
|
||||
array: true,
|
||||
type: "Instruction"
|
||||
},
|
||||
funcs: {
|
||||
array: true,
|
||||
type: "Index"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("IndexInFuncSection", {
|
||||
unionType: ["Node"],
|
||||
fields: {
|
||||
index: {
|
||||
type: "Index"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("ValtypeLiteral", {
|
||||
unionType: ["Node", "Expression"],
|
||||
fields: {
|
||||
name: {
|
||||
type: "Valtype"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("TypeInstruction", {
|
||||
unionType: ["Node", "Instruction"],
|
||||
fields: {
|
||||
id: {
|
||||
maybe: true,
|
||||
type: "Index"
|
||||
},
|
||||
functype: {
|
||||
type: "Signature"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("Start", {
|
||||
unionType: ["Node"],
|
||||
fields: {
|
||||
index: {
|
||||
type: "Index"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("GlobalType", {
|
||||
unionType: ["Node", "ImportDescr"],
|
||||
fields: {
|
||||
valtype: {
|
||||
type: "Valtype"
|
||||
},
|
||||
mutability: {
|
||||
type: "Mutability"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("LeadingComment", {
|
||||
unionType: ["Node"],
|
||||
fields: {
|
||||
value: {
|
||||
type: "string"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("BlockComment", {
|
||||
unionType: ["Node"],
|
||||
fields: {
|
||||
value: {
|
||||
type: "string"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("Data", {
|
||||
unionType: ["Node"],
|
||||
fields: {
|
||||
memoryIndex: {
|
||||
type: "Memidx"
|
||||
},
|
||||
offset: {
|
||||
type: "Instruction"
|
||||
},
|
||||
init: {
|
||||
type: "ByteArray"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("Global", {
|
||||
unionType: ["Node"],
|
||||
fields: {
|
||||
globalType: {
|
||||
type: "GlobalType"
|
||||
},
|
||||
init: {
|
||||
array: true,
|
||||
type: "Instruction"
|
||||
},
|
||||
name: {
|
||||
maybe: true,
|
||||
type: "Identifier"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("Table", {
|
||||
unionType: ["Node", "ImportDescr"],
|
||||
fields: {
|
||||
elementType: {
|
||||
type: "TableElementType"
|
||||
},
|
||||
limits: {
|
||||
assertNodeType: true,
|
||||
type: "Limit"
|
||||
},
|
||||
name: {
|
||||
maybe: true,
|
||||
type: "Identifier"
|
||||
},
|
||||
elements: {
|
||||
array: true,
|
||||
optional: true,
|
||||
type: "Index"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("Memory", {
|
||||
unionType: ["Node", "ImportDescr"],
|
||||
fields: {
|
||||
limits: {
|
||||
type: "Limit"
|
||||
},
|
||||
id: {
|
||||
maybe: true,
|
||||
type: "Index"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("FuncImportDescr", {
|
||||
unionType: ["Node", "ImportDescr"],
|
||||
fields: {
|
||||
id: {
|
||||
type: "Identifier"
|
||||
},
|
||||
signature: {
|
||||
type: "Signature"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("ModuleImport", {
|
||||
unionType: ["Node"],
|
||||
fields: {
|
||||
module: {
|
||||
type: "string"
|
||||
},
|
||||
name: {
|
||||
type: "string"
|
||||
},
|
||||
descr: {
|
||||
type: "ImportDescr"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("ModuleExportDescr", {
|
||||
unionType: ["Node"],
|
||||
fields: {
|
||||
exportType: {
|
||||
type: "ExportDescrType"
|
||||
},
|
||||
id: {
|
||||
type: "Index"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("ModuleExport", {
|
||||
unionType: ["Node"],
|
||||
fields: {
|
||||
name: {
|
||||
type: "string"
|
||||
},
|
||||
descr: {
|
||||
type: "ModuleExportDescr"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("Limit", {
|
||||
unionType: ["Node"],
|
||||
fields: {
|
||||
min: {
|
||||
type: "number"
|
||||
},
|
||||
max: {
|
||||
optional: true,
|
||||
type: "number"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("Signature", {
|
||||
unionType: ["Node"],
|
||||
fields: {
|
||||
params: {
|
||||
array: true,
|
||||
type: "FuncParam"
|
||||
},
|
||||
results: {
|
||||
array: true,
|
||||
type: "Valtype"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("Program", {
|
||||
unionType: ["Node"],
|
||||
fields: {
|
||||
body: {
|
||||
array: true,
|
||||
type: "Node"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("Identifier", {
|
||||
unionType: ["Node", "Expression"],
|
||||
fields: {
|
||||
value: {
|
||||
type: "string"
|
||||
},
|
||||
raw: {
|
||||
optional: true,
|
||||
type: "string"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("BlockInstruction", {
|
||||
unionType: ["Node", "Block", "Instruction"],
|
||||
fields: {
|
||||
id: {
|
||||
constant: true,
|
||||
type: "string",
|
||||
value: "block"
|
||||
},
|
||||
label: {
|
||||
maybe: true,
|
||||
type: "Identifier"
|
||||
},
|
||||
instr: {
|
||||
array: true,
|
||||
type: "Instruction"
|
||||
},
|
||||
result: {
|
||||
maybe: true,
|
||||
type: "Valtype"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("CallInstruction", {
|
||||
unionType: ["Node", "Instruction"],
|
||||
fields: {
|
||||
id: {
|
||||
constant: true,
|
||||
type: "string",
|
||||
value: "call"
|
||||
},
|
||||
index: {
|
||||
type: "Index"
|
||||
},
|
||||
instrArgs: {
|
||||
array: true,
|
||||
optional: true,
|
||||
type: "Expression"
|
||||
},
|
||||
numeric: {
|
||||
type: "Index",
|
||||
optional: true
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("CallIndirectInstruction", {
|
||||
unionType: ["Node", "Instruction"],
|
||||
fields: {
|
||||
id: {
|
||||
constant: true,
|
||||
type: "string",
|
||||
value: "call_indirect"
|
||||
},
|
||||
signature: {
|
||||
type: "SignatureOrTypeRef"
|
||||
},
|
||||
intrs: {
|
||||
array: true,
|
||||
optional: true,
|
||||
type: "Expression"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("ByteArray", {
|
||||
unionType: ["Node"],
|
||||
fields: {
|
||||
values: {
|
||||
array: true,
|
||||
type: "Byte"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("Func", {
|
||||
unionType: ["Node", "Block"],
|
||||
fields: {
|
||||
name: {
|
||||
maybe: true,
|
||||
type: "Index"
|
||||
},
|
||||
signature: {
|
||||
type: "SignatureOrTypeRef"
|
||||
},
|
||||
body: {
|
||||
array: true,
|
||||
type: "Instruction"
|
||||
},
|
||||
isExternal: {
|
||||
comment: "means that it has been imported from the outside js",
|
||||
optional: true,
|
||||
type: "boolean"
|
||||
},
|
||||
metadata: {
|
||||
optional: true,
|
||||
type: "FuncMetadata"
|
||||
}
|
||||
}
|
||||
});
|
||||
/**
|
||||
* Intrinsics
|
||||
*/
|
||||
|
||||
defineType("InternalBrUnless", {
|
||||
unionType: ["Node", "Intrinsic"],
|
||||
fields: {
|
||||
target: {
|
||||
type: "number"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("InternalGoto", {
|
||||
unionType: ["Node", "Intrinsic"],
|
||||
fields: {
|
||||
target: {
|
||||
type: "number"
|
||||
}
|
||||
}
|
||||
});
|
||||
defineType("InternalCallExtern", {
|
||||
unionType: ["Node", "Intrinsic"],
|
||||
fields: {
|
||||
target: {
|
||||
type: "number"
|
||||
}
|
||||
}
|
||||
}); // function bodies are terminated by an `end` instruction but are missing a
|
||||
// return instruction
|
||||
//
|
||||
// Since we can't inject a new instruction we are injecting a new instruction.
|
||||
|
||||
defineType("InternalEndAndReturn", {
|
||||
unionType: ["Node", "Intrinsic"],
|
||||
fields: {}
|
||||
});
|
||||
module.exports = definitions;
|
||||
6
node_modules/@webassemblyjs/ast/esm/index.js
generated
vendored
6
node_modules/@webassemblyjs/ast/esm/index.js
generated
vendored
|
|
@ -1,6 +0,0 @@
|
|||
export * from "./nodes";
|
||||
export { numberLiteralFromRaw, withLoc, withRaw, funcParam, indexLiteral, memIndexLiteral, instruction, objectInstruction } from "./node-helpers.js";
|
||||
export { traverse } from "./traverse";
|
||||
export { signatures } from "./signatures";
|
||||
export * from "./utils";
|
||||
export { cloneNode } from "./clone";
|
||||
84
node_modules/@webassemblyjs/ast/esm/node-helpers.js
generated
vendored
84
node_modules/@webassemblyjs/ast/esm/node-helpers.js
generated
vendored
|
|
@ -1,84 +0,0 @@
|
|||
import { parse32F, parse64F, parse32I, parse64I, parseU32, isNanLiteral, isInfLiteral } from "@webassemblyjs/wast-parser";
|
||||
import { longNumberLiteral, floatLiteral, numberLiteral, instr } from "./nodes";
|
||||
export function numberLiteralFromRaw(rawValue) {
|
||||
var instructionType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "i32";
|
||||
var original = rawValue; // Remove numeric separators _
|
||||
|
||||
if (typeof rawValue === "string") {
|
||||
rawValue = rawValue.replace(/_/g, "");
|
||||
}
|
||||
|
||||
if (typeof rawValue === "number") {
|
||||
return numberLiteral(rawValue, String(original));
|
||||
} else {
|
||||
switch (instructionType) {
|
||||
case "i32":
|
||||
{
|
||||
return numberLiteral(parse32I(rawValue), String(original));
|
||||
}
|
||||
|
||||
case "u32":
|
||||
{
|
||||
return numberLiteral(parseU32(rawValue), String(original));
|
||||
}
|
||||
|
||||
case "i64":
|
||||
{
|
||||
return longNumberLiteral(parse64I(rawValue), String(original));
|
||||
}
|
||||
|
||||
case "f32":
|
||||
{
|
||||
return floatLiteral(parse32F(rawValue), isNanLiteral(rawValue), isInfLiteral(rawValue), String(original));
|
||||
}
|
||||
// f64
|
||||
|
||||
default:
|
||||
{
|
||||
return floatLiteral(parse64F(rawValue), isNanLiteral(rawValue), isInfLiteral(rawValue), String(original));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
export function instruction(id) {
|
||||
var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
||||
var namedArgs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
||||
return instr(id, undefined, args, namedArgs);
|
||||
}
|
||||
export function objectInstruction(id, object) {
|
||||
var args = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
||||
var namedArgs = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
||||
return instr(id, object, args, namedArgs);
|
||||
}
|
||||
/**
|
||||
* Decorators
|
||||
*/
|
||||
|
||||
export function withLoc(n, end, start) {
|
||||
var loc = {
|
||||
start: start,
|
||||
end: end
|
||||
};
|
||||
n.loc = loc;
|
||||
return n;
|
||||
}
|
||||
export function withRaw(n, raw) {
|
||||
n.raw = raw;
|
||||
return n;
|
||||
}
|
||||
export function funcParam(valtype, id) {
|
||||
return {
|
||||
id: id,
|
||||
valtype: valtype
|
||||
};
|
||||
}
|
||||
export function indexLiteral(value) {
|
||||
// $FlowIgnore
|
||||
var x = numberLiteralFromRaw(value, "u32");
|
||||
return x;
|
||||
}
|
||||
export function memIndexLiteral(value) {
|
||||
// $FlowIgnore
|
||||
var x = numberLiteralFromRaw(value, "u32");
|
||||
return x;
|
||||
}
|
||||
137
node_modules/@webassemblyjs/ast/esm/node-path.js
generated
vendored
137
node_modules/@webassemblyjs/ast/esm/node-path.js
generated
vendored
|
|
@ -1,137 +0,0 @@
|
|||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
||||
|
||||
function findParent(_ref, cb) {
|
||||
var parentPath = _ref.parentPath;
|
||||
|
||||
if (parentPath == null) {
|
||||
throw new Error("node is root");
|
||||
}
|
||||
|
||||
var currentPath = parentPath;
|
||||
|
||||
while (cb(currentPath) !== false) {
|
||||
// Hit the root node, stop
|
||||
// $FlowIgnore
|
||||
if (currentPath.parentPath == null) {
|
||||
return null;
|
||||
} // $FlowIgnore
|
||||
|
||||
|
||||
currentPath = currentPath.parentPath;
|
||||
}
|
||||
|
||||
return currentPath.node;
|
||||
}
|
||||
|
||||
function insertBefore(context, newNode) {
|
||||
return insert(context, newNode);
|
||||
}
|
||||
|
||||
function insertAfter(context, newNode) {
|
||||
return insert(context, newNode, 1);
|
||||
}
|
||||
|
||||
function insert(_ref2, newNode) {
|
||||
var node = _ref2.node,
|
||||
inList = _ref2.inList,
|
||||
parentPath = _ref2.parentPath,
|
||||
parentKey = _ref2.parentKey;
|
||||
var indexOffset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
||||
|
||||
if (!inList) {
|
||||
throw new Error('inList' + " error: " + ("insert can only be used for nodes that are within lists" || "unknown"));
|
||||
}
|
||||
|
||||
if (!(parentPath != null)) {
|
||||
throw new Error('parentPath != null' + " error: " + ("Can not remove root node" || "unknown"));
|
||||
}
|
||||
|
||||
// $FlowIgnore
|
||||
var parentList = parentPath.node[parentKey];
|
||||
var indexInList = parentList.findIndex(function (n) {
|
||||
return n === node;
|
||||
});
|
||||
parentList.splice(indexInList + indexOffset, 0, newNode);
|
||||
}
|
||||
|
||||
function remove(_ref3) {
|
||||
var node = _ref3.node,
|
||||
parentKey = _ref3.parentKey,
|
||||
parentPath = _ref3.parentPath;
|
||||
|
||||
if (!(parentPath != null)) {
|
||||
throw new Error('parentPath != null' + " error: " + ("Can not remove root node" || "unknown"));
|
||||
}
|
||||
|
||||
// $FlowIgnore
|
||||
var parentNode = parentPath.node; // $FlowIgnore
|
||||
|
||||
var parentProperty = parentNode[parentKey];
|
||||
|
||||
if (Array.isArray(parentProperty)) {
|
||||
// $FlowIgnore
|
||||
parentNode[parentKey] = parentProperty.filter(function (n) {
|
||||
return n !== node;
|
||||
});
|
||||
} else {
|
||||
// $FlowIgnore
|
||||
delete parentNode[parentKey];
|
||||
}
|
||||
|
||||
node._deleted = true;
|
||||
}
|
||||
|
||||
function stop(context) {
|
||||
context.shouldStop = true;
|
||||
}
|
||||
|
||||
function replaceWith(context, newNode) {
|
||||
// $FlowIgnore
|
||||
var parentNode = context.parentPath.node; // $FlowIgnore
|
||||
|
||||
var parentProperty = parentNode[context.parentKey];
|
||||
|
||||
if (Array.isArray(parentProperty)) {
|
||||
var indexInList = parentProperty.findIndex(function (n) {
|
||||
return n === context.node;
|
||||
});
|
||||
parentProperty.splice(indexInList, 1, newNode);
|
||||
} else {
|
||||
// $FlowIgnore
|
||||
parentNode[context.parentKey] = newNode;
|
||||
}
|
||||
|
||||
context.node._deleted = true;
|
||||
context.node = newNode;
|
||||
} // bind the context to the first argument of node operations
|
||||
|
||||
|
||||
function bindNodeOperations(operations, context) {
|
||||
var keys = Object.keys(operations);
|
||||
var boundOperations = {};
|
||||
keys.forEach(function (key) {
|
||||
boundOperations[key] = operations[key].bind(null, context);
|
||||
});
|
||||
return boundOperations;
|
||||
}
|
||||
|
||||
function createPathOperations(context) {
|
||||
// $FlowIgnore
|
||||
return bindNodeOperations({
|
||||
findParent: findParent,
|
||||
replaceWith: replaceWith,
|
||||
remove: remove,
|
||||
insertBefore: insertBefore,
|
||||
insertAfter: insertAfter,
|
||||
stop: stop
|
||||
}, context);
|
||||
}
|
||||
|
||||
export function createPath(context) {
|
||||
var path = _extends({}, context); // $FlowIgnore
|
||||
|
||||
|
||||
Object.assign(path, createPathOperations(path)); // $FlowIgnore
|
||||
|
||||
return path;
|
||||
}
|
||||
915
node_modules/@webassemblyjs/ast/esm/nodes.js
generated
vendored
915
node_modules/@webassemblyjs/ast/esm/nodes.js
generated
vendored
|
|
@ -1,915 +0,0 @@
|
|||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
// THIS FILE IS AUTOGENERATED
|
||||
// see scripts/generateNodeUtils.js
|
||||
function isTypeOf(t) {
|
||||
return function (n) {
|
||||
return n.type === t;
|
||||
};
|
||||
}
|
||||
|
||||
function assertTypeOf(t) {
|
||||
return function (n) {
|
||||
return function () {
|
||||
if (!(n.type === t)) {
|
||||
throw new Error('n.type === t' + " error: " + (undefined || "unknown"));
|
||||
}
|
||||
}();
|
||||
};
|
||||
}
|
||||
|
||||
export function module(id, fields, metadata) {
|
||||
if (id !== null && id !== undefined) {
|
||||
if (!(typeof id === "string")) {
|
||||
throw new Error('typeof id === "string"' + " error: " + ("Argument id must be of type string, given: " + _typeof(id) || "unknown"));
|
||||
}
|
||||
}
|
||||
|
||||
if (!(_typeof(fields) === "object" && typeof fields.length !== "undefined")) {
|
||||
throw new Error('typeof fields === "object" && typeof fields.length !== "undefined"' + " error: " + (undefined || "unknown"));
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "Module",
|
||||
id: id,
|
||||
fields: fields
|
||||
};
|
||||
|
||||
if (typeof metadata !== "undefined") {
|
||||
node.metadata = metadata;
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
export function moduleMetadata(sections, functionNames, localNames, producers) {
|
||||
if (!(_typeof(sections) === "object" && typeof sections.length !== "undefined")) {
|
||||
throw new Error('typeof sections === "object" && typeof sections.length !== "undefined"' + " error: " + (undefined || "unknown"));
|
||||
}
|
||||
|
||||
if (functionNames !== null && functionNames !== undefined) {
|
||||
if (!(_typeof(functionNames) === "object" && typeof functionNames.length !== "undefined")) {
|
||||
throw new Error('typeof functionNames === "object" && typeof functionNames.length !== "undefined"' + " error: " + (undefined || "unknown"));
|
||||
}
|
||||
}
|
||||
|
||||
if (localNames !== null && localNames !== undefined) {
|
||||
if (!(_typeof(localNames) === "object" && typeof localNames.length !== "undefined")) {
|
||||
throw new Error('typeof localNames === "object" && typeof localNames.length !== "undefined"' + " error: " + (undefined || "unknown"));
|
||||
}
|
||||
}
|
||||
|
||||
if (producers !== null && producers !== undefined) {
|
||||
if (!(_typeof(producers) === "object" && typeof producers.length !== "undefined")) {
|
||||
throw new Error('typeof producers === "object" && typeof producers.length !== "undefined"' + " error: " + (undefined || "unknown"));
|
||||
}
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "ModuleMetadata",
|
||||
sections: sections
|
||||
};
|
||||
|
||||
if (typeof functionNames !== "undefined" && functionNames.length > 0) {
|
||||
node.functionNames = functionNames;
|
||||
}
|
||||
|
||||
if (typeof localNames !== "undefined" && localNames.length > 0) {
|
||||
node.localNames = localNames;
|
||||
}
|
||||
|
||||
if (typeof producers !== "undefined" && producers.length > 0) {
|
||||
node.producers = producers;
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
export function moduleNameMetadata(value) {
|
||||
if (!(typeof value === "string")) {
|
||||
throw new Error('typeof value === "string"' + " error: " + ("Argument value must be of type string, given: " + _typeof(value) || "unknown"));
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "ModuleNameMetadata",
|
||||
value: value
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export function functionNameMetadata(value, index) {
|
||||
if (!(typeof value === "string")) {
|
||||
throw new Error('typeof value === "string"' + " error: " + ("Argument value must be of type string, given: " + _typeof(value) || "unknown"));
|
||||
}
|
||||
|
||||
if (!(typeof index === "number")) {
|
||||
throw new Error('typeof index === "number"' + " error: " + ("Argument index must be of type number, given: " + _typeof(index) || "unknown"));
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "FunctionNameMetadata",
|
||||
value: value,
|
||||
index: index
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export function localNameMetadata(value, localIndex, functionIndex) {
|
||||
if (!(typeof value === "string")) {
|
||||
throw new Error('typeof value === "string"' + " error: " + ("Argument value must be of type string, given: " + _typeof(value) || "unknown"));
|
||||
}
|
||||
|
||||
if (!(typeof localIndex === "number")) {
|
||||
throw new Error('typeof localIndex === "number"' + " error: " + ("Argument localIndex must be of type number, given: " + _typeof(localIndex) || "unknown"));
|
||||
}
|
||||
|
||||
if (!(typeof functionIndex === "number")) {
|
||||
throw new Error('typeof functionIndex === "number"' + " error: " + ("Argument functionIndex must be of type number, given: " + _typeof(functionIndex) || "unknown"));
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "LocalNameMetadata",
|
||||
value: value,
|
||||
localIndex: localIndex,
|
||||
functionIndex: functionIndex
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export function binaryModule(id, blob) {
|
||||
if (id !== null && id !== undefined) {
|
||||
if (!(typeof id === "string")) {
|
||||
throw new Error('typeof id === "string"' + " error: " + ("Argument id must be of type string, given: " + _typeof(id) || "unknown"));
|
||||
}
|
||||
}
|
||||
|
||||
if (!(_typeof(blob) === "object" && typeof blob.length !== "undefined")) {
|
||||
throw new Error('typeof blob === "object" && typeof blob.length !== "undefined"' + " error: " + (undefined || "unknown"));
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "BinaryModule",
|
||||
id: id,
|
||||
blob: blob
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export function quoteModule(id, string) {
|
||||
if (id !== null && id !== undefined) {
|
||||
if (!(typeof id === "string")) {
|
||||
throw new Error('typeof id === "string"' + " error: " + ("Argument id must be of type string, given: " + _typeof(id) || "unknown"));
|
||||
}
|
||||
}
|
||||
|
||||
if (!(_typeof(string) === "object" && typeof string.length !== "undefined")) {
|
||||
throw new Error('typeof string === "object" && typeof string.length !== "undefined"' + " error: " + (undefined || "unknown"));
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "QuoteModule",
|
||||
id: id,
|
||||
string: string
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export function sectionMetadata(section, startOffset, size, vectorOfSize) {
|
||||
if (!(typeof startOffset === "number")) {
|
||||
throw new Error('typeof startOffset === "number"' + " error: " + ("Argument startOffset must be of type number, given: " + _typeof(startOffset) || "unknown"));
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "SectionMetadata",
|
||||
section: section,
|
||||
startOffset: startOffset,
|
||||
size: size,
|
||||
vectorOfSize: vectorOfSize
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export function producersSectionMetadata(producers) {
|
||||
if (!(_typeof(producers) === "object" && typeof producers.length !== "undefined")) {
|
||||
throw new Error('typeof producers === "object" && typeof producers.length !== "undefined"' + " error: " + (undefined || "unknown"));
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "ProducersSectionMetadata",
|
||||
producers: producers
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export function producerMetadata(language, processedBy, sdk) {
|
||||
if (!(_typeof(language) === "object" && typeof language.length !== "undefined")) {
|
||||
throw new Error('typeof language === "object" && typeof language.length !== "undefined"' + " error: " + (undefined || "unknown"));
|
||||
}
|
||||
|
||||
if (!(_typeof(processedBy) === "object" && typeof processedBy.length !== "undefined")) {
|
||||
throw new Error('typeof processedBy === "object" && typeof processedBy.length !== "undefined"' + " error: " + (undefined || "unknown"));
|
||||
}
|
||||
|
||||
if (!(_typeof(sdk) === "object" && typeof sdk.length !== "undefined")) {
|
||||
throw new Error('typeof sdk === "object" && typeof sdk.length !== "undefined"' + " error: " + (undefined || "unknown"));
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "ProducerMetadata",
|
||||
language: language,
|
||||
processedBy: processedBy,
|
||||
sdk: sdk
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export function producerMetadataVersionedName(name, version) {
|
||||
if (!(typeof name === "string")) {
|
||||
throw new Error('typeof name === "string"' + " error: " + ("Argument name must be of type string, given: " + _typeof(name) || "unknown"));
|
||||
}
|
||||
|
||||
if (!(typeof version === "string")) {
|
||||
throw new Error('typeof version === "string"' + " error: " + ("Argument version must be of type string, given: " + _typeof(version) || "unknown"));
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "ProducerMetadataVersionedName",
|
||||
name: name,
|
||||
version: version
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export function loopInstruction(label, resulttype, instr) {
|
||||
if (!(_typeof(instr) === "object" && typeof instr.length !== "undefined")) {
|
||||
throw new Error('typeof instr === "object" && typeof instr.length !== "undefined"' + " error: " + (undefined || "unknown"));
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "LoopInstruction",
|
||||
id: "loop",
|
||||
label: label,
|
||||
resulttype: resulttype,
|
||||
instr: instr
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export function instr(id, object, args, namedArgs) {
|
||||
if (!(typeof id === "string")) {
|
||||
throw new Error('typeof id === "string"' + " error: " + ("Argument id must be of type string, given: " + _typeof(id) || "unknown"));
|
||||
}
|
||||
|
||||
if (!(_typeof(args) === "object" && typeof args.length !== "undefined")) {
|
||||
throw new Error('typeof args === "object" && typeof args.length !== "undefined"' + " error: " + (undefined || "unknown"));
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "Instr",
|
||||
id: id,
|
||||
args: args
|
||||
};
|
||||
|
||||
if (typeof object !== "undefined") {
|
||||
node.object = object;
|
||||
}
|
||||
|
||||
if (typeof namedArgs !== "undefined" && Object.keys(namedArgs).length !== 0) {
|
||||
node.namedArgs = namedArgs;
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
export function ifInstruction(testLabel, test, result, consequent, alternate) {
|
||||
if (!(_typeof(test) === "object" && typeof test.length !== "undefined")) {
|
||||
throw new Error('typeof test === "object" && typeof test.length !== "undefined"' + " error: " + (undefined || "unknown"));
|
||||
}
|
||||
|
||||
if (!(_typeof(consequent) === "object" && typeof consequent.length !== "undefined")) {
|
||||
throw new Error('typeof consequent === "object" && typeof consequent.length !== "undefined"' + " error: " + (undefined || "unknown"));
|
||||
}
|
||||
|
||||
if (!(_typeof(alternate) === "object" && typeof alternate.length !== "undefined")) {
|
||||
throw new Error('typeof alternate === "object" && typeof alternate.length !== "undefined"' + " error: " + (undefined || "unknown"));
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "IfInstruction",
|
||||
id: "if",
|
||||
testLabel: testLabel,
|
||||
test: test,
|
||||
result: result,
|
||||
consequent: consequent,
|
||||
alternate: alternate
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export function stringLiteral(value) {
|
||||
if (!(typeof value === "string")) {
|
||||
throw new Error('typeof value === "string"' + " error: " + ("Argument value must be of type string, given: " + _typeof(value) || "unknown"));
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "StringLiteral",
|
||||
value: value
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export function numberLiteral(value, raw) {
|
||||
if (!(typeof value === "number")) {
|
||||
throw new Error('typeof value === "number"' + " error: " + ("Argument value must be of type number, given: " + _typeof(value) || "unknown"));
|
||||
}
|
||||
|
||||
if (!(typeof raw === "string")) {
|
||||
throw new Error('typeof raw === "string"' + " error: " + ("Argument raw must be of type string, given: " + _typeof(raw) || "unknown"));
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "NumberLiteral",
|
||||
value: value,
|
||||
raw: raw
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export function longNumberLiteral(value, raw) {
|
||||
if (!(typeof raw === "string")) {
|
||||
throw new Error('typeof raw === "string"' + " error: " + ("Argument raw must be of type string, given: " + _typeof(raw) || "unknown"));
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "LongNumberLiteral",
|
||||
value: value,
|
||||
raw: raw
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export function floatLiteral(value, nan, inf, raw) {
|
||||
if (!(typeof value === "number")) {
|
||||
throw new Error('typeof value === "number"' + " error: " + ("Argument value must be of type number, given: " + _typeof(value) || "unknown"));
|
||||
}
|
||||
|
||||
if (nan !== null && nan !== undefined) {
|
||||
if (!(typeof nan === "boolean")) {
|
||||
throw new Error('typeof nan === "boolean"' + " error: " + ("Argument nan must be of type boolean, given: " + _typeof(nan) || "unknown"));
|
||||
}
|
||||
}
|
||||
|
||||
if (inf !== null && inf !== undefined) {
|
||||
if (!(typeof inf === "boolean")) {
|
||||
throw new Error('typeof inf === "boolean"' + " error: " + ("Argument inf must be of type boolean, given: " + _typeof(inf) || "unknown"));
|
||||
}
|
||||
}
|
||||
|
||||
if (!(typeof raw === "string")) {
|
||||
throw new Error('typeof raw === "string"' + " error: " + ("Argument raw must be of type string, given: " + _typeof(raw) || "unknown"));
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "FloatLiteral",
|
||||
value: value,
|
||||
raw: raw
|
||||
};
|
||||
|
||||
if (nan === true) {
|
||||
node.nan = true;
|
||||
}
|
||||
|
||||
if (inf === true) {
|
||||
node.inf = true;
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
export function elem(table, offset, funcs) {
|
||||
if (!(_typeof(offset) === "object" && typeof offset.length !== "undefined")) {
|
||||
throw new Error('typeof offset === "object" && typeof offset.length !== "undefined"' + " error: " + (undefined || "unknown"));
|
||||
}
|
||||
|
||||
if (!(_typeof(funcs) === "object" && typeof funcs.length !== "undefined")) {
|
||||
throw new Error('typeof funcs === "object" && typeof funcs.length !== "undefined"' + " error: " + (undefined || "unknown"));
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "Elem",
|
||||
table: table,
|
||||
offset: offset,
|
||||
funcs: funcs
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export function indexInFuncSection(index) {
|
||||
var node = {
|
||||
type: "IndexInFuncSection",
|
||||
index: index
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export function valtypeLiteral(name) {
|
||||
var node = {
|
||||
type: "ValtypeLiteral",
|
||||
name: name
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export function typeInstruction(id, functype) {
|
||||
var node = {
|
||||
type: "TypeInstruction",
|
||||
id: id,
|
||||
functype: functype
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export function start(index) {
|
||||
var node = {
|
||||
type: "Start",
|
||||
index: index
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export function globalType(valtype, mutability) {
|
||||
var node = {
|
||||
type: "GlobalType",
|
||||
valtype: valtype,
|
||||
mutability: mutability
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export function leadingComment(value) {
|
||||
if (!(typeof value === "string")) {
|
||||
throw new Error('typeof value === "string"' + " error: " + ("Argument value must be of type string, given: " + _typeof(value) || "unknown"));
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "LeadingComment",
|
||||
value: value
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export function blockComment(value) {
|
||||
if (!(typeof value === "string")) {
|
||||
throw new Error('typeof value === "string"' + " error: " + ("Argument value must be of type string, given: " + _typeof(value) || "unknown"));
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "BlockComment",
|
||||
value: value
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export function data(memoryIndex, offset, init) {
|
||||
var node = {
|
||||
type: "Data",
|
||||
memoryIndex: memoryIndex,
|
||||
offset: offset,
|
||||
init: init
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export function global(globalType, init, name) {
|
||||
if (!(_typeof(init) === "object" && typeof init.length !== "undefined")) {
|
||||
throw new Error('typeof init === "object" && typeof init.length !== "undefined"' + " error: " + (undefined || "unknown"));
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "Global",
|
||||
globalType: globalType,
|
||||
init: init,
|
||||
name: name
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export function table(elementType, limits, name, elements) {
|
||||
if (!(limits.type === "Limit")) {
|
||||
throw new Error('limits.type === "Limit"' + " error: " + ("Argument limits must be of type Limit, given: " + limits.type || "unknown"));
|
||||
}
|
||||
|
||||
if (elements !== null && elements !== undefined) {
|
||||
if (!(_typeof(elements) === "object" && typeof elements.length !== "undefined")) {
|
||||
throw new Error('typeof elements === "object" && typeof elements.length !== "undefined"' + " error: " + (undefined || "unknown"));
|
||||
}
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "Table",
|
||||
elementType: elementType,
|
||||
limits: limits,
|
||||
name: name
|
||||
};
|
||||
|
||||
if (typeof elements !== "undefined" && elements.length > 0) {
|
||||
node.elements = elements;
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
export function memory(limits, id) {
|
||||
var node = {
|
||||
type: "Memory",
|
||||
limits: limits,
|
||||
id: id
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export function funcImportDescr(id, signature) {
|
||||
var node = {
|
||||
type: "FuncImportDescr",
|
||||
id: id,
|
||||
signature: signature
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export function moduleImport(module, name, descr) {
|
||||
if (!(typeof module === "string")) {
|
||||
throw new Error('typeof module === "string"' + " error: " + ("Argument module must be of type string, given: " + _typeof(module) || "unknown"));
|
||||
}
|
||||
|
||||
if (!(typeof name === "string")) {
|
||||
throw new Error('typeof name === "string"' + " error: " + ("Argument name must be of type string, given: " + _typeof(name) || "unknown"));
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "ModuleImport",
|
||||
module: module,
|
||||
name: name,
|
||||
descr: descr
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export function moduleExportDescr(exportType, id) {
|
||||
var node = {
|
||||
type: "ModuleExportDescr",
|
||||
exportType: exportType,
|
||||
id: id
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export function moduleExport(name, descr) {
|
||||
if (!(typeof name === "string")) {
|
||||
throw new Error('typeof name === "string"' + " error: " + ("Argument name must be of type string, given: " + _typeof(name) || "unknown"));
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "ModuleExport",
|
||||
name: name,
|
||||
descr: descr
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export function limit(min, max) {
|
||||
if (!(typeof min === "number")) {
|
||||
throw new Error('typeof min === "number"' + " error: " + ("Argument min must be of type number, given: " + _typeof(min) || "unknown"));
|
||||
}
|
||||
|
||||
if (max !== null && max !== undefined) {
|
||||
if (!(typeof max === "number")) {
|
||||
throw new Error('typeof max === "number"' + " error: " + ("Argument max must be of type number, given: " + _typeof(max) || "unknown"));
|
||||
}
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "Limit",
|
||||
min: min
|
||||
};
|
||||
|
||||
if (typeof max !== "undefined") {
|
||||
node.max = max;
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
export function signature(params, results) {
|
||||
if (!(_typeof(params) === "object" && typeof params.length !== "undefined")) {
|
||||
throw new Error('typeof params === "object" && typeof params.length !== "undefined"' + " error: " + (undefined || "unknown"));
|
||||
}
|
||||
|
||||
if (!(_typeof(results) === "object" && typeof results.length !== "undefined")) {
|
||||
throw new Error('typeof results === "object" && typeof results.length !== "undefined"' + " error: " + (undefined || "unknown"));
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "Signature",
|
||||
params: params,
|
||||
results: results
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export function program(body) {
|
||||
if (!(_typeof(body) === "object" && typeof body.length !== "undefined")) {
|
||||
throw new Error('typeof body === "object" && typeof body.length !== "undefined"' + " error: " + (undefined || "unknown"));
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "Program",
|
||||
body: body
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export function identifier(value, raw) {
|
||||
if (!(typeof value === "string")) {
|
||||
throw new Error('typeof value === "string"' + " error: " + ("Argument value must be of type string, given: " + _typeof(value) || "unknown"));
|
||||
}
|
||||
|
||||
if (raw !== null && raw !== undefined) {
|
||||
if (!(typeof raw === "string")) {
|
||||
throw new Error('typeof raw === "string"' + " error: " + ("Argument raw must be of type string, given: " + _typeof(raw) || "unknown"));
|
||||
}
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "Identifier",
|
||||
value: value
|
||||
};
|
||||
|
||||
if (typeof raw !== "undefined") {
|
||||
node.raw = raw;
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
export function blockInstruction(label, instr, result) {
|
||||
if (!(_typeof(instr) === "object" && typeof instr.length !== "undefined")) {
|
||||
throw new Error('typeof instr === "object" && typeof instr.length !== "undefined"' + " error: " + (undefined || "unknown"));
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "BlockInstruction",
|
||||
id: "block",
|
||||
label: label,
|
||||
instr: instr,
|
||||
result: result
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export function callInstruction(index, instrArgs, numeric) {
|
||||
if (instrArgs !== null && instrArgs !== undefined) {
|
||||
if (!(_typeof(instrArgs) === "object" && typeof instrArgs.length !== "undefined")) {
|
||||
throw new Error('typeof instrArgs === "object" && typeof instrArgs.length !== "undefined"' + " error: " + (undefined || "unknown"));
|
||||
}
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "CallInstruction",
|
||||
id: "call",
|
||||
index: index
|
||||
};
|
||||
|
||||
if (typeof instrArgs !== "undefined" && instrArgs.length > 0) {
|
||||
node.instrArgs = instrArgs;
|
||||
}
|
||||
|
||||
if (typeof numeric !== "undefined") {
|
||||
node.numeric = numeric;
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
export function callIndirectInstruction(signature, intrs) {
|
||||
if (intrs !== null && intrs !== undefined) {
|
||||
if (!(_typeof(intrs) === "object" && typeof intrs.length !== "undefined")) {
|
||||
throw new Error('typeof intrs === "object" && typeof intrs.length !== "undefined"' + " error: " + (undefined || "unknown"));
|
||||
}
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "CallIndirectInstruction",
|
||||
id: "call_indirect",
|
||||
signature: signature
|
||||
};
|
||||
|
||||
if (typeof intrs !== "undefined" && intrs.length > 0) {
|
||||
node.intrs = intrs;
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
export function byteArray(values) {
|
||||
if (!(_typeof(values) === "object" && typeof values.length !== "undefined")) {
|
||||
throw new Error('typeof values === "object" && typeof values.length !== "undefined"' + " error: " + (undefined || "unknown"));
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "ByteArray",
|
||||
values: values
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export function func(name, signature, body, isExternal, metadata) {
|
||||
if (!(_typeof(body) === "object" && typeof body.length !== "undefined")) {
|
||||
throw new Error('typeof body === "object" && typeof body.length !== "undefined"' + " error: " + (undefined || "unknown"));
|
||||
}
|
||||
|
||||
if (isExternal !== null && isExternal !== undefined) {
|
||||
if (!(typeof isExternal === "boolean")) {
|
||||
throw new Error('typeof isExternal === "boolean"' + " error: " + ("Argument isExternal must be of type boolean, given: " + _typeof(isExternal) || "unknown"));
|
||||
}
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "Func",
|
||||
name: name,
|
||||
signature: signature,
|
||||
body: body
|
||||
};
|
||||
|
||||
if (isExternal === true) {
|
||||
node.isExternal = true;
|
||||
}
|
||||
|
||||
if (typeof metadata !== "undefined") {
|
||||
node.metadata = metadata;
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
export function internalBrUnless(target) {
|
||||
if (!(typeof target === "number")) {
|
||||
throw new Error('typeof target === "number"' + " error: " + ("Argument target must be of type number, given: " + _typeof(target) || "unknown"));
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "InternalBrUnless",
|
||||
target: target
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export function internalGoto(target) {
|
||||
if (!(typeof target === "number")) {
|
||||
throw new Error('typeof target === "number"' + " error: " + ("Argument target must be of type number, given: " + _typeof(target) || "unknown"));
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "InternalGoto",
|
||||
target: target
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export function internalCallExtern(target) {
|
||||
if (!(typeof target === "number")) {
|
||||
throw new Error('typeof target === "number"' + " error: " + ("Argument target must be of type number, given: " + _typeof(target) || "unknown"));
|
||||
}
|
||||
|
||||
var node = {
|
||||
type: "InternalCallExtern",
|
||||
target: target
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export function internalEndAndReturn() {
|
||||
var node = {
|
||||
type: "InternalEndAndReturn"
|
||||
};
|
||||
return node;
|
||||
}
|
||||
export var isModule = isTypeOf("Module");
|
||||
export var isModuleMetadata = isTypeOf("ModuleMetadata");
|
||||
export var isModuleNameMetadata = isTypeOf("ModuleNameMetadata");
|
||||
export var isFunctionNameMetadata = isTypeOf("FunctionNameMetadata");
|
||||
export var isLocalNameMetadata = isTypeOf("LocalNameMetadata");
|
||||
export var isBinaryModule = isTypeOf("BinaryModule");
|
||||
export var isQuoteModule = isTypeOf("QuoteModule");
|
||||
export var isSectionMetadata = isTypeOf("SectionMetadata");
|
||||
export var isProducersSectionMetadata = isTypeOf("ProducersSectionMetadata");
|
||||
export var isProducerMetadata = isTypeOf("ProducerMetadata");
|
||||
export var isProducerMetadataVersionedName = isTypeOf("ProducerMetadataVersionedName");
|
||||
export var isLoopInstruction = isTypeOf("LoopInstruction");
|
||||
export var isInstr = isTypeOf("Instr");
|
||||
export var isIfInstruction = isTypeOf("IfInstruction");
|
||||
export var isStringLiteral = isTypeOf("StringLiteral");
|
||||
export var isNumberLiteral = isTypeOf("NumberLiteral");
|
||||
export var isLongNumberLiteral = isTypeOf("LongNumberLiteral");
|
||||
export var isFloatLiteral = isTypeOf("FloatLiteral");
|
||||
export var isElem = isTypeOf("Elem");
|
||||
export var isIndexInFuncSection = isTypeOf("IndexInFuncSection");
|
||||
export var isValtypeLiteral = isTypeOf("ValtypeLiteral");
|
||||
export var isTypeInstruction = isTypeOf("TypeInstruction");
|
||||
export var isStart = isTypeOf("Start");
|
||||
export var isGlobalType = isTypeOf("GlobalType");
|
||||
export var isLeadingComment = isTypeOf("LeadingComment");
|
||||
export var isBlockComment = isTypeOf("BlockComment");
|
||||
export var isData = isTypeOf("Data");
|
||||
export var isGlobal = isTypeOf("Global");
|
||||
export var isTable = isTypeOf("Table");
|
||||
export var isMemory = isTypeOf("Memory");
|
||||
export var isFuncImportDescr = isTypeOf("FuncImportDescr");
|
||||
export var isModuleImport = isTypeOf("ModuleImport");
|
||||
export var isModuleExportDescr = isTypeOf("ModuleExportDescr");
|
||||
export var isModuleExport = isTypeOf("ModuleExport");
|
||||
export var isLimit = isTypeOf("Limit");
|
||||
export var isSignature = isTypeOf("Signature");
|
||||
export var isProgram = isTypeOf("Program");
|
||||
export var isIdentifier = isTypeOf("Identifier");
|
||||
export var isBlockInstruction = isTypeOf("BlockInstruction");
|
||||
export var isCallInstruction = isTypeOf("CallInstruction");
|
||||
export var isCallIndirectInstruction = isTypeOf("CallIndirectInstruction");
|
||||
export var isByteArray = isTypeOf("ByteArray");
|
||||
export var isFunc = isTypeOf("Func");
|
||||
export var isInternalBrUnless = isTypeOf("InternalBrUnless");
|
||||
export var isInternalGoto = isTypeOf("InternalGoto");
|
||||
export var isInternalCallExtern = isTypeOf("InternalCallExtern");
|
||||
export var isInternalEndAndReturn = isTypeOf("InternalEndAndReturn");
|
||||
export var isNode = function isNode(node) {
|
||||
return isModule(node) || isModuleMetadata(node) || isModuleNameMetadata(node) || isFunctionNameMetadata(node) || isLocalNameMetadata(node) || isBinaryModule(node) || isQuoteModule(node) || isSectionMetadata(node) || isProducersSectionMetadata(node) || isProducerMetadata(node) || isProducerMetadataVersionedName(node) || isLoopInstruction(node) || isInstr(node) || isIfInstruction(node) || isStringLiteral(node) || isNumberLiteral(node) || isLongNumberLiteral(node) || isFloatLiteral(node) || isElem(node) || isIndexInFuncSection(node) || isValtypeLiteral(node) || isTypeInstruction(node) || isStart(node) || isGlobalType(node) || isLeadingComment(node) || isBlockComment(node) || isData(node) || isGlobal(node) || isTable(node) || isMemory(node) || isFuncImportDescr(node) || isModuleImport(node) || isModuleExportDescr(node) || isModuleExport(node) || isLimit(node) || isSignature(node) || isProgram(node) || isIdentifier(node) || isBlockInstruction(node) || isCallInstruction(node) || isCallIndirectInstruction(node) || isByteArray(node) || isFunc(node) || isInternalBrUnless(node) || isInternalGoto(node) || isInternalCallExtern(node) || isInternalEndAndReturn(node);
|
||||
};
|
||||
export var isBlock = function isBlock(node) {
|
||||
return isLoopInstruction(node) || isBlockInstruction(node) || isFunc(node);
|
||||
};
|
||||
export var isInstruction = function isInstruction(node) {
|
||||
return isLoopInstruction(node) || isInstr(node) || isIfInstruction(node) || isTypeInstruction(node) || isBlockInstruction(node) || isCallInstruction(node) || isCallIndirectInstruction(node);
|
||||
};
|
||||
export var isExpression = function isExpression(node) {
|
||||
return isInstr(node) || isStringLiteral(node) || isNumberLiteral(node) || isLongNumberLiteral(node) || isFloatLiteral(node) || isValtypeLiteral(node) || isIdentifier(node);
|
||||
};
|
||||
export var isNumericLiteral = function isNumericLiteral(node) {
|
||||
return isNumberLiteral(node) || isLongNumberLiteral(node) || isFloatLiteral(node);
|
||||
};
|
||||
export var isImportDescr = function isImportDescr(node) {
|
||||
return isGlobalType(node) || isTable(node) || isMemory(node) || isFuncImportDescr(node);
|
||||
};
|
||||
export var isIntrinsic = function isIntrinsic(node) {
|
||||
return isInternalBrUnless(node) || isInternalGoto(node) || isInternalCallExtern(node) || isInternalEndAndReturn(node);
|
||||
};
|
||||
export var assertModule = assertTypeOf("Module");
|
||||
export var assertModuleMetadata = assertTypeOf("ModuleMetadata");
|
||||
export var assertModuleNameMetadata = assertTypeOf("ModuleNameMetadata");
|
||||
export var assertFunctionNameMetadata = assertTypeOf("FunctionNameMetadata");
|
||||
export var assertLocalNameMetadata = assertTypeOf("LocalNameMetadata");
|
||||
export var assertBinaryModule = assertTypeOf("BinaryModule");
|
||||
export var assertQuoteModule = assertTypeOf("QuoteModule");
|
||||
export var assertSectionMetadata = assertTypeOf("SectionMetadata");
|
||||
export var assertProducersSectionMetadata = assertTypeOf("ProducersSectionMetadata");
|
||||
export var assertProducerMetadata = assertTypeOf("ProducerMetadata");
|
||||
export var assertProducerMetadataVersionedName = assertTypeOf("ProducerMetadataVersionedName");
|
||||
export var assertLoopInstruction = assertTypeOf("LoopInstruction");
|
||||
export var assertInstr = assertTypeOf("Instr");
|
||||
export var assertIfInstruction = assertTypeOf("IfInstruction");
|
||||
export var assertStringLiteral = assertTypeOf("StringLiteral");
|
||||
export var assertNumberLiteral = assertTypeOf("NumberLiteral");
|
||||
export var assertLongNumberLiteral = assertTypeOf("LongNumberLiteral");
|
||||
export var assertFloatLiteral = assertTypeOf("FloatLiteral");
|
||||
export var assertElem = assertTypeOf("Elem");
|
||||
export var assertIndexInFuncSection = assertTypeOf("IndexInFuncSection");
|
||||
export var assertValtypeLiteral = assertTypeOf("ValtypeLiteral");
|
||||
export var assertTypeInstruction = assertTypeOf("TypeInstruction");
|
||||
export var assertStart = assertTypeOf("Start");
|
||||
export var assertGlobalType = assertTypeOf("GlobalType");
|
||||
export var assertLeadingComment = assertTypeOf("LeadingComment");
|
||||
export var assertBlockComment = assertTypeOf("BlockComment");
|
||||
export var assertData = assertTypeOf("Data");
|
||||
export var assertGlobal = assertTypeOf("Global");
|
||||
export var assertTable = assertTypeOf("Table");
|
||||
export var assertMemory = assertTypeOf("Memory");
|
||||
export var assertFuncImportDescr = assertTypeOf("FuncImportDescr");
|
||||
export var assertModuleImport = assertTypeOf("ModuleImport");
|
||||
export var assertModuleExportDescr = assertTypeOf("ModuleExportDescr");
|
||||
export var assertModuleExport = assertTypeOf("ModuleExport");
|
||||
export var assertLimit = assertTypeOf("Limit");
|
||||
export var assertSignature = assertTypeOf("Signature");
|
||||
export var assertProgram = assertTypeOf("Program");
|
||||
export var assertIdentifier = assertTypeOf("Identifier");
|
||||
export var assertBlockInstruction = assertTypeOf("BlockInstruction");
|
||||
export var assertCallInstruction = assertTypeOf("CallInstruction");
|
||||
export var assertCallIndirectInstruction = assertTypeOf("CallIndirectInstruction");
|
||||
export var assertByteArray = assertTypeOf("ByteArray");
|
||||
export var assertFunc = assertTypeOf("Func");
|
||||
export var assertInternalBrUnless = assertTypeOf("InternalBrUnless");
|
||||
export var assertInternalGoto = assertTypeOf("InternalGoto");
|
||||
export var assertInternalCallExtern = assertTypeOf("InternalCallExtern");
|
||||
export var assertInternalEndAndReturn = assertTypeOf("InternalEndAndReturn");
|
||||
export var unionTypesMap = {
|
||||
Module: ["Node"],
|
||||
ModuleMetadata: ["Node"],
|
||||
ModuleNameMetadata: ["Node"],
|
||||
FunctionNameMetadata: ["Node"],
|
||||
LocalNameMetadata: ["Node"],
|
||||
BinaryModule: ["Node"],
|
||||
QuoteModule: ["Node"],
|
||||
SectionMetadata: ["Node"],
|
||||
ProducersSectionMetadata: ["Node"],
|
||||
ProducerMetadata: ["Node"],
|
||||
ProducerMetadataVersionedName: ["Node"],
|
||||
LoopInstruction: ["Node", "Block", "Instruction"],
|
||||
Instr: ["Node", "Expression", "Instruction"],
|
||||
IfInstruction: ["Node", "Instruction"],
|
||||
StringLiteral: ["Node", "Expression"],
|
||||
NumberLiteral: ["Node", "NumericLiteral", "Expression"],
|
||||
LongNumberLiteral: ["Node", "NumericLiteral", "Expression"],
|
||||
FloatLiteral: ["Node", "NumericLiteral", "Expression"],
|
||||
Elem: ["Node"],
|
||||
IndexInFuncSection: ["Node"],
|
||||
ValtypeLiteral: ["Node", "Expression"],
|
||||
TypeInstruction: ["Node", "Instruction"],
|
||||
Start: ["Node"],
|
||||
GlobalType: ["Node", "ImportDescr"],
|
||||
LeadingComment: ["Node"],
|
||||
BlockComment: ["Node"],
|
||||
Data: ["Node"],
|
||||
Global: ["Node"],
|
||||
Table: ["Node", "ImportDescr"],
|
||||
Memory: ["Node", "ImportDescr"],
|
||||
FuncImportDescr: ["Node", "ImportDescr"],
|
||||
ModuleImport: ["Node"],
|
||||
ModuleExportDescr: ["Node"],
|
||||
ModuleExport: ["Node"],
|
||||
Limit: ["Node"],
|
||||
Signature: ["Node"],
|
||||
Program: ["Node"],
|
||||
Identifier: ["Node", "Expression"],
|
||||
BlockInstruction: ["Node", "Block", "Instruction"],
|
||||
CallInstruction: ["Node", "Instruction"],
|
||||
CallIndirectInstruction: ["Node", "Instruction"],
|
||||
ByteArray: ["Node"],
|
||||
Func: ["Node", "Block"],
|
||||
InternalBrUnless: ["Node", "Intrinsic"],
|
||||
InternalGoto: ["Node", "Intrinsic"],
|
||||
InternalCallExtern: ["Node", "Intrinsic"],
|
||||
InternalEndAndReturn: ["Node", "Intrinsic"]
|
||||
};
|
||||
export var nodeAndUnionTypes = ["Module", "ModuleMetadata", "ModuleNameMetadata", "FunctionNameMetadata", "LocalNameMetadata", "BinaryModule", "QuoteModule", "SectionMetadata", "ProducersSectionMetadata", "ProducerMetadata", "ProducerMetadataVersionedName", "LoopInstruction", "Instr", "IfInstruction", "StringLiteral", "NumberLiteral", "LongNumberLiteral", "FloatLiteral", "Elem", "IndexInFuncSection", "ValtypeLiteral", "TypeInstruction", "Start", "GlobalType", "LeadingComment", "BlockComment", "Data", "Global", "Table", "Memory", "FuncImportDescr", "ModuleImport", "ModuleExportDescr", "ModuleExport", "Limit", "Signature", "Program", "Identifier", "BlockInstruction", "CallInstruction", "CallIndirectInstruction", "ByteArray", "Func", "InternalBrUnless", "InternalGoto", "InternalCallExtern", "InternalEndAndReturn", "Node", "Block", "Instruction", "Expression", "NumericLiteral", "ImportDescr", "Intrinsic"];
|
||||
199
node_modules/@webassemblyjs/ast/esm/signatures.js
generated
vendored
199
node_modules/@webassemblyjs/ast/esm/signatures.js
generated
vendored
|
|
@ -1,199 +0,0 @@
|
|||
function sign(input, output) {
|
||||
return [input, output];
|
||||
}
|
||||
|
||||
var u32 = "u32";
|
||||
var i32 = "i32";
|
||||
var i64 = "i64";
|
||||
var f32 = "f32";
|
||||
var f64 = "f64";
|
||||
|
||||
var vector = function vector(t) {
|
||||
var vecType = [t]; // $FlowIgnore
|
||||
|
||||
vecType.vector = true;
|
||||
return vecType;
|
||||
};
|
||||
|
||||
var controlInstructions = {
|
||||
unreachable: sign([], []),
|
||||
nop: sign([], []),
|
||||
// block ?
|
||||
// loop ?
|
||||
// if ?
|
||||
// if else ?
|
||||
br: sign([u32], []),
|
||||
br_if: sign([u32], []),
|
||||
br_table: sign(vector(u32), []),
|
||||
return: sign([], []),
|
||||
call: sign([u32], []),
|
||||
call_indirect: sign([u32], [])
|
||||
};
|
||||
var parametricInstructions = {
|
||||
drop: sign([], []),
|
||||
select: sign([], [])
|
||||
};
|
||||
var variableInstructions = {
|
||||
get_local: sign([u32], []),
|
||||
set_local: sign([u32], []),
|
||||
tee_local: sign([u32], []),
|
||||
get_global: sign([u32], []),
|
||||
set_global: sign([u32], [])
|
||||
};
|
||||
var memoryInstructions = {
|
||||
"i32.load": sign([u32, u32], [i32]),
|
||||
"i64.load": sign([u32, u32], []),
|
||||
"f32.load": sign([u32, u32], []),
|
||||
"f64.load": sign([u32, u32], []),
|
||||
"i32.load8_s": sign([u32, u32], [i32]),
|
||||
"i32.load8_u": sign([u32, u32], [i32]),
|
||||
"i32.load16_s": sign([u32, u32], [i32]),
|
||||
"i32.load16_u": sign([u32, u32], [i32]),
|
||||
"i64.load8_s": sign([u32, u32], [i64]),
|
||||
"i64.load8_u": sign([u32, u32], [i64]),
|
||||
"i64.load16_s": sign([u32, u32], [i64]),
|
||||
"i64.load16_u": sign([u32, u32], [i64]),
|
||||
"i64.load32_s": sign([u32, u32], [i64]),
|
||||
"i64.load32_u": sign([u32, u32], [i64]),
|
||||
"i32.store": sign([u32, u32], []),
|
||||
"i64.store": sign([u32, u32], []),
|
||||
"f32.store": sign([u32, u32], []),
|
||||
"f64.store": sign([u32, u32], []),
|
||||
"i32.store8": sign([u32, u32], []),
|
||||
"i32.store16": sign([u32, u32], []),
|
||||
"i64.store8": sign([u32, u32], []),
|
||||
"i64.store16": sign([u32, u32], []),
|
||||
"i64.store32": sign([u32, u32], []),
|
||||
current_memory: sign([], []),
|
||||
grow_memory: sign([], [])
|
||||
};
|
||||
var numericInstructions = {
|
||||
"i32.const": sign([i32], [i32]),
|
||||
"i64.const": sign([i64], [i64]),
|
||||
"f32.const": sign([f32], [f32]),
|
||||
"f64.const": sign([f64], [f64]),
|
||||
"i32.eqz": sign([i32], [i32]),
|
||||
"i32.eq": sign([i32, i32], [i32]),
|
||||
"i32.ne": sign([i32, i32], [i32]),
|
||||
"i32.lt_s": sign([i32, i32], [i32]),
|
||||
"i32.lt_u": sign([i32, i32], [i32]),
|
||||
"i32.gt_s": sign([i32, i32], [i32]),
|
||||
"i32.gt_u": sign([i32, i32], [i32]),
|
||||
"i32.le_s": sign([i32, i32], [i32]),
|
||||
"i32.le_u": sign([i32, i32], [i32]),
|
||||
"i32.ge_s": sign([i32, i32], [i32]),
|
||||
"i32.ge_u": sign([i32, i32], [i32]),
|
||||
"i64.eqz": sign([i64], [i64]),
|
||||
"i64.eq": sign([i64, i64], [i32]),
|
||||
"i64.ne": sign([i64, i64], [i32]),
|
||||
"i64.lt_s": sign([i64, i64], [i32]),
|
||||
"i64.lt_u": sign([i64, i64], [i32]),
|
||||
"i64.gt_s": sign([i64, i64], [i32]),
|
||||
"i64.gt_u": sign([i64, i64], [i32]),
|
||||
"i64.le_s": sign([i64, i64], [i32]),
|
||||
"i64.le_u": sign([i64, i64], [i32]),
|
||||
"i64.ge_s": sign([i64, i64], [i32]),
|
||||
"i64.ge_u": sign([i64, i64], [i32]),
|
||||
"f32.eq": sign([f32, f32], [i32]),
|
||||
"f32.ne": sign([f32, f32], [i32]),
|
||||
"f32.lt": sign([f32, f32], [i32]),
|
||||
"f32.gt": sign([f32, f32], [i32]),
|
||||
"f32.le": sign([f32, f32], [i32]),
|
||||
"f32.ge": sign([f32, f32], [i32]),
|
||||
"f64.eq": sign([f64, f64], [i32]),
|
||||
"f64.ne": sign([f64, f64], [i32]),
|
||||
"f64.lt": sign([f64, f64], [i32]),
|
||||
"f64.gt": sign([f64, f64], [i32]),
|
||||
"f64.le": sign([f64, f64], [i32]),
|
||||
"f64.ge": sign([f64, f64], [i32]),
|
||||
"i32.clz": sign([i32], [i32]),
|
||||
"i32.ctz": sign([i32], [i32]),
|
||||
"i32.popcnt": sign([i32], [i32]),
|
||||
"i32.add": sign([i32, i32], [i32]),
|
||||
"i32.sub": sign([i32, i32], [i32]),
|
||||
"i32.mul": sign([i32, i32], [i32]),
|
||||
"i32.div_s": sign([i32, i32], [i32]),
|
||||
"i32.div_u": sign([i32, i32], [i32]),
|
||||
"i32.rem_s": sign([i32, i32], [i32]),
|
||||
"i32.rem_u": sign([i32, i32], [i32]),
|
||||
"i32.and": sign([i32, i32], [i32]),
|
||||
"i32.or": sign([i32, i32], [i32]),
|
||||
"i32.xor": sign([i32, i32], [i32]),
|
||||
"i32.shl": sign([i32, i32], [i32]),
|
||||
"i32.shr_s": sign([i32, i32], [i32]),
|
||||
"i32.shr_u": sign([i32, i32], [i32]),
|
||||
"i32.rotl": sign([i32, i32], [i32]),
|
||||
"i32.rotr": sign([i32, i32], [i32]),
|
||||
"i64.clz": sign([i64], [i64]),
|
||||
"i64.ctz": sign([i64], [i64]),
|
||||
"i64.popcnt": sign([i64], [i64]),
|
||||
"i64.add": sign([i64, i64], [i64]),
|
||||
"i64.sub": sign([i64, i64], [i64]),
|
||||
"i64.mul": sign([i64, i64], [i64]),
|
||||
"i64.div_s": sign([i64, i64], [i64]),
|
||||
"i64.div_u": sign([i64, i64], [i64]),
|
||||
"i64.rem_s": sign([i64, i64], [i64]),
|
||||
"i64.rem_u": sign([i64, i64], [i64]),
|
||||
"i64.and": sign([i64, i64], [i64]),
|
||||
"i64.or": sign([i64, i64], [i64]),
|
||||
"i64.xor": sign([i64, i64], [i64]),
|
||||
"i64.shl": sign([i64, i64], [i64]),
|
||||
"i64.shr_s": sign([i64, i64], [i64]),
|
||||
"i64.shr_u": sign([i64, i64], [i64]),
|
||||
"i64.rotl": sign([i64, i64], [i64]),
|
||||
"i64.rotr": sign([i64, i64], [i64]),
|
||||
"f32.abs": sign([f32], [f32]),
|
||||
"f32.neg": sign([f32], [f32]),
|
||||
"f32.ceil": sign([f32], [f32]),
|
||||
"f32.floor": sign([f32], [f32]),
|
||||
"f32.trunc": sign([f32], [f32]),
|
||||
"f32.nearest": sign([f32], [f32]),
|
||||
"f32.sqrt": sign([f32], [f32]),
|
||||
"f32.add": sign([f32, f32], [f32]),
|
||||
"f32.sub": sign([f32, f32], [f32]),
|
||||
"f32.mul": sign([f32, f32], [f32]),
|
||||
"f32.div": sign([f32, f32], [f32]),
|
||||
"f32.min": sign([f32, f32], [f32]),
|
||||
"f32.max": sign([f32, f32], [f32]),
|
||||
"f32.copysign": sign([f32, f32], [f32]),
|
||||
"f64.abs": sign([f64], [f64]),
|
||||
"f64.neg": sign([f64], [f64]),
|
||||
"f64.ceil": sign([f64], [f64]),
|
||||
"f64.floor": sign([f64], [f64]),
|
||||
"f64.trunc": sign([f64], [f64]),
|
||||
"f64.nearest": sign([f64], [f64]),
|
||||
"f64.sqrt": sign([f64], [f64]),
|
||||
"f64.add": sign([f64, f64], [f64]),
|
||||
"f64.sub": sign([f64, f64], [f64]),
|
||||
"f64.mul": sign([f64, f64], [f64]),
|
||||
"f64.div": sign([f64, f64], [f64]),
|
||||
"f64.min": sign([f64, f64], [f64]),
|
||||
"f64.max": sign([f64, f64], [f64]),
|
||||
"f64.copysign": sign([f64, f64], [f64]),
|
||||
"i32.wrap/i64": sign([i64], [i32]),
|
||||
"i32.trunc_s/f32": sign([f32], [i32]),
|
||||
"i32.trunc_u/f32": sign([f32], [i32]),
|
||||
"i32.trunc_s/f64": sign([f32], [i32]),
|
||||
"i32.trunc_u/f64": sign([f64], [i32]),
|
||||
"i64.extend_s/i32": sign([i32], [i64]),
|
||||
"i64.extend_u/i32": sign([i32], [i64]),
|
||||
"i64.trunc_s/f32": sign([f32], [i64]),
|
||||
"i64.trunc_u/f32": sign([f32], [i64]),
|
||||
"i64.trunc_s/f64": sign([f64], [i64]),
|
||||
"i64.trunc_u/f64": sign([f64], [i64]),
|
||||
"f32.convert_s/i32": sign([i32], [f32]),
|
||||
"f32.convert_u/i32": sign([i32], [f32]),
|
||||
"f32.convert_s/i64": sign([i64], [f32]),
|
||||
"f32.convert_u/i64": sign([i64], [f32]),
|
||||
"f32.demote/f64": sign([f64], [f32]),
|
||||
"f64.convert_s/i32": sign([i32], [f64]),
|
||||
"f64.convert_u/i32": sign([i32], [f64]),
|
||||
"f64.convert_s/i64": sign([i64], [f64]),
|
||||
"f64.convert_u/i64": sign([i64], [f64]),
|
||||
"f64.promote/f32": sign([f32], [f64]),
|
||||
"i32.reinterpret/f32": sign([f32], [i32]),
|
||||
"i64.reinterpret/f64": sign([f64], [i64]),
|
||||
"f32.reinterpret/i32": sign([i32], [f32]),
|
||||
"f64.reinterpret/i64": sign([i64], [f64])
|
||||
};
|
||||
export var signatures = Object.assign({}, controlInstructions, parametricInstructions, variableInstructions, memoryInstructions, numericInstructions);
|
||||
76
node_modules/@webassemblyjs/ast/esm/transform/denormalize-type-references/index.js
generated
vendored
76
node_modules/@webassemblyjs/ast/esm/transform/denormalize-type-references/index.js
generated
vendored
|
|
@ -1,76 +0,0 @@
|
|||
var t = require("../../index"); // func and call_indirect instructions can either define a signature inline, or
|
||||
// reference a signature, e.g.
|
||||
//
|
||||
// ;; inline signature
|
||||
// (func (result i64)
|
||||
// (i64.const 2)
|
||||
// )
|
||||
// ;; signature reference
|
||||
// (type (func (result i64)))
|
||||
// (func (type 0)
|
||||
// (i64.const 2))
|
||||
// )
|
||||
//
|
||||
// this AST transform denormalises the type references, making all signatures within the module
|
||||
// inline.
|
||||
|
||||
|
||||
export function transform(ast) {
|
||||
var typeInstructions = [];
|
||||
t.traverse(ast, {
|
||||
TypeInstruction: function TypeInstruction(_ref) {
|
||||
var node = _ref.node;
|
||||
typeInstructions.push(node);
|
||||
}
|
||||
});
|
||||
|
||||
if (!typeInstructions.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
function denormalizeSignature(signature) {
|
||||
// signature referenced by identifier
|
||||
if (signature.type === "Identifier") {
|
||||
var identifier = signature;
|
||||
var typeInstruction = typeInstructions.find(function (t) {
|
||||
return t.id.type === identifier.type && t.id.value === identifier.value;
|
||||
});
|
||||
|
||||
if (!typeInstruction) {
|
||||
throw new Error("A type instruction reference was not found ".concat(JSON.stringify(signature)));
|
||||
}
|
||||
|
||||
return typeInstruction.functype;
|
||||
} // signature referenced by index
|
||||
|
||||
|
||||
if (signature.type === "NumberLiteral") {
|
||||
var signatureRef = signature;
|
||||
var _typeInstruction = typeInstructions[signatureRef.value];
|
||||
return _typeInstruction.functype;
|
||||
}
|
||||
|
||||
return signature;
|
||||
}
|
||||
|
||||
t.traverse(ast, {
|
||||
Func: function (_Func) {
|
||||
function Func(_x) {
|
||||
return _Func.apply(this, arguments);
|
||||
}
|
||||
|
||||
Func.toString = function () {
|
||||
return _Func.toString();
|
||||
};
|
||||
|
||||
return Func;
|
||||
}(function (_ref2) {
|
||||
var node = _ref2.node;
|
||||
node.signature = denormalizeSignature(node.signature);
|
||||
}),
|
||||
CallIndirectInstruction: function CallIndirectInstruction(_ref3) {
|
||||
var node = _ref3.node;
|
||||
node.signature = denormalizeSignature(node.signature);
|
||||
}
|
||||
});
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue