Skip to content

Commit

Permalink
Auto merge of #8509 - ehuss:stabilize-crate-version, r=Eh2406
Browse files Browse the repository at this point in the history
Stabilize -Z crate-versions

This stabilizes the `-Z crate-versions` flag which forwards the crate version to rustdoc so it can display the version in the sidebar.

The flag in rustdoc was stabilized in 1.44.

Closes #7907
  • Loading branch information
bors committed Jul 23, 2020
2 parents eb7bc68 + 3ce3d34 commit dbbab42
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 49 deletions.
1 change: 0 additions & 1 deletion src/bin/cargo/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ Available unstable (nightly-only) flags:
-Z unstable-options -- Allow the usage of unstable options
-Z timings -- Display concurrency information
-Z doctest-xcompile -- Compile and run doctests for non-host target using runner config
-Z crate-versions -- Add crate versions to generated docs
-Z terminal-width -- Provide a terminal width to rustc for error truncation
Run with 'cargo -Z [FLAG] [SUBCOMMAND]'"
Expand Down
14 changes: 3 additions & 11 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,9 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {

rustdoc.args(bcx.rustdocflags_args(unit));

add_crate_versions_if_requested(bcx, unit, &mut rustdoc);
if !crate_version_flag_already_present(&rustdoc) {
append_crate_version_flag(unit, &mut rustdoc);
}

let name = unit.pkg.name().to_string();
let build_script_outputs = Arc::clone(&cx.build_script_outputs);
Expand Down Expand Up @@ -617,16 +619,6 @@ fn rustdoc(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Work> {
}))
}

fn add_crate_versions_if_requested(
bcx: &BuildContext<'_, '_>,
unit: &Unit,
rustdoc: &mut ProcessBuilder,
) {
if bcx.config.cli_unstable().crate_versions && !crate_version_flag_already_present(rustdoc) {
append_crate_version_flag(unit, rustdoc);
}
}

