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

Stabilize -Z crate-versions #8509

Merged
merged 1 commit into from
Jul 23, 2020
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: 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 @@ -1483,10 +1483,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 @@ -1500,8 +1496,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 @@ -1512,10 +1514,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 @@ -1538,16 +1536,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();
}