|
|
|
use guess_host_triple::guess_host_triple;
|
|
|
|
use platforms::{Platform as LibPlatform, PlatformReq};
|
|
|
|
use serde::Deserialize;
|
|
|
|
use std::str::FromStr;
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
|
pub struct Platform(String);
|
|
|
|
|
|
|
|
impl Platform {
|
|
|
|
pub fn new(p: impl Into<String>) -> Self {
|
|
|
|
Platform(p.into())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn matches(&self, pf: impl AsRef<str>) -> bool {
|
|
|
|
// this finder needs a full triple, so when the .0 is empty, return true
|
|
|
|
// this is fucked up tbh
|
|
|
|
let Some(platform_to_match_against) = LibPlatform::find(&self.0) else {
|
|
|
|
return self.0.is_empty()
|
|
|
|
};
|
|
|
|
|
|
|
|
match PlatformReq::from_str(pf.as_ref()) {
|
|
|
|
Ok(p) => p.matches(&platform_to_match_against),
|
|
|
|
Err(_) => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn into_string(self) -> String {
|
|
|
|
self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn current() -> Platform {
|
|
|
|
Platform(guess_host_triple().unwrap().to_string())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn current_as_string() -> String {
|
|
|
|
current().into_string()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_valid_glob(platform_req: impl AsRef<str>) -> bool {
|
|
|
|
PlatformReq::from_str(platform_req.as_ref()).is_ok()
|
|
|
|
}
|