@@ -17,7 +17,7 @@ import type { VersionInfo } from "./cli/types";
1717import { CliError , wrapCliConfigurationError } from "./cli-errors" ;
1818import { appendExtraQueryExclusions , type Config } from "./config-utils" ;
1919import { DocUrl } from "./doc-url" ;
20- import { EnvVar , getEnv , exportEnvVar } from "./environment" ;
20+ import { EnvVar , getEnv , exportEnvVar , Env , ReadOnlyEnv } from "./environment" ;
2121import {
2222 CodeQLDefaultVersionInfo ,
2323 Feature ,
@@ -493,8 +493,9 @@ export function createStubCodeQL(partialCodeql: Partial<CodeQL>): CodeQL {
493493export async function getCodeQLForTesting (
494494 cmd = "codeql-for-testing" ,
495495 logger : Logger = getRunnerLogger ( true ) ,
496+ env : Env = getEnv ( ) ,
496497) : Promise < CodeQL > {
497- return getCodeQLForCmd ( logger , cmd , false ) ;
498+ return getCodeQLForCmd ( logger , cmd , false , env ) ;
498499}
499500
500501/**
@@ -509,13 +510,14 @@ async function getCodeQLForCmd(
509510 logger : Logger ,
510511 cmd : string ,
511512 checkVersion : boolean ,
513+ env : Env = getEnv ( ) ,
512514) : Promise < CodeQL > {
513515 const codeql : CodeQL = {
514516 getPath ( ) {
515517 return cmd ;
516518 } ,
517519 async getVersion ( ) {
518- const cacheFilePath = outputCache . getCommandCacheFilePath ( getEnv ( ) ) ;
520+ const cacheFilePath = outputCache . getCommandCacheFilePath ( env ) ;
519521 let result = outputCache . getCachedCodeQlVersion (
520522 logger ,
521523 cacheFilePath ,
@@ -641,7 +643,7 @@ async function getCodeQLForCmd(
641643 }
642644 } ,
643645 async runAutobuild ( config : Config , language : Language ) {
644- applyAutobuildAzurePipelinesTimeoutFix ( ) ;
646+ applyAutobuildAzurePipelinesTimeoutFix ( env ) ;
645647
646648 const autobuildCmd = path . join (
647649 await this . resolveExtractor ( language ) ,
@@ -651,8 +653,11 @@ async function getCodeQLForCmd(
651653
652654 // Bump the verbosity of the autobuild command if we're in debug mode
653655 if ( config . debugMode ) {
654- process . env [ EnvVar . CLI_VERBOSITY ] =
655- process . env [ EnvVar . CLI_VERBOSITY ] || EXTRACTION_DEBUG_MODE_VERBOSITY ;
656+ env . set (
657+ EnvVar . CLI_VERBOSITY ,
658+ env . getOptional ( EnvVar . CLI_VERBOSITY ) ??
659+ EXTRACTION_DEBUG_MODE_VERBOSITY ,
660+ ) ;
656661 }
657662
658663 // On macOS, System Integrity Protection (SIP) typically interferes with
@@ -684,7 +689,7 @@ async function getCodeQLForCmd(
684689 } ,
685690 async extractUsingBuildMode ( config : Config , language : Language ) {
686691 if ( config . buildMode === BuildMode . Autobuild ) {
687- applyAutobuildAzurePipelinesTimeoutFix ( ) ;
692+ applyAutobuildAzurePipelinesTimeoutFix ( env ) ;
688693 }
689694 try {
690695 await runCli ( cmd , [
@@ -816,7 +821,7 @@ async function getCodeQLForCmd(
816821 "--sarif-group-rules-by-pack" ,
817822 "--sarif-include-query-help=always" ,
818823 "--sublanguage-file-coverage" ,
819- ...( await getJobRunUuidSarifOptions ( ) ) ,
824+ ...( await getJobRunUuidSarifOptions ( env ) ) ,
820825 ...getExtraOptionsFromEnv ( [ "database" , "interpret-results" ] ) ,
821826 ] ;
822827 if ( sarifRunPropertyFlag !== undefined ) {
@@ -1036,7 +1041,7 @@ async function getCodeQLForCmd(
10361041 ) ;
10371042 } else if (
10381043 checkVersion &&
1039- process . env [ EnvVar . SUPPRESS_DEPRECATED_SOON_WARNING ] !== "true" &&
1044+ env . getOptional ( EnvVar . SUPPRESS_DEPRECATED_SOON_WARNING ) !== "true" &&
10401045 ! ( await util . codeQlVersionAtLeast ( codeql , CODEQL_NEXT_MINIMUM_VERSION ) )
10411046 ) {
10421047 const result = await codeql . getVersion ( ) ;
@@ -1256,17 +1261,20 @@ function getExtractionVerbosityArguments(
12561261 * Without the fix, long build processes will timeout when pulling down Java packages
12571262 * https://developercommunity.visualstudio.com/content/problem/292284/maven-hosted-agent-connection-timeout.html
12581263 */
1259- function applyAutobuildAzurePipelinesTimeoutFix ( ) {
1260- const javaToolOptions = process . env [ "JAVA_TOOL_OPTIONS" ] || "" ;
1261- process . env [ "JAVA_TOOL_OPTIONS" ] = [
1262- ...javaToolOptions . split ( / \s + / ) ,
1263- "-Dhttp.keepAlive=false" ,
1264- "-Dmaven.wagon.http.pool=false" ,
1265- ] . join ( " " ) ;
1264+ function applyAutobuildAzurePipelinesTimeoutFix ( env : Env ) {
1265+ const javaToolOptions = env . getOptional ( "JAVA_TOOL_OPTIONS" ) ?? "" ;
1266+ env . set (
1267+ "JAVA_TOOL_OPTIONS" ,
1268+ [
1269+ ...javaToolOptions . split ( / \s + / ) ,
1270+ "-Dhttp.keepAlive=false" ,
1271+ "-Dmaven.wagon.http.pool=false" ,
1272+ ] . join ( " " ) ,
1273+ ) ;
12661274}
12671275
1268- async function getJobRunUuidSarifOptions ( ) {
1269- const jobRunUuid = process . env [ EnvVar . JOB_RUN_UUID ] ;
1276+ async function getJobRunUuidSarifOptions ( env : ReadOnlyEnv ) {
1277+ const jobRunUuid = env . getOptional ( EnvVar . JOB_RUN_UUID ) ;
12701278
12711279 return jobRunUuid ? [ `--sarif-run-property=jobRunUuid=${ jobRunUuid } ` ] : [ ] ;
12721280}
0 commit comments