Merge pull request #167 from github/windows_tracing
Fix tracing on windows for the runner, and when using multiple self-hosted actions runners
This commit is contained in:
commit
506e641669
9 changed files with 224 additions and 35 deletions
3
lib/init-action.js
generated
3
lib/init-action.js
generated
|
|
@ -63,6 +63,9 @@ async function run() {
|
||||||
const tracerConfig = await init_1.runInit(codeql, config);
|
const tracerConfig = await init_1.runInit(codeql, config);
|
||||||
if (tracerConfig !== undefined) {
|
if (tracerConfig !== undefined) {
|
||||||
Object.entries(tracerConfig.env).forEach(([key, value]) => core.exportVariable(key, value));
|
Object.entries(tracerConfig.env).forEach(([key, value]) => core.exportVariable(key, value));
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
await init_1.injectWindowsTracer('Runner.Worker.exe', undefined, config, codeql, tracerConfig);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"init-action.js","sourceRoot":"","sources":["../src/init-action.ts"],"names":[],"mappings":";;;;;;;;;AAAA,oDAAsC;AAItC,iCAAyD;AACzD,uCAA6C;AAC7C,6CAAkD;AAClD,6CAA+B;AAkB/B,KAAK,UAAU,uBAAuB,CAAC,SAAe,EAAE,MAA0B;IAChF,MAAM,gBAAgB,GAAG,MAAM,IAAI,CAAC,sBAAsB,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;IAEzF,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC7C,MAAM,iBAAiB,GAAG,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;IAC1E,MAAM,KAAK,GAAG,CAAC,MAAM,CAAC,iBAAiB,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC/D,MAAM,WAAW,GAAG,CAAC,MAAM,CAA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AAC,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"}
|
||||||
87
lib/init.js
generated
87
lib/init.js
generated
|
|
@ -39,25 +39,84 @@ async function runInit(codeql, config) {
|
||||||
// Init language database
|
// Init language database
|
||||||
await codeql.databaseInit(util.getCodeQLDatabasePath(config.tempDir, language), language, sourceRoot);
|
await codeql.databaseInit(util.getCodeQLDatabasePath(config.tempDir, language), language, sourceRoot);
|
||||||
}
|
}
|
||||||
const tracerConfig = await tracer_config_1.getCombinedTracerConfig(config, codeql);
|
return await tracer_config_1.getCombinedTracerConfig(config, codeql);
|
||||||
if (tracerConfig !== undefined && process.platform === 'win32') {
|
}
|
||||||
const injectTracerPath = path.join(config.tempDir, 'inject-tracer.ps1');
|
exports.runInit = runInit;
|
||||||
fs.writeFileSync(injectTracerPath, `
|
// Runs a powershell script to inject the tracer into a parent process
|
||||||
|
// so it can tracer future processes, hopefully including the build process.
|
||||||
|
// If processName is given then injects into the nearest parent process with
|
||||||
|
// this name, otherwise uses the processLevel-th parent if defined, otherwise
|
||||||
|
// defaults to the 3rd parent as a rough guess.
|
||||||
|
async function injectWindowsTracer(processName, processLevel, config, codeql, tracerConfig) {
|
||||||
|
let script;
|
||||||
|
if (processName !== undefined) {
|
||||||
|
script = `
|
||||||
Param(
|
Param(
|
||||||
[Parameter(Position=0)]
|
[Parameter(Position=0)]
|
||||||
[String]
|
[String]
|
||||||
$tracer
|
$tracer
|
||||||
)
|
)
|
||||||
Get-Process -Name Runner.Worker
|
|
||||||
$process=Get-Process -Name Runner.Worker
|
$id = $PID
|
||||||
$id=$process.Id
|
while ($true) {
|
||||||
Invoke-Expression "&$tracer --inject=$id"`);
|
$p = Get-CimInstance -Class Win32_Process -Filter "ProcessId = $id"
|
||||||
await new toolrunnner.ToolRunner('powershell', [
|
Write-Host "Found process: $p"
|
||||||
injectTracerPath,
|
if ($p -eq $null) {
|
||||||
path.resolve(path.dirname(codeql.getPath()), 'tools', 'win64', 'tracer.exe'),
|
throw "Could not determine ${processName} process"
|
||||||
], { env: { 'ODASA_TRACER_CONFIGURATION': tracerConfig.spec } }).exec();
|
}
|
||||||
|
if ($p[0].Name -eq "${processName}") {
|
||||||
|
Break
|
||||||
|
} else {
|
||||||
|
$id = $p[0].ParentProcessId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Write-Host "Final process: $p"
|
||||||
|
|
||||||
|
Invoke-Expression "&$tracer --inject=$id"`;
|
||||||
}
|
}
|
||||||
return tracerConfig;
|
else {
|
||||||
|
// If the level is not defined then guess at the 3rd parent process.
|
||||||
|
// This won't be correct in every setting but it should be enough in most settings,
|
||||||
|
// and overestimating is likely better in this situation so we definitely trace
|
||||||
|
// what we want, though this does run the risk of interfering with future CI jobs.
|
||||||
|
// Note that the default of 3 doesn't work on github actions, so we include a
|
||||||
|
// special case in the script that checks for Runner.Worker.exe so we can still work
|
||||||
|
// on actions if the runner is invoked there.
|
||||||
|
processLevel = processLevel || 3;
|
||||||
|
script = `
|
||||||
|
Param(
|
||||||
|
[Parameter(Position=0)]
|
||||||
|
[String]
|
||||||
|
$tracer
|
||||||
|
)
|
||||||
|
|
||||||
|
$id = $PID
|
||||||
|
for ($i = 0; $i -le ${processLevel}; $i++) {
|
||||||
|
$p = Get-CimInstance -Class Win32_Process -Filter "ProcessId = $id"
|
||||||
|
Write-Host "Parent process \${i}: $p"
|
||||||
|
if ($p -eq $null) {
|
||||||
|
throw "Process tree ended before reaching required level"
|
||||||
|
}
|
||||||
|
# Special case just in case the runner is used on actions
|
||||||
|
if ($p[0].Name -eq "Runner.Worker.exe") {
|
||||||
|
Write-Host "Found Runner.Worker.exe process which means we are running on GitHub Actions"
|
||||||
|
Write-Host "Aborting search early and using process: $p"
|
||||||
|
Break
|
||||||
|
} else {
|
||||||
|
$id = $p[0].ParentProcessId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Write-Host "Final process: $p"
|
||||||
|
|
||||||
|
Invoke-Expression "&$tracer --inject=$id"`;
|
||||||
|
}
|
||||||
|
const injectTracerPath = path.join(config.tempDir, 'inject-tracer.ps1');
|
||||||
|
fs.writeFileSync(injectTracerPath, script);
|
||||||
|
await new toolrunnner.ToolRunner('powershell', [
|
||||||
|
'-ExecutionPolicy', 'Bypass',
|
||||||
|
'-file', injectTracerPath,
|
||||||
|
path.resolve(path.dirname(codeql.getPath()), 'tools', 'win64', 'tracer.exe'),
|
||||||
|
], { env: { 'ODASA_TRACER_CONFIGURATION': tracerConfig.spec } }).exec();
|
||||||
}
|
}
|
||||||
exports.runInit = runInit;
|
exports.injectWindowsTracer = injectWindowsTracer;
|
||||||
//# sourceMappingURL=init.js.map
|
//# sourceMappingURL=init.js.map
|
||||||
|
|
@ -1 +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;AAG9C,mDAAwE;AACxE,6CAA+B;AAExB,KAAK,UAAU,UAAU,CAC9B,SAA6B,EAC7B,UAAkB,EAClB,SAAiB,EACjB,OAAe,EACf,QAAgB,EAChB,IAAe,EACf,MAAc;IAEd,MAAM,CAAC,UAAU,CAAC,oBAAoB,CAAC,CAAC;IACxC,MAAM,MAAM,GAAG,MAAM,oBAAW,CAC9B,SAAS,EACT,UAAU,EACV,SAAS,EACT,OAAO,EACP,QAAQ,EACR,IAAI,EACJ,MAAM,CAAC,CAAC;IACV,MAAM,MAAM,CAAC,YAAY,EAAE,CAAC;IAC5B,MAAM,CAAC,QAAQ,EAAE,CAAC;IAClB,OAAO,MAAM,CAAC;AAChB,CAAC;AArBD,gCAqBC;AAEM,KAAK,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QO,CAAC;KAC9C;SAAM;QACL,oEAAoE;QACpE,mFAAmF;QACnF,+EAA+E;QAC/E,kFAAkF;QAClF,6EAA6E;QAC7E,oFAAoF;QACpF,6CAA6C;QAC7C,YAAY,GAAG,YAAY,IAAI,CAAC,CAAC;QACjC,MAAM,GAAG;;;;;;;;4BAQe,YAAY;;;;;;;;;;;;;;;;;gDAiBQ,CAAC;KAC9C;IAED,MAAM,gBAAgB,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;IACxE,EAAE,CAAC,aAAa,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;IAE3C,MAAM,IAAI,WAAW,CAAC,UAAU,CAC9B,YAAY,EACZ;QACE,kBAAkB,EAAE,QAAQ;QAC5B,OAAO,EAAE,gBAAgB;QACzB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC;KAC7E,EACD,EAAE,GAAG,EAAE,EAAE,4BAA4B,EAAE,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;AACzE,CAAC;AAhFD,kDAgFC"}
|
||||||
25
lib/runner.js
generated
25
lib/runner.js
generated
|
|
@ -74,6 +74,25 @@ function parseRef(userInput) {
|
||||||
return 'refs/heads/' + userInput;
|
return 'refs/heads/' + userInput;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Parses the --trace-process-name arg from process.argv, or returns undefined
|
||||||
|
function parseTraceProcessName() {
|
||||||
|
for (let i = 0; i < process.argv.length - 1; i++) {
|
||||||
|
if (process.argv[i] === '--trace-process-name') {
|
||||||
|
return process.argv[i + 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
// Parses the --trace-process-level arg from process.argv, or returns undefined
|
||||||
|
function parseTraceProcessLevel() {
|
||||||
|
for (let i = 0; i < process.argv.length - 1; i++) {
|
||||||
|
if (process.argv[i] === '--trace-process-level') {
|
||||||
|
const v = parseInt(process.argv[i + 1], 10);
|
||||||
|
return isNaN(v) ? undefined : v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
program
|
program
|
||||||
.command('init')
|
.command('init')
|
||||||
.description('Initializes CodeQL')
|
.description('Initializes CodeQL')
|
||||||
|
|
@ -88,6 +107,9 @@ program
|
||||||
.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('--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('--checkout-path <path>', 'Checkout path. Default is the current working directory.')
|
||||||
.option('--debug', 'Print more verbose output', false)
|
.option('--debug', 'Print more verbose output', false)
|
||||||
|
// This prevents a message like: error: unknown option '--trace-process-level'
|
||||||
|
// Remove this if commander.js starts supporting hidden options.
|
||||||
|
.allowUnknownOption()
|
||||||
.action(async (cmd) => {
|
.action(async (cmd) => {
|
||||||
const logger = logging_1.getRunnerLogger(cmd.debug);
|
const logger = logging_1.getRunnerLogger(cmd.debug);
|
||||||
try {
|
try {
|
||||||
|
|
@ -109,6 +131,9 @@ program
|
||||||
if (tracerConfig === undefined) {
|
if (tracerConfig === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
await init_1.injectWindowsTracer(parseTraceProcessName(), parseTraceProcessLevel(), config, codeql, tracerConfig);
|
||||||
|
}
|
||||||
// Always output a json file of the env that can be consumed programatically
|
// Always output a json file of the env that can be consumed programatically
|
||||||
const jsonEnvFile = path.join(config.tempDir, codeqlEnvJsonFilename);
|
const jsonEnvFile = path.join(config.tempDir, codeqlEnvJsonFilename);
|
||||||
fs.writeFileSync(jsonEnvFile, JSON.stringify(tracerConfig.env));
|
fs.writeFileSync(jsonEnvFile, JSON.stringify(tracerConfig.env));
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -2,7 +2,7 @@ import * as core from '@actions/core';
|
||||||
|
|
||||||
import { CodeQL } from './codeql';
|
import { CodeQL } from './codeql';
|
||||||
import * as configUtils from './config-utils';
|
import * as configUtils from './config-utils';
|
||||||
import { initCodeQL, initConfig, runInit } from './init';
|
import { initCodeQL, initConfig, injectWindowsTracer, runInit } from './init';
|
||||||
import { getActionsLogger } from './logging';
|
import { getActionsLogger } from './logging';
|
||||||
import { parseRepositoryNwo } from './repository';
|
import { parseRepositoryNwo } from './repository';
|
||||||
import * as util from './util';
|
import * as util from './util';
|
||||||
|
|
@ -102,6 +102,10 @@ async function run() {
|
||||||
const tracerConfig = await runInit(codeql, config);
|
const tracerConfig = await runInit(codeql, config);
|
||||||
if (tracerConfig !== undefined) {
|
if (tracerConfig !== undefined) {
|
||||||
Object.entries(tracerConfig.env).forEach(([key, value]) => core.exportVariable(key, value));
|
Object.entries(tracerConfig.env).forEach(([key, value]) => core.exportVariable(key, value));
|
||||||
|
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
await injectWindowsTracer('Runner.Worker.exe', undefined, config, codeql, tracerConfig);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
97
src/init.ts
97
src/init.ts
|
|
@ -78,27 +78,92 @@ export async function runInit(
|
||||||
await codeql.databaseInit(util.getCodeQLDatabasePath(config.tempDir, language), language, sourceRoot);
|
await codeql.databaseInit(util.getCodeQLDatabasePath(config.tempDir, language), language, sourceRoot);
|
||||||
}
|
}
|
||||||
|
|
||||||
const tracerConfig = await getCombinedTracerConfig(config, codeql);
|
return await getCombinedTracerConfig(config, codeql);
|
||||||
if (tracerConfig !== undefined && process.platform === 'win32') {
|
}
|
||||||
const injectTracerPath = path.join(config.tempDir, 'inject-tracer.ps1');
|
|
||||||
fs.writeFileSync(injectTracerPath, `
|
// Runs a powershell script to inject the tracer into a parent process
|
||||||
|
// so it can tracer future processes, hopefully including the build process.
|
||||||
|
// If processName is given then injects into the nearest parent process with
|
||||||
|
// this name, otherwise uses the processLevel-th parent if defined, otherwise
|
||||||
|
// defaults to the 3rd parent as a rough guess.
|
||||||
|
export async function injectWindowsTracer(
|
||||||
|
processName: string | undefined,
|
||||||
|
processLevel: number | undefined,
|
||||||
|
config: configUtils.Config,
|
||||||
|
codeql: CodeQL,
|
||||||
|
tracerConfig: TracerConfig) {
|
||||||
|
|
||||||
|
let script: string;
|
||||||
|
if (processName !== undefined) {
|
||||||
|
script = `
|
||||||
Param(
|
Param(
|
||||||
[Parameter(Position=0)]
|
[Parameter(Position=0)]
|
||||||
[String]
|
[String]
|
||||||
$tracer
|
$tracer
|
||||||
)
|
)
|
||||||
Get-Process -Name Runner.Worker
|
|
||||||
$process=Get-Process -Name Runner.Worker
|
|
||||||
$id=$process.Id
|
|
||||||
Invoke-Expression "&$tracer --inject=$id"`);
|
|
||||||
|
|
||||||
await new toolrunnner.ToolRunner(
|
$id = $PID
|
||||||
'powershell',
|
while ($true) {
|
||||||
[
|
$p = Get-CimInstance -Class Win32_Process -Filter "ProcessId = $id"
|
||||||
injectTracerPath,
|
Write-Host "Found process: $p"
|
||||||
path.resolve(path.dirname(codeql.getPath()), 'tools', 'win64', 'tracer.exe'),
|
if ($p -eq $null) {
|
||||||
],
|
throw "Could not determine ${processName} process"
|
||||||
{ env: { 'ODASA_TRACER_CONFIGURATION': tracerConfig.spec } }).exec();
|
}
|
||||||
|
if ($p[0].Name -eq "${processName}") {
|
||||||
|
Break
|
||||||
|
} else {
|
||||||
|
$id = $p[0].ParentProcessId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Write-Host "Final process: $p"
|
||||||
|
|
||||||
|
Invoke-Expression "&$tracer --inject=$id"`;
|
||||||
|
} else {
|
||||||
|
// If the level is not defined then guess at the 3rd parent process.
|
||||||
|
// This won't be correct in every setting but it should be enough in most settings,
|
||||||
|
// and overestimating is likely better in this situation so we definitely trace
|
||||||
|
// what we want, though this does run the risk of interfering with future CI jobs.
|
||||||
|
// Note that the default of 3 doesn't work on github actions, so we include a
|
||||||
|
// special case in the script that checks for Runner.Worker.exe so we can still work
|
||||||
|
// on actions if the runner is invoked there.
|
||||||
|
processLevel = processLevel || 3;
|
||||||
|
script = `
|
||||||
|
Param(
|
||||||
|
[Parameter(Position=0)]
|
||||||
|
[String]
|
||||||
|
$tracer
|
||||||
|
)
|
||||||
|
|
||||||
|
$id = $PID
|
||||||
|
for ($i = 0; $i -le ${processLevel}; $i++) {
|
||||||
|
$p = Get-CimInstance -Class Win32_Process -Filter "ProcessId = $id"
|
||||||
|
Write-Host "Parent process \${i}: $p"
|
||||||
|
if ($p -eq $null) {
|
||||||
|
throw "Process tree ended before reaching required level"
|
||||||
|
}
|
||||||
|
# Special case just in case the runner is used on actions
|
||||||
|
if ($p[0].Name -eq "Runner.Worker.exe") {
|
||||||
|
Write-Host "Found Runner.Worker.exe process which means we are running on GitHub Actions"
|
||||||
|
Write-Host "Aborting search early and using process: $p"
|
||||||
|
Break
|
||||||
|
} else {
|
||||||
|
$id = $p[0].ParentProcessId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Write-Host "Final process: $p"
|
||||||
|
|
||||||
|
Invoke-Expression "&$tracer --inject=$id"`;
|
||||||
}
|
}
|
||||||
return tracerConfig;
|
|
||||||
|
const injectTracerPath = path.join(config.tempDir, 'inject-tracer.ps1');
|
||||||
|
fs.writeFileSync(injectTracerPath, script);
|
||||||
|
|
||||||
|
await new toolrunnner.ToolRunner(
|
||||||
|
'powershell',
|
||||||
|
[
|
||||||
|
'-ExecutionPolicy', 'Bypass',
|
||||||
|
'-file', injectTracerPath,
|
||||||
|
path.resolve(path.dirname(codeql.getPath()), 'tools', 'win64', 'tracer.exe'),
|
||||||
|
],
|
||||||
|
{ env: { 'ODASA_TRACER_CONFIGURATION': tracerConfig.spec } }).exec();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import { runAnalyze } from './analyze';
|
||||||
import { determineAutobuildLanguage, runAutobuild } from './autobuild';
|
import { determineAutobuildLanguage, runAutobuild } from './autobuild';
|
||||||
import { CodeQL, getCodeQL } from './codeql';
|
import { CodeQL, getCodeQL } from './codeql';
|
||||||
import { Config, getConfig } from './config-utils';
|
import { Config, getConfig } from './config-utils';
|
||||||
import { initCodeQL, initConfig, runInit } from './init';
|
import { initCodeQL, initConfig, injectWindowsTracer, runInit } from './init';
|
||||||
import { Language, parseLanguage } from './languages';
|
import { Language, parseLanguage } from './languages';
|
||||||
import { getRunnerLogger } from './logging';
|
import { getRunnerLogger } from './logging';
|
||||||
import { parseRepositoryNwo } from './repository';
|
import { parseRepositoryNwo } from './repository';
|
||||||
|
|
@ -76,6 +76,27 @@ function parseRef(userInput: string): string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parses the --trace-process-name arg from process.argv, or returns undefined
|
||||||
|
function parseTraceProcessName(): string | undefined {
|
||||||
|
for (let i = 0; i < process.argv.length - 1; i++) {
|
||||||
|
if (process.argv[i] === '--trace-process-name') {
|
||||||
|
return process.argv[i + 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parses the --trace-process-level arg from process.argv, or returns undefined
|
||||||
|
function parseTraceProcessLevel(): number | undefined {
|
||||||
|
for (let i = 0; i < process.argv.length - 1; i++) {
|
||||||
|
if (process.argv[i] === '--trace-process-level') {
|
||||||
|
const v = parseInt(process.argv[i + 1], 10);
|
||||||
|
return isNaN(v) ? undefined : v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
interface InitArgs {
|
interface InitArgs {
|
||||||
languages: string | undefined;
|
languages: string | undefined;
|
||||||
queries: string | undefined;
|
queries: string | undefined;
|
||||||
|
|
@ -104,6 +125,9 @@ program
|
||||||
.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('--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('--checkout-path <path>', 'Checkout path. Default is the current working directory.')
|
||||||
.option('--debug', 'Print more verbose output', false)
|
.option('--debug', 'Print more verbose output', false)
|
||||||
|
// This prevents a message like: error: unknown option '--trace-process-level'
|
||||||
|
// Remove this if commander.js starts supporting hidden options.
|
||||||
|
.allowUnknownOption()
|
||||||
.action(async (cmd: InitArgs) => {
|
.action(async (cmd: InitArgs) => {
|
||||||
const logger = getRunnerLogger(cmd.debug);
|
const logger = getRunnerLogger(cmd.debug);
|
||||||
try {
|
try {
|
||||||
|
|
@ -147,6 +171,15 @@ program
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
await injectWindowsTracer(
|
||||||
|
parseTraceProcessName(),
|
||||||
|
parseTraceProcessLevel(),
|
||||||
|
config,
|
||||||
|
codeql,
|
||||||
|
tracerConfig);
|
||||||
|
}
|
||||||
|
|
||||||
// Always output a json file of the env that can be consumed programatically
|
// Always output a json file of the env that can be consumed programatically
|
||||||
const jsonEnvFile = path.join(config.tempDir, codeqlEnvJsonFilename);
|
const jsonEnvFile = path.join(config.tempDir, codeqlEnvJsonFilename);
|
||||||
fs.writeFileSync(jsonEnvFile, JSON.stringify(tracerConfig.env));
|
fs.writeFileSync(jsonEnvFile, JSON.stringify(tracerConfig.env));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue