mirror of
https://github.com/rust-lang/cargo
synced 2024-10-04 06:49:15 +00:00
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:
parent
4aa1ec2419
commit
10224938bf
|
@ -15,7 +15,7 @@ use std::process::{Command, Output};
|
|||
use std::str;
|
||||
use std::time::{self, Duration};
|
||||
|
||||
use cargo::util::{CargoResult, Rustc};
|
||||
use cargo::util::CargoResult;
|
||||
use cargo_util::{is_ci, ProcessBuilder, ProcessError};
|
||||
use serde_json::{self, Value};
|
||||
use url::Url;
|
||||
|
@ -1549,25 +1549,44 @@ fn substitute_macros(input: &str) -> String {
|
|||
|
||||
pub mod install;
|
||||
|
||||
thread_local!(
|
||||
pub static RUSTC: Rustc = Rustc::new(
|
||||
PathBuf::from("rustc"),
|
||||
None,
|
||||
None,
|
||||
Path::new("should be path to rustup rustc, but we don't care in tests"),
|
||||
None,
|
||||
).unwrap()
|
||||
);
|
||||
struct RustcInfo {
|
||||
verbose_version: String,
|
||||
host: String,
|
||||
}
|
||||
|
||||
impl RustcInfo {
|
||||
fn new() -> RustcInfo {
|
||||
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`.
|
||||
pub fn rustc_host() -> String {
|
||||
RUSTC.with(|r| r.host.to_string())
|
||||
pub fn rustc_host() -> &'static str {
|
||||
&RUSTC_INFO.host
|
||||
}
|
||||
|
||||
pub fn is_nightly() -> bool {
|
||||
let vv = &RUSTC_INFO.verbose_version;
|
||||
env::var("CARGO_TEST_DISABLE_NIGHTLY").is_err()
|
||||
&& RUSTC
|
||||
.with(|r| r.verbose_version.contains("-nightly") || r.verbose_version.contains("-dev"))
|
||||
&& (vv.contains("-nightly") || vv.contains("-dev"))
|
||||
}
|
||||
|
||||
pub fn process<T: AsRef<OsStr>>(t: T) -> ProcessBuilder {
|
||||
|
|
Loading…
Reference in a new issue