Skip to content
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

Fix issue 5345 #5361

Merged
merged 3 commits into from
Apr 17, 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
2 changes: 2 additions & 0 deletions src/cargo/core/compiler/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,8 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
self.unit_dependencies[unit].clone()
}

/// Whether a dependency should be compiled for the host or target platform,
/// specified by `Kind`.
fn dep_platform_activated(&self, dep: &Dependency, kind: Kind) -> bool {
// If this dependency is only available for certain platforms,
// make sure we're only enabling it for that platform.
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/context/unit_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ fn compute_deps_doc<'a, 'cfg>(
unit.pkg
.dependencies()
.iter()
.filter(|d| d.name() == dep.name())
.filter(|d| d.name() == dep.name() && d.version_req().matches(dep.version()))
.any(|dep| match dep.kind() {
DepKind::Normal => cx.dep_platform_activated(dep, unit.kind),
_ => false,
Expand Down
1 change: 1 addition & 0 deletions src/cargo/core/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ impl hash::Hash for Package {
}
}

#[derive(Debug)]
pub struct PackageSet<'cfg> {
packages: HashMap<PackageId, LazyCell<Package>>,
sources: RefCell<SourceMap<'cfg>>,
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ use self::types::{RcVecIter, RegistryQueryer};

pub use self::encode::{EncodableDependency, EncodablePackageId, EncodableResolve};
pub use self::encode::{Metadata, WorkspaceResolve};
pub use self::resolve::Resolve;
pub use self::resolve::{Resolve, Deps, DepsNotReplaced};
pub use self::types::Method;

mod context;
Expand Down
9 changes: 9 additions & 0 deletions src/cargo/core/source/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::collections::hash_map::{HashMap, IterMut, Values};
use std::fmt;

use core::{Package, PackageId, Registry};
use util::CargoResult;
Expand Down Expand Up @@ -78,6 +79,14 @@ pub struct SourceMap<'src> {
map: HashMap<SourceId, Box<Source + 'src>>,
}

// impl debug on source requires specialization, if even desirable at all
impl<'src> fmt::Debug for SourceMap<'src> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "SourceMap ")?;
f.debug_set().entries(self.map.keys()).finish()
}
}

/// A `std::collection::hash_map::Values` for `SourceMap`
pub type Sources<'a, 'src> = Values<'a, SourceId, Box<Source + 'src>>;

Expand Down
2 changes: 2 additions & 0 deletions src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ pub fn compile<'a>(
compile_with_exec(ws, options, Arc::new(DefaultExecutor))
}

/// Like `compile` but allows specifing a custom `Executor` that will be able to intercept build
/// calls and add custom logic. `compile` uses `DefaultExecutor` which just passes calls through.
pub fn compile_with_exec<'a>(
ws: &Workspace<'a>,
options: &CompileOptions<'a>,
Expand Down
5 changes: 5 additions & 0 deletions src/cargo/ops/cargo_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ use core::Workspace;
use ops;
use util::CargoResult;

/// Strongly typed options for the `cargo doc` command.
#[derive(Debug)]
pub struct DocOptions<'a> {
/// Whether to attempt to open the browser after compiling the docs
pub open_result: bool,
/// Options to pass through to the compiler
pub compile_opts: ops::CompileOptions<'a>,
}

/// Main method for `cargo doc`.
pub fn doc(ws: &Workspace, options: &DocOptions) -> CargoResult<()> {
let specs = options.compile_opts.spec.into_package_id_specs(ws)?;
let resolve = ops::resolve_ws_precisely(
Expand Down
29 changes: 29 additions & 0 deletions tests/testsuite/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1494,3 +1494,32 @@ fn doc_edition() {
.with_stderr_contains("[RUNNING] `rustdoc [..]-Zunstable-options --edition=2018[..]"),
);
}

// Tests an issue where depending on different versions of the same crate depending on `cfg`s
// caused `cargo doc` to fail.
#[test]
fn issue_5345() {
let foo = project("foo")
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
authors = []

[target.'cfg(all(windows, target_arch = "x86"))'.dependencies]
bar = "0.1"

[target.'cfg(not(all(windows, target_arch = "x86")))'.dependencies]
bar = "0.2"
"#,
)
.file("src/lib.rs", "extern crate bar;")
.build();
Package::new("bar", "0.1.0").publish();
Package::new("bar", "0.2.0").publish();

assert_that(foo.cargo("build"), execs().with_status(0));
assert_that(foo.cargo("doc"), execs().with_status(0));
}