mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
Allow enabling config-include
feature in config
Prior to this change, it is not possible to enable the unstable `config-include` flag from within a config file itself. This is due to the fact that, while cargo does reload configuration files if this flag is set, it does not parse the top-level configuration file's unstable flags before checking whether this flag is present. This commit forces cargo to load unstable features before this check, and if the flag is present, re-loads configuration files with `config-include` enabled.
This commit is contained in:
parent
45e5cb4964
commit
0e35bea6c3
@ -1035,6 +1035,11 @@ impl GlobalContext {
|
||||
self.cli_config = Some(cli_config.iter().map(|s| s.to_string()).collect());
|
||||
self.merge_cli_args()?;
|
||||
}
|
||||
|
||||
// Load the unstable flags from config file here first, as the config
|
||||
// file itself may enable inclusion of other configs. In that case, we
|
||||
// want to re-load configs with includes enabled:
|
||||
self.load_unstable_flags_from_config()?;
|
||||
if self.unstable_flags.config_include {
|
||||
// If the config was already loaded (like when fetching the
|
||||
// `[alias]` table), it was loaded with includes disabled because
|
||||
@ -1091,8 +1096,6 @@ impl GlobalContext {
|
||||
let cli_target_dir = target_dir.as_ref().map(|dir| Filesystem::new(dir.clone()));
|
||||
self.target_dir = cli_target_dir;
|
||||
|
||||
self.load_unstable_flags_from_config()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -72,11 +72,9 @@ fn enable_in_unstable_config() {
|
||||
let gctx = GlobalContextBuilder::new()
|
||||
.nightly_features_allowed(true)
|
||||
.build();
|
||||
// On this commit, enabling `config-include` in the top-level
|
||||
// configuration does not yet work.
|
||||
assert_eq!(gctx.get::<i32>("key1").unwrap(), 1);
|
||||
assert_eq!(gctx.get::<i32>("key2").unwrap(), 2);
|
||||
assert_eq!(gctx.get::<i32>("key3").ok(), None);
|
||||
assert_eq!(gctx.get::<i32>("key3").unwrap(), 4);
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
@ -200,15 +198,18 @@ fn mix_of_hierarchy_and_include_with_enable_in_unstable_config() {
|
||||
.cwd("foo")
|
||||
.nightly_features_allowed(true)
|
||||
.build();
|
||||
// On this commit, enabling `config-include` in the top-level
|
||||
// configuration does not yet work.
|
||||
assert_eq!(gctx.get::<i32>("key1").unwrap(), 1);
|
||||
assert_eq!(gctx.get::<i32>("key2").unwrap(), 3);
|
||||
assert_eq!(gctx.get::<i32>("key2").unwrap(), 2);
|
||||
assert_eq!(gctx.get::<i32>("key3").unwrap(), 3);
|
||||
assert_eq!(gctx.get::<i32>("key4").ok(), None);
|
||||
assert_eq!(gctx.get::<i32>("key4").unwrap(), 4);
|
||||
assert_eq!(
|
||||
gctx.get::<Vec<String>>("unstable.features").unwrap(),
|
||||
vec!["3".to_string(), "1".to_string()]
|
||||
vec![
|
||||
"4".to_string(),
|
||||
"3".to_string(),
|
||||
"2".to_string(),
|
||||
"1".to_string()
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user