self.cli_config = Some(cli_config.iter().map(|s| s.to_string()).collect());
self.merge_cli_args()?;
}
+ 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
+ // the `unstable_flags` hadn't been set up, yet. Any values
+ // fetched before this step will not process includes, but that
+ // should be fine (`[alias]` is one of the only things loaded
+ // before configure). This can be removed when stabilized.
+ self.reload_rooted_at(self.cwd.clone())?;
+ }
let extra_verbose = verbose >= 2;
let verbose = verbose != 0;
/// `seen` is used to check for cyclic includes.
fn load_includes(&self, mut value: CV, seen: &mut HashSet<PathBuf>) -> CargoResult<CV> {
// Get the list of files to load.
- let (includes, def) = match &mut value {
+ let includes = match &mut value {
CV::Table(table, _def) => match table.remove("include") {
- Some(CV::String(s, def)) => (vec![(s, def.clone())], def),
- Some(CV::List(list, def)) => (list, def),
+ Some(CV::String(s, def)) => vec![(s, def.clone())],
+ Some(CV::List(list, _def)) => list,
Some(other) => bail!(
"`include` expected a string or list, but found {} in `{}`",
other.desc(),
};
// Check unstable.
if !self.cli_unstable().config_include {
- self.shell().warn(format!("config `include` in `{}` ignored, the -Zconfig-include command-line flag is required",
- def))?;
return Ok(value);
}
// Accumulate all values here.
//! Tests for `include` config field.
-use super::config::{
- assert_error, assert_match, read_output, write_config, write_config_at, ConfigBuilder,
-};
-use cargo_test_support::{no_such_file_err_msg, paths};
+use super::config::{assert_error, write_config, write_config_at, ConfigBuilder};
+use cargo_test_support::{no_such_file_err_msg, paths, project};
use std::fs;
#[cargo_test]
fn gated() {
// Requires -Z flag.
write_config("include='other'");
+ write_config_at(
+ ".cargo/other",
+ "
+ othervalue = 1
+ ",
+ );
let config = ConfigBuilder::new().build();
- let output = read_output(config);
- let expected = "\
-warning: config `include` in `[..]/.cargo/config` ignored, \
-the -Zconfig-include command-line flag is required
-";
- assert_match(expected, &output);
+ assert_eq!(config.get::<Option<i32>>("othervalue").unwrap(), None);
+ let config = ConfigBuilder::new().unstable_flag("config-include").build();
+ assert_eq!(config.get::<i32>("othervalue").unwrap(), 1);
}
#[cargo_test]
assert_eq!(config.get::<i32>("key3").unwrap(), 4);
}
+#[cargo_test]
+fn works_with_cli() {
+ write_config_at(
+ ".cargo/config.toml",
+ "
+ include = 'other.toml'
+ [build]
+ rustflags = ['-W', 'unused']
+ ",
+ );
+ write_config_at(
+ ".cargo/other.toml",
+ "
+ [build]
+ rustflags = ['-W', 'unsafe-code']
+ ",
+ );
+ let p = project().file("src/lib.rs", "").build();
+ p.cargo("build -v")
+ .with_stderr(
+ "\
+[COMPILING] foo v0.0.1 [..]
+[RUNNING] `rustc [..]-W unused`
+[FINISHED] [..]
+",
+ )
+ .run();
+ p.cargo("build -v -Z config-include")
+ .masquerade_as_nightly_cargo()
+ .with_stderr(
+ "\
+[COMPILING] foo v0.0.1 [..]
+[RUNNING] `rustc [..]-W unsafe-code -W unused`
+[FINISHED] [..]
+",
+ )
+ .run();
+}
+
#[cargo_test]
fn left_to_right() {
// How it merges multiple includes.
fn missing_file() {
// Error when there's a missing file.
write_config("include='missing'");
- let config = ConfigBuilder::new().unstable_flag("config-include").build();
+ let config = ConfigBuilder::new()
+ .unstable_flag("config-include")
+ .build_err();
assert_error(
- config.get::<i32>("whatever").unwrap_err(),
+ config.unwrap_err(),
&format!(
"\
could not load Cargo configuration
write_config_at(".cargo/config", "include='one'");
write_config_at(".cargo/one", "include='two'");
write_config_at(".cargo/two", "include='config'");
- let config = ConfigBuilder::new().unstable_flag("config-include").build();
+ let config = ConfigBuilder::new()
+ .unstable_flag("config-include")
+ .build_err();
assert_error(
- config.get::<i32>("whatever").unwrap_err(),
+ config.unwrap_err(),
"\
could not load Cargo configuration
fn bad_format() {
// Not a valid format.
write_config("include = 1");
- let config = ConfigBuilder::new().unstable_flag("config-include").build();
+ let config = ConfigBuilder::new()
+ .unstable_flag("config-include")
+ .build_err();
assert_error(
- config.get::<i32>("whatever").unwrap_err(),
+ config.unwrap_err(),
"\
could not load Cargo configuration