@@ -18,7 +18,7 @@ import { CliError, wrapCliConfigurationError } from "./cli-errors";
1818import type { ActionConfig } from "./config/action-config" ;
1919import { appendExtraQueryExclusions , type Config } from "./config-utils" ;
2020import { DocUrl } from "./doc-url" ;
21- import { EnvVar , getEnv , exportEnvVar } from "./environment" ;
21+ import { EnvVar , getEnv , exportEnvVar , Env , ReadOnlyEnv } from "./environment" ;
2222import {
2323 CodeQLDefaultVersionInfo ,
2424 Feature ,
@@ -495,8 +495,9 @@ export function createStubCodeQL(partialCodeql: Partial<CodeQL>): CodeQL {
495495export async function getCodeQLForTesting (
496496 cmd = "codeql-for-testing" ,
497497 logger : Logger = getRunnerLogger ( true ) ,
498+ env : Env = getEnv ( ) ,
498499) : Promise < CodeQL > {
499- return getCodeQLForCmd ( logger , cmd , false ) ;
500+ return getCodeQLForCmd ( logger , cmd , false , env ) ;
500501}
501502
502503/**
@@ -511,13 +512,14 @@ async function getCodeQLForCmd(
511512 logger : Logger ,
512513 cmd : string ,
513514 checkVersion : boolean ,
515+ env : Env = getEnv ( ) ,
514516) : Promise < CodeQL > {
515517 const codeql : CodeQL = {
516518 getPath ( ) {
517519 return cmd ;
518520 } ,
519521 async getVersion ( ) {
520- const cacheFilePath = outputCache . getCommandCacheFilePath ( getEnv ( ) ) ;
522+ const cacheFilePath = outputCache . getCommandCacheFilePath ( env ) ;
521523 let result = outputCache . getCachedCodeQlVersion (
522524 logger ,
523525 cacheFilePath ,
@@ -643,7 +645,7 @@ async function getCodeQLForCmd(
643645 }
644646 } ,
645647 async runAutobuild ( config : Config , language : Language ) {
646- applyAutobuildAzurePipelinesTimeoutFix ( ) ;
648+ applyAutobuildAzurePipelinesTimeoutFix ( env ) ;
647649
648650 const autobuildCmd = path . join (
649651 await this . resolveExtractor ( language ) ,
@@ -653,8 +655,11 @@ async function getCodeQLForCmd(
653655
654656 // Bump the verbosity of the autobuild command if we're in debug mode
655657 if ( config . debugMode ) {
656- process . env [ EnvVar . CLI_VERBOSITY ] =
657- process . env [ EnvVar . CLI_VERBOSITY ] || EXTRACTION_DEBUG_MODE_VERBOSITY ;
658+ env . set (
659+ EnvVar . CLI_VERBOSITY ,
660+ env . getOptional ( EnvVar . CLI_VERBOSITY ) ??
661+ EXTRACTION_DEBUG_MODE_VERBOSITY ,
662+ ) ;
658663 }
659664
660665 // On macOS, System Integrity Protection (SIP) typically interferes with
@@ -686,7 +691,7 @@ async function getCodeQLForCmd(
686691 } ,
687692 async extractUsingBuildMode ( config : Config , language : Language ) {
688693 if ( config . buildMode === BuildMode . Autobuild ) {
689- applyAutobuildAzurePipelinesTimeoutFix ( ) ;
694+ applyAutobuildAzurePipelinesTimeoutFix ( env ) ;
690695 }
691696 try {
692697 await runCli ( cmd , [
@@ -818,7 +823,7 @@ async function getCodeQLForCmd(
818823 "--sarif-group-rules-by-pack" ,
819824 "--sarif-include-query-help=always" ,
820825 "--sublanguage-file-coverage" ,
821- ...( await getJobRunUuidSarifOptions ( ) ) ,
826+ ...( await getJobRunUuidSarifOptions ( env ) ) ,
822827 ...getExtraOptionsFromEnv ( [ "database" , "interpret-results" ] ) ,
823828 ] ;
824829 if ( sarifRunPropertyFlag !== undefined ) {
@@ -1042,7 +1047,7 @@ async function getCodeQLForCmd(
10421047 ) ;
10431048 } else if (
10441049 checkVersion &&
1045- process . env [ EnvVar . SUPPRESS_DEPRECATED_SOON_WARNING ] !== "true" &&
1050+ env . getOptional ( EnvVar . SUPPRESS_DEPRECATED_SOON_WARNING ) !== "true" &&
10461051 ! ( await util . codeQlVersionAtLeast ( codeql , CODEQL_NEXT_MINIMUM_VERSION ) )
10471052 ) {
10481053 const result = await codeql . getVersion ( ) ;
@@ -1264,17 +1269,20 @@ function getExtractionVerbosityArguments(
12641269 * Without the fix, long build processes will timeout when pulling down Java packages
12651270 * https://developercommunity.visualstudio.com/content/problem/292284/maven-hosted-agent-connection-timeout.html
12661271 */
1267- function applyAutobuildAzurePipelinesTimeoutFix ( ) {
1268- const javaToolOptions = process . env [ "JAVA_TOOL_OPTIONS" ] || "" ;
1269- process . env [ "JAVA_TOOL_OPTIONS" ] = [
1270- ...javaToolOptions . split ( / \s + / ) ,
1271- "-Dhttp.keepAlive=false" ,
1272- "-Dmaven.wagon.http.pool=false" ,
1273- ] . join ( " " ) ;
1272+ function applyAutobuildAzurePipelinesTimeoutFix ( env : Env ) {
1273+ const javaToolOptions = env . getOptional ( "JAVA_TOOL_OPTIONS" ) ?? "" ;
1274+ env . set (
1275+ "JAVA_TOOL_OPTIONS" ,
1276+ [
1277+ ...javaToolOptions . split ( / \s + / ) ,
1278+ "-Dhttp.keepAlive=false" ,
1279+ "-Dmaven.wagon.http.pool=false" ,
1280+ ] . join ( " " ) ,
1281+ ) ;
12741282}
12751283
1276- async function getJobRunUuidSarifOptions ( ) {
1277- const jobRunUuid = process . env [ EnvVar . JOB_RUN_UUID ] ;
1284+ async function getJobRunUuidSarifOptions ( env : ReadOnlyEnv ) {
1285+ const jobRunUuid = env . getOptional ( EnvVar . JOB_RUN_UUID ) ;
12781286
12791287 return jobRunUuid ? [ `--sarif-run-property=jobRunUuid=${ jobRunUuid } ` ] : [ ] ;
12801288}
0 commit comments