Skip to content

Commit

Permalink
Code cleanups for the split-host work
Browse files Browse the repository at this point in the history
  • Loading branch information
joshtriplett committed Apr 30, 2021
1 parent e24bf92 commit e797526
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
9 changes: 3 additions & 6 deletions src/cargo/core/compiler/build_context/target_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -691,14 +691,11 @@ impl<'cfg> RustcTargetData<'cfg> {
// `--target` flag is not specified. Since the unit_dependency code
// needs access to the target config data, create a copy so that it
// can be found. See `rebuild_unit_graph_shared` for why this is done.
let target_applies_to_host = config.target_applies_to_host();
if target_applies_to_host.is_err() {
return Err(target_applies_to_host.unwrap_err());
}
let target_applies_to_host = config.target_applies_to_host()?;
let host_config = if requested_kinds.iter().any(CompileKind::is_host) {
let ct = CompileTarget::new(&rustc.host)?;
target_info.insert(ct, host_info.clone());
let target_host_config = if target_applies_to_host.unwrap() {
let target_host_config = if target_applies_to_host {
let target_cfg_clone = config.target_cfg_triple(&rustc.host)?;
target_config.insert(ct, target_cfg_clone.clone());
target_cfg_clone
Expand All @@ -708,7 +705,7 @@ impl<'cfg> RustcTargetData<'cfg> {
};
target_host_config
} else {
if target_applies_to_host.unwrap() {
if target_applies_to_host {
config.target_cfg_triple(&rustc.host)?
} else {
config.host_cfg_triple(&rustc.host)?
Expand Down
16 changes: 6 additions & 10 deletions src/cargo/util/config/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,10 @@ pub(super) fn load_target_cfgs(config: &Config) -> CargoResult<Vec<(String, Targ
/// Returns true if the `[target]` table should be applied to host targets.
pub(super) fn get_target_applies_to_host(config: &Config) -> CargoResult<bool> {
if config.cli_unstable().target_applies_to_host {
let target_applies_to_host = config.get::<bool>("target-applies-to-host");
if target_applies_to_host.is_ok() {
Ok(target_applies_to_host.unwrap())
if let Ok(target_applies_to_host) = config.get::<bool>("target-applies-to-host") {
Ok(target_applies_to_host)
} else {
if config.cli_unstable().host_config {
Ok(false)
} else {
Ok(true)
}
Ok(!config.cli_unstable().host_config)
}
} else {
if config.cli_unstable().host_config {
Expand All @@ -91,9 +86,10 @@ pub(super) fn get_target_applies_to_host(config: &Config) -> CargoResult<bool> {
/// Loads a single `[host]` table for the given triple.
pub(super) fn load_host_triple(config: &Config, triple: &str) -> CargoResult<TargetConfig> {
if config.cli_unstable().host_config {
let host_triple_key = ConfigKey::from_str(&format!("host.{}", triple));
let host_triple_prefix = format!("host.{}", triple);
let host_triple_key = ConfigKey::from_str(&host_triple_prefix);
let host_prefix = match config.get_cv(&host_triple_key)? {
Some(_) => format!("host.{}", triple),
Some(_) => host_triple_prefix,
None => "host".to_string(),
};
load_config_table(config, &host_prefix)
Expand Down

0 comments on commit e797526

Please sign in to comment.