1 |
From 95827ad3bf7a6fc6d501c3ccd45b5636434a07b5 Mon Sep 17 00:00:00 2001 |
2 |
From: Eric Huss <eric@huss.org> |
3 |
Date: Mon, 8 Mar 2021 07:54:01 -0800 |
4 |
Subject: [PATCH] Fix filter_platform to run on targets other than x86. |
5 |
|
6 |
--- |
7 |
tests/testsuite/metadata.rs | 57 +++++++++++++++++++++++-------------- |
8 |
1 file changed, 36 insertions(+), 21 deletions(-) |
9 |
|
10 |
diff --git a/tests/testsuite/metadata.rs b/tests/testsuite/metadata.rs |
11 |
index 1909847b7e..b403bb406e 100644 |
12 |
--- a/tests/testsuite/metadata.rs |
13 |
+++ b/tests/testsuite/metadata.rs |
14 |
@@ -2057,6 +2057,7 @@ fn filter_platform() { |
15 |
// Just needs to be a valid target that is different from host. |
16 |
// Presumably nobody runs these tests on wasm. 🙃 |
17 |
let alt_target = "wasm32-unknown-unknown"; |
18 |
+ let host_target = rustc_host(); |
19 |
let p = project() |
20 |
.file( |
21 |
"Cargo.toml", |
22 |
@@ -2078,8 +2079,7 @@ fn filter_platform() { |
23 |
[target.'cfg(foobar)'.dependencies] |
24 |
cfg-dep = "0.0.1" |
25 |
"#, |
26 |
- rustc_host(), |
27 |
- alt_target |
28 |
+ host_target, alt_target |
29 |
), |
30 |
) |
31 |
.file("src/lib.rs", "") |
32 |
@@ -2253,16 +2253,10 @@ fn filter_platform() { |
33 |
} |
34 |
"#; |
35 |
|
36 |
- let foo = r#" |
37 |
- { |
38 |
- "name": "foo", |
39 |
- "version": "0.1.0", |
40 |
- "id": "foo 0.1.0 (path+file:[..]foo)", |
41 |
- "license": null, |
42 |
- "license_file": null, |
43 |
- "description": null, |
44 |
- "source": null, |
45 |
- "dependencies": [ |
46 |
+ // The dependencies are stored in sorted order by target and then by name. |
47 |
+ // Since the testsuite may run on different targets, this needs to be |
48 |
+ // sorted before it can be compared. |
49 |
+ let mut foo_deps = serde_json::json!([ |
50 |
{ |
51 |
"name": "normal-dep", |
52 |
"source": "registry+https://github.com/rust-lang/crates.io-index", |
53 |
@@ -2296,7 +2290,7 @@ fn filter_platform() { |
54 |
"optional": false, |
55 |
"uses_default_features": true, |
56 |
"features": [], |
57 |
- "target": "$ALT_TRIPLE", |
58 |
+ "target": alt_target, |
59 |
"registry": null |
60 |
}, |
61 |
{ |
62 |
@@ -2308,10 +2302,30 @@ fn filter_platform() { |
63 |
"optional": false, |
64 |
"uses_default_features": true, |
65 |
"features": [], |
66 |
- "target": "$HOST_TRIPLE", |
67 |
+ "target": host_target, |
68 |
"registry": null |
69 |
} |
70 |
- ], |
71 |
+ ]); |
72 |
+ foo_deps.as_array_mut().unwrap().sort_by(|a, b| { |
73 |
+ // This really should be `rename`, but not needed here. |
74 |
+ // Also, sorting on `name` isn't really necessary since this test |
75 |
+ // only has one package per target, but leaving it here to be safe. |
76 |
+ let a = (a["target"].as_str(), a["name"].as_str()); |
77 |
+ let b = (b["target"].as_str(), b["name"].as_str()); |
78 |
+ a.cmp(&b) |
79 |
+ }); |
80 |
+ |
81 |
+ let foo = r#" |
82 |
+ { |
83 |
+ "name": "foo", |
84 |
+ "version": "0.1.0", |
85 |
+ "id": "foo 0.1.0 (path+file:[..]foo)", |
86 |
+ "license": null, |
87 |
+ "license_file": null, |
88 |
+ "description": null, |
89 |
+ "source": null, |
90 |
+ "dependencies": |
91 |
+ $FOO_DEPS, |
92 |
"targets": [ |
93 |
{ |
94 |
"kind": [ |
95 |
@@ -2344,7 +2358,8 @@ fn filter_platform() { |
96 |
} |
97 |
"# |
98 |
.replace("$ALT_TRIPLE", alt_target) |
99 |
- .replace("$HOST_TRIPLE", &rustc_host()); |
100 |
+ .replace("$HOST_TRIPLE", &host_target) |
101 |
+ .replace("$FOO_DEPS", &foo_deps.to_string()); |
102 |
|
103 |
// We're going to be checking that we don't download excessively, |
104 |
// so we need to ensure that downloads will happen. |
105 |
@@ -2468,7 +2483,7 @@ fn filter_platform() { |
106 |
} |
107 |
"# |
108 |
.replace("$ALT_TRIPLE", alt_target) |
109 |
- .replace("$HOST_TRIPLE", &rustc_host()) |
110 |
+ .replace("$HOST_TRIPLE", &host_target) |
111 |
.replace("$ALT_DEP", alt_dep) |
112 |
.replace("$CFG_DEP", cfg_dep) |
113 |
.replace("$HOST_DEP", host_dep) |
114 |
@@ -2562,7 +2577,7 @@ fn filter_platform() { |
115 |
|
116 |
// Filter on host, removes alt and cfg. |
117 |
p.cargo("metadata --filter-platform") |
118 |
- .arg(rustc_host()) |
119 |
+ .arg(&host_target) |
120 |
.with_stderr_unordered( |
121 |
"\ |
122 |
[WARNING] please specify `--format-version` flag explicitly to avoid compatibility problems |
123 |
@@ -2633,7 +2648,7 @@ fn filter_platform() { |
124 |
"metadata": null |
125 |
} |
126 |
"# |
127 |
- .replace("$HOST_TRIPLE", &rustc_host()) |
128 |
+ .replace("$HOST_TRIPLE", &host_target) |
129 |
.replace("$HOST_DEP", host_dep) |
130 |
.replace("$NORMAL_DEP", normal_dep) |
131 |
.replace("$FOO", &foo), |
132 |
@@ -2643,7 +2658,7 @@ fn filter_platform() { |
133 |
|
134 |
// Filter host with cfg, removes alt only |
135 |
p.cargo("metadata --filter-platform") |
136 |
- .arg(rustc_host()) |
137 |
+ .arg(&host_target) |
138 |
.env("RUSTFLAGS", "--cfg=foobar") |
139 |
.with_stderr_unordered( |
140 |
"\ |
141 |
@@ -2734,7 +2749,7 @@ fn filter_platform() { |
142 |
"metadata": null |
143 |
} |
144 |
"# |
145 |
- .replace("$HOST_TRIPLE", &rustc_host()) |
146 |
+ .replace("$HOST_TRIPLE", &host_target) |
147 |
.replace("$CFG_DEP", cfg_dep) |
148 |
.replace("$HOST_DEP", host_dep) |
149 |
.replace("$NORMAL_DEP", normal_dep) |