Skip to content

Commit 0b35010

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 606adee commit 0b35010

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/cargo/util/context/mod.rs

+5
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

tests/testsuite/config_include.rs

+29
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,35 @@ fn simple() {
4848
assert_eq!(gctx.get::<i32>("key3").unwrap(), 4);
4949
}
5050

51+
#[cargo_test]
52+
fn enable_in_unstable_config() {
53+
// config-include enabled in the unstable config table:
54+
write_config_at(
55+
".cargo/config.toml",
56+
"
57+
include = 'other.toml'
58+
key1 = 1
59+
key2 = 2
60+
61+
[unstable]
62+
config-include = true
63+
",
64+
);
65+
write_config_at(
66+
".cargo/other.toml",
67+
"
68+
key2 = 3
69+
key3 = 4
70+
",
71+
);
72+
let gctx = GlobalContextBuilder::new()
73+
.nightly_features_allowed(true)
74+
.build();
75+
assert_eq!(gctx.get::<i32>("key1").unwrap(), 1);
76+
assert_eq!(gctx.get::<i32>("key2").unwrap(), 2);
77+
assert_eq!(gctx.get::<i32>("key3").unwrap(), 4);
78+
}
79+
5180
#[cargo_test]
5281
fn works_with_cli() {
5382
write_config_at(

0 commit comments

Comments
 (0)