11use crate :: environment:: Environment ;
22use 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} ;
44use anyhow:: Context ;
5- use camino:: Utf8PathBuf ;
5+ use camino:: { Utf8Path , Utf8PathBuf } ;
66
77/// Run tests on optimized dist artifacts.
88pub fn run_tests ( env : & dyn Environment ) -> anyhow:: Result < ( ) > {
@@ -22,13 +22,14 @@ pub fn run_tests(env: &dyn Environment) -> anyhow::Result<()> {
2222 Ok ( extracted_path)
2323 } ;
2424 let host_triple = env. host_triple ( ) ;
25+ let version = find_dist_version ( & dist_dir) ?;
2526
2627 // 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}" ) ) ?
2930 . 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" ) ;
3233
3334 // We need to manually copy libstd to the extracted rustc sysroot
3435 copy_directory (
@@ -99,3 +100,15 @@ llvm-config = "{llvm_config}"
99100 }
100101 cmd ( & args) . env ( "COMPILETEST_FORCE_STAGE0" , "1" ) . run ( ) . context ( "Cannot execute tests" )
101102}
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