1
1
use crate :: environment:: Environment ;
2
2
use crate :: exec:: cmd;
3
- use crate :: utils:: io:: { copy_directory, unpack_archive} ;
3
+ use crate :: utils:: io:: { copy_directory, find_file_in_dir , unpack_archive} ;
4
4
use anyhow:: Context ;
5
- use camino:: Utf8PathBuf ;
5
+ use camino:: { Utf8Path , Utf8PathBuf } ;
6
6
7
7
/// Run tests on optimized dist artifacts.
8
8
pub fn run_tests ( env : & dyn Environment ) -> anyhow:: Result < ( ) > {
@@ -22,13 +22,14 @@ pub fn run_tests(env: &dyn Environment) -> anyhow::Result<()> {
22
22
Ok ( extracted_path)
23
23
} ;
24
24
let host_triple = env. host_triple ( ) ;
25
+ let version = find_dist_version ( & dist_dir) ?;
25
26
26
27
// Extract rustc, libstd, cargo and src archives to create the optimized sysroot
27
- let rustc_dir = extract_dist_dir ( & format ! ( "rustc-nightly -{host_triple}" ) ) ?. join ( "rustc" ) ;
28
- let libstd_dir = extract_dist_dir ( & format ! ( "rust-std-nightly -{host_triple}" ) ) ?
28
+ let rustc_dir = extract_dist_dir ( & format ! ( "rustc-{version} -{host_triple}" ) ) ?. join ( "rustc" ) ;
29
+ let libstd_dir = extract_dist_dir ( & format ! ( "rust-std-{version} -{host_triple}" ) ) ?
29
30
. join ( format ! ( "rust-std-{host_triple}" ) ) ;
30
- let cargo_dir = extract_dist_dir ( & format ! ( "cargo-nightly -{host_triple}" ) ) ?. join ( "cargo" ) ;
31
- let extracted_src_dir = extract_dist_dir ( "rust-src-nightly" ) ?. join ( "rust-src" ) ;
31
+ let cargo_dir = extract_dist_dir ( & format ! ( "cargo-{version} -{host_triple}" ) ) ?. join ( "cargo" ) ;
32
+ let extracted_src_dir = extract_dist_dir ( & format ! ( "rust-src-{version}" ) ) ?. join ( "rust-src" ) ;
32
33
33
34
// We need to manually copy libstd to the extracted rustc sysroot
34
35
copy_directory (
@@ -99,3 +100,15 @@ llvm-config = "{llvm_config}"
99
100
}
100
101
cmd ( & args) . env ( "COMPILETEST_FORCE_STAGE0" , "1" ) . run ( ) . context ( "Cannot execute tests" )
101
102
}
103
+
104
+ /// Tries to find the version of the dist artifacts (either nightly, beta, or 1.XY.Z).
105
+ fn find_dist_version ( directory : & Utf8Path ) -> anyhow:: Result < String > {
106
+ // Lookup a known file with a unique prefix and extract the version from its filename
107
+ let archive = find_file_in_dir ( directory, "reproducible-artifacts-" , ".tar.xz" ) ?
108
+ . file_name ( )
109
+ . unwrap ( )
110
+ . to_string ( ) ;
111
+ let ( version, _) =
112
+ archive. strip_prefix ( "reproducible-artifacts-" ) . unwrap ( ) . split_once ( "-" ) . unwrap ( ) ;
113
+ Ok ( version. to_string ( ) )
114
+ }
0 commit comments