mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
Add -Z advanced-env
feature flag.
This commit is contained in:
parent
4d53519606
commit
154c787c72
@ -308,6 +308,7 @@ pub struct CliUnstable {
|
|||||||
pub avoid_dev_deps: bool,
|
pub avoid_dev_deps: bool,
|
||||||
pub minimal_versions: bool,
|
pub minimal_versions: bool,
|
||||||
pub package_features: bool,
|
pub package_features: bool,
|
||||||
|
pub advanced_env: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CliUnstable {
|
impl CliUnstable {
|
||||||
@ -342,6 +343,7 @@ impl CliUnstable {
|
|||||||
"avoid-dev-deps" => self.avoid_dev_deps = true,
|
"avoid-dev-deps" => self.avoid_dev_deps = true,
|
||||||
"minimal-versions" => self.minimal_versions = true,
|
"minimal-versions" => self.minimal_versions = true,
|
||||||
"package-features" => self.package_features = true,
|
"package-features" => self.package_features = true,
|
||||||
|
"advanced-env" => self.advanced_env = true,
|
||||||
_ => bail!("unknown `-Z` flag specified: {}", k),
|
_ => bail!("unknown `-Z` flag specified: {}", k),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -965,7 +965,10 @@ impl<'de, 'config> de::Deserializer<'de> for Deserializer<'config> {
|
|||||||
visitor.visit_bool(v.parse().unwrap())
|
visitor.visit_bool(v.parse().unwrap())
|
||||||
} else if let Ok(v) = v.parse::<i64>() {
|
} else if let Ok(v) = v.parse::<i64>() {
|
||||||
visitor.visit_i64(v)
|
visitor.visit_i64(v)
|
||||||
} else if v.starts_with("[") && v.ends_with("]") {
|
} else if self.config.cli_unstable().advanced_env
|
||||||
|
&& v.starts_with("[")
|
||||||
|
&& v.ends_with("]")
|
||||||
|
{
|
||||||
visitor.visit_seq(ConfigSeqAccess::new(self.config, self.key.clone())?)
|
visitor.visit_seq(ConfigSeqAccess::new(self.config, self.key.clone())?)
|
||||||
} else {
|
} else {
|
||||||
visitor.visit_string(v.clone())
|
visitor.visit_string(v.clone())
|
||||||
@ -1121,16 +1124,18 @@ impl<'config> ConfigMapAccess<'config> {
|
|||||||
set.insert(ConfigKeyPart::CasePart(key));
|
set.insert(ConfigKeyPart::CasePart(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// CARGO_PROFILE_DEV_OVERRIDES_
|
if config.cli_unstable().advanced_env {
|
||||||
let env_pattern = format!("{}_", key.to_env());
|
// CARGO_PROFILE_DEV_OVERRIDES_
|
||||||
for env_key in config.env.keys() {
|
let env_pattern = format!("{}_", key.to_env());
|
||||||
if env_key.starts_with(&env_pattern) {
|
for env_key in config.env.keys() {
|
||||||
// CARGO_PROFILE_DEV_OVERRIDES_bar_OPT_LEVEL = 3
|
if env_key.starts_with(&env_pattern) {
|
||||||
let rest = &env_key[env_pattern.len()..];
|
// CARGO_PROFILE_DEV_OVERRIDES_bar_OPT_LEVEL = 3
|
||||||
// rest = bar_OPT_LEVEL
|
let rest = &env_key[env_pattern.len()..];
|
||||||
let part = rest.splitn(2, "_").next().unwrap();
|
// rest = bar_OPT_LEVEL
|
||||||
// part = "bar"
|
let part = rest.splitn(2, "_").next().unwrap();
|
||||||
set.insert(ConfigKeyPart::CasePart(part.to_string()));
|
// part = "bar"
|
||||||
|
set.insert(ConfigKeyPart::CasePart(part.to_string()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(ConfigMapAccess {
|
Ok(ConfigMapAccess {
|
||||||
@ -1214,37 +1219,39 @@ impl ConfigSeqAccess {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse an environment string as a TOML array.
|
if config.cli_unstable().advanced_env {
|
||||||
let env_key = key.to_env();
|
// Parse an environment string as a TOML array.
|
||||||
let def = Definition::Environment(env_key.clone());
|
let env_key = key.to_env();
|
||||||
if let Some(v) = config.env.get(&env_key) {
|
let def = Definition::Environment(env_key.clone());
|
||||||
if !(v.starts_with("[") && v.ends_with("]")) {
|
if let Some(v) = config.env.get(&env_key) {
|
||||||
return Err(ConfigError::new(
|
if !(v.starts_with("[") && v.ends_with("]")) {
|
||||||
format!("should have TOML list syntax, found `{}`", v),
|
return Err(ConfigError::new(
|
||||||
def.clone(),
|
format!("should have TOML list syntax, found `{}`", v),
|
||||||
));
|
|
||||||
}
|
|
||||||
let temp_key = key.last().to_env();
|
|
||||||
let toml_s = format!("{}={}", temp_key, v);
|
|
||||||
let toml_v: toml::Value = toml::de::from_str(&toml_s).map_err(|e| {
|
|
||||||
ConfigError::new(format!("could not parse TOML list: {}", e), def.clone())
|
|
||||||
})?;
|
|
||||||
let values = toml_v
|
|
||||||
.as_table()
|
|
||||||
.unwrap()
|
|
||||||
.get(&temp_key)
|
|
||||||
.unwrap()
|
|
||||||
.as_array()
|
|
||||||
.expect("env var was not array");
|
|
||||||
for value in values {
|
|
||||||
// TODO: support other types
|
|
||||||
let s = value.as_str().ok_or_else(|| {
|
|
||||||
ConfigError::new(
|
|
||||||
format!("expected string, found {}", value.type_str()),
|
|
||||||
def.clone(),
|
def.clone(),
|
||||||
)
|
));
|
||||||
|
}
|
||||||
|
let temp_key = key.last().to_env();
|
||||||
|
let toml_s = format!("{}={}", temp_key, v);
|
||||||
|
let toml_v: toml::Value = toml::de::from_str(&toml_s).map_err(|e| {
|
||||||
|
ConfigError::new(format!("could not parse TOML list: {}", e), def.clone())
|
||||||
})?;
|
})?;
|
||||||
res.push((s.to_string(), def.clone()));
|
let values = toml_v
|
||||||
|
.as_table()
|
||||||
|
.unwrap()
|
||||||
|
.get(&temp_key)
|
||||||
|
.unwrap()
|
||||||
|
.as_array()
|
||||||
|
.expect("env var was not array");
|
||||||
|
for value in values {
|
||||||
|
// TODO: support other types
|
||||||
|
let s = value.as_str().ok_or_else(|| {
|
||||||
|
ConfigError::new(
|
||||||
|
format!("expected string, found {}", value.type_str()),
|
||||||
|
def.clone(),
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
res.push((s.to_string(), def.clone()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(ConfigSeqAccess {
|
Ok(ConfigSeqAccess {
|
||||||
|
@ -55,6 +55,15 @@ fn new_config(env: &[(&str, &str)]) -> Config {
|
|||||||
.collect();
|
.collect();
|
||||||
let mut config = Config::new(shell, cwd, homedir);
|
let mut config = Config::new(shell, cwd, homedir);
|
||||||
config.set_env(env);
|
config.set_env(env);
|
||||||
|
config.configure(
|
||||||
|
0,
|
||||||
|
None,
|
||||||
|
&None,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
&None,
|
||||||
|
&["advanced-env".into()],
|
||||||
|
).unwrap();
|
||||||
config
|
config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user