Skip to content

Commit c1c4fc2

Browse files
committed
Auto merge of #5994 - zachlute:convert-file-uris, r=alexcrichton
Print file paths instead of file:// URLs. Fixes #4661. This change ensures cargo will output file paths in the expected format (C:\foo\... on Windows, /foo/... elsewhere). Previously it would output file:// URLs instead. To support this change, additional changes were made to the test suite string processing such that [ROOT] is now replaced with the appropriate file path root for the platform. The CWD template was also updated to use [CWD] like other replacement templates and to do the replacement on the expected value rather than the actual value to avoid replacing things we don't expect with CWD.
2 parents b917e35 + 730d07c commit c1c4fc2

38 files changed

+591
-565
lines changed

src/cargo/core/source/source_id.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ impl SourceId {
213213
if self.is_default_registry() {
214214
"crates.io index".to_string()
215215
} else {
216-
format!("`{}` index", self.url())
216+
format!("`{}` index", url_display(self.url()))
217217
}
218218
}
219219

@@ -367,20 +367,34 @@ impl<'de> de::Deserialize<'de> for SourceId {
367367
}
368368
}
369369

370+
fn url_display(url: &Url) -> String {
371+
if url.scheme() == "file" {
372+
if let Ok(path) = url.to_file_path() {
373+
if let Some(path_str) = path.to_str() {
374+
return path_str.to_string();
375+
}
376+
}
377+
}
378+
379+
url.as_str().to_string()
380+
}
381+
370382
impl fmt::Display for SourceId {
371383
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
372384
match *self.inner {
373385
SourceIdInner {
374386
kind: Kind::Path,
375387
ref url,
376388
..
377-
} => fmt::Display::fmt(url, f),
389+
} => write!(f, "{}", url_display(url)),
378390
SourceIdInner {
379391
kind: Kind::Git(ref reference),
380392
ref url,
381393
ref precise,
382394
..
383395
} => {
396+
// Don't replace the URL display for git references,
397+
// because those are kind of expected to be URLs.
384398
write!(f, "{}", url)?;
385399
if let Some(pretty) = reference.pretty_ref() {
386400
write!(f, "?{}", pretty)?;
@@ -401,12 +415,12 @@ impl fmt::Display for SourceId {
401415
kind: Kind::LocalRegistry,
402416
ref url,
403417
..
404-
} => write!(f, "registry `{}`", url),
418+
} => write!(f, "registry `{}`", url_display(url)),
405419
SourceIdInner {
406420
kind: Kind::Directory,
407421
ref url,
408422
..
409-
} => write!(f, "dir {}", url),
423+
} => write!(f, "dir {}", url_display(url)),
410424
}
411425
}
412426
}

src/doc/src/reference/specifying-dependencies.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,13 @@ In any case, typically all you need to do now is:
250250

251251
```console
252252
$ cargo build
253-
Compiling uuid v1.0.0 (file://.../uuid)
254-
Compiling my-library v0.1.0 (file://.../my-library)
253+
Compiling uuid v1.0.0 (.../uuid)
254+
Compiling my-library v0.1.0 (.../my-library)
255255
Finished dev [unoptimized + debuginfo] target(s) in 0.32 secs
256256
```
257257

258258
And that's it! You're now building with the local version of `uuid` (note the
259-
`file://` in the build output). If you don't see the `file://` version getting
259+
path in parentheses in the build output). If you don't see the local path version getting
260260
built then you may need to run `cargo update -p uuid --precise $version` where
261261
`$version` is the version of the locally checked out copy of `uuid`.
262262

