From d17ccec2e8c06f1a9157424aee0bf89e8854a9de Mon Sep 17 00:00:00 2001 From: Hidehito Yabuuchi Date: Sat, 23 Feb 2019 13:12:18 +0900 Subject: [PATCH 1/3] Warn on misspelled env vars 'RUST_FLAGS' and 'RUSTDOC_FLAGS' --- src/cargo/ops/cargo_compile.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index 169fcaab9a5..fbfe62b0470 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -245,6 +245,27 @@ pub fn compile_ws<'a>( ref export_dir, } = *options; + match build_config.mode { + CompileMode::Test + | CompileMode::Build + | CompileMode::Check { .. } + | CompileMode::Bench + | CompileMode::RunCustomBuild => { + if std::env::var("RUST_FLAGS").is_ok() { + config.shell().warn( + "Cargo does not read `RUST_FLAGS` environment variable. Did you mean `RUSTFLAGS`?", + )?; + } + } + CompileMode::Doc { .. } | CompileMode::Doctest => { + if std::env::var("RUSTDOC_FLAGS").is_ok() { + config.shell().warn( + "Cargo does not read `RUSTDOC_FLAGS` environment variable. Did you mean `RUSTDOCFLAGS`?" + )?; + } + } + } + let default_arch_kind = if build_config.requested_target.is_some() { Kind::Target } else { From 44aec50e4ed60a35b9a7612022a1f781bcb786d0 Mon Sep 17 00:00:00 2001 From: Hidehito Yabuuchi Date: Sat, 23 Feb 2019 17:07:59 +0900 Subject: [PATCH 2/3] Add tests for warning on misspelled env vars --- tests/testsuite/rustdocflags.rs | 10 ++++++++++ tests/testsuite/rustflags.rs | 34 +++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/tests/testsuite/rustdocflags.rs b/tests/testsuite/rustdocflags.rs index 7ac963da710..b429a7cebac 100644 --- a/tests/testsuite/rustdocflags.rs +++ b/tests/testsuite/rustdocflags.rs @@ -85,3 +85,13 @@ fn rustdocflags_passed_to_rustdoc_through_cargo_test_only_once() { .env("RUSTDOCFLAGS", "--markdown-no-toc") .run(); } + +#[test] +fn rustdocflags_misspelled() { + let p = project().file("src/main.rs", "fn main() { }").build(); + + p.cargo("doc") + .env("RUSTDOC_FLAGS", "foo") + .with_stderr_contains("[WARNING] Cargo does not read `RUSTDOC_FLAGS` environment variable. Did you mean `RUSTDOCFLAGS`?") + .run(); +} diff --git a/tests/testsuite/rustflags.rs b/tests/testsuite/rustflags.rs index 84ee109748b..ba6171082d0 100644 --- a/tests/testsuite/rustflags.rs +++ b/tests/testsuite/rustflags.rs @@ -1325,3 +1325,37 @@ fn two_matching_in_config() { p1.cargo("run").run(); p1.cargo("build").with_stderr("[FINISHED] [..]").run(); } + +#[test] +fn env_rustflags_misspelled() { + let p = project().file("src/main.rs", "fn main() { }").build(); + + for cmd in &["check", "build", "run", "test", "bench"] { + p.cargo(cmd) + .env("RUST_FLAGS", "foo") + .with_stderr_contains("[WARNING] Cargo does not read `RUST_FLAGS` environment variable. Did you mean `RUSTFLAGS`?") + .run(); + } +} + +#[test] +fn env_rustflags_misspelled_build_script() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + build = "build.rs" + "#, + ) + .file("src/lib.rs", "") + .file("build.rs", "fn main() { }") + .build(); + + p.cargo("build") + .env("RUST_FLAGS", "foo") + .with_stderr_contains("[WARNING] Cargo does not read `RUST_FLAGS` environment variable. Did you mean `RUSTFLAGS`?") + .run(); +} From 3ca98adbbac5752cdef337f5ac803e7843ab601a Mon Sep 17 00:00:00 2001 From: Hidehito Yabuuchi Date: Sun, 24 Feb 2019 14:27:10 +0900 Subject: [PATCH 3/3] cargo fmt tests/testsuite/rustflags.rs --- tests/testsuite/rustflags.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/testsuite/rustflags.rs b/tests/testsuite/rustflags.rs index ba6171082d0..da5b5eb78c2 100644 --- a/tests/testsuite/rustflags.rs +++ b/tests/testsuite/rustflags.rs @@ -1332,9 +1332,9 @@ fn env_rustflags_misspelled() { for cmd in &["check", "build", "run", "test", "bench"] { p.cargo(cmd) - .env("RUST_FLAGS", "foo") - .with_stderr_contains("[WARNING] Cargo does not read `RUST_FLAGS` environment variable. Did you mean `RUSTFLAGS`?") - .run(); + .env("RUST_FLAGS", "foo") + .with_stderr_contains("[WARNING] Cargo does not read `RUST_FLAGS` environment variable. Did you mean `RUSTFLAGS`?") + .run(); } }