Check $CARGO before $PATH

This commit is contained in:
Jubilee Young 2023-12-09 14:07:25 -08:00
parent 1c8cbe79ab
commit 9083b52122
5 changed files with 15 additions and 11 deletions

View File

@ -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<Item = &'a String>) {
let is_file = match fs::metadata(path) {
@ -13,7 +13,7 @@ pub fn run<'a>(path: &str, args: impl Iterator<Item = &'a String>) {
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<Item = &'a String>) {
.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")

View File

@ -2,8 +2,8 @@ use std::ffi::OsStr;
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()

View File

@ -28,12 +28,12 @@ use rustc_span::{sym, Loc, Span, Symbol};
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")

View File

@ -367,7 +367,7 @@ impl Crate {
//
// 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 @@ impl Crate {
/// 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();

View File

@ -105,7 +105,7 @@ impl ClippyCmd {
}
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()