Skip to content

Commit 0e35bea

Browse files
committed
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.
1 parent 45e5cb4 commit 0e35bea

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/cargo/util/context/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,11 @@ impl GlobalContext {
10351035
self.cli_config = Some(cli_config.iter().map(|s| s.to_string()).collect());
10361036
self.merge_cli_args()?;
10371037
}
1038+
1039+
// Load the unstable flags from config file here first, as the config
1040+
// file itself may enable inclusion of other configs. In that case, we
1041+
// want to re-load configs with includes enabled:
1042+
self.load_unstable_flags_from_config()?;
10381043
if self.unstable_flags.config_include {
10391044
// If the config was already loaded (like when fetching the
10401045
// `[alias]` table), it was loaded with includes disabled because
@@ -1091,8 +1096,6 @@ impl GlobalContext {
10911096
let cli_target_dir = target_dir.as_ref().map(|dir| Filesystem::new(dir.clone()));
10921097
self.target_dir = cli_target_dir;
10931098

1094-
self.load_unstable_flags_from_config()?;
1095-
10961099
Ok(())
10971100
}
10981101

tests/testsuite/config_include.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,9 @@ fn enable_in_unstable_config() {
7272
let gctx = GlobalContextBuilder::new()
7373
.nightly_features_allowed(true)
7474
.build();
75-
// On this commit, enabling `config-include` in the top-level
76-
// configuration does not yet work.
7775
assert_eq!(gctx.get::<i32>("key1").unwrap(), 1);
7876
assert_eq!(gctx.get::<i32>("key2").unwrap(), 2);
79-
assert_eq!(gctx.get::<i32>("key3").ok(), None);
77+
assert_eq!(gctx.get::<i32>("key3").unwrap(), 4);
8078
}
8179

8280
#[cargo_test]
@@ -200,15 +198,18 @@ fn mix_of_hierarchy_and_include_with_enable_in_unstable_config() {
200198
.cwd("foo")
201199
.nightly_features_allowed(true)
202200
.build();
203-
// On this commit, enabling `config-include` in the top-level
204-
// configuration does not yet work.
205201
assert_eq!(gctx.get::<i32>("key1").unwrap(), 1);
206-
assert_eq!(gctx.get::<i32>("key2").unwrap(), 3);
202+
assert_eq!(gctx.get::<i32>("key2").unwrap(), 2);
207203
assert_eq!(gctx.get::<i32>("key3").unwrap(), 3);
208-
assert_eq!(gctx.get::<i32>("key4").ok(), None);
204+
assert_eq!(gctx.get::<i32>("key4").unwrap(), 4);
209205
assert_eq!(
210206
gctx.get::<Vec<String>>("unstable.features").unwrap(),
211-
vec!["3".to_string(), "1".to_string()]
207+
vec![
208+
"4".to_string(),
209+
"3".to_string(),
210+
"2".to_string(),
211+
"1".to_string()
212+
]
212213
);
213214
}
214215

0 commit comments

Comments
 (0)