Further improve doubly-linked error-msg
authorLukas Lueg <lukas.lueg@gmail.com>
Thu, 21 Sep 2017 15:08:51 +0000 (17:08 +0200)
committerLukas Lueg <lukas.lueg@gmail.com>
Thu, 21 Sep 2017 15:08:51 +0000 (17:08 +0200)
src/cargo/ops/cargo_rustc/links.rs
tests/build-script.rs

index 7c8d251a64916b10bf12008b172e56a742c87be2..79bb240cf82b38cc9197afb5d3e0169e0ede4fab 100644 (file)
@@ -32,37 +32,27 @@ impl<'a> Links<'a> {
             let describe_path = |pkgid: &PackageId| -> String {
                 let dep_path = resolve.path_to_top(pkgid);
                 if dep_path.is_empty() {
-                    String::from("(This is the root-package)")
+                    String::from("The root-package ")
                 } else {
-                    let mut pkg_path_desc = String::from("(Dependency via ");
-                    let mut dep_path_iter = dep_path.into_iter().peekable();
-                    while let Some(dep) = dep_path_iter.next() {
-                        write!(pkg_path_desc, "{}", dep).unwrap();
-                        if dep_path_iter.peek().is_some() {
-                            pkg_path_desc.push_str(" => ");
-                        }
+                    let mut dep_path_desc = format!("Package `{}`\n", pkgid);
+                    for dep in dep_path {
+                        write!(dep_path_desc,
+                               "    ... which is depended on by `{}`\n",
+                               dep).unwrap();
                     }
-                    pkg_path_desc.push(')');
-                    pkg_path_desc
+                    dep_path_desc
                 }
             };
 
-            bail!("More than one package links to native library `{}`, \
-                   which can only be linked once.\n\n\
-                   Package {} links to native library `{}`.\n\
-                   {}\n\
+            bail!("Multiple packages link to native library `{}`. \
+                   A native library can be linked only once.\n\
                    \n\
-                   Package {} also links to native library `{}`.\n\
-                   {}\n\
+                   {}links to native library `{}`.\n\
                    \n\
-                   Try updating or pinning your dependencies to ensure that \
-                   native library `{}` is only linked once.",
+                   {}also links to native library `{}`.",
                   lib,
-                  prev, lib,
-                  describe_path(prev),
-                  pkg, lib,
-                  describe_path(pkg),
-                  lib)
+                  describe_path(prev), lib,
+                  describe_path(pkg), lib)
         }
         if !unit.pkg.manifest().targets().iter().any(|t| t.is_custom_build()) {
             bail!("package `{}` specifies that it links to `{}` but does not \
index fd0dc95503efabc2ca481d1ddf64e2124053524b..4e7a5816f69fdf8dab3f95ee0d24f0cd97640934 100644 (file)
@@ -248,16 +248,14 @@ fn links_duplicates() {
     assert_that(p.cargo_process("build"),
                 execs().with_status(101)
                        .with_stderr("\
-error: More than one package links to native library `a`, which can only be \
-linked once.
+[ERROR] Multiple packages link to native library `a`. A native library can be \
+linked only once.
 
-Package foo v0.5.0 (file://[..]) links to native library `a`.
-(This is the root-package)
+The root-package links to native library `a`.
 
-Package a-sys v0.5.0 (file://[..]) also links to native library `a`.
-(Dependency via foo v0.5.0 (file://[..]))
-
-Try updating[..]
+Package `a-sys v0.5.0 (file://[..])`
+    ... which is depended on by `foo v0.5.0 (file://[..])`
+also links to native library `a`.
 "));
 }
 
@@ -303,16 +301,15 @@ fn links_duplicates_deep_dependency() {
     assert_that(p.cargo_process("build"),
                 execs().with_status(101)
                        .with_stderr("\
-error: More than one package links to native library `a`, which can only be \
-linked once.
-
-Package foo v0.5.0 (file://[..]) links to native library `a`.
-(This is the root-package)
+[ERROR] Multiple packages link to native library `a`. A native library can be \
+linked only once.
 
-Package a-sys v0.5.0 (file://[..]) also links to native library `a`.
-(Dependency via a v0.5.0 (file://[..]) => foo v0.5.0 (file://[..]))
+The root-package links to native library `a`.
 
-Try updating[..]
+Package `a-sys v0.5.0 (file://[..])`
+    ... which is depended on by `a v0.5.0 (file://[..])`
+    ... which is depended on by `foo v0.5.0 (file://[..])`
+also links to native library `a`.
 "));
 }