Skip to content

Commit

Permalink
Evaluate boolean environment variables as truthy or falsey.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Alexhuszagh committed May 26, 2022
1 parent 2f24bd4 commit c943b0b
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 != ""
}
}

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 c943b0b

Please sign in to comment.