tests/testsuite/alt_registry.rs

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ fn depend_on_alt_registry() {
5757
.with_stderr(&format!(
5858
"\
5959
[UPDATING] `{reg}` index
60-
[DOWNLOADING] bar v0.0.1 (registry `file://[..]`)
61-
[COMPILING] bar v0.0.1 (registry `file://[..]`)
62-
[COMPILING] foo v0.0.1 (CWD)
60+
[DOWNLOADING] bar v0.0.1 (registry `[ROOT][..]`)
61+
[COMPILING] bar v0.0.1 (registry `[ROOT][..]`)
62+
[COMPILING] foo v0.0.1 ([CWD])
6363
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
6464
",
65-
reg = registry::alt_registry()
65+
reg = registry::alt_registry_path().to_str().unwrap()
6666
)).run();
6767

6868
p.cargo("clean").masquerade_as_nightly_cargo().run();
@@ -72,8 +72,8 @@ fn depend_on_alt_registry() {
7272
.masquerade_as_nightly_cargo()
7373
.with_stderr(
7474
"\
75-
[COMPILING] bar v0.0.1 (registry `file://[..]`)
76-
[COMPILING] foo v0.0.1 (CWD)
75+
[COMPILING] bar v0.0.1 (registry `[ROOT][..]`)
76+
[COMPILING] foo v0.0.1 ([CWD])
7777
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
7878
",
7979
).run();
@@ -110,14 +110,14 @@ fn depend_on_alt_registry_depends_on_same_registry_no_index() {
110110
.with_stderr(&format!(
111111
"\
112112
[UPDATING] `{reg}` index
113-
[DOWNLOADING] [..] v0.0.1 (registry `file://[..]`)
114-
[DOWNLOADING] [..] v0.0.1 (registry `file://[..]`)
115-
[COMPILING] baz v0.0.1 (registry `file://[..]`)
116-
[COMPILING] bar v0.0.1 (registry `file://[..]`)
117-
[COMPILING] foo v0.0.1 (CWD)
113+
[DOWNLOADING] [..] v0.0.1 (registry `[ROOT][..]`)
114+
[DOWNLOADING] [..] v0.0.1 (registry `[ROOT][..]`)
115+
[COMPILING] baz v0.0.1 (registry `[ROOT][..]`)
116+
[COMPILING] bar v0.0.1 (registry `[ROOT][..]`)
117+
[COMPILING] foo v0.0.1 ([CWD])
118118
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
119119
",
120-
reg = registry::alt_registry()
120+
reg = registry::alt_registry_path().to_str().unwrap()
121121
)).run();
122122
}
123123

@@ -152,14 +152,14 @@ fn depend_on_alt_registry_depends_on_same_registry() {
152152
.with_stderr(&format!(
153153
"\
154154
[UPDATING] `{reg}` index
155-
[DOWNLOADING] [..] v0.0.1 (registry `file://[..]`)
156-
[DOWNLOADING] [..] v0.0.1 (registry `file://[..]`)
157-
[COMPILING] baz v0.0.1 (registry `file://[..]`)
158-
[COMPILING] bar v0.0.1 (registry `file://[..]`)
159-
[COMPILING] foo v0.0.1 (CWD)
155+
[DOWNLOADING] [..] v0.0.1 (registry `[ROOT][..]`)
156+
[DOWNLOADING] [..] v0.0.1 (registry `[ROOT][..]`)
157+
[COMPILING] baz v0.0.1 (registry `[ROOT][..]`)
158+
[COMPILING] bar v0.0.1 (registry `[ROOT][..]`)
159+
[COMPILING] foo v0.0.1 ([CWD])
160160
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
161161
",
162-
reg = registry::alt_registry()
162+
reg = registry::alt_registry_path().to_str().unwrap()
163163
)).run();
164164
}
165165

@@ -195,15 +195,15 @@ fn depend_on_alt_registry_depends_on_crates_io() {
195195
"\
196196
[UPDATING] `{alt_reg}` index
197197
[UPDATING] `{reg}` index
198-
[DOWNLOADING] [..] v0.0.1 (registry `file://[..]`)
199-
[DOWNLOADING] [..] v0.0.1 (registry `file://[..]`)
200-
[COMPILING] baz v0.0.1 (registry `file://[..]`)
201-
[COMPILING] bar v0.0.1 (registry `file://[..]`)
202-
[COMPILING] foo v0.0.1 (CWD)
198+
[DOWNLOADING] [..] v0.0.1 (registry `[ROOT][..]`)
199+
[DOWNLOADING] [..] v0.0.1 (registry `[ROOT][..]`)
200+
[COMPILING] baz v0.0.1 (registry `[ROOT][..]`)
201+
[COMPILING] bar v0.0.1 (registry `[ROOT][..]`)
202+
[COMPILING] foo v0.0.1 ([CWD])
203203
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
204204
",
205-
alt_reg = registry::alt_registry(),
206-
reg = registry::registry()
205+
alt_reg = registry::alt_registry_path().to_str().unwrap(),
206+
reg = registry::registry_path().to_str().unwrap()
207207
)).run();
208208
}
209209

