From 9083b52122a2b57f0cfefa98e64846c110ade933 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Sat, 9 Dec 2023 14:07:25 -0800 Subject: [PATCH] Check $CARGO before $PATH --- clippy_dev/src/lint.rs | 10 +++++++--- clippy_dev/src/serve.rs | 4 ++-- .../src/utils/internal_lints/metadata_collector.rs | 4 ++-- lintcheck/src/main.rs | 6 +++--- src/main.rs | 2 +- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/clippy_dev/src/lint.rs b/clippy_dev/src/lint.rs index a19be1bca6c..906a9727810 100644 --- a/clippy_dev/src/lint.rs +++ b/clippy_dev/src/lint.rs @@ -1,6 +1,6 @@ use crate::{cargo_clippy_path, exit_if_err}; -use std::fs; use std::process::{self, Command}; +use std::{env, fs}; pub fn run<'a>(path: &str, args: impl Iterator) { let is_file = match fs::metadata(path) { @@ -13,7 +13,7 @@ pub fn run<'a>(path: &str, args: impl Iterator) { if is_file { exit_if_err( - Command::new("cargo") + Command::new(env::var("CARGO").unwrap_or("cargo".into())) .args(["run", "--bin", "clippy-driver", "--"]) .args(["-L", "./target/debug"]) .args(["-Z", "no-codegen"]) @@ -23,7 +23,11 @@ pub fn run<'a>(path: &str, args: impl Iterator) { .status(), ); } else { - exit_if_err(Command::new("cargo").arg("build").status()); + exit_if_err( + Command::new(env::var("CARGO").unwrap_or("cargo".into())) + .arg("build") + .status(), + ); let status = Command::new(cargo_clippy_path()) .arg("clippy") diff --git a/clippy_dev/src/serve.rs b/clippy_dev/src/serve.rs index 535c25e69f1..ea925f6709f 100644 --- a/clippy_dev/src/serve.rs +++ b/clippy_dev/src/serve.rs @@ -2,8 +2,8 @@ use std::num::ParseIntError; use std::path::Path; use std::process::Command; -use std::thread; use std::time::{Duration, SystemTime}; +use std::{env, thread}; /// # Panics /// @@ -16,7 +16,7 @@ pub fn run(port: u16, lint: Option<&String>) -> ! { loop { if mtime("util/gh-pages/lints.json") < mtime("clippy_lints/src") { - Command::new("cargo") + Command::new(env::var("CARGO").unwrap_or("cargo".into())) .arg("collect-metadata") .spawn() .unwrap() diff --git a/clippy_lints/src/utils/internal_lints/metadata_collector.rs b/clippy_lints/src/utils/internal_lints/metadata_collector.rs index 373b076f92c..fae1b90ace2 100644 --- a/clippy_lints/src/utils/internal_lints/metadata_collector.rs +++ b/clippy_lints/src/utils/internal_lints/metadata_collector.rs @@ -28,12 +28,12 @@ use serde::ser::SerializeStruct; use serde::{Serialize, Serializer}; use std::collections::{BTreeSet, BinaryHeap}; -use std::fmt; use std::fmt::Write as _; use std::fs::{self, File}; use std::io::prelude::*; use std::path::{Path, PathBuf}; use std::process::Command; +use std::{env, fmt}; /// This is the json output file of the lint collector. const JSON_OUTPUT_FILE: &str = "../util/gh-pages/lints.json"; @@ -415,7 +415,7 @@ fn get_lint_output(lint_name: &str, example: &[&mut String], clippy_project_root let prefixed_name = format!("{CLIPPY_LINT_GROUP_PREFIX}{lint_name}"); - let mut cmd = Command::new("cargo"); + let mut cmd = Command::new(env::var("CARGO").unwrap_or("cargo".into())); cmd.current_dir(clippy_project_root) .env("CARGO_INCREMENTAL", "0") diff --git a/lintcheck/src/main.rs b/lintcheck/src/main.rs index 841b605f5fb..88966b41f69 100644 --- a/lintcheck/src/main.rs +++ b/lintcheck/src/main.rs @@ -367,7 +367,7 @@ fn run_clippy_lints( // // The wrapper is set to the `lintcheck` so we can force enable linting and ignore certain crates // (see `crate::driver`) - let status = Command::new("cargo") + let status = Command::new(env::var("CARGO").unwrap_or("cargo".into())) .arg("check") .arg("--quiet") .current_dir(&self.path) @@ -441,7 +441,7 @@ fn run_clippy_lints( /// Builds clippy inside the repo to make sure we have a clippy executable we can use. fn build_clippy() { - let status = Command::new("cargo") + let status = Command::new(env::var("CARGO").unwrap_or("cargo".into())) .arg("build") .status() .expect("Failed to build clippy!"); @@ -816,7 +816,7 @@ fn lintcheck_test() { "--crates-toml", "lintcheck/test_sources.toml", ]; - let status = std::process::Command::new("cargo") + let status = std::process::Command::new(env::var("CARGO").unwrap_or("cargo".into())) .args(args) .current_dir("..") // repo root .status(); diff --git a/src/main.rs b/src/main.rs index bbf7d22c850..dffa854177b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -105,7 +105,7 @@ fn path() -> PathBuf { } fn into_std_cmd(self) -> Command { - let mut cmd = Command::new("cargo"); + let mut cmd = Command::new(env::var("CARGO").unwrap_or("cargo".into())); let clippy_args: String = self .clippy_args .iter()