diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index 9611c866df599..117e13771ec2c 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").expect("RUSTC_STAGE was not set"); @@ -70,6 +81,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 @@ -142,6 +157,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); } @@ -215,6 +240,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 5b19a658fb543..87f678c060f1f 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -420,13 +420,14 @@ 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 self.program_out_of_date(self.rustc_stamp(), key)): if os.path.exists(bin_root): shutil.rmtree(bin_root) - tarball_suffix = '.tar.gz' if lzma is None else '.tar.xz' filename = "rust-std-{}-{}{}".format( rustc_channel, self.build, tarball_suffix) pattern = "rust-std-{}".format(self.build) @@ -451,6 +452,29 @@ def download_toolchain(self): with output(self.rustc_stamp()) as rust_stamp: rust_stamp.write(key) + clippy_path = self.clippy() + clippy_needs_download = not os.path.exists(clippy_path) \ + or self.program_out_of_date(self.clippy_stamp(), key) + if clippy_path.startswith(bin_root) and clippy_needs_download: + # download Clippy + # the component name is clippy, but the bin containing folder name is clippy-preview + filename = self._format_component_filename( + "clippy", + rustc_channel, + self.build, + tarball_suffix + ) + self._download_component_helper(filename, "clippy-preview", tarball_suffix) + if self.should_fix_bins_and_dylibs(): + self.fix_bin_or_dylib("{}/bin/clippy-driver".format(bin_root)) + self.fix_bin_or_dylib("{}/bin/cargo-clippy".format(bin_root)) + + with output(self.clippy_stamp()) as clippy_stamp: + clippy_stamp.write(key) + + def _format_component_filename(self, component_name, version, build, tarball_suffix): + return "{}-{}-{}{}".format(component_name, version, build, tarball_suffix) + def _download_component_helper( self, filename, pattern, tarball_suffix, ): @@ -592,6 +616,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: @@ -665,6 +700,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 b4fc1d4f28da7..8cb5c738c834e 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -12,7 +12,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; @@ -21,7 +21,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}; @@ -1061,6 +1063,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()) @@ -1114,7 +1154,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); @@ -1236,6 +1281,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") { @@ -1247,41 +1310,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(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 { @@ -1455,18 +1495,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. // @@ -1479,6 +1507,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. @@ -1489,6 +1539,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")) @@ -1502,11 +1553,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-13/Dockerfile b/src/ci/docker/host-x86_64/x86_64-gnu-llvm-13/Dockerfile index 9fc9e9cbffbed..5e32609348d9a 100644 --- a/src/ci/docker/host-x86_64/x86_64-gnu-llvm-13/Dockerfile +++ b/src/ci/docker/host-x86_64/x86_64-gnu-llvm-13/Dockerfile @@ -65,5 +65,7 @@ ENV SCRIPT ../x.py --stage 2 test --exclude src/tools/tidy && \ # ../x.ps1 --stage 2 test tests/ui --pass=check \ --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 && \ # Run tidy at the very end, after all the other tests. python2.7 ../x.py --stage 2 test src/tools/tidy diff --git a/src/stage0.json b/src/stage0.json index 46f70b1ef4b09..e437e32eaee2b 100644 --- a/src/stage0.json +++ b/src/stage0.json @@ -79,6 +79,60 @@ "dist/2023-01-25/cargo-beta-x86_64-unknown-linux-musl.tar.xz": "7a0817ef29d6511d4fd9dbbdf3e9a92635f076d9b0633cb55b325cebeee4efb9", "dist/2023-01-25/cargo-beta-x86_64-unknown-netbsd.tar.gz": "1330a1b4f975b1d96692bdc4a6392ca87e8e99982768acefc2815e386b6f4e77", "dist/2023-01-25/cargo-beta-x86_64-unknown-netbsd.tar.xz": "919e25bd54133f4a8cbbf09218415ca7a5041298b32181fa566c5d4a8bfd8b90", + "dist/2023-01-25/clippy-beta-aarch64-apple-darwin.tar.gz": "26afa71d7752a23c9d83c912a97760c6490d34d661e8522bf307e738bdd43773", + "dist/2023-01-25/clippy-beta-aarch64-apple-darwin.tar.xz": "1428bc56dfa7807c7948ef4e5da4b2ef244f1bd36ed134ce4ef3844949f66e10", + "dist/2023-01-25/clippy-beta-aarch64-pc-windows-msvc.tar.gz": "43363851e78eec783b86d348e1204b23bebb64b1580ad16babb048ff93359015", + "dist/2023-01-25/clippy-beta-aarch64-pc-windows-msvc.tar.xz": "f91e2fa34d7f533baf6f93a02c1ad4e2b00a0a9cedf049aba6b5e3c35939fd6b", + "dist/2023-01-25/clippy-beta-aarch64-unknown-linux-gnu.tar.gz": "f73ca0854c516af4e91dba82771a35f1015ffaf029d65cdb9e6c648962ab59ee", + "dist/2023-01-25/clippy-beta-aarch64-unknown-linux-gnu.tar.xz": "95286c31f21c6b18698616778ec27dbc392942f91f38c5c3fa7d4a6c3029a888", + "dist/2023-01-25/clippy-beta-aarch64-unknown-linux-musl.tar.gz": "61320dea5cda4f8bd4ec1f1b98f77dcfb9a0c3705687ec61a184e7c448f323bd", + "dist/2023-01-25/clippy-beta-aarch64-unknown-linux-musl.tar.xz": "dbba8139717ec0e1ee9045ebb176e56e36737dc2b1f37b6e444e566ab9ac4535", + "dist/2023-01-25/clippy-beta-arm-unknown-linux-gnueabi.tar.gz": "e0a3cbd4985865216a54eba4d84940a523d9ac97d186a9d9f6d31aee29e1d286", + "dist/2023-01-25/clippy-beta-arm-unknown-linux-gnueabi.tar.xz": "c1b71b5da218f36e8eb8bbdbd6485d32a578e1bba2a964ca171a5fb2d640644f", + "dist/2023-01-25/clippy-beta-arm-unknown-linux-gnueabihf.tar.gz": "19fe29206c8642f34baf072ff590cde5fb06ebbde6474b7a7838ed97a538025f", + "dist/2023-01-25/clippy-beta-arm-unknown-linux-gnueabihf.tar.xz": "19ccf699771065f8bb8bfef6a7ecff026800c38bce02af8bd2d3cbad07e57bce", + "dist/2023-01-25/clippy-beta-armv7-unknown-linux-gnueabihf.tar.gz": "812a5cb6f08e671d51103abe6f2000033a5cb81ea31d1522ba9b459ded005bec", + "dist/2023-01-25/clippy-beta-armv7-unknown-linux-gnueabihf.tar.xz": "3f2d80d457f8f1a74c0c3a2317320ec2c1eca48e0e36ac4984a15499c8b66623", + "dist/2023-01-25/clippy-beta-i686-pc-windows-gnu.tar.gz": "e4ee1994580cdb7c2906d01aaa6e457a9d7a86717dac05c35abbb4b326281b1b", + "dist/2023-01-25/clippy-beta-i686-pc-windows-gnu.tar.xz": "fce3737d8557adf8b7315907765afaa85a9ed640be1e299929379f9553293045", + "dist/2023-01-25/clippy-beta-i686-pc-windows-msvc.tar.gz": "acc56c203523b9b84bff01291c57978dcc236b95d9a1e1ff18b8243a6e7e4671", + "dist/2023-01-25/clippy-beta-i686-pc-windows-msvc.tar.xz": "fcd75f7242cfd434e87b51932d5e18d05ea06e3e632ebb50622974491d67a051", + "dist/2023-01-25/clippy-beta-i686-unknown-linux-gnu.tar.gz": "5acf0dc45c33ab363a61ed0230f4574017ce6407f363a11084ff365379d9981f", + "dist/2023-01-25/clippy-beta-i686-unknown-linux-gnu.tar.xz": "93fd2bc566d49bdd924257de544b664fe136a8189abbd3a37318c9b9386c117d", + "dist/2023-01-25/clippy-beta-mips-unknown-linux-gnu.tar.gz": "fa490ce473c06f5d93863e77382f35f151d54e50823e1c44f86e52e0d7ed1653", + "dist/2023-01-25/clippy-beta-mips-unknown-linux-gnu.tar.xz": "708976de6ec640b6270a38dfa42ce1a08e539cab05621139904fff188407363b", + "dist/2023-01-25/clippy-beta-mips64-unknown-linux-gnuabi64.tar.gz": "9e343ed25f22da59ddcf4f611c6e7ebd35305c1577dbf08156fc825b7bf645b4", + "dist/2023-01-25/clippy-beta-mips64-unknown-linux-gnuabi64.tar.xz": "bce724a0757da8b733d1fa4297e7fe894c3e48d697e480271f3b55eec0e1816d", + "dist/2023-01-25/clippy-beta-mips64el-unknown-linux-gnuabi64.tar.gz": "51f0a39d8375cd4fe5eaa0ad643a91bccf33b4a2712c30289c398d84b8ccc6c0", + "dist/2023-01-25/clippy-beta-mips64el-unknown-linux-gnuabi64.tar.xz": "3cab00b985c10d7d0b91da808642941b2c331731e2a0095181d41c74343fa56d", + "dist/2023-01-25/clippy-beta-mipsel-unknown-linux-gnu.tar.gz": "58acbe3e8afb34ccbfe4c0bde8bf72a1572440aa92f63adf16c69f455e549356", + "dist/2023-01-25/clippy-beta-mipsel-unknown-linux-gnu.tar.xz": "25e52a93798e09c5ac43ecf408087ae8675ec9fe15c4fbf7a6cd155b1a444cfa", + "dist/2023-01-25/clippy-beta-powerpc-unknown-linux-gnu.tar.gz": "ec1109b1ce59d2453b598fa1f3ea5bcdb45da63c07b409aafa839390a194267b", + "dist/2023-01-25/clippy-beta-powerpc-unknown-linux-gnu.tar.xz": "782359b09ab5222aceadcebc1d9944ff6512cb2c49472ddbe3c06db75c34e90e", + "dist/2023-01-25/clippy-beta-powerpc64-unknown-linux-gnu.tar.gz": "570798394dbef1db5b216c44cdb778456532dc7d367d2cd9858ca347cc2a92cf", + "dist/2023-01-25/clippy-beta-powerpc64-unknown-linux-gnu.tar.xz": "c34c8987b2491997a7ab05ff74812b169f5575df69ab17ec0452c8ad7cd7879c", + "dist/2023-01-25/clippy-beta-powerpc64le-unknown-linux-gnu.tar.gz": "bafed8773fe17733800886fc6f7e0a07930df7889c0ddf49bd150534afb64c10", + "dist/2023-01-25/clippy-beta-powerpc64le-unknown-linux-gnu.tar.xz": "e4ffbac68a869496d8e95d5c3eceaae063a8b03809852441e09f38170b6f9218", + "dist/2023-01-25/clippy-beta-riscv64gc-unknown-linux-gnu.tar.gz": "cd87edfc9152d0512d1631898391520725cfd7ace9ea32da7f1223182830026c", + "dist/2023-01-25/clippy-beta-riscv64gc-unknown-linux-gnu.tar.xz": "0820f2ddec262fff4c1ee27177d7b9a0100303235dea4aa11cb98505c829db37", + "dist/2023-01-25/clippy-beta-s390x-unknown-linux-gnu.tar.gz": "e74a9620aea2212b9768c7809f5386b1c603921ec12dfa2bc4c016b716d37823", + "dist/2023-01-25/clippy-beta-s390x-unknown-linux-gnu.tar.xz": "51003f959974ec3284eadd94fd19a09e9450d10483444e51958892e7557924d1", + "dist/2023-01-25/clippy-beta-x86_64-apple-darwin.tar.gz": "0012cdc61872dd1a987df1a4f9b253e0f5303d92ea1c8e67c016f35922e9a48d", + "dist/2023-01-25/clippy-beta-x86_64-apple-darwin.tar.xz": "f4f631e8886c70ef5a39cde2b1b69db50b9cd749e3f167282c874fc1af6999bd", + "dist/2023-01-25/clippy-beta-x86_64-pc-windows-gnu.tar.gz": "fd782d790be199a6f3706f610fa4e7e5832cc04a229cc98b37593276c25eba7d", + "dist/2023-01-25/clippy-beta-x86_64-pc-windows-gnu.tar.xz": "680e592f0c62171e1c8c7c225bdfc9e8227638151616ca87e28ed3f0ba5622c3", + "dist/2023-01-25/clippy-beta-x86_64-pc-windows-msvc.tar.gz": "1c725bd3fb9c9c5f4b1b5aa3db0b02eb4f4685327763c637c01cd264cdd60e46", + "dist/2023-01-25/clippy-beta-x86_64-pc-windows-msvc.tar.xz": "a401370ad139d01849afb7777e04be21d2f6460584a0f6b0d91e510a55837be2", + "dist/2023-01-25/clippy-beta-x86_64-unknown-freebsd.tar.gz": "988834513feab7eea5b75ca9cef78c3dfb8a067afcdcdf4974a89617b25fe83c", + "dist/2023-01-25/clippy-beta-x86_64-unknown-freebsd.tar.xz": "152c8c99074771e8b2b405a6ea0e1b365c74e0292993b776c18ed5e498d795dd", + "dist/2023-01-25/clippy-beta-x86_64-unknown-illumos.tar.gz": "caaea3f48bf1dc5ee27e05ec81daed4d9ded7da913d9f4bd9fbb67fb5319e14d", + "dist/2023-01-25/clippy-beta-x86_64-unknown-illumos.tar.xz": "74eccd731e9155e092ddc0050f912c1abffc0a91e4bb62fbd97ffac9a07fa36c", + "dist/2023-01-25/clippy-beta-x86_64-unknown-linux-gnu.tar.gz": "18fca11bb897b3c98b8dbdb6c8731e4a8fded61c495d527c26acfa0e33e8dcf9", + "dist/2023-01-25/clippy-beta-x86_64-unknown-linux-gnu.tar.xz": "fe60622697a5929372250dbc006fba95162062ae456e60e2daaa0321ca8e9458", + "dist/2023-01-25/clippy-beta-x86_64-unknown-linux-musl.tar.gz": "e0da52b3c49ec0c86220b7754379edc303c98bb8f28d352cf217b005e2257c9c", + "dist/2023-01-25/clippy-beta-x86_64-unknown-linux-musl.tar.xz": "ee8dd05052e10246a462cec879825e10ed69b5ba1d03a38c4158e653384360e4", + "dist/2023-01-25/clippy-beta-x86_64-unknown-netbsd.tar.gz": "d14ccb0bbe0b90cb1c27fda867d8a764d54df526cdf05857d833c4ecfe2e07a4", + "dist/2023-01-25/clippy-beta-x86_64-unknown-netbsd.tar.xz": "d71ceb68d69a1164159481ef74d672d1ae678553649b873fb229cef88772cab6", "dist/2023-01-25/rust-std-beta-aarch64-apple-darwin.tar.gz": "3dcf5c58141e44d1c84f33f58ca4dd99edd277ef15a69fc6b94fbe7c67a27483", "dist/2023-01-25/rust-std-beta-aarch64-apple-darwin.tar.xz": "a651af6487e2f3246075b984fffb4072338a559ff8e6c373289a6242c0ca3ea7", "dist/2023-01-25/rust-std-beta-aarch64-apple-ios-sim.tar.gz": "5e3d5aa50784ee63c6df03b07ac92649f76c40ac6fb49c24d97896814002697c", diff --git a/src/tools/bump-stage0/src/main.rs b/src/tools/bump-stage0/src/main.rs index f530a4d73d360..7813050fe597f 100644 --- a/src/tools/bump-stage0/src/main.rs +++ b/src/tools/bump-stage0/src/main.rs @@ -5,7 +5,7 @@ use std::collections::HashMap; use std::convert::TryInto; 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 d521e8d883983..17631fa752da7 100644 --- a/src/tools/clippy/src/driver.rs +++ b/src/tools/clippy/src/driver.rs @@ -25,7 +25,7 @@ use std::env; use std::ops::Deref; use std::panic; use std::path::Path; -use std::process::exit; +use std::process::{Command, exit}; use std::sync::LazyLock; /// If a command-line option matches `find_arg`, then apply the predicate `pred` on its value. If @@ -290,10 +290,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(); @@ -301,6 +303,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;