address review comments
This commit is contained in:
parent
6f422a4303
commit
1fd45d7407
9 changed files with 147 additions and 149 deletions
39
lib/codeql.js
generated
39
lib/codeql.js
generated
|
|
@ -31,24 +31,22 @@ const CODEQL_BUNDLE_VERSION = defaults.bundleVersion;
|
|||
const CODEQL_BUNDLE_NAME = "codeql-bundle.tar.gz";
|
||||
const CODEQL_DEFAULT_ACTION_REPOSITORY = "github/codeql-action";
|
||||
function getCodeQLActionRepository(mode) {
|
||||
if (mode === 'actions') {
|
||||
// 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.
|
||||
const runnerTemp = util.getRequiredEnvParam("RUNNER_TEMP");
|
||||
const actionsDirectory = path.join(path.dirname(runnerTemp), "_actions");
|
||||
const relativeScriptPath = path.relative(actionsDirectory, __filename);
|
||||
// This handles the case where the Action does not come from an Action repository,
|
||||
// e.g. our integration tests which use the Action code from the current checkout.
|
||||
if (relativeScriptPath.startsWith("..") || path.isAbsolute(relativeScriptPath)) {
|
||||
return CODEQL_DEFAULT_ACTION_REPOSITORY;
|
||||
}
|
||||
const relativeScriptPathParts = relativeScriptPath.split(path.sep);
|
||||
return relativeScriptPathParts[0] + "/" + relativeScriptPathParts[1];
|
||||
}
|
||||
else {
|
||||
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.
|
||||
const runnerTemp = util.getRequiredEnvParam("RUNNER_TEMP");
|
||||
const actionsDirectory = path.join(path.dirname(runnerTemp), "_actions");
|
||||
const relativeScriptPath = path.relative(actionsDirectory, __filename);
|
||||
// This handles the case where the Action does not come from an Action repository,
|
||||
// e.g. our integration tests which use the Action code from the current checkout.
|
||||
if (relativeScriptPath.startsWith("..") || path.isAbsolute(relativeScriptPath)) {
|
||||
return CODEQL_DEFAULT_ACTION_REPOSITORY;
|
||||
}
|
||||
const relativeScriptPathParts = relativeScriptPath.split(path.sep);
|
||||
return relativeScriptPathParts[0] + "/" + relativeScriptPathParts[1];
|
||||
}
|
||||
async function getCodeQLBundleDownloadURL(githubUrl, mode, logger) {
|
||||
const codeQLActionRepository = getCodeQLActionRepository(mode);
|
||||
|
|
@ -89,6 +87,8 @@ async function getCodeQLBundleDownloadURL(githubUrl, mode, logger) {
|
|||
}
|
||||
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, tempDir, logger) {
|
||||
const client = new http.HttpClient('CodeQL Action');
|
||||
const dest = path.join(tempDir, v4_1.default());
|
||||
|
|
@ -103,8 +103,8 @@ async function toolcacheDownloadTool(url, headers, tempDir, logger) {
|
|||
return dest;
|
||||
}
|
||||
async function setupCodeQL(codeqlURL, githubAuth, githubUrl, tempDir, toolsDir, mode, logger) {
|
||||
// Setting these two env vars makes the toolcache code safe to use,
|
||||
// but this is obviously not a great thing we're doing and it would
|
||||
// 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;
|
||||
|
|
@ -236,8 +236,7 @@ function getCodeQLForCmd(cmd) {
|
|||
]);
|
||||
},
|
||||
getTracerEnv: async function (databasePath) {
|
||||
// Write tracer-env.js to a temp location. When running in CLI mode we can't rely
|
||||
// on this file existing so we have to create it ourselves.
|
||||
// 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, `
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
34
lib/init.js
generated
34
lib/init.js
generated
|
|
@ -40,24 +40,22 @@ async function runInit(codeql, config) {
|
|||
await codeql.databaseInit(util.getCodeQLDatabasePath(config.tempDir, language), language, sourceRoot);
|
||||
}
|
||||
const tracerConfig = await tracer_config_1.getCombinedTracerConfig(config, codeql);
|
||||
if (tracerConfig !== undefined) {
|
||||
if (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 exec.exec('powershell', [
|
||||
injectTracerPath,
|
||||
path.resolve(path.dirname(codeql.getPath()), 'tools', 'win64', 'tracer.exe'),
|
||||
], { env: { 'ODASA_TRACER_CONFIGURATION': tracerConfig.spec } });
|
||||
}
|
||||
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 exec.exec('powershell', [
|
||||
injectTracerPath,
|
||||
path.resolve(path.dirname(codeql.getPath()), 'tools', 'win64', 'tracer.exe'),
|
||||
], { env: { 'ODASA_TRACER_CONFIGURATION': tracerConfig.spec } });
|
||||
}
|
||||
return tracerConfig;
|
||||
}
|
||||
|
|
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AAE,IAAI,EAAE,CAAC,CAAC;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,CAAC,IAAI,CACb,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;KACjE;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AArCD,0BAqCC"}
|
||||
69
lib/runner.js
generated
69
lib/runner.js
generated
|
|
@ -64,7 +64,7 @@ function checkEnvironmentSetup(config) {
|
|||
if (config.languages.some(languages_1.isTracedLanguage) && !('ODASA_TRACER_CONFIGURATION' in process.env)) {
|
||||
throw new Error("Could not detect 'ODASA_TRACER_CONFIGURATION' in environment. " +
|
||||
"Make sure that environment variables were correctly exported to future processes. " +
|
||||
"See end out output from 'init' command for instructions.");
|
||||
"See end of output from 'init' command for instructions.");
|
||||
}
|
||||
}
|
||||
program
|
||||
|
|
@ -77,7 +77,7 @@ program
|
|||
.option('--queries <queries>', 'Comma-separated list of additional queries to run. By default, 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. By default will use current working directory.')
|
||||
.option('--temp-dir <dir>', 'Directory to use for temporary files. By default will use a subdirectory of the current working directory.')
|
||||
.option('--tools-dir <dir>', 'Directory to use for CodeQL tools and other files to store between runs. By default will use home directory.')
|
||||
.option('--checkout-path <path>', 'Checkout path (default: current working directory)')
|
||||
.option('--debug', 'Print more verbose output', false)
|
||||
|
|
@ -98,35 +98,36 @@ program
|
|||
}
|
||||
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) {
|
||||
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 outputted to "${batEnvFileContents}" and "${powershellEnvFile}". ` +
|
||||
`Please export these variables to future processes so the build can tbe traced. ` +
|
||||
`If using cmd/batch run "call ${batEnvFileContents}" ` +
|
||||
`or if using PowerShell run "cat ${powershellEnvFile} | Invoke-Expression".`);
|
||||
}
|
||||
else {
|
||||
// Assume that anything that's not windows is using a unix-style shell
|
||||
const envFile = path.join(config.tempDir, 'codeql-env.sh');
|
||||
const envFileContents = 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(envFile, envFileContents);
|
||||
logger.info(`\nCodeQL environment outputted to "${envFile}". ` +
|
||||
`Please export these variables to future processes so the build can tbe traced, ` +
|
||||
`for example by running "source ${envFile}".`);
|
||||
}
|
||||
if (tracerConfig === undefined) {
|
||||
return;
|
||||
}
|
||||
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 "${batEnvFileContents}" and "${powershellEnvFile}". ` +
|
||||
`Please export these variables to future processes so the build can be traced. ` +
|
||||
`If using cmd/batch run "call ${batEnvFileContents}" ` +
|
||||
`or if using PowerShell run "cat ${powershellEnvFile} | Invoke-Expression".`);
|
||||
}
|
||||
else {
|
||||
// Assume that anything that's not windows is using a unix-style shell
|
||||
const envFile = path.join(config.tempDir, 'codeql-env.sh');
|
||||
const envFileContents = 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(envFile, envFileContents);
|
||||
logger.info(`\nCodeQL environment output to "${envFile}". ` +
|
||||
`Please export these variables to future processes so the build can be traced, ` +
|
||||
`for example by running "source ${envFile}".`);
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
|
|
@ -139,7 +140,7 @@ program
|
|||
.command('autobuild')
|
||||
.description('Attempts to automatically build code')
|
||||
.option('--language <language>', 'The language to build. By default will try to detect the dominant language.')
|
||||
.option('--temp-dir <dir>', 'Directory to use for temporary files. By default will use current working directory.')
|
||||
.option('--temp-dir <dir>', 'Directory to use for temporary files. By default will use a subdirectory of the current working directory.')
|
||||
.option('--debug', 'Print more verbose output', false)
|
||||
.action(async (cmd) => {
|
||||
const logger = logging_1.getRunnerLogger(cmd.debug);
|
||||
|
|
@ -178,7 +179,7 @@ program
|
|||
.option('--checkout-path <path>', 'Checkout path (default: current working directory)')
|
||||
.option('--no-upload', 'Do not upload results after analysis', false)
|
||||
.option('--output-dir <dir>', 'Directory to output SARIF files to. By default will use temp directory.')
|
||||
.option('--temp-dir <dir>', 'Directory to use for temporary files. By default will use current working directory.')
|
||||
.option('--temp-dir <dir>', 'Directory to use for temporary files. By default will use a subdirectory of the current working directory.')
|
||||
.option('--debug', 'Print more verbose output', false)
|
||||
.action(async (cmd) => {
|
||||
const logger = logging_1.getRunnerLogger(cmd.debug);
|
||||
|
|
@ -190,7 +191,7 @@ program
|
|||
await analyze_1.runAnalyze(repository_1.parseRepositoryNwo(cmd.repository), cmd.commit, cmd.ref, undefined, undefined, undefined, cmd.checkoutPath || process.cwd(), undefined, cmd.githubAuth, parseGithubUrl(cmd.githubUrl), cmd.upload, 'runner', outputDir, config, logger);
|
||||
}
|
||||
catch (e) {
|
||||
logger.error('Upload failed');
|
||||
logger.error('Analyze failed');
|
||||
logger.error(e);
|
||||
process.exitCode = 1;
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -102,24 +102,23 @@ const CODEQL_BUNDLE_NAME = "codeql-bundle.tar.gz";
|
|||
const CODEQL_DEFAULT_ACTION_REPOSITORY = "github/codeql-action";
|
||||
|
||||
function getCodeQLActionRepository(mode: util.Mode): string {
|
||||
if (mode === 'actions') {
|
||||
// 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.
|
||||
const runnerTemp = util.getRequiredEnvParam("RUNNER_TEMP");
|
||||
const actionsDirectory = path.join(path.dirname(runnerTemp), "_actions");
|
||||
const relativeScriptPath = path.relative(actionsDirectory, __filename);
|
||||
// This handles the case where the Action does not come from an Action repository,
|
||||
// e.g. our integration tests which use the Action code from the current checkout.
|
||||
if (relativeScriptPath.startsWith("..") || path.isAbsolute(relativeScriptPath)) {
|
||||
return CODEQL_DEFAULT_ACTION_REPOSITORY;
|
||||
}
|
||||
const relativeScriptPathParts = relativeScriptPath.split(path.sep);
|
||||
return relativeScriptPathParts[0] + "/" + relativeScriptPathParts[1];
|
||||
|
||||
} else {
|
||||
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.
|
||||
const runnerTemp = util.getRequiredEnvParam("RUNNER_TEMP");
|
||||
const actionsDirectory = path.join(path.dirname(runnerTemp), "_actions");
|
||||
const relativeScriptPath = path.relative(actionsDirectory, __filename);
|
||||
// This handles the case where the Action does not come from an Action repository,
|
||||
// e.g. our integration tests which use the Action code from the current checkout.
|
||||
if (relativeScriptPath.startsWith("..") || path.isAbsolute(relativeScriptPath)) {
|
||||
return CODEQL_DEFAULT_ACTION_REPOSITORY;
|
||||
}
|
||||
const relativeScriptPathParts = relativeScriptPath.split(path.sep);
|
||||
return relativeScriptPathParts[0] + "/" + relativeScriptPathParts[1];
|
||||
}
|
||||
|
||||
async function getCodeQLBundleDownloadURL(githubUrl: string, mode: util.Mode, logger: Logger): Promise<string> {
|
||||
|
|
@ -161,6 +160,8 @@ async function getCodeQLBundleDownloadURL(githubUrl: string, mode: util.Mode, lo
|
|||
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: string,
|
||||
headers: IHeaders | undefined,
|
||||
|
|
@ -189,8 +190,8 @@ export async function setupCodeQL(
|
|||
mode: util.Mode,
|
||||
logger: Logger): Promise<CodeQL> {
|
||||
|
||||
// Setting these two env vars makes the toolcache code safe to use,
|
||||
// but this is obviously not a great thing we're doing and it would
|
||||
// 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;
|
||||
|
|
@ -334,8 +335,7 @@ function getCodeQLForCmd(cmd: string): CodeQL {
|
|||
]);
|
||||
},
|
||||
getTracerEnv: async function(databasePath: string) {
|
||||
// Write tracer-env.js to a temp location. When running in CLI mode we can't rely
|
||||
// on this file existing so we have to create it ourselves.
|
||||
// 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, `
|
||||
|
|
|
|||
40
src/init.ts
40
src/init.ts
|
|
@ -79,28 +79,26 @@ export async function runInit(
|
|||
}
|
||||
|
||||
const tracerConfig = await getCombinedTracerConfig(config, codeql);
|
||||
if (tracerConfig !== undefined) {
|
||||
if (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"`);
|
||||
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 exec.exec(
|
||||
'powershell',
|
||||
[
|
||||
injectTracerPath,
|
||||
path.resolve(path.dirname(codeql.getPath()), 'tools', 'win64', 'tracer.exe'),
|
||||
],
|
||||
{ env: { 'ODASA_TRACER_CONFIGURATION': tracerConfig.spec } });
|
||||
}
|
||||
await exec.exec(
|
||||
'powershell',
|
||||
[
|
||||
injectTracerPath,
|
||||
path.resolve(path.dirname(codeql.getPath()), 'tools', 'win64', 'tracer.exe'),
|
||||
],
|
||||
{ env: { 'ODASA_TRACER_CONFIGURATION': tracerConfig.spec } });
|
||||
}
|
||||
return tracerConfig;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ function checkEnvironmentSetup(config: Config) {
|
|||
if (config.languages.some(isTracedLanguage) && !('ODASA_TRACER_CONFIGURATION' in process.env)) {
|
||||
throw new Error("Could not detect 'ODASA_TRACER_CONFIGURATION' in environment. " +
|
||||
"Make sure that environment variables were correctly exported to future processes. " +
|
||||
"See end out output from 'init' command for instructions.");
|
||||
"See end of output from 'init' command for instructions.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -89,7 +89,7 @@ program
|
|||
.option('--queries <queries>', 'Comma-separated list of additional queries to run. By default, 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. By default will use current working directory.')
|
||||
.option('--temp-dir <dir>', 'Directory to use for temporary files. By default will use a subdirectory of the current working directory.')
|
||||
.option('--tools-dir <dir>', 'Directory to use for CodeQL tools and other files to store between runs. By default will use home directory.')
|
||||
.option('--checkout-path <path>', 'Checkout path (default: current working directory)')
|
||||
.option('--debug', 'Print more verbose output', false)
|
||||
|
|
@ -131,38 +131,40 @@ program
|
|||
logger);
|
||||
|
||||
const tracerConfig = await runInit(codeql, config);
|
||||
if (tracerConfig !== undefined) {
|
||||
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);
|
||||
if (tracerConfig === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
logger.info(`\nCodeQL environment outputted to "${batEnvFileContents}" and "${powershellEnvFile}". ` +
|
||||
`Please export these variables to future processes so the build can tbe traced. ` +
|
||||
`If using cmd/batch run "call ${batEnvFileContents}" ` +
|
||||
`or if using PowerShell run "cat ${powershellEnvFile} | Invoke-Expression".`);
|
||||
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);
|
||||
|
||||
} else {
|
||||
// Assume that anything that's not windows is using a unix-style shell
|
||||
const envFile = path.join(config.tempDir, 'codeql-env.sh');
|
||||
const envFileContents = 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(envFile, envFileContents);
|
||||
logger.info(`\nCodeQL environment output to "${batEnvFileContents}" and "${powershellEnvFile}". ` +
|
||||
`Please export these variables to future processes so the build can be traced. ` +
|
||||
`If using cmd/batch run "call ${batEnvFileContents}" ` +
|
||||
`or if using PowerShell run "cat ${powershellEnvFile} | Invoke-Expression".`);
|
||||
|
||||
logger.info(`\nCodeQL environment outputted to "${envFile}". ` +
|
||||
`Please export these variables to future processes so the build can tbe traced, ` +
|
||||
`for example by running "source ${envFile}".`);
|
||||
}
|
||||
} else {
|
||||
// Assume that anything that's not windows is using a unix-style shell
|
||||
const envFile = path.join(config.tempDir, 'codeql-env.sh');
|
||||
const envFileContents = 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(envFile, envFileContents);
|
||||
|
||||
logger.info(`\nCodeQL environment output to "${envFile}". ` +
|
||||
`Please export these variables to future processes so the build can be traced, ` +
|
||||
`for example by running "source ${envFile}".`);
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
|
|
@ -182,7 +184,7 @@ program
|
|||
.command('autobuild')
|
||||
.description('Attempts to automatically build code')
|
||||
.option('--language <language>', 'The language to build. By default will try to detect the dominant language.')
|
||||
.option('--temp-dir <dir>', 'Directory to use for temporary files. By default will use current working directory.')
|
||||
.option('--temp-dir <dir>', 'Directory to use for temporary files. By default will use a subdirectory of the current working directory.')
|
||||
.option('--debug', 'Print more verbose output', false)
|
||||
.action(async (cmd: AutobuildArgs) => {
|
||||
const logger = getRunnerLogger(cmd.debug);
|
||||
|
|
@ -233,7 +235,7 @@ program
|
|||
.option('--checkout-path <path>', 'Checkout path (default: current working directory)')
|
||||
.option('--no-upload', 'Do not upload results after analysis', false)
|
||||
.option('--output-dir <dir>', 'Directory to output SARIF files to. By default will use temp directory.')
|
||||
.option('--temp-dir <dir>', 'Directory to use for temporary files. By default will use current working directory.')
|
||||
.option('--temp-dir <dir>', 'Directory to use for temporary files. By default will use a subdirectory of the current working directory.')
|
||||
.option('--debug', 'Print more verbose output', false)
|
||||
.action(async (cmd: AnalyzeArgs) => {
|
||||
const logger = getRunnerLogger(cmd.debug);
|
||||
|
|
@ -259,7 +261,7 @@ program
|
|||
config,
|
||||
logger);
|
||||
} catch (e) {
|
||||
logger.error('Upload failed');
|
||||
logger.error('Analyze failed');
|
||||
logger.error(e);
|
||||
process.exitCode = 1;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue