Skip to content

Commit

Permalink
Allow error from cargo-config
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Aug 26, 2021
1 parent da4385b commit 819727e
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,6 @@ impl Cargo {
}
}

pub(crate) fn config(cargo: &Cargo, workspace_root: &Utf8Path) -> Result<Config> {
let s = cargo
.process()
.args(&["-Z", "unstable-options", "config", "get", "--format", "json"])
.env("RUSTC_BOOTSTRAP", "1")
.dir(workspace_root)
.stderr_capture()
.read()?;
let mut config: Config = serde_json::from_str(&s)?;
config.apply_env()?;
Ok(config)
}

pub(crate) fn locate_project() -> Result<String> {
cmd!("cargo", "locate-project", "--message-format", "plain").read()
}
Expand Down Expand Up @@ -190,8 +177,29 @@ pub(crate) fn append_args(cx: &Context, cmd: &mut ProcessBuilder) {
//
// Refs:
// - https://doc.rust-lang.org/nightly/cargo/reference/config.html
// - https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#cargo-config
// - https://github.com/rust-lang/cargo/issues/9301

pub(crate) fn config(cargo: &Cargo, workspace_root: &Utf8Path) -> Result<Config> {
let mut config = match cargo
.process()
.args(&["-Z", "unstable-options", "config", "get", "--format", "json"])
.env("RUSTC_BOOTSTRAP", "1")
.dir(workspace_root)
.stderr_capture()
.read()
{
Ok(s) => serde_json::from_str(&s)?,
Err(e) => {
// Allow error from cargo-config as it is an unstable feature.
warn!("{:#}", e);
Config::default()
}
};
config.apply_env()?;
Ok(config)
}

#[derive(Debug, Default, Deserialize)]
pub(crate) struct Config {
#[serde(default)]
Expand Down

0 comments on commit 819727e

Please sign in to comment.