Add code to output required env to files

This commit is contained in:
Robert Brignull 2020-08-26 13:20:46 +01:00
parent 217483dfd6
commit 3ffe4b7421
3 changed files with 64 additions and 3 deletions

View file

@ -114,7 +114,39 @@ program
parseGithubUrl(cmd.githubUrl),
logger);
await runInit(codeql, config);
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);
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(`CodeQL 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)
.map(([key, value]) => `${key}="${value}"`)
.join('\n');
fs.writeFileSync(envFile, envFileContents);
logger.info(`CodeQL environment outputted to "${envFile}". ` +
`Please export these variables to future processes so the build can tbe traced, ` +
`for example by running "source ${envFile}".`);
}
}
} catch (e) {
logger.error('Init failed');