compiletest: Replace bool with enum AuxType for clarity
This commit is contained in:
parent
9de0921852
commit
4c95d76660
@ -82,21 +82,22 @@ fn disable_error_reporting<F: FnOnce() -> R, R>(f: F) -> R {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The platform-specific library name
|
/// The platform-specific library name
|
||||||
fn get_lib_name(lib: &str, dylib: bool) -> String {
|
fn get_lib_name(lib: &str, aux_type: AuxType) -> String {
|
||||||
// In some cases (e.g. MUSL), we build a static
|
match aux_type {
|
||||||
// library, rather than a dynamic library.
|
// In some cases (e.g. MUSL), we build a static
|
||||||
// In this case, the only path we can pass
|
// library, rather than a dynamic library.
|
||||||
// with '--extern-meta' is the '.rlib' file
|
// In this case, the only path we can pass
|
||||||
if !dylib {
|
// with '--extern-meta' is the '.rlib' file
|
||||||
return format!("lib{}.rlib", lib);
|
AuxType::Lib => format!("lib{}.rlib", lib),
|
||||||
}
|
AuxType::Dylib => {
|
||||||
|
if cfg!(windows) {
|
||||||
if cfg!(windows) {
|
format!("{}.dll", lib)
|
||||||
format!("{}.dll", lib)
|
} else if cfg!(target_os = "macos") {
|
||||||
} else if cfg!(target_os = "macos") {
|
format!("lib{}.dylib", lib)
|
||||||
format!("lib{}.dylib", lib)
|
} else {
|
||||||
} else {
|
format!("lib{}.so", lib)
|
||||||
format!("lib{}.so", lib)
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2107,9 +2108,9 @@ impl<'test> TestCx<'test> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (aux_name, aux_path) in &self.props.aux_crates {
|
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 =
|
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));
|
rustc.arg("--extern").arg(format!("{}={}/{}", aux_name, aux_dir.display(), lib_name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2131,7 +2132,7 @@ impl<'test> TestCx<'test> {
|
|||||||
/// Builds an aux dependency.
|
/// Builds an aux dependency.
|
||||||
///
|
///
|
||||||
/// Returns whether or not it is a dylib.
|
/// 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_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_props = self.props.from_aux_file(&aux_testpaths.file, self.revision, self.config);
|
||||||
let aux_output = TargetLocation::ThisDirectory(aux_dir.to_path_buf());
|
let aux_output = TargetLocation::ThisDirectory(aux_dir.to_path_buf());
|
||||||
@ -2159,8 +2160,8 @@ impl<'test> TestCx<'test> {
|
|||||||
}
|
}
|
||||||
aux_rustc.envs(aux_props.rustc_env.clone());
|
aux_rustc.envs(aux_props.rustc_env.clone());
|
||||||
|
|
||||||
let (dylib, crate_type) = if aux_props.no_prefer_dynamic {
|
let (aux_type, crate_type) = if aux_props.no_prefer_dynamic {
|
||||||
(true, None)
|
(AuxType::Dylib, None)
|
||||||
} else if self.config.target.contains("emscripten")
|
} else if self.config.target.contains("emscripten")
|
||||||
|| (self.config.target.contains("musl")
|
|| (self.config.target.contains("musl")
|
||||||
&& !aux_props.force_host
|
&& !aux_props.force_host
|
||||||
@ -2185,9 +2186,9 @@ impl<'test> TestCx<'test> {
|
|||||||
// Coverage tests want static linking by default so that coverage
|
// Coverage tests want static linking by default so that coverage
|
||||||
// mappings in auxiliary libraries can be merged into the final
|
// mappings in auxiliary libraries can be merged into the final
|
||||||
// executable.
|
// executable.
|
||||||
(false, Some("lib"))
|
(AuxType::Lib, Some("lib"))
|
||||||
} else {
|
} else {
|
||||||
(true, Some("dylib"))
|
(AuxType::Dylib, Some("dylib"))
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(crate_type) = crate_type {
|
if let Some(crate_type) = crate_type {
|
||||||
@ -2211,7 +2212,7 @@ impl<'test> TestCx<'test> {
|
|||||||
&auxres,
|
&auxres,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
dylib
|
aux_type
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read2_abbreviated(&self, child: Child) -> (Output, Truncated) {
|
fn read2_abbreviated(&self, child: Child) -> (Output, Truncated) {
|
||||||
@ -4826,3 +4827,8 @@ enum LinkToAux {
|
|||||||
Yes,
|
Yes,
|
||||||
No,
|
No,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum AuxType {
|
||||||
|
Lib,
|
||||||
|
Dylib,
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user