@@ -235,8 +235,8 @@ fn registry_and_path_dep_works() {
235235
.masquerade_as_nightly_cargo()
236236
.with_stderr(
237237
"\
238-
[COMPILING] bar v0.0.1 (CWD/bar)
239-
[COMPILING] foo v0.0.1 (CWD)
238+
[COMPILING] bar v0.0.1 ([CWD]/bar)
239+
[COMPILING] foo v0.0.1 ([CWD])
240240
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
241241
",
242242
).run();
@@ -359,13 +359,15 @@ fn alt_registry_and_crates_io_deps() {
359359
.masquerade_as_nightly_cargo()
360360
.with_stderr_contains(format!(
361361
"[UPDATING] `{}` index",
362-
registry::alt_registry()
363-
)).with_stderr_contains(&format!("[UPDATING] `{}` index", registry::registry()))
364-
.with_stderr_contains("[DOWNLOADING] crates_io_dep v0.0.1 (registry `file://[..]`)")
365-
.with_stderr_contains("[DOWNLOADING] alt_reg_dep v0.1.0 (registry `file://[..]`)")
366-
.with_stderr_contains("[COMPILING] alt_reg_dep v0.1.0 (registry `file://[..]`)")
362+
registry::alt_registry_path().to_str().unwrap()
363+
)).with_stderr_contains(&format!(
364+
"[UPDATING] `{}` index",
365+
registry::registry_path().to_str().unwrap()))
366+
.with_stderr_contains("[DOWNLOADING] crates_io_dep v0.0.1 (registry `[ROOT][..]`)")
367+
.with_stderr_contains("[DOWNLOADING] alt_reg_dep v0.1.0 (registry `[ROOT][..]`)")
368+
.with_stderr_contains("[COMPILING] alt_reg_dep v0.1.0 (registry `[ROOT][..]`)")
367369
.with_stderr_contains("[COMPILING] crates_io_dep v0.0.1")
368-
.with_stderr_contains("[COMPILING] foo v0.0.1 (CWD)")
370+
.with_stderr_contains("[COMPILING] foo v0.0.1 ([CWD])")
369371
.with_stderr_contains("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s")
370372
.run();
371373
}

