Remove use of Rustc from cargo-test-support.

cargo-test-support wasn't using any of the caching or other logic from
Rustc, so this just swaps with a very basic implementation in order to
remove the dependency on `cargo`.
This commit is contained in:
Eric Huss 2021-03-20 14:31:09 -07:00
parent 4aa1ec2419
commit 10224938bf

View File

@ -15,7 +15,7 @@ use std::process::{Command, Output};
use std::str; use std::str;
use std::time::{self, Duration}; use std::time::{self, Duration};
use cargo::util::{CargoResult, Rustc}; use cargo::util::CargoResult;
use cargo_util::{is_ci, ProcessBuilder, ProcessError}; use cargo_util::{is_ci, ProcessBuilder, ProcessError};
use serde_json::{self, Value}; use serde_json::{self, Value};
use url::Url; use url::Url;
@ -1549,25 +1549,44 @@ fn substitute_macros(input: &str) -> String {
pub mod install; pub mod install;
thread_local!( struct RustcInfo {
pub static RUSTC: Rustc = Rustc::new( verbose_version: String,
PathBuf::from("rustc"), host: String,
None, }
None,
Path::new("should be path to rustup rustc, but we don't care in tests"), impl RustcInfo {
None, fn new() -> RustcInfo {
).unwrap() let output = ProcessBuilder::new("rustc")
); .arg("-vV")
.exec_with_output()
.expect("rustc should exec");
let verbose_version = String::from_utf8(output.stdout).expect("utf8 output");
let host = verbose_version
.lines()
.filter_map(|line| line.strip_prefix("host: "))
.next()
.expect("verbose version has host: field")
.to_string();
RustcInfo {
verbose_version,
host,
}
}
}
lazy_static::lazy_static! {
static ref RUSTC_INFO: RustcInfo = RustcInfo::new();
}
/// The rustc host such as `x86_64-unknown-linux-gnu`. /// The rustc host such as `x86_64-unknown-linux-gnu`.
pub fn rustc_host() -> String { pub fn rustc_host() -> &'static str {
RUSTC.with(|r| r.host.to_string()) &RUSTC_INFO.host
} }
pub fn is_nightly() -> bool { pub fn is_nightly() -> bool {
let vv = &RUSTC_INFO.verbose_version;
env::var("CARGO_TEST_DISABLE_NIGHTLY").is_err() env::var("CARGO_TEST_DISABLE_NIGHTLY").is_err()
&& RUSTC && (vv.contains("-nightly") || vv.contains("-dev"))
.with(|r| r.verbose_version.contains("-nightly") || r.verbose_version.contains("-dev"))
} }
pub fn process<T: AsRef<OsStr>>(t: T) -> ProcessBuilder { pub fn process<T: AsRef<OsStr>>(t: T) -> ProcessBuilder {