Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/bin/cargo/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ fn execute_subcommand(
cmd: &str,
subcommand_args: &ArgMatches<'_>,
) -> CliResult {
if subcommand_args.is_present("ignore-local-config") {
config.reload_rooted_at(config.home().clone().into_path_unlocked())?;
}

if let Some(exec) = commands::builtin_exec(cmd) {
return exec(config, subcommand_args);
}
Expand Down Expand Up @@ -329,6 +333,11 @@ See 'cargo help <command>' for more information on a specific command.\n",
.global(true)
.hidden(true),
)
.arg(
opt("ignore-local-config", "Ignore local `.cargo/config` files")
.global(true)
.hidden(true),
)
.arg(
Arg::with_name("unstable-features")
.help("Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details")
Expand Down
2 changes: 2 additions & 0 deletions src/cargo/core/compiler/build_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub struct BuildConfig {
// Note that, although the cmd-line flag name is `out-dir`, in code we use
// `export_dir`, to avoid confusion with out dir at `target/debug/deps`.
pub export_dir: Option<PathBuf>,
pub ignore_local_config: bool,
}

impl BuildConfig {
Expand Down Expand Up @@ -80,6 +81,7 @@ impl BuildConfig {
primary_unit_rustc: None,
rustfix_diagnostic_server: RefCell::new(None),
export_dir: None,
ignore_local_config: false,
})
}

Expand Down
13 changes: 13 additions & 0 deletions src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ pub trait AppExt: Sized {
))
}

fn arg_ignore_local_config(self) -> Self {
self._arg(opt(
"ignore-local-config",
"Ignore local `.cargo/config.toml` files (unstable)",
))
}

fn arg_unit_graph(self) -> Self {
self._arg(opt("unit-graph", "Output build graph in JSON (unstable)").hidden(true))
}
Expand Down Expand Up @@ -459,6 +466,7 @@ pub trait ArgMatchesExt {
build_config.requested_profile = self.get_profile_name(config, "dev", profile_checking)?;
build_config.build_plan = self._is_present("build-plan");
build_config.unit_graph = self._is_present("unit-graph");
build_config.ignore_local_config = self._is_present("ignore-local-config");
if build_config.build_plan {
config
.cli_unstable()
Expand All @@ -469,6 +477,11 @@ pub trait ArgMatchesExt {
.cli_unstable()
.fail_if_stable_opt("--unit-graph", 8002)?;
}
if build_config.ignore_local_config {
config
.cli_unstable()
.fail_if_stable_opt("--ignore-local-config", 0000)?;
}

let opts = CompileOptions {
build_config,
Expand Down
46 changes: 46 additions & 0 deletions tests/testsuite/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1483,3 +1483,49 @@ Caused by:
unknown variant `invalid`, expected one of `debuginfo`, `none`, `symbols`",
);
}

#[cargo_test]
fn ignore_local_config_gated() {
// Requires -Zunstable-options
let p = project().file("src/lib.rs", "").build();

p.cargo("build --ignore-local-config")
.with_status(101)
.with_stderr(
"\
[ERROR] the `--ignore-local-config` flag is unstable, and only available \
on the nightly channel of Cargo, [..]
See [..]
See [..]
",
)
.run();

p.cargo("build --ignore-local-config")
.masquerade_as_nightly_cargo()
.with_status(101)
.with_stderr(
"\
[ERROR] the `--ignore-local-config` flag is unstable, pass `-Z unstable-options` to enable it
See [..]
",
)
.run();
}

#[cargo_test]
fn ignore_local_config_basic() {
let p = project()
.file("src/lib.rs", "")
.file(
".cargo/config",
r#"
[build]
target = "non-existent"
"#,
)
.build();
p.cargo("build -v --ignore-local-config -Z unstable-options")
.masquerade_as_nightly_cargo()
.run();
}