@@ -2057,6 +2057,7 @@ fn filter_platform() {
2057
2057
// Just needs to be a valid target that is different from host.
2058
2058
// Presumably nobody runs these tests on wasm. 🙃
2059
2059
let alt_target = "wasm32-unknown-unknown" ;
2060
+ let host_target = rustc_host ( ) ;
2060
2061
let p = project ( )
2061
2062
. file (
2062
2063
"Cargo.toml" ,
@@ -2078,8 +2079,7 @@ fn filter_platform() {
2078
2079
[target.'cfg(foobar)'.dependencies]
2079
2080
cfg-dep = "0.0.1"
2080
2081
"# ,
2081
- rustc_host( ) ,
2082
- alt_target
2082
+ host_target, alt_target
2083
2083
) ,
2084
2084
)
2085
2085
. file ( "src/lib.rs" , "" )
@@ -2253,16 +2253,10 @@ fn filter_platform() {
2253
2253
}
2254
2254
"# ;
2255
2255
2256
- let foo = r#"
2257
- {
2258
- "name": "foo",
2259
- "version": "0.1.0",
2260
- "id": "foo 0.1.0 (path+file:[..]foo)",
2261
- "license": null,
2262
- "license_file": null,
2263
- "description": null,
2264
- "source": null,
2265
- "dependencies": [
2256
+ // The dependencies are stored in sorted order by target and then by name.
2257
+ // Since the testsuite may run on different targets, this needs to be
2258
+ // sorted before it can be compared.
2259
+ let mut foo_deps = serde_json:: json!( [
2266
2260
{
2267
2261
"name" : "normal-dep" ,
2268
2262
"source" : "registry+https://github.com/rust-lang/crates.io-index" ,
@@ -2296,7 +2290,7 @@ fn filter_platform() {
2296
2290
"optional" : false ,
2297
2291
"uses_default_features" : true ,
2298
2292
"features" : [ ] ,
2299
- "target": "$ALT_TRIPLE" ,
2293
+ "target" : alt_target ,
2300
2294
"registry" : null
2301
2295
} ,
2302
2296
{
@@ -2308,10 +2302,30 @@ fn filter_platform() {
2308
2302
"optional" : false ,
2309
2303
"uses_default_features" : true ,
2310
2304
"features" : [ ] ,
2311
- "target": "$HOST_TRIPLE" ,
2305
+ "target" : host_target ,
2312
2306
"registry" : null
2313
2307
}
2314
- ],
2308
+ ] ) ;
2309
+ foo_deps. as_array_mut ( ) . unwrap ( ) . sort_by ( |a, b| {
2310
+ // This really should be `rename`, but not needed here.
2311
+ // Also, sorting on `name` isn't really necessary since this test
2312
+ // only has one package per target, but leaving it here to be safe.
2313
+ let a = ( a[ "target" ] . as_str ( ) , a[ "name" ] . as_str ( ) ) ;
2314
+ let b = ( b[ "target" ] . as_str ( ) , b[ "name" ] . as_str ( ) ) ;
2315
+ a. cmp ( & b)
2316
+ } ) ;
2317
+
2318
+ let foo = r#"
2319
+ {
2320
+ "name": "foo",
2321
+ "version": "0.1.0",
2322
+ "id": "foo 0.1.0 (path+file:[..]foo)",
2323
+ "license": null,
2324
+ "license_file": null,
2325
+ "description": null,
2326
+ "source": null,
2327
+ "dependencies":
2328
+ $FOO_DEPS,
2315
2329
"targets": [
2316
2330
{
2317
2331
"kind": [
@@ -2344,7 +2358,8 @@ fn filter_platform() {
2344
2358
}
2345
2359
"#
2346
2360
. replace ( "$ALT_TRIPLE" , alt_target)
2347
- . replace ( "$HOST_TRIPLE" , & rustc_host ( ) ) ;
2361
+ . replace ( "$HOST_TRIPLE" , & host_target)
2362
+ . replace ( "$FOO_DEPS" , & foo_deps. to_string ( ) ) ;
2348
2363
2349
2364
// We're going to be checking that we don't download excessively,
2350
2365
// so we need to ensure that downloads will happen.
@@ -2468,7 +2483,7 @@ fn filter_platform() {
2468
2483
}
2469
2484
"#
2470
2485
. replace ( "$ALT_TRIPLE" , alt_target)
2471
- . replace ( "$HOST_TRIPLE" , & rustc_host ( ) )
2486
+ . replace ( "$HOST_TRIPLE" , & host_target )
2472
2487
. replace ( "$ALT_DEP" , alt_dep)
2473
2488
. replace ( "$CFG_DEP" , cfg_dep)
2474
2489
. replace ( "$HOST_DEP" , host_dep)
@@ -2562,7 +2577,7 @@ fn filter_platform() {
2562
2577
2563
2578
// Filter on host, removes alt and cfg.
2564
2579
p. cargo ( "metadata --filter-platform" )
2565
- . arg ( rustc_host ( ) )
2580
+ . arg ( & host_target )
2566
2581
. with_stderr_unordered (
2567
2582
"\
2568
2583
[WARNING] please specify `--format-version` flag explicitly to avoid compatibility problems
@@ -2633,7 +2648,7 @@ fn filter_platform() {
2633
2648
"metadata": null
2634
2649
}
2635
2650
"#
2636
- . replace ( "$HOST_TRIPLE" , & rustc_host ( ) )
2651
+ . replace ( "$HOST_TRIPLE" , & host_target )
2637
2652
. replace ( "$HOST_DEP" , host_dep)
2638
2653
. replace ( "$NORMAL_DEP" , normal_dep)
2639
2654
. replace ( "$FOO" , & foo) ,
@@ -2643,7 +2658,7 @@ fn filter_platform() {
2643
2658
2644
2659
// Filter host with cfg, removes alt only
2645
2660
p. cargo ( "metadata --filter-platform" )
2646
- . arg ( rustc_host ( ) )
2661
+ . arg ( & host_target )
2647
2662
. env ( "RUSTFLAGS" , "--cfg=foobar" )
2648
2663
. with_stderr_unordered (
2649
2664
"\
@@ -2734,7 +2749,7 @@ fn filter_platform() {
2734
2749
"metadata": null
2735
2750
}
2736
2751
"#
2737
- . replace ( "$HOST_TRIPLE" , & rustc_host ( ) )
2752
+ . replace ( "$HOST_TRIPLE" , & host_target )
2738
2753
. replace ( "$CFG_DEP" , cfg_dep)
2739
2754
. replace ( "$HOST_DEP" , host_dep)
2740
2755
. replace ( "$NORMAL_DEP" , normal_dep)
0 commit comments