@@ -51,6 +51,9 @@ use crate::executor::{CollectedTest, ColorConfig};
5151/// some code here that inspects environment variables or even runs executables
5252/// (e.g. when discovering debugger versions).
5353fn parse_config ( args : Vec < String > ) -> Config {
54+ // FIXME(jieyouxu): this says "parse_config", but in reality also in some cases read from
55+ // env vars!
56+
5457 let mut opts = Options :: new ( ) ;
5558 opts. reqopt ( "" , "compile-lib-path" , "path to host shared libraries" , "PATH" )
5659 . reqopt ( "" , "run-lib-path" , "path to target shared libraries" , "PATH" )
@@ -180,11 +183,6 @@ fn parse_config(args: Vec<String>) -> Config {
180183 . optflag ( "" , "profiler-runtime" , "is the profiler runtime enabled for this target" )
181184 . optflag ( "h" , "help" , "show this message" )
182185 . reqopt ( "" , "channel" , "current Rust channel" , "CHANNEL" )
183- . optflag (
184- "" ,
185- "git-hash" ,
186- "run tests which rely on commit version being compiled into the binaries" ,
187- )
188186 . optopt ( "" , "edition" , "default Rust edition" , "EDITION" )
189187 . reqopt ( "" , "nightly-branch" , "name of the git branch for nightly" , "BRANCH" )
190188 . reqopt (
@@ -370,6 +368,19 @@ fn parse_config(args: Vec<String>) -> Config {
370368 let build_test_suite_root = opt_path ( matches, "build-test-suite-root" ) ;
371369 assert ! ( build_test_suite_root. starts_with( & build_root) ) ;
372370
371+ // NOTE: we cannot trust bootstrap for git hash availability, therefore we use an env var to
372+ // communicate directly between compiletest and CI/local environment, bypassing bootstrap.
373+ let git_hash = if build_helper:: ci:: CiEnv :: is_ci ( ) {
374+ // In CI environment, we expect that the env var must be set to prevent it from being forgotten.
375+ let _ = env:: var_os ( "RUSTC_TEST_GIT_HASH" )
376+ . expect ( "`RUSTC_TEST_GIT_HASH` must be set under CI environments" ) ;
377+ true
378+ } else {
379+ // But locally, we don't want to do so -- only run the test that requires git hash
380+ // availability if the user explicitly sets the env var.
381+ env:: var_os ( "RUSTC_TEST_GIT_HASH" ) . is_some ( )
382+ } ;
383+
373384 Config {
374385 bless : matches. opt_present ( "bless" ) ,
375386 fail_fast : matches. opt_present ( "fail-fast" )
@@ -455,9 +466,10 @@ fn parse_config(args: Vec<String>) -> Config {
455466 has_html_tidy,
456467 has_enzyme,
457468 channel : matches. opt_str ( "channel" ) . unwrap ( ) ,
458- git_hash : matches. opt_present ( "git-hash" ) ,
459469 edition : matches. opt_str ( "edition" ) . as_deref ( ) . map ( parse_edition) ,
460470
471+ git_hash,
472+
461473 cc : matches. opt_str ( "cc" ) . unwrap ( ) ,
462474 cxx : matches. opt_str ( "cxx" ) . unwrap ( ) ,
463475 cflags : matches. opt_str ( "cflags" ) . unwrap ( ) ,
0 commit comments