]>
Commit | Line | Data |
---|---|---|
83571aee EH |
1 | //! Tests for configuration values that point to programs. |
2 | ||
18bc90cd | 3 | use cargo_test_support::{basic_lib_manifest, no_such_file_err_msg, project, rustc_host}; |
5a04a4d4 | 4 | |
0e0d9688 | 5 | #[cargo_test] |
6950bbb0 | 6 | fn pathless_tools() { |
763ba535 | 7 | let target = rustc_host(); |
5a04a4d4 | 8 | |
7fe2fbc8 | 9 | let foo = project() |
081e7930 | 10 | .file("Cargo.toml", &basic_lib_manifest("foo")) |
5a04a4d4 | 11 | .file("src/lib.rs", "") |
1e682848 AC |
12 | .file( |
13 | ".cargo/config", | |
14 | &format!( | |
15 | r#" | |
6f8c7d5a EH |
16 | [target.{}] |
17 | linker = "nonexistent-linker" | |
18 | "#, | |
1e682848 AC |
19 | target |
20 | ), | |
fecb7246 AC |
21 | ) |
22 | .build(); | |
5a04a4d4 | 23 | |
85984a87 | 24 | foo.cargo("build --verbose") |
2cd9cce6 | 25 | .with_stderr( |
1e682848 | 26 | "\ |
89f43938 | 27 | [COMPILING] foo v0.5.0 ([CWD]) |
35b924db | 28 | [RUNNING] `rustc [..] -C linker=nonexistent-linker [..]` |
34628b65 | 29 | [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] |
1e682848 | 30 | ", |
fecb7246 AC |
31 | ) |
32 | .run(); | |
6950bbb0 | 33 | } |
5a04a4d4 | 34 | |
0e0d9688 | 35 | #[cargo_test] |
6950bbb0 | 36 | fn absolute_tools() { |
763ba535 | 37 | let target = rustc_host(); |
5a04a4d4 MB |
38 | |
39 | // Escaped as they appear within a TOML config file | |
35b924db EH |
40 | let linker = if cfg!(windows) { |
41 | r#"C:\\bogus\\nonexistent-linker"# | |
5a04a4d4 | 42 | } else { |
35b924db | 43 | r#"/bogus/nonexistent-linker"# |
5a04a4d4 MB |
44 | }; |
45 | ||
7fe2fbc8 | 46 | let foo = project() |
081e7930 | 47 | .file("Cargo.toml", &basic_lib_manifest("foo")) |
5a04a4d4 | 48 | .file("src/lib.rs", "") |
1e682848 AC |
49 | .file( |
50 | ".cargo/config", | |
51 | &format!( | |
52 | r#" | |
6f8c7d5a EH |
53 | [target.{target}] |
54 | linker = "{linker}" | |
55 | "#, | |
1e682848 | 56 | target = target, |
35b924db | 57 | linker = linker |
1e682848 | 58 | ), |
fecb7246 AC |
59 | ) |
60 | .build(); | |
5a04a4d4 | 61 | |
c2354b9a AC |
62 | foo.cargo("build --verbose") |
63 | .with_stderr( | |
64 | "\ | |
89f43938 | 65 | [COMPILING] foo v0.5.0 ([CWD]) |
35b924db | 66 | [RUNNING] `rustc [..] -C linker=[..]bogus/nonexistent-linker [..]` |
34628b65 | 67 | [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] |
c2354b9a AC |
68 | ", |
69 | ) | |
70 | .run(); | |
6950bbb0 | 71 | } |
5a04a4d4 | 72 | |
0e0d9688 | 73 | #[cargo_test] |
6950bbb0 | 74 | fn relative_tools() { |
763ba535 | 75 | let target = rustc_host(); |
5a04a4d4 MB |
76 | |
77 | // Escaped as they appear within a TOML config file | |
35b924db EH |
78 | let linker = if cfg!(windows) { |
79 | r#".\\tools\\nonexistent-linker"# | |
5a04a4d4 | 80 | } else { |
35b924db | 81 | r#"./tools/nonexistent-linker"# |
5a04a4d4 MB |
82 | }; |
83 | ||
84 | // Funky directory structure to test that relative tool paths are made absolute | |
85 | // by reference to the `.cargo/..` directory and not to (for example) the CWD. | |
f8c9928c | 86 | let p = project() |
252f6e8e | 87 | .no_manifest() |
ab19c483 | 88 | .file("bar/Cargo.toml", &basic_lib_manifest("bar")) |
f8c9928c | 89 | .file("bar/src/lib.rs", "") |
1e682848 AC |
90 | .file( |
91 | ".cargo/config", | |
92 | &format!( | |
93 | r#" | |
6f8c7d5a EH |
94 | [target.{target}] |
95 | linker = "{linker}" | |
96 | "#, | |
1e682848 | 97 | target = target, |
35b924db | 98 | linker = linker |
1e682848 | 99 | ), |
fecb7246 AC |
100 | ) |
101 | .build(); | |
5a04a4d4 | 102 | |
f8c9928c | 103 | let prefix = p.root().into_os_string().into_string().unwrap(); |
5a04a4d4 | 104 | |
35b924db EH |
105 | p.cargo("build --verbose") |
106 | .cwd("bar") | |
107 | .with_stderr(&format!( | |
1e682848 | 108 | "\ |
89f43938 | 109 | [COMPILING] bar v0.5.0 ([CWD]) |
35b924db | 110 | [RUNNING] `rustc [..] -C linker={prefix}/./tools/nonexistent-linker [..]` |
34628b65 | 111 | [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] |
1e682848 | 112 | ", |
4c9d42e0 | 113 | prefix = prefix, |
35b924db EH |
114 | )) |
115 | .run(); | |
6950bbb0 | 116 | } |
e1a85a60 | 117 | |
0e0d9688 | 118 | #[cargo_test] |
e1a85a60 IS |
119 | fn custom_runner() { |
120 | let target = rustc_host(); | |
121 | ||
7fe2fbc8 | 122 | let p = project() |
e1a85a60 IS |
123 | .file("src/main.rs", "fn main() {}") |
124 | .file("tests/test.rs", "") | |
125 | .file("benches/bench.rs", "") | |
1e682848 AC |
126 | .file( |
127 | ".cargo/config", | |
128 | &format!( | |
129 | r#" | |
6f8c7d5a EH |
130 | [target.{}] |
131 | runner = "nonexistent-runner -r" | |
132 | "#, | |
1e682848 AC |
133 | target |
134 | ), | |
fecb7246 AC |
135 | ) |
136 | .build(); | |
e1a85a60 | 137 | |
85984a87 DW |
138 | p.cargo("run -- --param") |
139 | .with_status(101) | |
2cd9cce6 | 140 | .with_stderr_contains( |
1e682848 | 141 | "\ |
89f43938 | 142 | [COMPILING] foo v0.0.1 ([CWD]) |
e1a85a60 | 143 | [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] |
05400b80 | 144 | [RUNNING] `nonexistent-runner -r target/debug/foo[EXE] --param` |
1e682848 | 145 | ", |
fecb7246 AC |
146 | ) |
147 | .run(); | |
e1a85a60 | 148 | |
85984a87 DW |
149 | p.cargo("test --test test --verbose -- --param") |
150 | .with_status(101) | |
2cd9cce6 | 151 | .with_stderr_contains( |
1e682848 | 152 | "\ |
89f43938 | 153 | [COMPILING] foo v0.0.1 ([CWD]) |
e1a85a60 | 154 | [RUNNING] `rustc [..]` |
e25f6a42 | 155 | [FINISHED] test [unoptimized + debuginfo] target(s) in [..] |
05400b80 | 156 | [RUNNING] `nonexistent-runner -r [..]/target/debug/deps/test-[..][EXE] --param` |
1e682848 | 157 | ", |
fecb7246 AC |
158 | ) |
159 | .run(); | |
e1a85a60 | 160 | |
85984a87 DW |
161 | p.cargo("bench --bench bench --verbose -- --param") |
162 | .with_status(101) | |
2cd9cce6 | 163 | .with_stderr_contains( |
1e682848 | 164 | "\ |
89f43938 | 165 | [COMPILING] foo v0.0.1 ([CWD]) |
e1a85a60 IS |
166 | [RUNNING] `rustc [..]` |
167 | [RUNNING] `rustc [..]` | |
e25f6a42 | 168 | [FINISHED] bench [optimized] target(s) in [..] |
05400b80 | 169 | [RUNNING] `nonexistent-runner -r [..]/target/release/deps/bench-[..][EXE] --param --bench` |
1e682848 | 170 | ", |
fecb7246 AC |
171 | ) |
172 | .run(); | |
e1a85a60 | 173 | } |
6a12aa56 JA |
174 | |
175 | // can set a custom runner via `target.'cfg(..)'.runner` | |
0e0d9688 | 176 | #[cargo_test] |
6a12aa56 JA |
177 | fn custom_runner_cfg() { |
178 | let p = project() | |
179 | .file("src/main.rs", "fn main() {}") | |
180 | .file( | |
181 | ".cargo/config", | |
182 | r#" | |
183 | [target.'cfg(not(target_os = "none"))'] | |
184 | runner = "nonexistent-runner -r" | |
185 | "#, | |
fecb7246 AC |
186 | ) |
187 | .build(); | |
6a12aa56 JA |
188 | |
189 | p.cargo("run -- --param") | |
190 | .with_status(101) | |
f16efff1 AC |
191 | .with_stderr_contains( |
192 | "\ | |
ad6bc8e4 | 193 | [COMPILING] foo v0.0.1 ([CWD]) |
6a12aa56 JA |
194 | [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] |
195 | [RUNNING] `nonexistent-runner -r target/debug/foo[EXE] --param` | |
f16efff1 AC |
196 | ", |
197 | ) | |
fecb7246 | 198 | .run(); |
6a12aa56 JA |
199 | } |
200 | ||
34f2d471 | 201 | // custom runner set via `target.$triple.runner` have precedence over `target.'cfg(..)'.runner` |
0e0d9688 | 202 | #[cargo_test] |
6a12aa56 JA |
203 | fn custom_runner_cfg_precedence() { |
204 | let target = rustc_host(); | |
205 | ||
206 | let p = project() | |
207 | .file("src/main.rs", "fn main() {}") | |
208 | .file( | |
209 | ".cargo/config", | |
210 | &format!( | |
211 | r#" | |
6f8c7d5a EH |
212 | [target.'cfg(not(target_os = "none"))'] |
213 | runner = "ignored-runner" | |
6a12aa56 | 214 | |
6f8c7d5a EH |
215 | [target.{}] |
216 | runner = "nonexistent-runner -r" | |
217 | "#, | |
6a12aa56 JA |
218 | target |
219 | ), | |
fecb7246 AC |
220 | ) |
221 | .build(); | |
6a12aa56 JA |
222 | |
223 | p.cargo("run -- --param") | |
224 | .with_status(101) | |
f16efff1 AC |
225 | .with_stderr_contains( |
226 | "\ | |
a4e96114 | 227 | [COMPILING] foo v0.0.1 ([CWD]) |
6a12aa56 JA |
228 | [FINISHED] dev [unoptimized + debuginfo] target(s) in [..] |
229 | [RUNNING] `nonexistent-runner -r target/debug/foo[EXE] --param` | |
f16efff1 AC |
230 | ", |
231 | ) | |
fecb7246 | 232 | .run(); |
6a12aa56 JA |
233 | } |
234 | ||
0e0d9688 | 235 | #[cargo_test] |
6a12aa56 JA |
236 | fn custom_runner_cfg_collision() { |
237 | let p = project() | |
238 | .file("src/main.rs", "fn main() {}") | |
239 | .file( | |
240 | ".cargo/config", | |
241 | r#" | |
242 | [target.'cfg(not(target_arch = "avr"))'] | |
243 | runner = "true" | |
244 | ||
245 | [target.'cfg(not(target_os = "none"))'] | |
246 | runner = "false" | |
247 | "#, | |
fecb7246 AC |
248 | ) |
249 | .build(); | |
6a12aa56 JA |
250 | |
251 | p.cargo("run -- --param") | |
252 | .with_status(101) | |
381251aa | 253 | .with_stderr( |
f16efff1 | 254 | "\ |
6a12aa56 | 255 | [ERROR] several matching instances of `target.'cfg(..)'.runner` in `.cargo/config` |
381251aa EH |
256 | first match `cfg(not(target_arch = \"avr\"))` located in [..]/foo/.cargo/config |
257 | second match `cfg(not(target_os = \"none\"))` located in [..]/foo/.cargo/config | |
258 | ", | |
259 | ) | |
260 | .run(); | |
261 | } | |
262 | ||
263 | #[cargo_test] | |
264 | fn custom_runner_env() { | |
265 | let target = rustc_host(); | |
266 | let p = project().file("src/main.rs", "fn main() {}").build(); | |
267 | ||
268 | let key = format!( | |
269 | "CARGO_TARGET_{}_RUNNER", | |
270 | target.to_uppercase().replace('-', "_") | |
271 | ); | |
272 | ||
273 | p.cargo("run") | |
274 | .env(&key, "nonexistent-runner --foo") | |
275 | .with_status(101) | |
18bc90cd EH |
276 | .with_stderr(&format!( |
277 | "\ | |
278 | [COMPILING] foo [..] | |
279 | [FINISHED] dev [..] | |
280 | [RUNNING] `nonexistent-runner --foo target/debug/foo[EXE]` | |
281 | [ERROR] could not execute process `nonexistent-runner --foo target/debug/foo[EXE]` (never executed) | |
282 | ||
283 | Caused by: | |
284 | {} | |
285 | ", | |
286 | no_such_file_err_msg() | |
287 | )) | |
381251aa EH |
288 | .run(); |
289 | } | |
290 | ||
a9a154f7 JS |
291 | #[cargo_test] |
292 | fn custom_runner_env_overrides_config() { | |
293 | let target = rustc_host(); | |
294 | let p = project() | |
295 | .file("src/main.rs", "fn main() {}") | |
296 | .file( | |
297 | ".cargo/config.toml", | |
298 | &format!( | |
299 | r#" | |
6f8c7d5a EH |
300 | [target.{}] |
301 | runner = "should-not-run -r" | |
302 | "#, | |
a9a154f7 JS |
303 | target |
304 | ), | |
305 | ) | |
306 | .build(); | |
307 | ||
308 | let key = format!( | |
309 | "CARGO_TARGET_{}_RUNNER", | |
310 | target.to_uppercase().replace('-', "_") | |
311 | ); | |
312 | ||
313 | p.cargo("run") | |
314 | .env(&key, "should-run --foo") | |
a9a154f7 JS |
315 | .with_status(101) |
316 | .with_stderr_contains("[RUNNING] `should-run --foo target/debug/foo[EXE]`") | |
317 | .run(); | |
318 | } | |
319 | ||
fd258634 EH |
320 | #[cargo_test] |
321 | #[cfg(unix)] // Assumes `true` is in PATH. | |
322 | fn custom_runner_env_true() { | |
323 | // Check for a bug where "true" was interpreted as a boolean instead of | |
324 | // the executable. | |
325 | let target = rustc_host(); | |
326 | let p = project().file("src/main.rs", "fn main() {}").build(); | |
327 | ||
328 | let key = format!( | |
329 | "CARGO_TARGET_{}_RUNNER", | |
330 | target.to_uppercase().replace('-', "_") | |
331 | ); | |
332 | ||
333 | p.cargo("run") | |
334 | .env(&key, "true") | |
335 | .with_stderr_contains("[RUNNING] `true target/debug/foo[EXE]`") | |
336 | .run(); | |
337 | } | |
338 | ||
35b924db EH |
339 | #[cargo_test] |
340 | fn custom_linker_env() { | |
341 | let target = rustc_host(); | |
342 | let p = project().file("src/main.rs", "fn main() {}").build(); | |
343 | ||
344 | let key = format!( | |
345 | "CARGO_TARGET_{}_LINKER", | |
346 | target.to_uppercase().replace('-', "_") | |
347 | ); | |
348 | ||
349 | p.cargo("build -v") | |
350 | .env(&key, "nonexistent-linker") | |
351 | .with_status(101) | |
352 | .with_stderr_contains("[RUNNING] `rustc [..]-C linker=nonexistent-linker [..]") | |
353 | .run(); | |
354 | } | |
355 | ||
381251aa EH |
356 | #[cargo_test] |
357 | fn cfg_ignored_fields() { | |
358 | // Test for some ignored fields in [target.'cfg()'] tables. | |
359 | let p = project() | |
360 | .file( | |
361 | ".cargo/config", | |
362 | r#" | |
363 | # Try some empty tables. | |
364 | [target.'cfg(not(foo))'] | |
365 | [target.'cfg(not(bar))'.somelib] | |
366 | ||
367 | # A bunch of unused fields. | |
368 | [target.'cfg(not(target_os = "none"))'] | |
369 | linker = 'false' | |
370 | ar = 'false' | |
371 | foo = {rustc-flags = "-l foo"} | |
372 | invalid = 1 | |
373 | runner = 'false' | |
374 | rustflags = '' | |
375 | "#, | |
376 | ) | |
377 | .file("src/lib.rs", "") | |
378 | .build(); | |
379 | ||
380 | p.cargo("check") | |
381 | .with_stderr( | |
382 | "\ | |
383 | [WARNING] unused key `somelib` in [target] config table `cfg(not(bar))` | |
384 | [WARNING] unused key `ar` in [target] config table `cfg(not(target_os = \"none\"))` | |
385 | [WARNING] unused key `foo` in [target] config table `cfg(not(target_os = \"none\"))` | |
386 | [WARNING] unused key `invalid` in [target] config table `cfg(not(target_os = \"none\"))` | |
387 | [WARNING] unused key `linker` in [target] config table `cfg(not(target_os = \"none\"))` | |
388 | [CHECKING] foo v0.0.1 ([..]) | |
389 | [FINISHED] [..] | |
f16efff1 AC |
390 | ", |
391 | ) | |
fecb7246 | 392 | .run(); |
6a12aa56 | 393 | } |