@@ -165,17 +165,23 @@ impl std::str::FromStr for ImageTarget {
165
165
type Err = std:: convert:: Infallible ;
166
166
167
167
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
+ }
178
179
}
180
+
181
+ Ok ( ImageTarget {
182
+ name : s. to_string ( ) ,
183
+ sub : None ,
184
+ } )
179
185
}
180
186
}
181
187
@@ -270,6 +276,40 @@ mod tests {
270
276
use cross:: shell:: Verbosity ;
271
277
use std:: collections:: BTreeMap ;
272
278
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
+
273
313
#[ test]
274
314
fn check_ubuntu_base ( ) -> cross:: Result < ( ) > {
275
315
// count all the entries of FROM for our images
0 commit comments