Resolve correct archive version name in opt-dist
This commit is contained in:
parent
c4e6fe9240
commit
50d117ee7d
2 changed files with 38 additions and 6 deletions
|
@ -1,8 +1,8 @@
|
|||
use crate::environment::Environment;
|
||||
use crate::exec::cmd;
|
||||
use crate::utils::io::{copy_directory, unpack_archive};
|
||||
use crate::utils::io::{copy_directory, find_file_in_dir, unpack_archive};
|
||||
use anyhow::Context;
|
||||
use camino::Utf8PathBuf;
|
||||
use camino::{Utf8Path, Utf8PathBuf};
|
||||
|
||||
/// Run tests on optimized dist artifacts.
|
||||
pub fn run_tests(env: &dyn Environment) -> anyhow::Result<()> {
|
||||
|
@ -22,13 +22,14 @@ pub fn run_tests(env: &dyn Environment) -> anyhow::Result<()> {
|
|||
Ok(extracted_path)
|
||||
};
|
||||
let host_triple = env.host_triple();
|
||||
let version = find_dist_version(&dist_dir)?;
|
||||
|
||||
// Extract rustc, libstd, cargo and src archives to create the optimized sysroot
|
||||
let rustc_dir = extract_dist_dir(&format!("rustc-nightly-{host_triple}"))?.join("rustc");
|
||||
let libstd_dir = extract_dist_dir(&format!("rust-std-nightly-{host_triple}"))?
|
||||
let rustc_dir = extract_dist_dir(&format!("rustc-{version}-{host_triple}"))?.join("rustc");
|
||||
let libstd_dir = extract_dist_dir(&format!("rust-std-{version}-{host_triple}"))?
|
||||
.join(format!("rust-std-{host_triple}"));
|
||||
let cargo_dir = extract_dist_dir(&format!("cargo-nightly-{host_triple}"))?.join("cargo");
|
||||
let extracted_src_dir = extract_dist_dir("rust-src-nightly")?.join("rust-src");
|
||||
let cargo_dir = extract_dist_dir(&format!("cargo-{version}-{host_triple}"))?.join("cargo");
|
||||
let extracted_src_dir = extract_dist_dir(&format!("rust-src-{version}"))?.join("rust-src");
|
||||
|
||||
// We need to manually copy libstd to the extracted rustc sysroot
|
||||
copy_directory(
|
||||
|
@ -99,3 +100,15 @@ llvm-config = "{llvm_config}"
|
|||
}
|
||||
cmd(&args).env("COMPILETEST_FORCE_STAGE0", "1").run().context("Cannot execute tests")
|
||||
}
|
||||
|
||||
/// Tries to find the version of the dist artifacts (either nightly, beta, or 1.XY.Z).
|
||||
fn find_dist_version(directory: &Utf8Path) -> anyhow::Result<String> {
|
||||
// Lookup a known file with a unique prefix and extract the version from its filename
|
||||
let archive = find_file_in_dir(directory, "reproducible-artifacts-", ".tar.xz")?
|
||||
.file_name()
|
||||
.unwrap()
|
||||
.to_string();
|
||||
let (version, _) =
|
||||
archive.strip_prefix("reproducible-artifacts-").unwrap().split_once("-").unwrap();
|
||||
Ok(version.to_string())
|
||||
}
|
||||
|
|
|
@ -60,3 +60,22 @@ pub fn get_files_from_dir(
|
|||
.map(|p| p.map(|p| Utf8PathBuf::from_path_buf(p).unwrap()))
|
||||
.collect::<Result<Vec<_>, _>>()?)
|
||||
}
|
||||
|
||||
/// Finds a single file in the specified `directory` with the given `prefix` and `suffix`.
|
||||
pub fn find_file_in_dir(
|
||||
directory: &Utf8Path,
|
||||
prefix: &str,
|
||||
suffix: &str,
|
||||
) -> anyhow::Result<Utf8PathBuf> {
|
||||
let files = glob::glob(&format!("{directory}/{prefix}*{suffix}"))?
|
||||
.into_iter()
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
match files.len() {
|
||||
0 => Err(anyhow::anyhow!("No file with prefix {prefix} found in {directory}")),
|
||||
1 => Ok(Utf8PathBuf::from_path_buf(files[0].clone()).unwrap()),
|
||||
_ => Err(anyhow::anyhow!(
|
||||
"More than one file with prefix {prefix} found in {directory}: {:?}",
|
||||
files
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue