Skip to content

Commit

Permalink
Allow setting default target via environment
Browse files Browse the repository at this point in the history
  • Loading branch information
zappolowski committed Jan 8, 2022
1 parent 6ac0d21 commit 913f457
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ impl Environment {
self.get_values_for("ENV_VOLUMES", target)
}

fn target(&self) -> Option<String> {
self.get_build_var("TARGET")
}

fn get_values_for(
&self,
var: &str,
Expand Down Expand Up @@ -180,7 +184,10 @@ impl Config {
Ok(collected)
}

pub fn target(&self, _target_list: &TargetList) -> Result<Option<Target>> {
pub fn target(&self, target_list: &TargetList) -> Result<Option<Target>> {
if let Some(env_value) = self.env.target() {
return Ok(Some(Target::from(&env_value, target_list)));
}
Ok(None)
}

Expand Down Expand Up @@ -379,6 +386,22 @@ mod tests {
Ok(())
}

#[test]
pub fn env_and_toml_default_target_then_use_env() -> Result<()> {
let mut map = HashMap::new();
map.insert("CROSS_BUILD_TARGET", "armv7-unknown-linux-musleabihf");
let env = Environment::new(Some(map));
let config = Config::new_with(Some(toml(TOML_DEFAULT_TARGET)?), env);

let config_target = config.target(&target_list())?.unwrap();
assert!(matches!(
config_target.triple(),
"armv7-unknown-linux-musleabihf"
));

Ok(())
}

static TOML_BUILD_XARGO_FALSE: &str = r#"
[build]
xargo = false
Expand All @@ -394,6 +417,11 @@ mod tests {
volumes = ["VOLUME3", "VOLUME4"]
[target.aarch64-unknown-linux-gnu]
xargo = false
"#;

static TOML_DEFAULT_TARGET: &str = r#"
[build]
default = "aarch64-unknown-linux-gnu"
"#;
}
}

0 comments on commit 913f457

Please sign in to comment.