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 --document-private-items for multiple targets. #6022

Merged
merged 1 commit into from
Sep 13, 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
1 change: 1 addition & 0 deletions src/bin/cargo/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ pub trait ArgMatchesExt {
),
target_rustdoc_args: None,
target_rustc_args: None,
local_rustdoc_args: None,
export_dir: None,
};
Ok(opts)
Expand Down
2 changes: 1 addition & 1 deletion src/bin/cargo/commands/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
deps: !args.is_present("no-deps"),
};
let mut compile_opts = args.compile_options(config, mode)?;
compile_opts.target_rustdoc_args = if args.is_present("document-private-items") {
compile_opts.local_rustdoc_args = if args.is_present("document-private-items") {
Some(vec!["--document-private-items".to_string()])
} else {
None
Expand Down
17 changes: 4 additions & 13 deletions src/cargo/core/compiler/build_context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,8 @@ pub struct BuildContext<'a, 'cfg: 'a> {
pub resolve: &'a Resolve,
pub profiles: &'a Profiles,
pub build_config: &'a BuildConfig,
/// This is a workaround to carry the extra compiler args for either
/// `rustc` or `rustdoc` given on the command-line for the commands `cargo
/// rustc` and `cargo rustdoc`. These commands only support one target,
/// but we don't want the args passed to any dependencies, so we include
/// the `Unit` corresponding to the top-level target.
pub extra_compiler_args: Option<(Unit<'a>, Vec<String>)>,
/// Extra compiler args for either `rustc` or `rustdoc`.
pub extra_compiler_args: HashMap<Unit<'a>, Vec<String>>,
pub packages: &'a PackageSet<'cfg>,

/// Information about the compiler
Expand All @@ -51,7 +47,7 @@ impl<'a, 'cfg> BuildContext<'a, 'cfg> {
config: &'cfg Config,
build_config: &'a BuildConfig,
profiles: &'a Profiles,
extra_compiler_args: Option<(Unit<'a>, Vec<String>)>,
extra_compiler_args: HashMap<Unit<'a>, Vec<String>>,
) -> CargoResult<BuildContext<'a, 'cfg>> {
let incremental_env = match env::var("CARGO_INCREMENTAL") {
Ok(v) => Some(v == "1"),
Expand Down Expand Up @@ -200,12 +196,7 @@ impl<'a, 'cfg> BuildContext<'a, 'cfg> {
}

pub fn extra_args_for(&self, unit: &Unit<'a>) -> Option<&Vec<String>> {
if let Some((ref args_unit, ref args)) = self.extra_compiler_args {
if args_unit == unit {
return Some(args);
}
}
None
self.extra_compiler_args.get(unit)
}

/// Return the list of filenames read by cargo to generate the BuildContext
Expand Down
3 changes: 2 additions & 1 deletion src/cargo/ops/cargo_clean.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::collections::HashMap;
use std::fs;
use std::path::Path;

Expand Down Expand Up @@ -97,7 +98,7 @@ pub fn clean(ws: &Workspace, opts: &CleanOptions) -> CargoResult<()> {
opts.config,
&build_config,
profiles,
None,
HashMap::new(),
)?;
let mut cx = Context::new(config, &bcx)?;
cx.prepare_units(None, &units)?;
Expand Down
18 changes: 14 additions & 4 deletions src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ pub struct CompileOptions<'a> {
/// Filter to apply to the root package to select which targets will be
/// built.
pub filter: CompileFilter,
/// Extra arguments to be passed to rustdoc (for main crate and dependencies)
/// Extra arguments to be passed to rustdoc (single target only)
pub target_rustdoc_args: Option<Vec<String>>,
/// The specified target will be compiled with all the available arguments,
/// note that this only accounts for the *final* invocation of rustc
pub target_rustc_args: Option<Vec<String>>,
/// Extra arguments passed to all selected targets for rustdoc.
pub local_rustdoc_args: Option<Vec<String>>,
/// The directory to copy final artifacts to. Note that even if `out_dir` is
/// set, a copy of artifacts still could be found a `target/(debug\release)`
/// as usual.
Expand All @@ -80,6 +82,7 @@ impl<'a> CompileOptions<'a> {
},
target_rustdoc_args: None,
target_rustc_args: None,
local_rustdoc_args: None,
export_dir: None,
})
}
Expand Down Expand Up @@ -219,6 +222,7 @@ pub fn compile_ws<'a>(
ref filter,
ref target_rustdoc_args,
ref target_rustc_args,
ref local_rustdoc_args,
ref export_dir,
} = *options;

Expand Down Expand Up @@ -265,8 +269,6 @@ pub fn compile_ws<'a>(
let profiles = ws.profiles();
profiles.validate_packages(&mut config.shell(), &packages)?;

let mut extra_compiler_args = None;

let units = generate_targets(
ws,
profiles,
Expand All @@ -277,6 +279,7 @@ pub fn compile_ws<'a>(
build_config,
)?;

let mut extra_compiler_args = HashMap::new();
if let Some(args) = extra_args {
if units.len() != 1 {
bail!(
Expand All @@ -286,7 +289,14 @@ pub fn compile_ws<'a>(
extra_args_name
);
}
extra_compiler_args = Some((units[0], args));
extra_compiler_args.insert(units[0], args);
}
if let Some(args) = local_rustdoc_args {
for unit in &units {
if unit.mode.is_doc() {
extra_compiler_args.insert(*unit, args.clone());
}
}
}

let ret = {
Expand Down
1 change: 1 addition & 0 deletions src/cargo/ops/cargo_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ fn run_verify(ws: &Workspace, tar: &FileLock, opts: &PackageOpts) -> CargoResult
},
target_rustdoc_args: None,
target_rustc_args: None,
local_rustdoc_args: None,
export_dir: None,
},
&exec,
Expand Down
25 changes: 25 additions & 0 deletions tests/testsuite/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,31 @@ fn doc_private_items() {
);
}

#[test]
fn doc_private_ws() {
let p = project()
.file(
"Cargo.toml",
r#"
[workspace]
members = ["a", "b"]
"#,
).file("a/Cargo.toml", &basic_manifest("a", "0.0.1"))
.file("a/src/lib.rs", "fn p() {}")
.file("b/Cargo.toml", &basic_manifest("b", "0.0.1"))
.file("b/src/lib.rs", "fn p2() {}")
.file("b/src/main.rs", "fn main() {}")
.build();
p.cargo("doc --all --bins --lib --document-private-items -v")
.with_stderr_contains(
"[RUNNING] `rustdoc [..] a/src/lib.rs [..]--document-private-items[..]",
).with_stderr_contains(
"[RUNNING] `rustdoc [..] b/src/lib.rs [..]--document-private-items[..]",
).with_stderr_contains(
"[RUNNING] `rustdoc [..] b/src/main.rs [..]--document-private-items[..]",
).run();
}

const BAD_INTRA_LINK_LIB: &str = r#"
#![deny(intra_doc_link_resolution_failure)]

Expand Down