Skip to content

Commit

Permalink
[nextest-runner] more BuildPlatforms cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sunshowers committed Apr 24, 2024
1 parent 2072328 commit 1439087
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
20 changes: 0 additions & 20 deletions nextest-runner/src/cargo_config/target_triple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,6 @@ pub struct TargetTriple {
}

impl TargetTriple {
/// Converts a target triple to a `String` that can be stored in the build-metadata.
/// cargo-nextest represents the host triple with `None` during runtime.
/// However the build-metadata might be used on a system with a different host triple.
/// Therefore the host triple is detected if `target_triple` is `None`
pub fn serialize(target_triple: Option<&TargetTriple>) -> Option<PlatformSummary> {
if let Some(target) = &target_triple {
Some(target.platform.to_summary())
} else {
match Platform::current() {
Ok(host) => Some(host.to_summary()),
Err(err) => {
log::warn!(
"failed to detect host target: {err}!\n cargo nextest may use the wrong test runner for this archive."
);
None
}
}
}
}

/// Converts a `PlatformSummary` that was output by `TargetTriple::serialize` back to a target triple.
/// This target triple is assumed to originate from a build-metadata config.
pub fn deserialize(
Expand Down
4 changes: 1 addition & 3 deletions nextest-runner/src/list/rust_build_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,7 @@ impl<State> RustBuildMeta<State> {
.as_ref()
.map(|triple| triple.platform.triple_str().to_owned()),
// TODO: support multiple --target options
target_platforms: TargetTriple::serialize(self.build_platforms.target.as_ref())
.into_iter()
.collect(),
target_platforms: vec![self.build_platforms.to_summary()],
}
}
}
17 changes: 17 additions & 0 deletions nextest-runner/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{
cargo_config::{CargoTargetArg, TargetTriple},
errors::{TargetTripleError, UnknownHostPlatform},
};
use target_spec::summaries::PlatformSummary;
pub use target_spec::Platform;

/// A representation of host and target platforms.
Expand Down Expand Up @@ -48,4 +49,20 @@ impl BuildPlatforms {
}
}
}

/// Converts a target triple to a `String` that can be stored in the build-metadata.
///
/// cargo-nextest represents the host triple with `None` during runtime. However the
/// build-metadata might be used on a system with a different host triple. Therefore, the host
/// triple is detected if `target_triple` is `None`.
///
/// XXX: This isn't quite correct -- instead, we should serialize this into our own
/// `BuildPlatformsSummary`.
pub fn to_summary(&self) -> PlatformSummary {
if let Some(target) = &self.target {
target.platform.to_summary()
} else {
self.host.to_summary()
}
}
}

0 comments on commit 1439087

Please sign in to comment.