Skip to content

Commit

Permalink
Auto merge of #4295 - xftroxgpx:use_full_path_in_warning_for_issue429…
Browse files Browse the repository at this point in the history
…3, r=matklad

Fixes #4293

locally tested with:
`cargo test legacy_ many_crate_types_old_style_lib_location`
  • Loading branch information
bors committed Jul 18, 2017
2 parents 93b444f + 41df5d1 commit baa2e8a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 36 deletions.
46 changes: 15 additions & 31 deletions src/cargo/util/toml/targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use std::collections::HashSet;
use core::Target;
use ops::is_bad_artifact_name;
use util::errors::CargoResult;
use util::paths::without_prefix;
use super::{TomlTarget, LibKind, PathValue, TomlManifest, StringOrBool,
TomlLibTarget, TomlBinTarget, TomlBenchTarget, TomlExampleTarget, TomlTestTarget};

Expand Down Expand Up @@ -105,16 +104,11 @@ fn clean_lib(toml_lib: Option<&TomlLibTarget>,
(None, None) => {
let legacy_path = package_root.join("src").join(format!("{}.rs", lib.name()));
if legacy_path.exists() {
{
let short_path = without_prefix(&legacy_path, package_root)
.unwrap_or(&legacy_path);

warnings.push(format!(
"path `{}` was erroneously implicitly accepted for library `{}`,\n\
please rename the file to `src/lib.rs` or set lib.path in Cargo.toml",
short_path.display(), lib.name()
));
}
warnings.push(format!(
"path `{}` was erroneously implicitly accepted for library `{}`,\n\
please rename the file to `src/lib.rs` or set lib.path in Cargo.toml",
legacy_path.display(), lib.name()
));
legacy_path
} else {
bail!("can't find library `{}`, \
Expand Down Expand Up @@ -177,16 +171,11 @@ fn clean_bins(toml_bins: Option<&Vec<TomlBinTarget>>,
for bin in bins.iter() {
let path = target_path(bin, &inferred, "bin", package_root, &mut |_| {
if let Some(legacy_path) = legacy_bin_path(package_root, &bin.name(), has_lib) {
{
let short_path = without_prefix(&legacy_path, package_root)
.unwrap_or(&legacy_path);

warnings.push(format!(
"path `{}` was erroneously implicitly accepted for binary `{}`,\n\
please set bin.path in Cargo.toml",
short_path.display(), bin.name()
));
}
warnings.push(format!(
"path `{}` was erroneously implicitly accepted for binary `{}`,\n\
please set bin.path in Cargo.toml",
legacy_path.display(), bin.name()
));
Some(legacy_path)
} else {
None
Expand Down Expand Up @@ -267,16 +256,11 @@ fn clean_benches(toml_benches: Option<&Vec<TomlBenchTarget>>,
if !(bench.name() == "bench" && legacy_path.exists()) {
return None;
}
{
let short_path = without_prefix(&legacy_path, package_root)
.unwrap_or(&legacy_path);

warnings.push(format!(
"path `{}` was erroneously implicitly accepted for benchmark `{}`,\n\
please set bench.path in Cargo.toml",
short_path.display(), bench.name()
));
}
warnings.push(format!(
"path `{}` was erroneously implicitly accepted for benchmark `{}`,\n\
please set bench.path in Cargo.toml",
legacy_path.display(), bench.name()
));
Some(legacy_path)
};

Expand Down
2 changes: 1 addition & 1 deletion tests/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,6 @@ fn legacy_bench_name() {
"#);

assert_that(p.cargo_process("bench"), execs().with_status(0).with_stderr_contains("\
[WARNING] path `src[/]bench.rs` was erroneously implicitly accepted for benchmark `bench`,
[WARNING] path `[..]src[/]bench.rs` was erroneously implicitly accepted for benchmark `bench`,
please set bench.path in Cargo.toml"));
}
8 changes: 4 additions & 4 deletions tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@ fn many_crate_types_old_style_lib_location() {
pub fn foo() {}
"#);
assert_that(p.cargo_process("build"), execs().with_status(0).with_stderr_contains("\
[WARNING] path `src[/]foo.rs` was erroneously implicitly accepted for library `foo`,
[WARNING] path `[..]src[/]foo.rs` was erroneously implicitly accepted for library `foo`,
please rename the file to `src/lib.rs` or set lib.path in Cargo.toml"));

assert_that(&p.root().join("target/debug/libfoo.rlib"), existing_file());
Expand Down Expand Up @@ -1402,7 +1402,7 @@ fn legacy_binary_paths_warinigs() {
.file("src/main.rs", "fn main() {}");

assert_that(p.cargo_process("build").arg("-v"), execs().with_status(0).with_stderr_contains("\
[WARNING] path `src[/]main.rs` was erroneously implicitly accepted for binary `bar`,
[WARNING] path `[..]src[/]main.rs` was erroneously implicitly accepted for binary `bar`,
please set bin.path in Cargo.toml"));

let mut p = project("world");
Expand All @@ -1419,7 +1419,7 @@ please set bin.path in Cargo.toml"));
.file("src/bin/main.rs", "fn main() {}");

assert_that(p.cargo_process("build").arg("-v"), execs().with_status(0).with_stderr_contains("\
[WARNING] path `src[/]bin[/]main.rs` was erroneously implicitly accepted for binary `bar`,
[WARNING] path `[..]src[/]bin[/]main.rs` was erroneously implicitly accepted for binary `bar`,
please set bin.path in Cargo.toml"));

let mut p = project("world");
Expand All @@ -1435,7 +1435,7 @@ please set bin.path in Cargo.toml"));
.file("src/bar.rs", "fn main() {}");

assert_that(p.cargo_process("build").arg("-v"), execs().with_status(0).with_stderr_contains("\
[WARNING] path `src[/]bar.rs` was erroneously implicitly accepted for binary `bar`,
[WARNING] path `[..]src[/]bar.rs` was erroneously implicitly accepted for binary `bar`,
please set bin.path in Cargo.toml"));
}

Expand Down

0 comments on commit baa2e8a

Please sign in to comment.