// The --crate-version flag could have already been passed in RUSTDOCFLAGS
// or as an extra compiler argument for rustdoc
fn crate_version_flag_already_present(rustdoc: &ProcessBuilder) -> bool {
Expand Down
2 changes: 0 additions & 2 deletions src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ pub struct CliUnstable {
pub panic_abort_tests: bool,
pub jobserver_per_rustc: bool,
pub features: Option<Vec<String>>,
pub crate_versions: bool,
pub separate_nightlies: bool,
pub multitarget: bool,
pub rustdoc_map: bool,
Expand Down Expand Up @@ -462,7 +461,6 @@ impl CliUnstable {
"panic-abort-tests" => self.panic_abort_tests = parse_empty(k, v)?,
"jobserver-per-rustc" => self.jobserver_per_rustc = parse_empty(k, v)?,
"features" => self.features = Some(parse_features(v)),
"crate-versions" => self.crate_versions = parse_empty(k, v)?,
"separate-nightlies" => self.separate_nightlies = parse_empty(k, v)?,
"multitarget" => self.multitarget = parse_empty(k, v)?,
"rustdoc-map" => self.rustdoc_map = parse_empty(k, v)?,
Expand Down
7 changes: 0 additions & 7 deletions src/doc/src/reference/unstable.md
Original file line number Diff line number Diff line change
Expand Up @@ -646,13 +646,6 @@ resolver = "2"
The `resolver` field is ignored in dependencies, only the top-level project or
workspace can control the new behavior.

### crate-versions
* Tracking Issue: [#7907](/~https://github.com/rust-lang/cargo/issues/7907)

The `-Z crate-versions` flag will make `cargo doc` include appropriate crate versions for the current crate and all of its dependencies (unless `--no-deps` was provided) in the compiled documentation.

You can find an example screenshot for the cargo itself in the tracking issue.

### unit-graph
* Tracking Issue: [#8002](/~https://github.com/rust-lang/cargo/issues/8002)

Expand Down
25 changes: 10 additions & 15 deletions tests/testsuite/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1479,10 +1479,6 @@ fn bin_private_items_deps() {

#[cargo_test]
fn crate_versions() {
// Testing flag that will reach stable on 1.44
if !is_nightly() {
return;
}
let p = project()
.file(
"Cargo.toml",
Expand All @@ -1496,8 +1492,14 @@ fn crate_versions() {
.file("src/lib.rs", "")
.build();

p.cargo("-Z crate-versions doc")
.masquerade_as_nightly_cargo()
p.cargo("doc -v")
.with_stderr(
"\
[DOCUMENTING] foo v1.2.4 [..]
[RUNNING] `rustdoc --crate-type lib --crate-name foo src/lib.rs [..]--crate-version 1.2.4`
[FINISHED] [..]
",
)
.run();

let output_path = p.root().join("target/doc/foo/index.html");
Expand All @@ -1508,10 +1510,6 @@ fn crate_versions() {

#[cargo_test]
fn crate_versions_flag_is_overridden() {
// Testing flag that will reach stable on 1.44
if !is_nightly() {
return;
}
let p = project()
.file(
"Cargo.toml",
Expand All @@ -1534,16 +1532,13 @@ fn crate_versions_flag_is_overridden() {
assert!(html.contains("Version 2.0.3"));
};

p.cargo("-Z crate-versions doc")
.masquerade_as_nightly_cargo()
p.cargo("doc")
.env("RUSTDOCFLAGS", "--crate-version 2.0.3")
.run();
asserts(output_documentation());

p.build_dir().rm_rf();

p.cargo("-Z crate-versions rustdoc -- --crate-version 2.0.3")
.masquerade_as_nightly_cargo()
.run();
p.cargo("rustdoc -- --crate-version 2.0.3").run();
asserts(output_documentation());
}
31 changes: 18 additions & 13 deletions tests/testsuite/rustdoc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Tests for the `cargo rustdoc` command.
use cargo_test_support::{basic_manifest, project};
use cargo_test_support::{basic_manifest, cross_compile, project};

#[cargo_test]
fn rustdoc_simple() {
Expand All @@ -13,7 +13,7 @@ fn rustdoc_simple() {
[RUNNING] `rustdoc [..]--crate-name foo src/lib.rs [..]\
-o [CWD]/target/doc \
[..] \
-L dependency=[CWD]/target/debug/deps`
-L dependency=[CWD]/target/debug/deps [..]`
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
",
)
Expand All @@ -32,7 +32,7 @@ fn rustdoc_args() {
-o [CWD]/target/doc \
[..] \
--cfg=foo \
-L dependency=[CWD]/target/debug/deps`
-L dependency=[CWD]/target/debug/deps [..]`
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
",
)
Expand Down Expand Up @@ -122,7 +122,7 @@ fn rustdoc_only_bar_dependency() {
-o [CWD]/target/doc \
[..] \
--cfg=foo \
-L dependency=[CWD]/target/debug/deps`
-L dependency=[CWD]/target/debug/deps [..]`
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
",
)
Expand All @@ -144,7 +144,7 @@ fn rustdoc_same_name_documents_lib() {
-o [CWD]/target/doc \
[..] \
--cfg=foo \
-L dependency=[CWD]/target/debug/deps`
-L dependency=[CWD]/target/debug/deps [..]`
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
",
)
Expand Down Expand Up @@ -203,21 +203,26 @@ fn proc_macro_crate_type() {
}

#[cargo_test]
#[cfg(all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"))]
fn rustdoc_target() {
if cross_compile::disabled() {
return;
}

let p = project().file("src/lib.rs", "").build();

p.cargo("rustdoc --verbose --target x86_64-unknown-linux-gnu")
.with_stderr(
p.cargo("rustdoc --verbose --target")
.arg(cross_compile::alternate())
.with_stderr(format!(
"\
[DOCUMENTING] foo v0.0.1 ([..])
[RUNNING] `rustdoc [..]--crate-name foo src/lib.rs [..]\
--target x86_64-unknown-linux-gnu \
-o [CWD]/target/x86_64-unknown-linux-gnu/doc \
--target {target} \
-o [CWD]/target/{target}/doc \
[..] \
-L dependency=[CWD]/target/x86_64-unknown-linux-gnu/debug/deps \
-L dependency=[CWD]/target/debug/deps`
-L dependency=[CWD]/target/{target}/debug/deps \
-L dependency=[CWD]/target/debug/deps[..]`
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
)
target = cross_compile::alternate()
))
.run();
}

0 comments on commit dbbab42

Please sign in to comment.