tests/testsuite/bad_config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ fn unused_keys() {
641641
.with_stderr(
642642
"\
643643
warning: unused manifest key: target.foo.bar
644-
[COMPILING] foo v0.1.0 (CWD)
644+
[COMPILING] foo v0.1.0 ([CWD])
645645
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
646646
",
647647
).run();

tests/testsuite/bench.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn cargo_bench_simple() {
3939
p.cargo("bench")
4040
.with_stderr(
4141
"\
42-
[COMPILING] foo v0.5.0 (CWD)
42+
[COMPILING] foo v0.5.0 ([CWD])
4343
[FINISHED] release [optimized] target(s) in [..]
4444
[RUNNING] target/release/deps/foo-[..][EXE]",
4545
).with_stdout_contains("test bench_hello ... bench: [..]")
@@ -78,7 +78,7 @@ fn bench_bench_implicit() {
7878
p.cargo("bench --benches")
7979
.with_stderr(
8080
"\
81-
[COMPILING] foo v0.0.1 (CWD)
81+
[COMPILING] foo v0.0.1 ([CWD])
8282
[FINISHED] release [optimized] target(s) in [..]
8383
[RUNNING] target/release/deps/foo-[..][EXE]
8484
[RUNNING] target/release/deps/mybench-[..][EXE]
@@ -119,7 +119,7 @@ fn bench_bin_implicit() {
119119
p.cargo("bench --bins")
120120
.with_stderr(
121121
"\
122-
[COMPILING] foo v0.0.1 (CWD)
122+
[COMPILING] foo v0.0.1 ([CWD])
123123
[FINISHED] release [optimized] target(s) in [..]
124124
[RUNNING] target/release/deps/foo-[..][EXE]
125125
",
@@ -151,7 +151,7 @@ fn bench_tarname() {
151151
p.cargo("bench --bench bin2")
152152
.with_stderr(
153153
"\
154-
[COMPILING] foo v0.0.1 (CWD)
154+
[COMPILING] foo v0.0.1 ([CWD])
155155
[FINISHED] release [optimized] target(s) in [..]
156156
[RUNNING] target/release/deps/bin2-[..][EXE]
157157
",
@@ -215,7 +215,7 @@ fn cargo_bench_verbose() {
215215
p.cargo("bench -v hello")
216216
.with_stderr(
217217
"\
218-
[COMPILING] foo v0.5.0 (CWD)
218+
[COMPILING] foo v0.5.0 ([CWD])
219219
[RUNNING] `rustc [..] src/main.rs [..]`
220220
[FINISHED] release [optimized] target(s) in [..]
221221
[RUNNING] `[..]target/release/deps/foo-[..][EXE] hello --bench`",
@@ -305,7 +305,7 @@ fn cargo_bench_failing_test() {
305305
.with_stdout_contains("test bench_hello ...[..]")
306306
.with_stderr_contains(
307307
"\
308-
[COMPILING] foo v0.5.0 (CWD)[..]
308+
[COMPILING] foo v0.5.0 ([CWD])[..]
309309
[FINISHED] release [optimized] target(s) in [..]
310310
[RUNNING] target/release/deps/foo-[..][EXE]",
311311
).with_either_contains(
@@ -372,7 +372,7 @@ fn bench_with_lib_dep() {
372372
p.cargo("bench")
373373
.with_stderr(
374374
"\
375-
[COMPILING] foo v0.0.1 (CWD)
375+
[COMPILING] foo v0.0.1 ([CWD])
376376
[FINISHED] release [optimized] target(s) in [..]
377377
[RUNNING] target/release/deps/foo-[..][EXE]
378378
[RUNNING] target/release/deps/baz-[..][EXE]",
@@ -433,7 +433,7 @@ fn bench_with_deep_lib_dep() {
433433
.with_stderr(
434434
"\
435435
[COMPILING] foo v0.0.1 ([..])
436-
[COMPILING] bar v0.0.1 (CWD)
436+
[COMPILING] bar v0.0.1 ([CWD])
437437
[FINISHED] release [optimized] target(s) in [..]
438438
[RUNNING] target/release/deps/bar-[..][EXE]",
439439
).with_stdout_contains("test bar_bench ... bench: [..]")
@@ -486,7 +486,7 @@ fn external_bench_explicit() {
486486
p.cargo("bench")
487487
.with_stderr(
488488
"\
489-
[COMPILING] foo v0.0.1 (CWD)
489+
[COMPILING] foo v0.0.1 ([CWD])
490490
[FINISHED] release [optimized] target(s) in [..]
491491
[RUNNING] target/release/deps/foo-[..][EXE]
492492
[RUNNING] target/release/deps/bench-[..][EXE]",
@@ -530,7 +530,7 @@ fn external_bench_implicit() {
530530
p.cargo("bench")
531531
.with_stderr(
532532
"\
533-
[COMPILING] foo v0.0.1 (CWD)
533+
[COMPILING] foo v0.0.1 ([CWD])
534534
[FINISHED] release [optimized] target(s) in [..]
535535
[RUNNING] target/release/deps/foo-[..][EXE]
536536
[RUNNING] target/release/deps/external-[..][EXE]",
@@ -602,7 +602,7 @@ automatically infer them to be a target, such as in subfolders.
602602
603603
For more information on this warning you can consult
604604
https://github.com/rust-lang/cargo/issues/5330
605-
[COMPILING] foo v0.0.1 (CWD)
605+
[COMPILING] foo v0.0.1 ([CWD])
606606
[FINISHED] release [optimized] target(s) in [..]
607607
[RUNNING] target/release/deps/foo-[..][EXE]
608608
",
@@ -646,7 +646,7 @@ fn pass_through_command_line() {
646646
p.cargo("bench bar")
647647
.with_stderr(
648648
"\
649-
[COMPILING] foo v0.0.1 (CWD)
649+
[COMPILING] foo v0.0.1 ([CWD])
650650
[FINISHED] release [optimized] target(s) in [..]
651651
[RUNNING] target/release/deps/foo-[..][EXE]",
652652
).with_stdout_contains("test bar ... bench: [..]")
@@ -733,7 +733,7 @@ fn lib_bin_same_name() {
733733
p.cargo("bench")
734734
.with_stderr(
735735
"\
736-
[COMPILING] foo v0.0.1 (CWD)
736+
[COMPILING] foo v0.0.1 ([CWD])
737737
[FINISHED] release [optimized] target(s) in [..]
738738
[RUNNING] target/release/deps/foo-[..][EXE]
739739
[RUNNING] target/release/deps/foo-[..][EXE]",
@@ -779,7 +779,7 @@ fn lib_with_standard_name() {
779779
p.cargo("bench")
780780
.with_stderr(
781781
"\
782-
[COMPILING] syntax v0.0.1 (CWD)
782+
[COMPILING] syntax v0.0.1 ([CWD])
783783
[FINISHED] release [optimized] target(s) in [..]
784784
[RUNNING] target/release/deps/syntax-[..][EXE]
785785
[RUNNING] target/release/deps/bench-[..][EXE]",
@@ -828,7 +828,7 @@ fn lib_with_standard_name2() {
828828
p.cargo("bench")
829829
.with_stderr(
830830
"\
831-
[COMPILING] syntax v0.0.1 (CWD)
831+
[COMPILING] syntax v0.0.1 ([CWD])
832832
[FINISHED] release [optimized] target(s) in [..]
833833
[RUNNING] target/release/deps/syntax-[..][EXE]",
834834
).with_stdout_contains("test bench ... bench: [..]")
@@ -898,9 +898,9 @@ fn bench_dylib() {
898898
p.cargo("bench -v")
899899
.with_stderr(
900900
"\
901-
[COMPILING] bar v0.0.1 (CWD/bar)
901+
[COMPILING] bar v0.0.1 ([CWD]/bar)
902902
[RUNNING] [..] -C opt-level=3 [..]
903-
[COMPILING] foo v0.0.1 (CWD)
903+
[COMPILING] foo v0.0.1 ([CWD])
904904
[RUNNING] [..] -C opt-level=3 [..]
905905
[RUNNING] [..] -C opt-level=3 [..]
906906
[RUNNING] [..] -C opt-level=3 [..]
@@ -914,8 +914,8 @@ fn bench_dylib() {
914914
p.cargo("bench -v")
915915
.with_stderr(
916916
"\
917-
[FRESH] bar v0.0.1 (CWD/bar)
918-
[FRESH] foo v0.0.1 (CWD)
917+
[FRESH] bar v0.0.1 ([CWD]/bar)
918+
[FRESH] foo v0.0.1 ([CWD])
919919
[FINISHED] release [optimized] target(s) in [..]
920920
[RUNNING] `[..]target/release/deps/foo-[..][EXE] --bench`
921921
[RUNNING] `[..]target/release/deps/bench-[..][EXE] --bench`",
@@ -954,7 +954,7 @@ fn bench_twice_with_build_cmd() {
954954
p.cargo("bench")
955955
.with_stderr(
956956
"\
957-
[COMPILING] foo v0.0.1 (CWD)
957+
[COMPILING] foo v0.0.1 ([CWD])
958958
[FINISHED] release [optimized] target(s) in [..]
959959
[RUNNING] target/release/deps/foo-[..][EXE]",
960960
).with_stdout_contains("test foo ... bench: [..]")
@@ -1038,13 +1038,13 @@ fn bench_with_examples() {
10381038
p.cargo("bench -v")
10391039
.with_stderr(
10401040
"\
1041-
[COMPILING] foo v6.6.6 (CWD)
1041+
[COMPILING] foo v6.6.6 ([CWD])
10421042
[RUNNING] `rustc [..]`
10431043
[RUNNING] `rustc [..]`
10441044
[RUNNING] `rustc [..]`
10451045
[FINISHED] release [optimized] target(s) in [..]
1046-
[RUNNING] `CWD/target/release/deps/foo-[..][EXE] --bench`
1047-
[RUNNING] `CWD/target/release/deps/testb1-[..][EXE] --bench`",
1046+
[RUNNING] `[CWD]/target/release/deps/foo-[..][EXE] --bench`
1047+
[RUNNING] `[CWD]/target/release/deps/testb1-[..][EXE] --bench`",
10481048
).with_stdout_contains("test bench_bench1 ... bench: [..]")
10491049
.with_stdout_contains("test bench_bench2 ... bench: [..]")
10501050
.run();

0 commit comments

Comments
 (0)