Skip to content

Commit ebe43bc

Browse files
committed
compiletest: Replace bool with enum AuxType for clarity
1 parent f71d86b commit ebe43bc

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

Diff for: src/tools/compiletest/src/runtest.rs

+29-23
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,22 @@ fn disable_error_reporting<F: FnOnce() -> R, R>(f: F) -> R {
8282
}
8383

8484
/// The platform-specific library name
85-
fn get_lib_name(lib: &str, dylib: bool) -> String {
86-
// In some casess (e.g. MUSL), we build a static
87-
// library, rather than a dynamic library.
88-
// In this case, the only path we can pass
89-
// with '--extern-meta' is the '.rlib' file
90-
if !dylib {
91-
return format!("lib{}.rlib", lib);
92-
}
93-
94-
if cfg!(windows) {
95-
format!("{}.dll", lib)
96-
} else if cfg!(target_os = "macos") {
97-
format!("lib{}.dylib", lib)
98-
} else {
99-
format!("lib{}.so", lib)
85+
fn get_lib_name(lib: &str, aux_type: AuxType) -> String {
86+
match aux_type {
87+
// In some casess (e.g. MUSL), we build a static
88+
// library, rather than a dynamic library.
89+
// In this case, the only path we can pass
90+
// with '--extern-meta' is the '.rlib' file
91+
AuxType::Lib => format!("lib{}.rlib", lib),
92+
AuxType::Dylib => {
93+
if cfg!(windows) {
94+
format!("{}.dll", lib)
95+
} else if cfg!(target_os = "macos") {
96+
format!("lib{}.dylib", lib)
97+
} else {
98+
format!("lib{}.so", lib)
99+
}
100+
}
100101
}
101102
}
102103

@@ -2148,9 +2149,9 @@ impl<'test> TestCx<'test> {
21482149
}
21492150

21502151
for (aux_name, aux_path) in &self.props.aux_crates {
2151-
let is_dylib = self.build_auxiliary(of, &aux_path, &aux_dir);
2152+
let aux_type = self.build_auxiliary(of, &aux_path, &aux_dir);
21522153
let lib_name =
2153-
get_lib_name(&aux_path.trim_end_matches(".rs").replace('-', "_"), is_dylib);
2154+
get_lib_name(&aux_path.trim_end_matches(".rs").replace('-', "_"), aux_type);
21542155
rustc.arg("--extern").arg(format!("{}={}/{}", aux_name, aux_dir.display(), lib_name));
21552156
}
21562157
}
@@ -2172,7 +2173,7 @@ impl<'test> TestCx<'test> {
21722173
/// Builds an aux dependency.
21732174
///
21742175
/// Returns whether or not it is a dylib.
2175-
fn build_auxiliary(&self, of: &TestPaths, source_path: &str, aux_dir: &Path) -> bool {
2176+
fn build_auxiliary(&self, of: &TestPaths, source_path: &str, aux_dir: &Path) -> AuxType {
21762177
let aux_testpaths = self.compute_aux_test_paths(of, source_path);
21772178
let aux_props = self.props.from_aux_file(&aux_testpaths.file, self.revision, self.config);
21782179
let aux_output = TargetLocation::ThisDirectory(aux_dir.to_path_buf());
@@ -2200,8 +2201,8 @@ impl<'test> TestCx<'test> {
22002201
}
22012202
aux_rustc.envs(aux_props.rustc_env.clone());
22022203

2203-
let (dylib, crate_type) = if aux_props.no_prefer_dynamic {
2204-
(true, None)
2204+
let (aux_type, crate_type) = if aux_props.no_prefer_dynamic {
2205+
(AuxType::Dylib, None)
22052206
} else if self.config.target.contains("emscripten")
22062207
|| (self.config.target.contains("musl")
22072208
&& !aux_props.force_host
@@ -2226,9 +2227,9 @@ impl<'test> TestCx<'test> {
22262227
// Coverage tests want static linking by default so that coverage
22272228
// mappings in auxiliary libraries can be merged into the final
22282229
// executable.
2229-
(false, Some("lib"))
2230+
(AuxType::Lib, Some("lib"))
22302231
} else {
2231-
(true, Some("dylib"))
2232+
(AuxType::Dylib, Some("dylib"))
22322233
};
22332234

22342235
if let Some(crate_type) = crate_type {
@@ -2252,7 +2253,7 @@ impl<'test> TestCx<'test> {
22522253
&auxres,
22532254
);
22542255
}
2255-
dylib
2256+
aux_type
22562257
}
22572258

22582259
fn read2_abbreviated(&self, child: Child) -> (Output, Truncated) {
@@ -4910,3 +4911,8 @@ enum LinkToAux {
49104911
Yes,
49114912
No,
49124913
}
4914+
4915+
enum AuxType {
4916+
Lib,
4917+
Dylib,
4918+
}

0 commit comments

Comments
 (0)