mirror of
https://github.com/rust-lang/cargo
synced 2024-10-02 05:53:53 +00:00
Auto merge of #5361 - derekdreery:issue_5345, r=matklad
Fix issue 5345 Fixes #5345. Also adds some docs and Debug impls.
This commit is contained in:
commit
30bf81b575
|
@ -433,6 +433,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.
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -198,6 +198,7 @@ impl hash::Hash for Package {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct PackageSet<'cfg> {
|
||||
packages: HashMap<PackageId, LazyCell<Package>>,
|
||||
sources: RefCell<SourceMap<'cfg>>,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use std::collections::hash_map::{HashMap, IterMut, Values};
|
||||
use std::fmt;
|
||||
|
||||
use core::{Package, PackageId, Registry};
|
||||
use util::CargoResult;
|
||||
|
@ -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>>;
|
||||
|
||||
|
|
|
@ -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>,
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue