Skip to content

compiletest: Replace bool with enum AuxType for clarity #122419

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

Closed
wants to merge 3 commits into from
Closed
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
52 changes: 29 additions & 23 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,22 @@ fn disable_error_reporting<F: FnOnce() -> R, R>(f: F) -> R {
}

/// The platform-specific library name
pub fn get_lib_name(lib: &str, dylib: bool) -> String {
// In some casess (e.g. MUSL), we build a static
// library, rather than a dynamic library.
// In this case, the only path we can pass
// with '--extern-meta' is the '.lib' file
if !dylib {
return format!("lib{}.rlib", lib);
}

if cfg!(windows) {
format!("{}.dll", lib)
} else if cfg!(target_os = "macos") {
format!("lib{}.dylib", lib)
} else {
format!("lib{}.so", lib)
fn get_lib_name(lib: &str, aux_type: AuxType) -> String {
match aux_type {
// In some cases (e.g. MUSL), we build a static
// library, rather than a dynamic library.
// In this case, the only path we can pass
// with '--extern-meta' is the '.rlib' file
AuxType::Lib => format!("lib{}.rlib", lib),
AuxType::Dylib => {
if cfg!(windows) {
format!("{}.dll", lib)
} else if cfg!(target_os = "macos") {
format!("lib{}.dylib", lib)
} else {
format!("lib{}.so", lib)
}
}
}
}

Expand Down Expand Up @@ -2140,9 +2141,9 @@ impl<'test> TestCx<'test> {
}

for (aux_name, aux_path) in &self.props.aux_crates {
let is_dylib = self.build_auxiliary(of, &aux_path, &aux_dir);
let aux_type = self.build_auxiliary(of, &aux_path, &aux_dir);
let lib_name =
get_lib_name(&aux_path.trim_end_matches(".rs").replace('-', "_"), is_dylib);
get_lib_name(&aux_path.trim_end_matches(".rs").replace('-', "_"), aux_type);
rustc.arg("--extern").arg(format!("{}={}/{}", aux_name, aux_dir.display(), lib_name));
}
}
Expand All @@ -2164,7 +2165,7 @@ impl<'test> TestCx<'test> {
/// Builds an aux dependency.
///
/// Returns whether or not it is a dylib.
fn build_auxiliary(&self, of: &TestPaths, source_path: &str, aux_dir: &Path) -> bool {
fn build_auxiliary(&self, of: &TestPaths, source_path: &str, aux_dir: &Path) -> AuxType {
let aux_testpaths = self.compute_aux_test_paths(of, source_path);
let aux_props = self.props.from_aux_file(&aux_testpaths.file, self.revision, self.config);
let aux_output = TargetLocation::ThisDirectory(aux_dir.to_path_buf());
Expand Down Expand Up @@ -2192,8 +2193,8 @@ impl<'test> TestCx<'test> {
}
aux_rustc.envs(aux_props.rustc_env.clone());

let (dylib, crate_type) = if aux_props.no_prefer_dynamic {
(true, None)
let (aux_type, crate_type) = if aux_props.no_prefer_dynamic {
(AuxType::Dylib, None)
} else if self.config.target.contains("emscripten")
|| (self.config.target.contains("musl")
&& !aux_props.force_host
Expand All @@ -2218,9 +2219,9 @@ impl<'test> TestCx<'test> {
// Coverage tests want static linking by default so that coverage
// mappings in auxiliary libraries can be merged into the final
// executable.
(false, Some("lib"))
(AuxType::Lib, Some("lib"))
} else {
(true, Some("dylib"))
(AuxType::Dylib, Some("dylib"))
};

if let Some(crate_type) = crate_type {
Expand All @@ -2244,7 +2245,7 @@ impl<'test> TestCx<'test> {
&auxres,
);
}
dylib
aux_type
}

fn read2_abbreviated(&self, child: Child) -> (Output, Truncated) {
Expand Down Expand Up @@ -4853,3 +4854,8 @@ enum LinkToAux {
Yes,
No,
}

enum AuxType {
Lib,
Dylib,
}