about summary refs log tree commit diff
path: root/src/bootstrap
diff options
context:
space:
mode:
authorJoshua Nelson <jyn514@gmail.com>2020-09-29 19:46:32 -0400
committerJoshua Nelson <jyn514@gmail.com>2020-10-26 18:56:55 -0400
commitb3246e0cb10a6a32e8f652312985d36581f77c19 (patch)
tree26360f5241d09a231e85581c7f19ebf68f6aad0b /src/bootstrap
parent0da6d42f297642a60f2640ec313b879b376b9ad8 (diff)
downloadrust-b3246e0cb10a6a32e8f652312985d36581f77c19.tar.gz
rust-b3246e0cb10a6a32e8f652312985d36581f77c19.zip
Set the proper sysroot for clippy
Clippy does its own runtime detection of the sysroot, which was
incorrect in this case (it used the beta sysroot). This overrides the
sysroot to use `stage0-sysroot` instead.

- Get `x.py clippy` to work on nightly
- Give a nice error message if nightly clippy isn't installed
Diffstat (limited to 'src/bootstrap')
-rw-r--r--src/bootstrap/builder.rs41
1 files changed, 39 insertions, 2 deletions
diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs
index dc4243a76d5..c0578dea1cd 100644
--- a/src/bootstrap/builder.rs
+++ b/src/bootstrap/builder.rs
@@ -850,7 +850,40 @@ impl<'a> Builder<'a> {
                 cargo.args(s.split_whitespace());
             }
             rustflags.env("RUSTFLAGS_BOOTSTRAP");
-            rustflags.arg("--cfg=bootstrap");
+            if cmd == "clippy" {
+                // clippy overwrites any sysroot we pass on the command line.
+                // Tell it to use the appropriate sysroot instead.
+                // NOTE: this can't be fixed in clippy because we explicitly don't set `RUSTC`,
+                // so it has no way of knowing the sysroot.
+                rustflags.arg("--sysroot");
+                rustflags.arg(
+                    self.sysroot(compiler)
+                        .as_os_str()
+                        .to_str()
+                        .expect("sysroot must be valid UTF-8"),
+                );
+                // Only run clippy on a very limited subset of crates (in particular, not build scripts).
+                cargo.arg("-Zunstable-options");
+                // Explicitly does *not* set `--cfg=bootstrap`, since we're using a nightly clippy.
+                let host_version = Command::new("rustc").arg("--version").output().map_err(|_| ());
+                if let Err(_) = host_version.and_then(|output| {
+                    if output.status.success()
+                        && t!(std::str::from_utf8(&output.stdout)).contains("nightly")
+                    {
+                        Ok(output)
+                    } else {
+                        Err(())
+                    }
+                }) {
+                    eprintln!(
+                        "error: `x.py clippy` requires a nightly host `rustc` toolchain with the `clippy` component"
+                    );
+                    eprintln!("help: try `rustup default nightly`");
+                    std::process::exit(1);
+                }
+            } else {
+                rustflags.arg("--cfg=bootstrap");
+            }
         }
 
         if self.config.rust_new_symbol_mangling {
@@ -975,7 +1008,6 @@ impl<'a> Builder<'a> {
         // src/bootstrap/bin/{rustc.rs,rustdoc.rs}
         cargo
             .env("RUSTBUILD_NATIVE_DIR", self.native_dir(target))
-            .env("RUSTC", self.out.join("bootstrap/debug/rustc"))
             .env("RUSTC_REAL", self.rustc(compiler))
             .env("RUSTC_STAGE", stage.to_string())
             .env("RUSTC_SYSROOT", &sysroot)
@@ -991,6 +1023,11 @@ impl<'a> Builder<'a> {
             )
             .env("RUSTC_ERROR_METADATA_DST", self.extended_error_dir())
             .env("RUSTC_BREAK_ON_ICE", "1");
+        // Clippy support is a hack and uses the default `cargo-clippy` in path.
+        // Don't override RUSTC so that the `cargo-clippy` in path will be run.
+        if cmd != "clippy" {
+            cargo.env("RUSTC", self.out.join("bootstrap/debug/rustc"));
+        }
 
         // Dealing with rpath here is a little special, so let's go into some
         // detail. First off, `-rpath` is a linker option on Unix platforms