Skip to content

Commit 83863ea

Browse files
committed
cargo doc --open always respect request_kind
1 parent 234d9f6 commit 83863ea

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

src/cargo/core/compiler/compilation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub struct Compilation<'cfg> {
5656
pub cdylibs: Vec<UnitOutput>,
5757

5858
/// The crate names of the root units specified on the command-line.
59-
pub root_crate_names: Vec<String>,
59+
pub root_crate_names: Vec<(String, CompileKind)>,
6060

6161
/// All directories for the output of native build commands.
6262
///

src/cargo/core/compiler/context/mod.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,12 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
321321
}
322322
self.primary_packages
323323
.extend(self.bcx.roots.iter().map(|u| u.pkg.package_id()));
324-
self.compilation
325-
.root_crate_names
326-
.extend(self.bcx.roots.iter().map(|u| u.target.crate_name()));
324+
self.compilation.root_crate_names.extend(
325+
self.bcx
326+
.roots
327+
.iter()
328+
.map(|u| (u.target.crate_name(), u.kind.clone())),
329+
);
327330

328331
self.record_units_requiring_metadata();
329332

src/cargo/ops/cargo_doc.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,21 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions) -> CargoResult<()> {
2020
let compilation = ops::compile(ws, &options.compile_opts)?;
2121

2222
if options.open_result {
23-
let name = &compilation
23+
// The open behavior is as follows:
24+
// cargo doc --open:
25+
// - Pick the first root unit that was built for host.
26+
// - If none found, pick the first one(whatever it's target is).
27+
// cargo doc --target TARGET --open:
28+
// - Pick the first root unit for the given target.
29+
// - If none found, pick the first one(whatever it's target is).
30+
let request_kind = options.compile_opts.build_config.single_requested_kind()?;
31+
let (name, kind) = &compilation
2432
.root_crate_names
25-
.get(0)
33+
.iter()
34+
.find(|(_, kind)| *kind == request_kind)
35+
.or_else(|| compilation.root_crate_names.get(0))
2636
.ok_or_else(|| anyhow::anyhow!("no crates with documentation"))?;
27-
let kind = options.compile_opts.build_config.single_requested_kind()?;
37+
2838
let path = compilation.root_output[&kind]
2939
.with_file_name("doc")
3040
.join(&name)

0 commit comments

Comments
 (0)