Support docker images with targets containing `.`s.
Fix parsing of image targets for building docker images so it only uses
subs containing only ASCII letters, so targets like
`thumbv8m.main-none-eabihf` aren't mistaken for a target/sub
combination.
@@ -165,19 +165,25 @@ impl std::str::FromStr for ImageTarget {
type Err = std::convert::Infallible;
fn from_str(s: &str) -> Result<Self, Self::Err> {
- if let Some((target, sub)) = s.split_once('.') {
- Ok(ImageTarget {
+ // we designate certain targets like `x86_64-unknown-linux-gnu.centos`,
+ // where `centos` is a subtype of `x86_64-unknown-linux-gnu`. however,
+ // LLVM triples can also contain `.` characters, such as with
+ // `thumbv8m.main-none-eabihf`, so we make sure it's only at the end.
+ if let Some((target, sub)) = s.rsplit_once('.') {
+ if sub.chars().all(|x| char::is_ascii_alphabetic(&x)) {
+ return Ok(ImageTarget {
name: target.to_string(),
sub: Some(sub.to_string()),
- })
- } else {
+ });
+ }
+ }
+
Ok(ImageTarget {
name: s.to_string(),
sub: None,
})
}
}
-}
impl std::fmt::Display for ImageTarget {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
@@ -270,6 +276,40 @@ mod tests {
use cross::shell::Verbosity;
use std::collections::BTreeMap;
+ #[test]
+ fn test_parse_image_target() {
+ assert_eq!(
+ ImageTarget {
+ name: "x86_64-unknown-linux-gnu".to_owned(),
+ sub: None,
+ },
+ "x86_64-unknown-linux-gnu".parse().unwrap()
+ );
+ assert_eq!(
+ ImageTarget {
+ name: "x86_64-unknown-linux-gnu".to_owned(),
+ sub: Some("centos".to_owned()),
+ },
+ "x86_64-unknown-linux-gnu.centos".parse().unwrap()
+ );
+ assert_eq!(
+ ImageTarget {
+ name: "thumbv8m.main-none-eabihf".to_owned(),
+ sub: None,
+ },
+ "thumbv8m.main-none-eabihf".parse().unwrap()
+ );
+ assert_eq!(
+ ImageTarget {
+ name: "thumbv8m.main-unknown-linux-gnueabihf".to_owned(),
+ sub: Some("alpine".to_owned()),
+ },
+ "thumbv8m.main-unknown-linux-gnueabihf.alpine"
+ .parse()
+ .unwrap()
+ );
+ }
+
#[test]
fn check_ubuntu_base() -> cross::Result<()> {
// count all the entries of FROM for our images
