mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-25 11:14:46 +00:00
test: extract checking installed target to a function
This commit is contained in:
parent
b696870dd8
commit
4a88f924c6
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -456,7 +456,7 @@ version = "0.4.0"
|
||||
|
||||
[[package]]
|
||||
name = "cargo-test-support"
|
||||
version = "0.7.0"
|
||||
version = "0.7.1"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
|
@ -33,7 +33,7 @@ cargo-credential-macos-keychain = { version = "0.4.7", path = "credential/cargo-
|
||||
cargo-credential-wincred = { version = "0.4.7", path = "credential/cargo-credential-wincred" }
|
||||
cargo-platform = { path = "crates/cargo-platform", version = "0.2.0" }
|
||||
cargo-test-macro = { version = "0.4.0", path = "crates/cargo-test-macro" }
|
||||
cargo-test-support = { version = "0.7.0", path = "crates/cargo-test-support" }
|
||||
cargo-test-support = { version = "0.7.1", path = "crates/cargo-test-support" }
|
||||
cargo-util = { version = "0.2.14", path = "crates/cargo-util" }
|
||||
cargo-util-schemas = { version = "0.7.0", path = "crates/cargo-util-schemas" }
|
||||
cargo_metadata = "0.19.0"
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "cargo-test-support"
|
||||
version = "0.7.0"
|
||||
version = "0.7.1"
|
||||
edition.workspace = true
|
||||
rust-version = "1.83" # MSRV:1
|
||||
license.workspace = true
|
||||
|
@ -267,3 +267,33 @@ pub fn can_run_on_host() -> bool {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// Check if the given target has been installed.
|
||||
///
|
||||
/// Generally [`disabled`] should be used to check if cross-compilation is allowed.
|
||||
/// And [`alternate`] to get the cross target.
|
||||
///
|
||||
/// You should only use this as a last resort to skip tests,
|
||||
/// because it doesn't report skipped tests as ignored.
|
||||
pub fn requires_target_installed(target: &str) -> bool {
|
||||
let has_target = std::process::Command::new("rustup")
|
||||
.args(["target", "list", "--installed"])
|
||||
.output()
|
||||
.ok()
|
||||
.map(|output| {
|
||||
String::from_utf8(output.stdout)
|
||||
.map(|stdout| stdout.contains(target))
|
||||
.unwrap_or_default()
|
||||
})
|
||||
.unwrap_or_default();
|
||||
if !has_target {
|
||||
let msg =
|
||||
format!("to run this test, run `rustup target add {target} --toolchain <toolchain>`",);
|
||||
if cargo_util::is_ci() {
|
||||
panic!("{msg}");
|
||||
} else {
|
||||
eprintln!("{msg}");
|
||||
}
|
||||
}
|
||||
has_target
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use cargo_test_support::cross_compile;
|
||||
use cargo_test_support::prelude::*;
|
||||
use cargo_test_support::registry::{Dependency, Package};
|
||||
use cargo_test_support::ProjectBuilder;
|
||||
@ -391,24 +392,8 @@ fn check_core() {
|
||||
|
||||
#[cargo_test(build_std_mock)]
|
||||
fn build_std_with_no_arg_for_core_only_target() {
|
||||
let has_rustup_aarch64_unknown_none = std::process::Command::new("rustup")
|
||||
.args(["target", "list", "--installed"])
|
||||
.output()
|
||||
.ok()
|
||||
.map(|output| {
|
||||
String::from_utf8(output.stdout)
|
||||
.map(|stdout| stdout.contains("aarch64-unknown-none"))
|
||||
.unwrap_or_default()
|
||||
})
|
||||
.unwrap_or_default();
|
||||
if !has_rustup_aarch64_unknown_none {
|
||||
let msg =
|
||||
"to run this test, run `rustup target add aarch64-unknown-none --toolchain nightly`";
|
||||
if cargo_util::is_ci() {
|
||||
panic!("{msg}");
|
||||
} else {
|
||||
eprintln!("{msg}");
|
||||
}
|
||||
let target = "aarch64-unknown-none";
|
||||
if !cross_compile::requires_target_installed(target) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -427,7 +412,8 @@ fn build_std_with_no_arg_for_core_only_target() {
|
||||
.build();
|
||||
|
||||
p.cargo("build -v")
|
||||
.arg("--target=aarch64-unknown-none")
|
||||
.arg("--target")
|
||||
.arg(target)
|
||||
.build_std(&setup)
|
||||
.with_stderr_data(
|
||||
str![[r#"
|
||||
@ -457,7 +443,8 @@ fn build_std_with_no_arg_for_core_only_target() {
|
||||
// Note that we don't download std dependencies for the second call
|
||||
// because `-Zbuild-std` downloads them all also when building for core only.
|
||||
p.cargo("build -v")
|
||||
.arg("--target=aarch64-unknown-none")
|
||||
.arg("--target")
|
||||
.arg(target)
|
||||
.target_host()
|
||||
.build_std(&setup)
|
||||
.with_stderr_data(
|
||||
|
Loading…
x
Reference in New Issue
Block a user