Skip to content

Commit

Permalink
Merge #772
Browse files Browse the repository at this point in the history
772: Add `CROSS_CONTAINER_OPTS` environment variable. r=Emilgardis a=Alexhuszagh

Rename `DOCKER_OPTS` to `CROSS_CONTAINER_OPTS`, and currently prefer `CROSS_CONTAINER_OPTS` to `DOCKER_OPTS`, although both are still valid.

Closes #770.

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

- #775 - forward Cargo exit code to host
- #772 - added `CROSS_CONTAINER_OPTS` environment variable to replace `DOCKER_OPTS`.
- #767 - added the `cross-util` and `cross-dev` commands.
- #745 - added `thumbv7neon-*` targets.
- #741 - added `armv7-unknown-linux-gnueabi` and `armv7-unknown-linux-musleabi` targets.
Expand Down
18 changes: 13 additions & 5 deletions src/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ fn validate_env_var(var: &str) -> Result<(&str, Option<&str>)> {
Ok((key, value))
}

fn parse_docker_opts(value: &str) -> Result<Vec<String>> {
shell_words::split(value).wrap_err_with(|| format!("could not parse docker opts of {}", value))
}

#[allow(unused_variables)]
pub fn mount(cmd: &mut Command, val: &Path, verbose: bool) -> Result<PathBuf> {
let host_path = file::canonicalize(&val)
Expand Down Expand Up @@ -291,11 +295,15 @@ pub fn run(
docker.args(&["-e", &format!("CROSS_DEBUG={value}")]);
}

if let Ok(value) = env::var("DOCKER_OPTS") {
let opts = shell_words::split(&value)
.wrap_err_with(|| format!("could not parse docker opts of {}", value))?;
docker.args(&opts);
}
if let Ok(value) = env::var("CROSS_CONTAINER_OPTS") {
if env::var("DOCKER_OPTS").is_ok() {
eprintln!("Warning: using both `CROSS_CONTAINER_OPTS` and `DOCKER_OPTS`.");
}
docker.args(&parse_docker_opts(&value)?);
} else if let Ok(value) = env::var("DOCKER_OPTS") {
// FIXME: remove this when we deprecate DOCKER_OPTS.
docker.args(&parse_docker_opts(&value)?);
};

docker
.args(&[
Expand Down

0 comments on commit 239e8cb

Please sign in to comment.