]> git.proxmox.com Git - cargo.git/commitdiff
Auto merge of #8939 - Andy-Python-Programmer:master, r=alexcrichton
authorbors <bors@rust-lang.org>
Thu, 25 Feb 2021 19:40:08 +0000 (19:40 +0000)
committerbors <bors@rust-lang.org>
Thu, 25 Feb 2021 19:40:08 +0000 (19:40 +0000)
Throw error if CARGO_TARGET_DIR is an empty string

This pull request makes the target dir to be target/ if `CARGO_TARGET_DIR` is `` with spaces trimmed and not delete the current project.

Fixes: #8866
1  2 
src/cargo/util/config/mod.rs
tests/testsuite/config.rs

Simple merge
index 1b45b65b3074ba825e3b66323de9b7d14fa1c361,89c5b9f5f2aee9b1e04f5e47dc6853a5a11bd53e..c53fc1e07fcd03e4ecd5dc43432124aa71715c25
@@@ -1458,5 -1458,56 +1458,33 @@@ strip = 'debuginfo
  
      let p: toml::TomlProfile = config.get("profile.release").unwrap();
      let strip = p.strip.unwrap();
 -    assert_eq!(strip, Strip::DebugInfo);
 -}
 -
 -#[cargo_test]
 -fn parse_enum_fail() {
 -    write_config(
 -        "\
 -[profile.release]
 -strip = 'invalid'
 -",
 -    );
 -
 -    let config = new_config();
 -
 -    assert_error(
 -        config
 -            .get::<toml::TomlProfile>("profile.release")
 -            .unwrap_err(),
 -        "\
 -error in [..]/.cargo/config: could not load config key `profile.release.strip`
 -
 -Caused by:
 -  unknown variant `invalid`, expected one of `debuginfo`, `none`, `symbols`",
 -    );
 +    assert_eq!(strip, toml::StringOrBool::String("debuginfo".to_string()));
  }
+ #[cargo_test]
+ fn cargo_target_empty_cfg() {
+     write_config(
+         "\
+ [build]
+ target-dir = ''
+ ",
+     );
+     let config = new_config();
+     assert_error(
+         config.target_dir().unwrap_err(),
+         "the target directory is set to an empty string in [..]/.cargo/config",
+     );
+ }
+ #[cargo_test]
+ fn cargo_target_empty_env() {
+     let project = project().build();
+     project.cargo("build")
+         .env("CARGO_TARGET_DIR", "")
+         .with_stderr("error: the target directory is set to an empty string in the `CARGO_TARGET_DIR` environment variable")
+         .with_status(101)
+         .run()
+ }