Skip to content

Print file paths instead of file:// URLs. #5994

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/cargo/core/source/source_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl SourceId {
if self.is_default_registry() {
"crates.io index".to_string()
} else {
format!("`{}` index", self.url())
format!("`{}` index", url_display(self.url()))
}
}

Expand Down Expand Up @@ -367,20 +367,34 @@ impl<'de> de::Deserialize<'de> for SourceId {
}
}

fn url_display(url: &Url) -> String {
if url.scheme() == "file" {
if let Ok(path) = url.to_file_path() {
if let Some(path_str) = path.to_str() {
return path_str.to_string();
}
}
}

url.as_str().to_string()
}

impl fmt::Display for SourceId {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match *self.inner {
SourceIdInner {
kind: Kind::Path,
ref url,
..
} => fmt::Display::fmt(url, f),
} => write!(f, "{}", url_display(url)),
SourceIdInner {
kind: Kind::Git(ref reference),
ref url,
ref precise,
..
} => {
// Don't replace the URL display for git references,
// because those are kind of expected to be URLs.
write!(f, "{}", url)?;
if let Some(pretty) = reference.pretty_ref() {
write!(f, "?{}", pretty)?;
Expand All @@ -401,12 +415,12 @@ impl fmt::Display for SourceId {
kind: Kind::LocalRegistry,
ref url,
..
} => write!(f, "registry `{}`", url),
} => write!(f, "registry `{}`", url_display(url)),
SourceIdInner {
kind: Kind::Directory,
ref url,
..
} => write!(f, "dir {}", url),
} => write!(f, "dir {}", url_display(url)),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/doc/src/reference/specifying-dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,13 @@ In any case, typically all you need to do now is:

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

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

Expand Down
68 changes: 35 additions & 33 deletions tests/testsuite/alt_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ fn depend_on_alt_registry() {
.with_stderr(&format!(
"\
[UPDATING] `{reg}` index
[DOWNLOADING] bar v0.0.1 (registry `file://[..]`)
[COMPILING] bar v0.0.1 (registry `file://[..]`)
[COMPILING] foo v0.0.1 (CWD)
[DOWNLOADING] bar v0.0.1 (registry `[ROOT][..]`)
[COMPILING] bar v0.0.1 (registry `[ROOT][..]`)
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
",
reg = registry::alt_registry()
reg = registry::alt_registry_path().to_str().unwrap()
)).run();

p.cargo("clean").masquerade_as_nightly_cargo().run();
Expand All @@ -72,8 +72,8 @@ fn depend_on_alt_registry() {
.masquerade_as_nightly_cargo()
.with_stderr(
"\
[COMPILING] bar v0.0.1 (registry `file://[..]`)
[COMPILING] foo v0.0.1 (CWD)
[COMPILING] bar v0.0.1 (registry `[ROOT][..]`)
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
",
).run();
Expand Down Expand Up @@ -110,14 +110,14 @@ fn depend_on_alt_registry_depends_on_same_registry_no_index() {
.with_stderr(&format!(
"\
[UPDATING] `{reg}` index
[DOWNLOADING] [..] v0.0.1 (registry `file://[..]`)
[DOWNLOADING] [..] v0.0.1 (registry `file://[..]`)
[COMPILING] baz v0.0.1 (registry `file://[..]`)
[COMPILING] bar v0.0.1 (registry `file://[..]`)
[COMPILING] foo v0.0.1 (CWD)
[DOWNLOADING] [..] v0.0.1 (registry `[ROOT][..]`)
[DOWNLOADING] [..] v0.0.1 (registry `[ROOT][..]`)
[COMPILING] baz v0.0.1 (registry `[ROOT][..]`)
[COMPILING] bar v0.0.1 (registry `[ROOT][..]`)
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
",
reg = registry::alt_registry()
reg = registry::alt_registry_path().to_str().unwrap()
)).run();
}

Expand Down Expand Up @@ -152,14 +152,14 @@ fn depend_on_alt_registry_depends_on_same_registry() {
.with_stderr(&format!(
"\
[UPDATING] `{reg}` index
[DOWNLOADING] [..] v0.0.1 (registry `file://[..]`)
[DOWNLOADING] [..] v0.0.1 (registry `file://[..]`)
[COMPILING] baz v0.0.1 (registry `file://[..]`)
[COMPILING] bar v0.0.1 (registry `file://[..]`)
[COMPILING] foo v0.0.1 (CWD)
[DOWNLOADING] [..] v0.0.1 (registry `[ROOT][..]`)
[DOWNLOADING] [..] v0.0.1 (registry `[ROOT][..]`)
[COMPILING] baz v0.0.1 (registry `[ROOT][..]`)
[COMPILING] bar v0.0.1 (registry `[ROOT][..]`)
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
",
reg = registry::alt_registry()
reg = registry::alt_registry_path().to_str().unwrap()
)).run();
}

Expand Down Expand Up @@ -195,15 +195,15 @@ fn depend_on_alt_registry_depends_on_crates_io() {
"\
[UPDATING] `{alt_reg}` index
[UPDATING] `{reg}` index
[DOWNLOADING] [..] v0.0.1 (registry `file://[..]`)
[DOWNLOADING] [..] v0.0.1 (registry `file://[..]`)
[COMPILING] baz v0.0.1 (registry `file://[..]`)
[COMPILING] bar v0.0.1 (registry `file://[..]`)
[COMPILING] foo v0.0.1 (CWD)
[DOWNLOADING] [..] v0.0.1 (registry `[ROOT][..]`)
[DOWNLOADING] [..] v0.0.1 (registry `[ROOT][..]`)
[COMPILING] baz v0.0.1 (registry `[ROOT][..]`)
[COMPILING] bar v0.0.1 (registry `[ROOT][..]`)
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
",
alt_reg = registry::alt_registry(),
reg = registry::registry()
alt_reg = registry::alt_registry_path().to_str().unwrap(),
reg = registry::registry_path().to_str().unwrap()
)).run();
}

Expand Down Expand Up @@ -235,8 +235,8 @@ fn registry_and_path_dep_works() {
.masquerade_as_nightly_cargo()
.with_stderr(
"\
[COMPILING] bar v0.0.1 (CWD/bar)
[COMPILING] foo v0.0.1 (CWD)
[COMPILING] bar v0.0.1 ([CWD]/bar)
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s
",
).run();
Expand Down Expand Up @@ -359,13 +359,15 @@ fn alt_registry_and_crates_io_deps() {
.masquerade_as_nightly_cargo()
.with_stderr_contains(format!(
"[UPDATING] `{}` index",
registry::alt_registry()
)).with_stderr_contains(&format!("[UPDATING] `{}` index", registry::registry()))
.with_stderr_contains("[DOWNLOADING] crates_io_dep v0.0.1 (registry `file://[..]`)")
.with_stderr_contains("[DOWNLOADING] alt_reg_dep v0.1.0 (registry `file://[..]`)")
.with_stderr_contains("[COMPILING] alt_reg_dep v0.1.0 (registry `file://[..]`)")
registry::alt_registry_path().to_str().unwrap()
)).with_stderr_contains(&format!(
"[UPDATING] `{}` index",
registry::registry_path().to_str().unwrap()))
.with_stderr_contains("[DOWNLOADING] crates_io_dep v0.0.1 (registry `[ROOT][..]`)")
.with_stderr_contains("[DOWNLOADING] alt_reg_dep v0.1.0 (registry `[ROOT][..]`)")
.with_stderr_contains("[COMPILING] alt_reg_dep v0.1.0 (registry `[ROOT][..]`)")
.with_stderr_contains("[COMPILING] crates_io_dep v0.0.1")
.with_stderr_contains("[COMPILING] foo v0.0.1 (CWD)")
.with_stderr_contains("[COMPILING] foo v0.0.1 ([CWD])")
.with_stderr_contains("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]s")
.run();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/bad_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ fn unused_keys() {
.with_stderr(
"\
warning: unused manifest key: target.foo.bar
[COMPILING] foo v0.1.0 (CWD)
[COMPILING] foo v0.1.0 ([CWD])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
",
).run();
Expand Down
46 changes: 23 additions & 23 deletions tests/testsuite/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn cargo_bench_simple() {
p.cargo("bench")
.with_stderr(
"\
[COMPILING] foo v0.5.0 (CWD)
[COMPILING] foo v0.5.0 ([CWD])
[FINISHED] release [optimized] target(s) in [..]
[RUNNING] target/release/deps/foo-[..][EXE]",
).with_stdout_contains("test bench_hello ... bench: [..]")
Expand Down Expand Up @@ -78,7 +78,7 @@ fn bench_bench_implicit() {
p.cargo("bench --benches")
.with_stderr(
"\
[COMPILING] foo v0.0.1 (CWD)
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] release [optimized] target(s) in [..]
[RUNNING] target/release/deps/foo-[..][EXE]
[RUNNING] target/release/deps/mybench-[..][EXE]
Expand Down Expand Up @@ -119,7 +119,7 @@ fn bench_bin_implicit() {
p.cargo("bench --bins")
.with_stderr(
"\
[COMPILING] foo v0.0.1 (CWD)
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] release [optimized] target(s) in [..]
[RUNNING] target/release/deps/foo-[..][EXE]
",
Expand Down Expand Up @@ -151,7 +151,7 @@ fn bench_tarname() {
p.cargo("bench --bench bin2")
.with_stderr(
"\
[COMPILING] foo v0.0.1 (CWD)
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] release [optimized] target(s) in [..]
[RUNNING] target/release/deps/bin2-[..][EXE]
",
Expand Down Expand Up @@ -215,7 +215,7 @@ fn cargo_bench_verbose() {
p.cargo("bench -v hello")
.with_stderr(
"\
[COMPILING] foo v0.5.0 (CWD)
[COMPILING] foo v0.5.0 ([CWD])
[RUNNING] `rustc [..] src/main.rs [..]`
[FINISHED] release [optimized] target(s) in [..]
[RUNNING] `[..]target/release/deps/foo-[..][EXE] hello --bench`",
Expand Down Expand Up @@ -305,7 +305,7 @@ fn cargo_bench_failing_test() {
.with_stdout_contains("test bench_hello ...[..]")
.with_stderr_contains(
"\
[COMPILING] foo v0.5.0 (CWD)[..]
[COMPILING] foo v0.5.0 ([CWD])[..]
[FINISHED] release [optimized] target(s) in [..]
[RUNNING] target/release/deps/foo-[..][EXE]",
).with_either_contains(
Expand Down Expand Up @@ -372,7 +372,7 @@ fn bench_with_lib_dep() {
p.cargo("bench")
.with_stderr(
"\
[COMPILING] foo v0.0.1 (CWD)
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] release [optimized] target(s) in [..]
[RUNNING] target/release/deps/foo-[..][EXE]
[RUNNING] target/release/deps/baz-[..][EXE]",
Expand Down Expand Up @@ -433,7 +433,7 @@ fn bench_with_deep_lib_dep() {
.with_stderr(
"\
[COMPILING] foo v0.0.1 ([..])
[COMPILING] bar v0.0.1 (CWD)
[COMPILING] bar v0.0.1 ([CWD])
[FINISHED] release [optimized] target(s) in [..]
[RUNNING] target/release/deps/bar-[..][EXE]",
).with_stdout_contains("test bar_bench ... bench: [..]")
Expand Down Expand Up @@ -486,7 +486,7 @@ fn external_bench_explicit() {
p.cargo("bench")
.with_stderr(
"\
[COMPILING] foo v0.0.1 (CWD)
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] release [optimized] target(s) in [..]
[RUNNING] target/release/deps/foo-[..][EXE]
[RUNNING] target/release/deps/bench-[..][EXE]",
Expand Down Expand Up @@ -530,7 +530,7 @@ fn external_bench_implicit() {
p.cargo("bench")
.with_stderr(
"\
[COMPILING] foo v0.0.1 (CWD)
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] release [optimized] target(s) in [..]
[RUNNING] target/release/deps/foo-[..][EXE]
[RUNNING] target/release/deps/external-[..][EXE]",
Expand Down Expand Up @@ -602,7 +602,7 @@ automatically infer them to be a target, such as in subfolders.

For more information on this warning you can consult
https://github.com/rust-lang/cargo/issues/5330
[COMPILING] foo v0.0.1 (CWD)
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] release [optimized] target(s) in [..]
[RUNNING] target/release/deps/foo-[..][EXE]
",
Expand Down Expand Up @@ -646,7 +646,7 @@ fn pass_through_command_line() {
p.cargo("bench bar")
.with_stderr(
"\
[COMPILING] foo v0.0.1 (CWD)
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] release [optimized] target(s) in [..]
[RUNNING] target/release/deps/foo-[..][EXE]",
).with_stdout_contains("test bar ... bench: [..]")
Expand Down Expand Up @@ -733,7 +733,7 @@ fn lib_bin_same_name() {
p.cargo("bench")
.with_stderr(
"\
[COMPILING] foo v0.0.1 (CWD)
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] release [optimized] target(s) in [..]
[RUNNING] target/release/deps/foo-[..][EXE]
[RUNNING] target/release/deps/foo-[..][EXE]",
Expand Down Expand Up @@ -779,7 +779,7 @@ fn lib_with_standard_name() {
p.cargo("bench")
.with_stderr(
"\
[COMPILING] syntax v0.0.1 (CWD)
[COMPILING] syntax v0.0.1 ([CWD])
[FINISHED] release [optimized] target(s) in [..]
[RUNNING] target/release/deps/syntax-[..][EXE]
[RUNNING] target/release/deps/bench-[..][EXE]",
Expand Down Expand Up @@ -828,7 +828,7 @@ fn lib_with_standard_name2() {
p.cargo("bench")
.with_stderr(
"\
[COMPILING] syntax v0.0.1 (CWD)
[COMPILING] syntax v0.0.1 ([CWD])
[FINISHED] release [optimized] target(s) in [..]
[RUNNING] target/release/deps/syntax-[..][EXE]",
).with_stdout_contains("test bench ... bench: [..]")
Expand Down Expand Up @@ -898,9 +898,9 @@ fn bench_dylib() {
p.cargo("bench -v")
.with_stderr(
"\
[COMPILING] bar v0.0.1 (CWD/bar)
[COMPILING] bar v0.0.1 ([CWD]/bar)
[RUNNING] [..] -C opt-level=3 [..]
[COMPILING] foo v0.0.1 (CWD)
[COMPILING] foo v0.0.1 ([CWD])
[RUNNING] [..] -C opt-level=3 [..]
[RUNNING] [..] -C opt-level=3 [..]
[RUNNING] [..] -C opt-level=3 [..]
Expand All @@ -914,8 +914,8 @@ fn bench_dylib() {
p.cargo("bench -v")
.with_stderr(
"\
[FRESH] bar v0.0.1 (CWD/bar)
[FRESH] foo v0.0.1 (CWD)
[FRESH] bar v0.0.1 ([CWD]/bar)
[FRESH] foo v0.0.1 ([CWD])
[FINISHED] release [optimized] target(s) in [..]
[RUNNING] `[..]target/release/deps/foo-[..][EXE] --bench`
[RUNNING] `[..]target/release/deps/bench-[..][EXE] --bench`",
Expand Down Expand Up @@ -954,7 +954,7 @@ fn bench_twice_with_build_cmd() {
p.cargo("bench")
.with_stderr(
"\
[COMPILING] foo v0.0.1 (CWD)
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] release [optimized] target(s) in [..]
[RUNNING] target/release/deps/foo-[..][EXE]",
).with_stdout_contains("test foo ... bench: [..]")
Expand Down Expand Up @@ -1038,13 +1038,13 @@ fn bench_with_examples() {
p.cargo("bench -v")
.with_stderr(
"\
[COMPILING] foo v6.6.6 (CWD)
[COMPILING] foo v6.6.6 ([CWD])
[RUNNING] `rustc [..]`
[RUNNING] `rustc [..]`
[RUNNING] `rustc [..]`
[FINISHED] release [optimized] target(s) in [..]
[RUNNING] `CWD/target/release/deps/foo-[..][EXE] --bench`
[RUNNING] `CWD/target/release/deps/testb1-[..][EXE] --bench`",
[RUNNING] `[CWD]/target/release/deps/foo-[..][EXE] --bench`
[RUNNING] `[CWD]/target/release/deps/testb1-[..][EXE] --bench`",
).with_stdout_contains("test bench_bench1 ... bench: [..]")
.with_stdout_contains("test bench_bench2 ... bench: [..]")
.run();
Expand Down
Loading