detect user-specified custom targets in compiletest
Signed-off-by: onur-ozkan <work@onurozkan.dev>
This commit is contained in:
parent
8aa7dd06f6
commit
26c71cbcf1
@ -479,6 +479,7 @@ fn new(config: &Config) -> TargetCfgs {
|
|||||||
let mut targets: HashMap<String, TargetCfg> = serde_json::from_str(&rustc_output(
|
let mut targets: HashMap<String, TargetCfg> = serde_json::from_str(&rustc_output(
|
||||||
config,
|
config,
|
||||||
&["--print=all-target-specs-json", "-Zunstable-options"],
|
&["--print=all-target-specs-json", "-Zunstable-options"],
|
||||||
|
Default::default(),
|
||||||
))
|
))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
@ -491,17 +492,34 @@ fn new(config: &Config) -> TargetCfgs {
|
|||||||
let mut all_families = HashSet::new();
|
let mut all_families = HashSet::new();
|
||||||
let mut all_pointer_widths = HashSet::new();
|
let mut all_pointer_widths = HashSet::new();
|
||||||
|
|
||||||
// Handle custom target specs, which are not included in `--print=all-target-specs-json`.
|
// If current target is not included in the `--print=all-target-specs-json` output,
|
||||||
if config.target.ends_with(".json") {
|
// we check whether it is a custom target from the user or a synthetic target from bootstrap.
|
||||||
|
if !targets.contains_key(&config.target) {
|
||||||
|
let mut envs: HashMap<String, String> = HashMap::new();
|
||||||
|
|
||||||
|
if let Ok(t) = std::env::var("RUST_TARGET_PATH") {
|
||||||
|
envs.insert("RUST_TARGET_PATH".into(), t);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This returns false only when the target is neither a synthetic target
|
||||||
|
// nor a custom target from the user, indicating it is most likely invalid.
|
||||||
|
if config.target.ends_with(".json") || !envs.is_empty() {
|
||||||
targets.insert(
|
targets.insert(
|
||||||
config.target.clone(),
|
config.target.clone(),
|
||||||
serde_json::from_str(&rustc_output(
|
serde_json::from_str(&rustc_output(
|
||||||
config,
|
config,
|
||||||
&["--print=target-spec-json", "-Zunstable-options", "--target", &config.target],
|
&[
|
||||||
|
"--print=target-spec-json",
|
||||||
|
"-Zunstable-options",
|
||||||
|
"--target",
|
||||||
|
&config.target,
|
||||||
|
],
|
||||||
|
envs,
|
||||||
))
|
))
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (target, cfg) in targets.iter() {
|
for (target, cfg) in targets.iter() {
|
||||||
all_archs.insert(cfg.arch.clone());
|
all_archs.insert(cfg.arch.clone());
|
||||||
@ -545,7 +563,9 @@ fn get_current_target_config(
|
|||||||
// code below extracts them from `--print=cfg`: make sure to only override fields that can
|
// code below extracts them from `--print=cfg`: make sure to only override fields that can
|
||||||
// actually be changed with `-C` flags.
|
// actually be changed with `-C` flags.
|
||||||
for config in
|
for config in
|
||||||
rustc_output(config, &["--print=cfg", "--target", &config.target]).trim().lines()
|
rustc_output(config, &["--print=cfg", "--target", &config.target], Default::default())
|
||||||
|
.trim()
|
||||||
|
.lines()
|
||||||
{
|
{
|
||||||
let (name, value) = config
|
let (name, value) = config
|
||||||
.split_once("=\"")
|
.split_once("=\"")
|
||||||
@ -624,11 +644,12 @@ pub enum Endian {
|
|||||||
Big,
|
Big,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rustc_output(config: &Config, args: &[&str]) -> String {
|
fn rustc_output(config: &Config, args: &[&str], envs: HashMap<String, String>) -> String {
|
||||||
let mut command = Command::new(&config.rustc_path);
|
let mut command = Command::new(&config.rustc_path);
|
||||||
add_dylib_path(&mut command, iter::once(&config.compile_lib_path));
|
add_dylib_path(&mut command, iter::once(&config.compile_lib_path));
|
||||||
command.args(&config.target_rustcflags).args(args);
|
command.args(&config.target_rustcflags).args(args);
|
||||||
command.env("RUSTC_BOOTSTRAP", "1");
|
command.env("RUSTC_BOOTSTRAP", "1");
|
||||||
|
command.envs(envs);
|
||||||
|
|
||||||
let output = match command.output() {
|
let output = match command.output() {
|
||||||
Ok(output) => output,
|
Ok(output) => output,
|
||||||
|
Loading…
Reference in New Issue
Block a user