From: George Hilliard Date: Sat, 15 Aug 2015 19:49:09 +0000 (-0500) Subject: Warn about and ignore invalid crate-types in manifest X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~22^2~17^2~109^2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=c2e6ba899d1b9cdf6d12f720870b7f8b0765f1d9;p=cargo.git Warn about and ignore invalid crate-types in manifest --- diff --git a/src/cargo/core/manifest.rs b/src/cargo/core/manifest.rs index 9b7907cc7..cc09b2d12 100644 --- a/src/cargo/core/manifest.rs +++ b/src/cargo/core/manifest.rs @@ -79,7 +79,7 @@ impl LibKind { "rlib" => Ok(LibKind::Rlib), "dylib" => Ok(LibKind::Dylib), "staticlib" => Ok(LibKind::StaticLib), - _ => Err(human(format!("{} was not one of lib|rlib|dylib|staticlib", + _ => Err(human(format!("crate-type \"{}\" was not one of lib|rlib|dylib|staticlib", string))) } } diff --git a/src/cargo/util/toml.rs b/src/cargo/util/toml.rs index 2b488beb8..f3a16517c 100644 --- a/src/cargo/util/toml.rs +++ b/src/cargo/util/toml.rs @@ -369,6 +369,7 @@ impl TomlManifest { config: &Config) -> CargoResult<(Manifest, Vec)> { let mut nested_paths = vec!(); + let mut warnings = vec!(); let project = self.project.as_ref().or_else(|| self.package.as_ref()); let project = try!(project.chain_error(|| { @@ -473,7 +474,8 @@ impl TomlManifest { &examples, &tests, &benches, - &metadata); + &metadata, + &mut warnings); if targets.is_empty() { debug!("manifest has no build targets"); @@ -550,6 +552,9 @@ impl TomlManifest { manifest.add_warning(format!("warning: only one of `license` or \ `license-file` is necessary")); } + for warning in warnings { + manifest.add_warning(warning.clone()); + } Ok((manifest, nested_paths)) } @@ -749,7 +754,8 @@ fn normalize(lib: &Option, examples: &[TomlExampleTarget], tests: &[TomlTestTarget], benches: &[TomlBenchTarget], - metadata: &Metadata) -> Vec { + metadata: &Metadata, + warnings: &mut Vec) -> Vec { fn configure(toml: &TomlTarget, target: &mut Target) { let t2 = target.clone(); target.set_tested(toml.test.unwrap_or(t2.tested())) @@ -760,19 +766,32 @@ fn normalize(lib: &Option, .set_for_host(toml.plugin.unwrap_or(t2.for_host())); } - fn lib_target(dst: &mut Vec, l: &TomlLibTarget, - metadata: &Metadata) { - let path = l.path.clone().unwrap_or_else(|| { + fn lib_target(dst: &mut Vec, + l: &TomlLibTarget, + metadata: &Metadata, + warnings: &mut Vec) { + let path = l.path.clone().unwrap_or( PathValue::Path(Path::new("src").join(&format!("{}.rs", l.name()))) - }); - let crate_types = l.crate_type.clone().and_then(|kinds| { - kinds.iter().map(|s| LibKind::from_str(s)) - .collect::>().ok() - }).unwrap_or_else(|| { - vec![if l.plugin == Some(true) {LibKind::Dylib} else {LibKind::Lib}] - }); - - let mut target = Target::lib_target(&l.name(), crate_types.clone(), + ); + let crate_types = match l.crate_type.clone() { + Some(kinds) => { + // For now, merely warn about invalid crate types. + // In the future, it might be nice to make them errors. + kinds.iter().filter_map(|s| { + let kind = LibKind::from_str(s); + if let Err(ref error) = kind { + warnings.push(format!("warning: {}", error)) + } + kind.ok() + }).collect() + } + None => { + vec![ if l.plugin == Some(true) {LibKind::Dylib} + else {LibKind::Lib} ] + } + }; + + let mut target = Target::lib_target(&l.name(), crate_types, &path.to_path(), metadata.clone()); configure(l, &mut target); @@ -855,7 +874,7 @@ fn normalize(lib: &Option, let mut ret = Vec::new(); if let Some(ref lib) = *lib { - lib_target(&mut ret, lib, metadata); + lib_target(&mut ret, lib, metadata, warnings); bin_targets(&mut ret, bins, &mut |bin| Path::new("src").join("bin") .join(&format!("{}.rs", bin.name()))); diff --git a/tests/test_bad_config.rs b/tests/test_bad_config.rs index cc4008e5b..069783906 100644 --- a/tests/test_bad_config.rs +++ b/tests/test_bad_config.rs @@ -239,3 +239,22 @@ Caused by: [7] 'file:///' is not a valid local file URI ")); }); + +test!(bad_crate_type { + let foo = project("foo") + .file("Cargo.toml", r#" + [package] + name = "foo" + version = "0.0.0" + authors = [] + + [lib] + crate-type = ["bad_type", "rlib"] + "#) + .file("src/lib.rs", ""); + + assert_that(foo.cargo_process("build").arg("-v"), + execs().with_status(0).with_stderr("\ +warning: crate-type \"bad_type\" was not one of lib|rlib|dylib|staticlib +")); +});