Skip to content

Commit

Permalink
Merge cross-rs#722
Browse files Browse the repository at this point in the history
722: Evaluate boolean environment variables as truthy or falsey. r=Emilgardis a=Alexhuszagh

Allow values of 0, 1, so values other than `true` or `false` can be provided. `VAR=0`, `VAR=`, `VAR=-0`, or `VAR=false` will evaluate to false, while the rest will evaluate to true.

Affects cross-rs#661 and cross-rs#721.

Co-authored-by: Alex Huszagh <[email protected]>
  • Loading branch information
bors[bot] and Alexhuszagh authored May 26, 2022
2 parents 2f24bd4 + 933c03f commit 10da657
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

- #722 - boolean environment variables are evaluated as truthy or falsey.
- #718 - remove deb subcommand.
- #714 - use host target directory when falling back to host cargo.
- #713 - convert relative target directories to absolute paths.
Expand Down
12 changes: 11 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ fn absolute_path(path: PathBuf) -> Result<PathBuf> {
})
}

fn bool_from_envvar(envvar: &str) -> bool {
if let Ok(value) = bool::from_str(envvar) {
value
} else if let Ok(value) = i32::from_str(envvar) {
value != 0
} else {
!envvar.is_empty()
}
}

pub fn parse(target_list: &TargetList) -> Result<Args> {
let mut channel = None;
let mut target = None;
Expand Down Expand Up @@ -73,7 +83,7 @@ pub fn parse(target_list: &TargetList) -> Result<Args> {
}

let docker_in_docker = env::var("CROSS_DOCKER_IN_DOCKER")
.map(|s| bool::from_str(&s).unwrap_or_default())
.map(|s| bool_from_envvar(&s))
.unwrap_or_default();

Ok(Args {
Expand Down

0 comments on commit 10da657

Please sign in to comment.