Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve correct archive version name in opt-dist #113804

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions src/tools/opt-dist/src/tests.rs
Original file line number Diff line number Diff line change
@@ -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<()> {
Expand All @@ -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(
Expand Down Expand Up @@ -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())
}
19 changes: 19 additions & 0 deletions src/tools/opt-dist/src/utils/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
)),
}
}