diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index e87125a49a6a0..abf897b1634f6 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -37,14 +37,25 @@ fn main() { Err(_) => 0, }; + if verbose > 1 { + eprintln!("target: {target:?}"); + eprintln!("version: {version:?}"); + } + // Use a different compiler for build scripts, since there may not yet be a // libstd for the real compiler to use. However, if Cargo is attempting to // determine the version of the compiler, the real compiler needs to be // used. Currently, these two states are differentiated based on whether // --target and -vV is/isn't passed. let (rustc, libdir) = if target.is_none() && version.is_none() { + if verbose > 1 { + eprintln!("Using snapshot complier"); + } ("RUSTC_SNAPSHOT", "RUSTC_SNAPSHOT_LIBDIR") } else { + if verbose > 1 { + eprintln!("Using real complier"); + } ("RUSTC_REAL", "RUSTC_LIBDIR") }; let stage = env::var("RUSTC_STAGE").unwrap_or_else(|_| { @@ -75,6 +86,10 @@ fn main() { cmd.arg("-Ztime-passes"); } } + + if crate_name == "build_script_build" && verbose > 0 { + eprintln!("building build scripts using sysroot {:?}", sysroot); + } } // Print backtrace in case of ICE @@ -147,6 +162,16 @@ fn main() { cmd.arg("--check-cfg=values(bootstrap)"); } + if let Ok(command) = env::var("RUSTC_COMMAND") { + if command == "clippy" && target.is_none() { + let libdir_string = libdir.to_string_lossy(); + let (sysroot, _) = libdir_string.rsplit_once('/').unwrap(); + if !args.iter().any(|arg| arg == "--sysroot") { + cmd.arg("--sysroot").arg(&sysroot); + } + } + } + if let Ok(map) = env::var("RUSTC_DEBUGINFO_MAP") { cmd.arg("--remap-path-prefix").arg(&map); } @@ -220,6 +245,7 @@ fn main() { env::join_paths(&dylib_path).unwrap(), cmd, ); + eprintln!("{} SYSROOT: {:?}", prefix, env::var("SYSROOT")); eprintln!("{} sysroot: {:?}", prefix, sysroot); eprintln!("{} libdir: {:?}", prefix, libdir); } diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index 5351c80eab9a6..a9e73e62f9770 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -518,6 +518,8 @@ def download_toolchain(self): rustc_channel = self.stage0_compiler.version bin_root = self.bin_root() + tarball_suffix = '.tar.gz' if lzma is None else '.tar.xz' + key = self.stage0_compiler.date if self.rustc().startswith(bin_root) and \ (not os.path.exists(self.rustc()) or @@ -602,22 +604,6 @@ def download_toolchain(self): with output(self.rustc_stamp()) as rust_stamp: rust_stamp.write(key) - def _download_component_helper( - self, filename, pattern, tarball_suffix, rustc_cache, - ): - key = self.stage0_compiler.date - - tarball = os.path.join(rustc_cache, filename) - if not os.path.exists(tarball): - get( - self.download_url, - "dist/{}/{}".format(key, filename), - tarball, - self.checksums_sha256, - verbose=self.verbose, - ) - unpack(tarball, tarball_suffix, self.bin_root(), match=pattern, verbose=self.verbose) - def should_fix_bins_and_dylibs(self): """Whether or not `fix_bin_or_dylib` needs to be run; can only be True on NixOS. @@ -740,6 +726,17 @@ def rustc_stamp(self): """ return os.path.join(self.bin_root(), '.rustc-stamp') + def clippy_stamp(self): + """Return the path for .clippy-stamp + + >>> rb = RustBuild() + >>> rb.build_dir = "build" + >>> rb.clippy_stamp() == os.path.join("build", "stage0", ".clippy-stamp") + True + """ + return os.path.join(self.bin_root(), '.clippy-stamp') + + def program_out_of_date(self, stamp_path, key): """Check if the given program stamp is out of date""" if not os.path.exists(stamp_path) or self.clean: @@ -810,6 +807,10 @@ def rustc(self): """Return config path for rustc""" return self.program_config('rustc') + def clippy(self): + """Return config path for clippy""" + return self.program_config('cargo-clippy') + def program_config(self, program): """Return config path for the given program at the given stage diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 7c8e3536df588..1c7cce8cd9d2e 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -13,7 +13,7 @@ use std::process::Command; use std::time::{Duration, Instant}; use crate::cache::{Cache, Interned, INTERNER}; -use crate::config::{SplitDebuginfo, TargetSelection}; +use crate::config::{DryRun, SplitDebuginfo, TargetSelection}; use crate::doc; use crate::flags::{Color, Subcommand}; use crate::install; @@ -22,7 +22,9 @@ use crate::run; use crate::setup; use crate::test; use crate::tool::{self, SourceType}; -use crate::util::{self, add_dylib_path, add_link_lib_path, exe, libdir, output, t}; +use crate::util::{ + self, add_dylib_path, add_link_lib_path, dylib_path, dylib_path_var, exe, libdir, output, t, +}; use crate::EXTRA_CHECK_CFGS; use crate::{check, compile, Crate}; use crate::{clean, dist}; @@ -1118,6 +1120,44 @@ impl<'a> Builder<'a> { self.ensure(tool::Rustdoc { compiler }) } + pub fn cargo_clippy_cmd(&self, run_compiler: Compiler) -> Command { + let initial_sysroot_bin = self.initial_rustc.parent().unwrap(); + // Set PATH to include the sysroot bin dir so clippy can find cargo. + let path = t!(env::join_paths( + // The sysroot comes first in PATH to avoid using rustup's cargo. + std::iter::once(PathBuf::from(initial_sysroot_bin)) + .chain(env::split_paths(&t!(env::var("PATH")))) + )); + + if run_compiler.stage == 0 { + // `ensure(Clippy { stage: 0 })` *builds* clippy with stage0, it doesn't use the beta clippy. + let cargo_clippy = self.initial_rustc.parent().unwrap().join("cargo-clippy"); + let mut cmd = Command::new(cargo_clippy); + cmd.env("PATH", &path); + return cmd; + } + + let build_compiler = self.compiler(run_compiler.stage - 1, self.build.build); + self.ensure(tool::Clippy { + compiler: build_compiler, + target: self.build.build, + extra_features: vec![], + }); + let cargo_clippy = self.ensure(tool::CargoClippy { + compiler: build_compiler, + target: self.build.build, + extra_features: vec![], + }); + let mut dylib_path = dylib_path(); + let run_compiler = self.compiler(build_compiler.stage + 1, self.build.build); + dylib_path.insert(0, self.sysroot(run_compiler).join("lib")); + + let mut cmd = Command::new(cargo_clippy.unwrap()); + cmd.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap()); + cmd.env("PATH", path); + cmd + } + pub fn rustdoc_cmd(&self, compiler: Compiler) -> Command { let mut cmd = Command::new(&self.bootstrap_out.join("rustdoc")); cmd.env("RUSTC_STAGE", compiler.stage.to_string()) @@ -1171,7 +1211,12 @@ impl<'a> Builder<'a> { target: TargetSelection, cmd: &str, ) -> Command { - let mut cargo = Command::new(&self.initial_cargo); + let mut cargo = if cmd == "clippy" { + self.cargo_clippy_cmd(compiler) + } else { + Command::new(&self.initial_cargo) + }; + // Run cargo from the source root so it can find .cargo/config. // This matters when using vendoring and the working directory is outside the repository. cargo.current_dir(&self.src); @@ -1293,6 +1338,24 @@ impl<'a> Builder<'a> { compiler.stage }; + // We synthetically interpret a stage0 compiler used to build tools as a + // "raw" compiler in that it's the exact snapshot we download. Normally + // the stage0 build means it uses libraries build by the stage0 + // compiler, but for tools we just use the precompiled libraries that + // we've downloaded + let use_snapshot = mode == Mode::ToolBootstrap; + assert!(!use_snapshot || stage == 0 || self.local_rebuild); + + let maybe_sysroot = self.sysroot(compiler); + let sysroot = if use_snapshot { self.rustc_snapshot_sysroot() } else { &maybe_sysroot }; + let libdir = self.rustc_libdir(compiler); + + let sysroot_str = sysroot.as_os_str().to_str().expect("sysroot should be UTF-8"); + if !matches!(self.config.dry_run, DryRun::SelfCheck) { + self.verbose_than(0, &format!("using sysroot {sysroot_str}")); + self.verbose_than(1, &format!("running cargo with mode {mode:?}")); + } + let mut rustflags = Rustflags::new(target); if stage != 0 { if let Ok(s) = env::var("CARGOFLAGS_NOT_BOOTSTRAP") { @@ -1304,41 +1367,18 @@ impl<'a> Builder<'a> { cargo.args(s.split_whitespace()); } rustflags.env("RUSTFLAGS_BOOTSTRAP"); - if cmd == "clippy" { - // clippy overwrites sysroot if we pass it to cargo. - // Pass it directly to clippy 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(|_| ()); - let output = host_version.and_then(|output| { - if output.status.success() { - Ok(output) - } else { - Err(()) - } - }).unwrap_or_else(|_| { - eprintln!( - "error: `x.py clippy` requires a host `rustc` toolchain with the `clippy` component" - ); - eprintln!("help: try `rustup component add clippy`"); - crate::detail_exit_macro!(1); - }); - if !t!(std::str::from_utf8(&output.stdout)).contains("nightly") { - rustflags.arg("--cfg=bootstrap"); - } - } else { - rustflags.arg("--cfg=bootstrap"); - } + rustflags.arg("--cfg=bootstrap"); + } + + if cmd == "clippy" { + // clippy overwrites sysroot if we pass it to cargo. + // Pass it directly to clippy 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(sysroot_str); + // Only run clippy on a very limited subset of crates (in particular, not build scripts). + cargo.arg("-Zunstable-options"); } let use_new_symbol_mangling = match self.config.rust_new_symbol_mangling { @@ -1520,18 +1560,6 @@ impl<'a> Builder<'a> { let want_rustdoc = self.doc_tests != DocTests::No; - // We synthetically interpret a stage0 compiler used to build tools as a - // "raw" compiler in that it's the exact snapshot we download. Normally - // the stage0 build means it uses libraries build by the stage0 - // compiler, but for tools we just use the precompiled libraries that - // we've downloaded - let use_snapshot = mode == Mode::ToolBootstrap; - assert!(!use_snapshot || stage == 0 || self.local_rebuild); - - let maybe_sysroot = self.sysroot(compiler); - let sysroot = if use_snapshot { self.rustc_snapshot_sysroot() } else { &maybe_sysroot }; - let libdir = self.rustc_libdir(compiler); - // Clear the output directory if the real rustc we're using has changed; // Cargo cannot detect this as it thinks rustc is bootstrap/debug/rustc. // @@ -1544,6 +1572,28 @@ impl<'a> Builder<'a> { self.clear_if_dirty(&out_dir, &self.rustc(compiler)); } + // // Cargo doesn't pass `--sysroot` for build scripts and proc-macros, which is exactly when we want to use a different sysroot. + // if + + if cmd == "clippy" { + let build_script_sysroot = if stage != 0 { + // Our fake rustc shim passes `-Zmark-unstable-if-unmarked` for stage != 0, which we can't + // replicate because clippy doesn't normally run the shim. We should talk with the clippy + // team about whether there's a way to do this; maybe cargo-clippy can invoke the shim + // which invokes clippy-driver? + cargo.env("RUSTC_CLIPPY_IGNORE_BUILD_SCRIPTS_AND_PROC_MACROS", "1"); + self.initial_rustc.ancestors().nth(2).unwrap() + } else { + sysroot.clone() + }; + // HACK: clippy will pass `--sysroot` to `RunCompiler` if and only if SYSROOT is set and + // `--sysroot is not already passed. We bypass clippy-driver altogether in stage 1 + // because there's no way to set `-Zforce-unstable-if-unmarked` for only the correct + // crates, but for stage 0 build scripts and proc-macros we want to still set the right + // sysroot. + cargo.env("SYSROOT", build_script_sysroot); + } + // Customize the compiler we're running. Specify the compiler to cargo // as our shim and then pass it some various options used to configure // how the actual compiler itself is called. @@ -1554,6 +1604,7 @@ impl<'a> Builder<'a> { .env("RUSTBUILD_NATIVE_DIR", self.native_dir(target)) .env("RUSTC_REAL", self.rustc(compiler)) .env("RUSTC_STAGE", stage.to_string()) + .env("RUSTC_COMMAND", cmd) .env("RUSTC_SYSROOT", &sysroot) .env("RUSTC_LIBDIR", &libdir) .env("RUSTDOC", self.bootstrap_out.join("rustdoc")) @@ -1567,11 +1618,8 @@ 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.bootstrap_out.join("rustc")); - } + + cargo.env("RUSTC", self.bootstrap_out.join("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 diff --git a/src/ci/docker/host-x86_64/x86_64-gnu-llvm-16/Dockerfile b/src/ci/docker/host-x86_64/x86_64-gnu-llvm-16/Dockerfile index 7c75d0df59083..ce844c85f065b 100644 --- a/src/ci/docker/host-x86_64/x86_64-gnu-llvm-16/Dockerfile +++ b/src/ci/docker/host-x86_64/x86_64-gnu-llvm-16/Dockerfile @@ -61,4 +61,6 @@ ENV SCRIPT ../x.py --stage 2 test --exclude src/tools/tidy && \ # work. # ../x.ps1 --stage 2 test tests/ui --pass=check \ - --host='' --target=i686-unknown-linux-gnu + --host='' --target=i686-unknown-linux-gnu && \ + # Run clippy just to make sure it doesn't error out; we don't actually want to gate on the warnings though. + python3 ../x.py --stage 1 clippy -Awarnings diff --git a/src/stage0.json b/src/stage0.json index 89ad4e0a649c1..7e7ec0352aadf 100644 --- a/src/stage0.json +++ b/src/stage0.json @@ -81,6 +81,62 @@ "dist/2023-05-30/cargo-beta-x86_64-unknown-linux-musl.tar.xz": "faeb090c8e1d15b20c256eb7b326de2375812ffc7984e8c11e28a0add3fddec5", "dist/2023-05-30/cargo-beta-x86_64-unknown-netbsd.tar.gz": "adc9720e065861ff8aeeec8ffdc231161755e603301521982f6ef405d2d12c95", "dist/2023-05-30/cargo-beta-x86_64-unknown-netbsd.tar.xz": "2def53546856b6cce7ddfce00329fe05be0f649f0b8421168fbab85d9c23715d", + "dist/2023-05-30/clippy-beta-aarch64-apple-darwin.tar.gz": "6e923d0166838827b09254e5fd727eb6bae8d4c882c042d75df5740bdae5ff68", + "dist/2023-05-30/clippy-beta-aarch64-apple-darwin.tar.xz": "fa45cfadc75c2f7ad31571a08e7b2da8e2fd6592fed9c7efe5cfc87167dbe32a", + "dist/2023-05-30/clippy-beta-aarch64-pc-windows-msvc.tar.gz": "9b56b7b244610ecb7b673dc863c4f585285da0a1f52beaafeefc1c5844553246", + "dist/2023-05-30/clippy-beta-aarch64-pc-windows-msvc.tar.xz": "045ed959ae34f6ec6ba35396a455eb14a7e7a10c7a2969c7d6b04d94ab1ea870", + "dist/2023-05-30/clippy-beta-aarch64-unknown-linux-gnu.tar.gz": "0b694443e76ca3e5b2c045c41a18bb467aad8334b60d15fb3709c31ec95f71a9", + "dist/2023-05-30/clippy-beta-aarch64-unknown-linux-gnu.tar.xz": "f8ce1b0a275d35980521231e52e214b7a1be3f33927ae64d0d2c3e27c58abeb3", + "dist/2023-05-30/clippy-beta-aarch64-unknown-linux-musl.tar.gz": "be01a22e843782b0519c92bc8f9780c0d7cbcb0b2daf1b0a3e699679f02fada6", + "dist/2023-05-30/clippy-beta-aarch64-unknown-linux-musl.tar.xz": "32a812ef87c11ea2b9f19a298bfa277133c267bd88746827e2941ad1ac787e0b", + "dist/2023-05-30/clippy-beta-arm-unknown-linux-gnueabi.tar.gz": "68bb8553bb9b77bdfa07a9ba5751e88598777b8af594dc7b95e973ba18b1d6b5", + "dist/2023-05-30/clippy-beta-arm-unknown-linux-gnueabi.tar.xz": "1a3a38879224acaa1039b92b34a7178b94aa9e6732bed4f819291dcdf9d104dc", + "dist/2023-05-30/clippy-beta-arm-unknown-linux-gnueabihf.tar.gz": "833812f15a704881834164a088a23d9cbab2ca2a38f84175cb4c7478b2e65809", + "dist/2023-05-30/clippy-beta-arm-unknown-linux-gnueabihf.tar.xz": "3df6c49a77ef6ba407e7704e9b54e00a2dca2f21b70a1142d91d6e7a33f5f5ba", + "dist/2023-05-30/clippy-beta-armv7-unknown-linux-gnueabihf.tar.gz": "8dc7c2222a008e60b00814b2958775b4fc3bee34bc614ef495ed9401de64a991", + "dist/2023-05-30/clippy-beta-armv7-unknown-linux-gnueabihf.tar.xz": "3d168e1599b1e54db3eada507a7445fff24887e4bf740f3671c0da1d61cdcd0b", + "dist/2023-05-30/clippy-beta-i686-pc-windows-gnu.tar.gz": "803df162e50d7601541336042ee74d4de87cb368d7fb9707b53b0cbf4e7e87c8", + "dist/2023-05-30/clippy-beta-i686-pc-windows-gnu.tar.xz": "c54433ac9f028622136553bd3330204bbeeae91f812aa71f2ca947a52643a723", + "dist/2023-05-30/clippy-beta-i686-pc-windows-msvc.tar.gz": "585fa3e81bed4538f4ba4670ae76d0c85f14e7b09efcff89517fe263e2fa5172", + "dist/2023-05-30/clippy-beta-i686-pc-windows-msvc.tar.xz": "3b9966f43546304805d1bb6c4a06de8633f068b607839caa0dc7f1cf488041d3", + "dist/2023-05-30/clippy-beta-i686-unknown-linux-gnu.tar.gz": "4b54e2462a08715c0a0e812834f21637a8d7ecc4487a134db39a4d0fc08b32cf", + "dist/2023-05-30/clippy-beta-i686-unknown-linux-gnu.tar.xz": "72b4cf91fb35bf17274d5d41b1aaf58675f27c0ba2941fac8c28590e538d4a89", + "dist/2023-05-30/clippy-beta-loongarch64-unknown-linux-gnu.tar.gz": "b404a5d2529d49eebe1777ac82bc1079135854207d54e993221b50cd35405327", + "dist/2023-05-30/clippy-beta-loongarch64-unknown-linux-gnu.tar.xz": "076c5d5764998153b3af6813db2c4233ac94f7b9712657ff3288422d45c52bf8", + "dist/2023-05-30/clippy-beta-mips-unknown-linux-gnu.tar.gz": "3feeb775ac8a17d5c9bc540e6063d297c611911dc3455e4c960e33dfaa8fd387", + "dist/2023-05-30/clippy-beta-mips-unknown-linux-gnu.tar.xz": "01658242f87aa214deb313e4cb2ecf521b638127e365eafa00035d2402d89eca", + "dist/2023-05-30/clippy-beta-mips64-unknown-linux-gnuabi64.tar.gz": "e3150b1872d445c6886b0246b5fce1c6b134a0c6e00ebb4e3b6d337f98fde344", + "dist/2023-05-30/clippy-beta-mips64-unknown-linux-gnuabi64.tar.xz": "e1222042aa7908099130b6d7101c8ae296352dfa6713ce2d33c2564c5bc754b9", + "dist/2023-05-30/clippy-beta-mips64el-unknown-linux-gnuabi64.tar.gz": "262827f76d8bf5f68e6a6e584071c40fafa4d2f81f8a58e4ca27776dbf28062c", + "dist/2023-05-30/clippy-beta-mips64el-unknown-linux-gnuabi64.tar.xz": "11e83f6d244b0084e709269f4ed6385371bae86010b358e42f536a306435775d", + "dist/2023-05-30/clippy-beta-mipsel-unknown-linux-gnu.tar.gz": "0766d6b3a996642b7115ce070e0b2f852e76e9c2539c3dcf65e82068ec5eb582", + "dist/2023-05-30/clippy-beta-mipsel-unknown-linux-gnu.tar.xz": "916558cac4c28d5b3b9e97a78ead099dcf747425de72087449950fbfe780eb16", + "dist/2023-05-30/clippy-beta-powerpc-unknown-linux-gnu.tar.gz": "e7d997df351a5c52727bef86b0fa20401ac7e36a390fb1405f1341435bcb5d93", + "dist/2023-05-30/clippy-beta-powerpc-unknown-linux-gnu.tar.xz": "8740fbe62a5e5177098f211adc68529930f05363e69cb583102458702ad718f3", + "dist/2023-05-30/clippy-beta-powerpc64-unknown-linux-gnu.tar.gz": "16ac52319fef5e978689c265fa1759aafa0b6a025aff683a8b3e0e37b91e6415", + "dist/2023-05-30/clippy-beta-powerpc64-unknown-linux-gnu.tar.xz": "ef263b330f20b1ece1391f71ecccc4e372af68b2e712259e550c0b202705e00e", + "dist/2023-05-30/clippy-beta-powerpc64le-unknown-linux-gnu.tar.gz": "2d1d6d9ef349fd4f1692de010d40ad7fa4ad2bcd60e084d7cdf81f3b09ed6d2a", + "dist/2023-05-30/clippy-beta-powerpc64le-unknown-linux-gnu.tar.xz": "4553d9a106bdeddc105ca1a808980ef6043d63e02544a9a37ce1c21a3dce4d48", + "dist/2023-05-30/clippy-beta-riscv64gc-unknown-linux-gnu.tar.gz": "2aa7a9501ba479535106782c76618302fd88f3e4733760126cce941ddfe20b83", + "dist/2023-05-30/clippy-beta-riscv64gc-unknown-linux-gnu.tar.xz": "35cc4dd1623e262a93e7c7a9944cc61dc8b28829c989b494d7b619a1aaa1817c", + "dist/2023-05-30/clippy-beta-s390x-unknown-linux-gnu.tar.gz": "0d2ab43ebcf42c32bf15e0d5445914eeaad90d479540c31cb57db66333f63777", + "dist/2023-05-30/clippy-beta-s390x-unknown-linux-gnu.tar.xz": "8eaf8980bb2782bc11f5a243719b864c3906dba6e49899f7aec08ced6b09db38", + "dist/2023-05-30/clippy-beta-x86_64-apple-darwin.tar.gz": "d91cab3e02a45fced5701506b4c7f49bd77f13d56681fbb92693cdb52d0f6ebf", + "dist/2023-05-30/clippy-beta-x86_64-apple-darwin.tar.xz": "c1ecd2317fe3f35c0e8a4534bd5d94ca85714bcff42f673ebdc4669292a0b0e1", + "dist/2023-05-30/clippy-beta-x86_64-pc-windows-gnu.tar.gz": "186bf9a5caddd5769cd5268d9b88677498b290d5437c9e081188e0afb9615f3e", + "dist/2023-05-30/clippy-beta-x86_64-pc-windows-gnu.tar.xz": "6ea811ecc57ae2316edb13deaae939126349d64dc4059cd28ff57f16985545bd", + "dist/2023-05-30/clippy-beta-x86_64-pc-windows-msvc.tar.gz": "d7b895a29da9aa6ba002175161c1f44edd0eff3f1522f4b9b161027876152e52", + "dist/2023-05-30/clippy-beta-x86_64-pc-windows-msvc.tar.xz": "e58de763e6036dca5471077f47c1934366526dface3b4845ed0faad76400792a", + "dist/2023-05-30/clippy-beta-x86_64-unknown-freebsd.tar.gz": "832dfadfc0d9300dba9a8143509527aaa678377afd6bd13a70a8cf6e7a8cdb03", + "dist/2023-05-30/clippy-beta-x86_64-unknown-freebsd.tar.xz": "634bc0454d8abdbbd7e128e634e44787b5a8bbde25ebd172bdbcbdb3e66f10c9", + "dist/2023-05-30/clippy-beta-x86_64-unknown-illumos.tar.gz": "69a0a0455a678a27fbfa8f6c7abf172cb6527b879c96f7e930476f3e11317ab5", + "dist/2023-05-30/clippy-beta-x86_64-unknown-illumos.tar.xz": "f6ff43c242e3b769bdfa17fbb01fac02d512179680ccaac8828576e8a82e2007", + "dist/2023-05-30/clippy-beta-x86_64-unknown-linux-gnu.tar.gz": "da13ee4a5627995638407be682878af01a740c4d99f8e455a077cb4e6439915b", + "dist/2023-05-30/clippy-beta-x86_64-unknown-linux-gnu.tar.xz": "257f474eeb5076d00127ba230a581130946efa3d380462bb32536f9959911cf1", + "dist/2023-05-30/clippy-beta-x86_64-unknown-linux-musl.tar.gz": "ac6545927f0b4749ce2bd9b1ad87f97687644a204d0518566cc63ff57a0b22f8", + "dist/2023-05-30/clippy-beta-x86_64-unknown-linux-musl.tar.xz": "d7157dfcbb624dbe13c6fb9f6ccebbeedbda96f2e9e30250e42a08f76c24797e", + "dist/2023-05-30/clippy-beta-x86_64-unknown-netbsd.tar.gz": "b3b4fbb9e6296d3959e99ebb3f42eaef1ac6001d3201fc164790b5908d400902", + "dist/2023-05-30/clippy-beta-x86_64-unknown-netbsd.tar.xz": "de76762af49a6174c5f6aeda3df2ea15472fc6b7c650dfb33f555fc9a83cdc27", "dist/2023-05-30/rust-std-beta-aarch64-apple-darwin.tar.gz": "ebd92098d173efea06a3e2d2edec299483fc77925427417e182800567ff6d642", "dist/2023-05-30/rust-std-beta-aarch64-apple-darwin.tar.xz": "028c6269d40f8adf897b5e6b61387ce49cb1c2c82244965d48efa68ca71d74e1", "dist/2023-05-30/rust-std-beta-aarch64-apple-ios-sim.tar.gz": "ea5654c6a23488e56c0b1c8c8c655c449bcadc9c3676db9ff37ef3fe742c4f9e", diff --git a/src/tools/bump-stage0/src/main.rs b/src/tools/bump-stage0/src/main.rs index b007f9a22c36f..bd97b4eaa3e4d 100644 --- a/src/tools/bump-stage0/src/main.rs +++ b/src/tools/bump-stage0/src/main.rs @@ -4,7 +4,7 @@ use indexmap::IndexMap; use std::collections::HashMap; const PATH: &str = "src/stage0.json"; -const COMPILER_COMPONENTS: &[&str] = &["rustc", "rust-std", "cargo"]; +const COMPILER_COMPONENTS: &[&str] = &["rustc", "rust-std", "cargo", "clippy-preview"]; const RUSTFMT_COMPONENTS: &[&str] = &["rustfmt-preview", "rustc"]; struct Tool { diff --git a/src/tools/clippy/src/driver.rs b/src/tools/clippy/src/driver.rs index 3c5b6e12b9688..384c35b3b5b9e 100644 --- a/src/tools/clippy/src/driver.rs +++ b/src/tools/clippy/src/driver.rs @@ -22,7 +22,7 @@ use rustc_span::symbol::Symbol; use std::env; use std::ops::Deref; use std::path::Path; -use std::process::exit; +use std::process::{Command, exit}; /// If a command-line option matches `find_arg`, then apply the predicate `pred` on its value. If /// true, then return it. The parameter is assumed to be either `--arg=value` or `--arg value`. @@ -233,10 +233,12 @@ pub fn main() { // We're invoking the compiler programmatically, so we ignore this/ let wrapper_mode = orig_args.get(1).map(Path::new).and_then(Path::file_stem) == Some("rustc".as_ref()); - if wrapper_mode { - // we still want to be able to invoke it normally though - orig_args.remove(1); - } + // we still want to be able to invoke it normally though + let orig_rustc_cmd = if wrapper_mode { + Some(orig_args.remove(1)) + } else { + None + }; if !wrapper_mode && (orig_args.iter().any(|a| a == "--help" || a == "-h") || orig_args.len() == 1) { display_help(); @@ -244,6 +246,23 @@ pub fn main() { } let mut args: Vec = orig_args.clone(); + + let is_build_script = arg_value(&orig_args, "--crate-name", |val| val == "build_script_build").is_some(); + let is_proc_macro = arg_value(&orig_args, "--crate-type", |val| val == "proc-macro").is_some(); + let ignore_crate_completely = (is_build_script || is_proc_macro) && env::var("RUSTC_CLIPPY_IGNORE_BUILD_SCRIPTS_AND_PROC_MACROS").map_or(false, |x| x == "1"); + + // This is a more extreme version of `clippy_enabled`: it launches the original `rustc` + // command (which may be a `RUSTC` wrapper, not rustc itself) rather than running + // clippy-driver. + if ignore_crate_completely { + if let Some(orig_cmd) = orig_rustc_cmd { + // Respect RUSTC shim. + args.remove(0); + let status = Command::new(orig_cmd).args(args).status(); + exit(status.ok().and_then(|status| status.code()).unwrap_or(1)); + } + } + pass_sysroot_env_if_given(&mut args, sys_root_env); let mut no_deps = false;