Skip to content

Commit 5c779c1

Browse files
committed
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.
1 parent 8d8d84b commit 5c779c1

File tree

1 file changed

+50
-10
lines changed

1 file changed

+50
-10
lines changed

xtask/src/util.rs

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -165,17 +165,23 @@ impl std::str::FromStr for ImageTarget {
165165
type Err = std::convert::Infallible;
166166

167167
fn from_str(s: &str) -> Result<Self, Self::Err> {
168-
if let Some((target, sub)) = s.split_once('.') {
169-
Ok(ImageTarget {
170-
name: target.to_string(),
171-
sub: Some(sub.to_string()),
172-
})
173-
} else {
174-
Ok(ImageTarget {
175-
name: s.to_string(),
176-
sub: None,
177-
})
168+
// we designate certain targets like `x86_64-unknown-linux-gnu.centos`,
169+
// where `centos` is a subtype of `x86_64-unknown-linux-gnu`. however,
170+
// LLVM triples can also contain `.` characters, such as with
171+
// `thumbv8m.main-none-eabihf`, so we make sure it's only at the end.
172+
if let Some((target, sub)) = s.rsplit_once('.') {
173+
if sub.chars().all(|x| char::is_ascii_alphabetic(&x)) {
174+
return Ok(ImageTarget {
175+
name: target.to_string(),
176+
sub: Some(sub.to_string()),
177+
});
178+
}
178179
}
180+
181+
Ok(ImageTarget {
182+
name: s.to_string(),
183+
sub: None,
184+
})
179185
}
180186
}
181187

@@ -270,6 +276,40 @@ mod tests {
270276
use cross::shell::Verbosity;
271277
use std::collections::BTreeMap;
272278

279+
#[test]
280+
fn test_parse_image_target() {
281+
assert_eq!(
282+
ImageTarget {
283+
name: "x86_64-unknown-linux-gnu".to_owned(),
284+
sub: None,
285+
},
286+
"x86_64-unknown-linux-gnu".parse().unwrap()
287+
);
288+
assert_eq!(
289+
ImageTarget {
290+
name: "x86_64-unknown-linux-gnu".to_owned(),
291+
sub: Some("centos".to_owned()),
292+
},
293+
"x86_64-unknown-linux-gnu.centos".parse().unwrap()
294+
);
295+
assert_eq!(
296+
ImageTarget {
297+
name: "thumbv8m.main-none-eabihf".to_owned(),
298+
sub: None,
299+
},
300+
"thumbv8m.main-none-eabihf".parse().unwrap()
301+
);
302+
assert_eq!(
303+
ImageTarget {
304+
name: "thumbv8m.main-unknown-linux-gnueabihf".to_owned(),
305+
sub: Some("alpine".to_owned()),
306+
},
307+
"thumbv8m.main-unknown-linux-gnueabihf.alpine"
308+
.parse()
309+
.unwrap()
310+
);
311+
}
312+
273313
#[test]
274314
fn check_ubuntu_base() -> cross::Result<()> {
275315
// count all the entries of FROM for our images

0 commit comments

Comments
 (0)