Auto merge of #3781 - alexcrichton:beta-backport, r=alexcrichton

[backport] Fix deps with `cargo test --all` and doctests

This commit fixes `cargo test --all` with the way we ship libraries to `rustdoc
--test`. I'm... not entirely sure what the previous incarnation was doing but
the current organization is to interpret `compilation.libraries` as a mapping
from a package to the list of crates it needs to link to test.

This updates the support in `cargo_rustc/mod.rs` to create the map appropriately
and tweaks the loop in `cargo_test.rs` as well.

Closes rust-lang/rust#39879
This commit is contained in:
bors 2017-03-03 19:21:26 +00:00
commit f9e54817e5
9 changed files with 98 additions and 98 deletions

View File

@ -154,8 +154,3 @@ deploy:
on:
branch: auto-cargo
condition: $DEPLOY = 1
cache:
directories:
- $HOME/.cargo
- target/openssl

10
Cargo.lock generated
View File

@ -131,7 +131,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"gcc 0.3.39 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
"libz-sys 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
"libz-sys 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)",
"openssl-sys 0.9.6 (registry+https://github.com/rust-lang/crates.io-index)",
"pkg-config 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
@ -280,7 +280,7 @@ dependencies = [
"gcc 0.3.39 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
"libssh2-sys 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
"libz-sys 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
"libz-sys 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)",
"openssl-sys 0.9.6 (registry+https://github.com/rust-lang/crates.io-index)",
"pkg-config 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -292,14 +292,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cmake 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
"libz-sys 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)",
"libz-sys 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)",
"openssl-sys 0.9.6 (registry+https://github.com/rust-lang/crates.io-index)",
"pkg-config 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "libz-sys"
version = "1.0.10"
version = "1.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"gcc 0.3.39 (registry+https://github.com/rust-lang/crates.io-index)",
@ -673,7 +673,7 @@ dependencies = [
"checksum libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "a51822fc847e7a8101514d1d44e354ba2ffa7d4c194dcab48870740e327cac70"
"checksum libgit2-sys 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c7a4e33e9f8b8883c1a5898e72cdc63c00c4f2265283651533b00373094e901c"
"checksum libssh2-sys 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "91e135645c2e198a39552c8c7686bb5b83b1b99f64831c040a6c2798a1195934"
"checksum libz-sys 1.0.10 (registry+https://github.com/rust-lang/crates.io-index)" = "905c72a0c260bcd89ddca5afa1c46bebd29b52878a3d58c86865ea42402f88e6"
"checksum libz-sys 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)" = "e5ee912a45d686d393d5ac87fac15ba0ba18daae14e8e7543c63ebf7fb7e970c"
"checksum log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ab83497bf8bf4ed2a74259c1c802351fcd67a65baa86394b6ba73c36f4838054"
"checksum matches 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "efd7622e3022e1a6eaa602c4cea8912254e5582c9c692e9167714182244801b1"
"checksum memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d8b629fb514376c675b98c1421e80b151d3817ac42d7c667717d282761418d20"

View File

@ -45,10 +45,6 @@ build: false
test_script:
- sh src/ci/run.sh %TARGET%
cache:
- target
- C:\Users\appveyor\.cargo\registry
before_deploy:
- ps: |
New-Item -Path deploy -ItemType directory

View File

@ -8,11 +8,9 @@ use util::{self, CargoResult, Config, ProcessBuilder, process, join_paths};
/// A structure returning the result of a compilation.
pub struct Compilation<'cfg> {
/// All libraries which were built for a package.
///
/// This is currently used for passing --extern flags to rustdoc tests later
/// on.
pub libraries: HashMap<PackageId, Vec<(Target, PathBuf)>>,
/// A mapping from a package to the list of libraries that need to be
/// linked when working with that package.
pub libraries: HashMap<PackageId, HashSet<(Target, PathBuf)>>,
/// An array of all tests created during this compilation.
pub tests: Vec<(Package, String, PathBuf)>,

View File

@ -153,33 +153,31 @@ pub fn compile_targets<'a, 'cfg: 'a>(ws: &Workspace<'cfg>,
cx.compilation.binaries.push(bindst);
} else if unit.target.is_lib() {
let pkgid = unit.pkg.package_id().clone();
cx.compilation.libraries.entry(pkgid).or_insert(Vec::new())
.push((unit.target.clone(), dst));
cx.compilation.libraries.entry(pkgid).or_insert(HashSet::new())
.insert((unit.target.clone(), dst));
}
}
for dep in cx.dep_targets(unit)?.iter() {
if !unit.target.is_lib() { continue }
// Include immediate lib deps as well
for unit in cx.dep_targets(unit)?.iter() {
if unit.profile.run_custom_build {
let out_dir = cx.build_script_out_dir(unit).display().to_string();
cx.compilation.extra_env.entry(unit.pkg.package_id().clone())
.or_insert(Vec::new())
.push(("OUT_DIR".to_string(), out_dir));
}
let pkgid = unit.pkg.package_id();
if !unit.target.is_lib() { continue }
if unit.profile.doc { continue }
if cx.compilation.libraries.contains_key(&pkgid) {
continue
}
let v = cx.target_filenames(unit)?;
let v = v.into_iter().map(|(f, _, _)| {
(unit.target.clone(), f)
}).collect::<Vec<_>>();
cx.compilation.libraries.insert(pkgid.clone(), v);
if dep.profile.run_custom_build {
let out_dir = cx.build_script_out_dir(dep).display().to_string();
cx.compilation.extra_env.entry(dep.pkg.package_id().clone())
.or_insert(Vec::new())
.push(("OUT_DIR".to_string(), out_dir));
}
if !dep.target.is_lib() { continue }
if dep.profile.doc { continue }
let v = cx.target_filenames(dep)?;
cx.compilation.libraries
.entry(unit.pkg.package_id().clone())
.or_insert(HashSet::new())
.extend(v.into_iter().map(|(f, _, _)| {
(dep.target.clone(), f)
}));
}
if let Some(feats) = cx.resolve.features(&unit.pkg.package_id()) {

View File

@ -151,27 +151,26 @@ fn run_doc_tests(options: &TestOptions,
}
}
for (_, libs) in compilation.libraries.iter() {
for &(ref target, ref lib) in libs.iter() {
// Note that we can *only* doctest rlib outputs here. A
// staticlib output cannot be linked by the compiler (it just
// doesn't do that). A dylib output, however, can be linked by
// the compiler, but will always fail. Currently all dylibs are
// built as "static dylibs" where the standard library is
// statically linked into the dylib. The doc tests fail,
// however, for now as they try to link the standard library
// dynamically as well, causing problems. As a result we only
// pass `--extern` for rlib deps and skip out on all other
// artifacts.
if lib.extension() != Some(OsStr::new("rlib")) &&
!target.for_host() {
continue
}
let mut arg = OsString::from(target.crate_name());
arg.push("=");
arg.push(lib);
p.arg("--extern").arg(&arg);
let libs = &compilation.libraries[package.package_id()];
for &(ref target, ref lib) in libs.iter() {
// Note that we can *only* doctest rlib outputs here. A
// staticlib output cannot be linked by the compiler (it just
// doesn't do that). A dylib output, however, can be linked by
// the compiler, but will always fail. Currently all dylibs are
// built as "static dylibs" where the standard library is
// statically linked into the dylib. The doc tests fail,
// however, for now as they try to link the standard library
// dynamically as well, causing problems. As a result we only
// pass `--extern` for rlib deps and skip out on all other
// artifacts.
if lib.extension() != Some(OsStr::new("rlib")) &&
!target.for_host() {
continue
}
let mut arg = OsString::from(target.crate_name());
arg.push("=");
arg.push(lib);
p.arg("--extern").arg(&arg);
}
config.shell().verbose(|shell| {

View File

@ -2511,16 +2511,7 @@ fn compiler_json_error_format() {
"reason":"compiler-message",
"package_id":"bar 0.5.0 ([..])",
"target":{"kind":["lib"],"name":"bar","src_path":"[..]lib.rs"},
"message":{
"children":[],"code":null,"level":"warning","rendered":null,
"message":"function is never used: `dead`, #[warn(dead_code)] on by default",
"spans":[{
"byte_end":12,"byte_start":0,"column_end":13,"column_start":1,"expansion":null,
"file_name":"[..]","is_primary":true,"label":null,"line_end":1,"line_start":1,
"suggested_replacement":null,
"text":[{"highlight_end":13,"highlight_start":1,"text":"fn dead() {}"}]
}]
}
"message":"{...}"
}
{
@ -2541,16 +2532,7 @@ fn compiler_json_error_format() {
"reason":"compiler-message",
"package_id":"foo 0.5.0 ([..])",
"target":{"kind":["bin"],"name":"foo","src_path":"[..]main.rs"},
"message":{
"children":[],"code":null,"level":"warning","rendered":null,
"message":"unused variable: `unused`, #[warn(unused_variables)] on by default",
"spans":[{
"byte_end":22,"byte_start":16,"column_end":23,"column_start":17,"expansion":null,
"file_name":"[..]","is_primary":true,"label":null,"line_end":1,"line_start":1,
"suggested_replacement":null,
"text":[{"highlight_end":23,"highlight_start":17,"text":"[..]"}]
}]
}
"message":"{...}"
}
{
@ -2599,20 +2581,7 @@ fn message_format_json_forward_stderr() {
"reason":"compiler-message",
"package_id":"foo 0.5.0 ([..])",
"target":{"kind":["bin"],"name":"foo","src_path":"[..]"},
"message":{
"children":[],"code":null,"level":"warning","rendered":null,
"message":"unused variable: `unused`, #[warn(unused_variables)] on by default",
"spans":[{
"byte_end":22,"byte_start":16,"column_end":23,"column_start":17,"expansion":null,
"file_name":"[..]","is_primary":true,"label":null,"line_end":1,"line_start":1,
"suggested_replacement":null,
"text":[{
"highlight_end":23,
"highlight_start":17,
"text":"fn main() { let unused = 0; }"
}]
}]
}
"message":"{...}"
}
{

View File

@ -570,6 +570,8 @@ fn lines_match_works() {
// Compares JSON object for approximate equality.
// You can use `[..]` wildcard in strings (useful for OS dependent things such as paths).
// You can use a `"{...}"` string literal as a wildcard for arbitrary nested JSON (useful
// for parts of object emitted by other programs (e.g. rustc) rather than Cargo itself).
// Arrays are sorted before comparison.
fn find_mismatch<'a>(expected: &'a Json, actual: &'a Json) -> Option<(&'a Json, &'a Json)> {
use rustc_serialize::json::Json::*;
@ -586,8 +588,7 @@ fn find_mismatch<'a>(expected: &'a Json, actual: &'a Json) -> Option<(&'a Json,
fn sorted(xs: &Vec<Json>) -> Vec<&Json> {
let mut result = xs.iter().collect::<Vec<_>>();
// `unwrap` should be safe because JSON spec does not allow NaNs
result.sort_by(|x, y| x.partial_cmp(y).unwrap());
result.sort_by(|x, y| x.partial_cmp(y).expect("JSON spec does not allow NaNs"));
result
}
@ -606,6 +607,8 @@ fn find_mismatch<'a>(expected: &'a Json, actual: &'a Json) -> Option<(&'a Json,
.nth(0)
}
(&Null, &Null) => None,
// magic string literal "{...}" acts as wildcard for any sub-JSON
(&String(ref l), _) if l == "{...}" => None,
_ => Some((expected, actual)),
}

View File

@ -2557,3 +2557,45 @@ fn doctest_only_with_dev_dep() {
assert_that(p.cargo_process("test").arg("--doc").arg("-v"),
execs().with_status(0));
}
#[test]
fn doctest_and_registry() {
let p = project("workspace")
.file("Cargo.toml", r#"
[project]
name = "a"
version = "0.1.0"
[dependencies]
b = { path = "b" }
c = { path = "c" }
[workspace]
"#)
.file("src/lib.rs", "")
.file("b/Cargo.toml", r#"
[project]
name = "b"
version = "0.1.0"
"#)
.file("b/src/lib.rs", "
/// ```
/// b::foo();
/// ```
pub fn foo() {}
")
.file("c/Cargo.toml", r#"
[project]
name = "c"
version = "0.1.0"
[dependencies]
b = "0.1"
"#)
.file("c/src/lib.rs", "");
Package::new("b", "0.1.0").publish();
assert_that(p.cargo_process("test").arg("--all").arg("-v"),
execs().with_status(0));
}