]> git.proxmox.com Git - cargo.git/commitdiff
fix: Fix unusual errors with `RUSTC_WRAPPER`
authorAlex Crichton <alex@alexcrichton.com>
Wed, 5 Sep 2018 22:17:43 +0000 (15:17 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Wed, 5 Sep 2018 22:18:40 +0000 (15:18 -0700)
This commit fixes the interaction of `cargo fix` and `RUSTC_WRAPPER`, ensuring
that Cargo at least doesn't die internally. For now `RUSTC_WRAPPER` is
overridden for normal execution but we can eventually one day probably support
`RUSTC_WRAPPER`!

Closes #5981

src/cargo/core/compiler/compilation.rs
src/cargo/util/rustc.rs
tests/testsuite/fix.rs

index a8d57e62bc6eb972586e44004d9f5da16f4880d2..7effc620cd0f4e34966df16308e7114a03ccc4e6 100644 (file)
@@ -82,18 +82,26 @@ pub struct Compilation<'cfg> {
 
 impl<'cfg> Compilation<'cfg> {
     pub fn new<'a>(bcx: &BuildContext<'a, 'cfg>) -> CargoResult<Compilation<'cfg>> {
-        let mut rustc = bcx.rustc.process();
+        // If we're using cargo as a rustc wrapper then we're in a situation
+        // like `cargo fix`. For now just disregard the `RUSTC_WRAPPER` env var
+        // (which is typically set to `sccache` for now). Eventually we'll
+        // probably want to implement `RUSTC_WRAPPER` for `cargo fix`, but we'll
+        // leave that open as a bug for now.
+        let mut rustc = if bcx.build_config.cargo_as_rustc_wrapper {
+            let mut rustc = bcx.rustc.process_no_wrapper();
+            let prog = rustc.get_program().to_owned();
+            rustc.env("RUSTC", prog);
+            rustc.program(env::current_exe()?);
+            rustc
+        } else {
+            bcx.rustc.process()
+        };
         for (k, v) in bcx.build_config.extra_rustc_env.iter() {
             rustc.env(k, v);
         }
         for arg in bcx.build_config.extra_rustc_args.iter() {
             rustc.arg(arg);
         }
-        if bcx.build_config.cargo_as_rustc_wrapper {
-            let prog = rustc.get_program().to_owned();
-            rustc.env("RUSTC", prog);
-            rustc.program(env::current_exe()?);
-        }
         let srv = bcx.build_config.rustfix_diagnostic_server.borrow();
         if let Some(server) = &*srv {
             server.configure(&mut rustc);
index ee6737743780659693dc260755a503533135daa7..1c25a79bef141aae732cc464f6b0c677898a4a3b 100644 (file)
@@ -68,15 +68,17 @@ impl Rustc {
     pub fn process(&self) -> ProcessBuilder {
         if let Some(ref wrapper) = self.wrapper {
             let mut cmd = util::process(wrapper);
-            {
-                cmd.arg(&self.path);
-            }
+            cmd.arg(&self.path);
             cmd
         } else {
-            util::process(&self.path)
+            self.process_no_wrapper()
         }
     }
 
+    pub fn process_no_wrapper(&self) -> ProcessBuilder {
+        util::process(&self.path)
+    }
+
     pub fn cached_output(&self, cmd: &ProcessBuilder) -> CargoResult<(String, String)> {
         self.cache.lock().unwrap().cached_output(cmd)
     }
index 06b213990521942bb313828d3c41348e226671d0..8a68f6a94e1b1a42c4ee6ce19cffdaf2a06aa356 100644 (file)
@@ -1117,3 +1117,26 @@ fn doesnt_rebuild_dependencies() {
 ")
         .run();
 }
+
+#[test]
+fn does_not_crash_with_rustc_wrapper() {
+    // We don't have /usr/bin/env on Windows.
+    if cfg!(windows) {
+        return;
+    }
+    let p = project()
+        .file(
+            "Cargo.toml",
+            r#"
+                [package]
+                name = "foo"
+                version = "0.1.0"
+            "#,
+        )
+        .file("src/lib.rs", "")
+        .build();
+
+    p.cargo("fix --allow-no-vcs")
+        .env("RUSTC_WRAPPER", "/usr/bin/env")
+        .run();
+}