From 0989dc1c3d7785bb31725bf75f090ca910f2b02d Mon Sep 17 00:00:00 2001 From: 5225225 <5225225@mailbox.org> Date: Tue, 1 Jun 2021 22:10:51 +0100 Subject: [PATCH 1/4] Put cfg in a scope so it's not borrowed twice --- src/cargo/ops/cargo_doc.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/cargo/ops/cargo_doc.rs b/src/cargo/ops/cargo_doc.rs index 640f2d9e381..065888a70e1 100644 --- a/src/cargo/ops/cargo_doc.rs +++ b/src/cargo/ops/cargo_doc.rs @@ -35,15 +35,16 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions) -> CargoResult<()> { .join(&name) .join("index.html"); if path.exists() { + let config_browser = { + let cfg = ws.config().get::("doc")?; + + cfg.browser + .map(|path_args| (path_args.path.resolve_program(ws.config()), path_args.args)) + }; + let mut shell = ws.config().shell(); shell.status("Opening", path.display())?; - let cfg = ws.config().get::("doc")?; - open_docs( - &path, - &mut shell, - cfg.browser - .map(|path_args| (path_args.path.resolve_program(ws.config()), path_args.args)), - )?; + open_docs(&path, &mut shell, config_browser)?; } } From 1919ce7ce52b95f21fc3119e6ec9cd5c0065aa0f Mon Sep 17 00:00:00 2001 From: 5225225 <5225225@mailbox.org> Date: Sun, 6 Jun 2021 13:28:45 +0100 Subject: [PATCH 2/4] Add test to try to catch doc --open issue with extern-map --- tests/testsuite/doc.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/testsuite/doc.rs b/tests/testsuite/doc.rs index 1dcf7735b6d..ecb54cf949a 100644 --- a/tests/testsuite/doc.rs +++ b/tests/testsuite/doc.rs @@ -1168,6 +1168,40 @@ fn doc_workspace_open_help_message() { .run(); } +#[cargo_test] +#[cfg(not(windows))] // `echo` may not be available +fn doc_extern_map_local() { + assert!(is_nightly()); + + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.change_file( + ".cargo/config.toml", + r#" + [doc.extern-map] + std = "local" + "#, + ); + + + p.cargo("doc -Zrustdoc-map --open") + .env("BROWSER", "echo") + .masquerade_as_nightly_cargo() + .with_stderr_contains("[..] Documenting foo v0.1.0 ([..])") + .with_stderr_does_not_contain("warning: unused config key `doc.extern-map` [..]") + .run(); +} + #[cargo_test] #[cfg(not(windows))] // `echo` may not be available fn doc_workspace_open_different_library_and_package_names() { From 9e4c0e1e4427e001eac56da38235d549d3e5935e Mon Sep 17 00:00:00 2001 From: 5225225 <5225225@mailbox.org> Date: Sat, 19 Jun 2021 17:45:44 +0100 Subject: [PATCH 3/4] Don't use CargoDocConfig struct --- src/cargo/ops/cargo_doc.rs | 14 ++------------ tests/testsuite/doc.rs | 7 +++---- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/src/cargo/ops/cargo_doc.rs b/src/cargo/ops/cargo_doc.rs index 065888a70e1..9e868c2064f 100644 --- a/src/cargo/ops/cargo_doc.rs +++ b/src/cargo/ops/cargo_doc.rs @@ -2,7 +2,6 @@ use crate::core::{Shell, Workspace}; use crate::ops; use crate::util::config::PathAndArgs; use crate::util::CargoResult; -use serde::Deserialize; use std::path::Path; use std::path::PathBuf; use std::process::Command; @@ -16,13 +15,6 @@ pub struct DocOptions { pub compile_opts: ops::CompileOptions, } -#[derive(Deserialize)] -struct CargoDocConfig { - /// Browser to use to open docs. If this is unset, the value of the environment variable - /// `BROWSER` will be used. - browser: Option, -} - /// Main method for `cargo doc`. pub fn doc(ws: &Workspace<'_>, options: &DocOptions) -> CargoResult<()> { let compilation = ops::compile(ws, &options.compile_opts)?; @@ -36,10 +28,8 @@ pub fn doc(ws: &Workspace<'_>, options: &DocOptions) -> CargoResult<()> { .join("index.html"); if path.exists() { let config_browser = { - let cfg = ws.config().get::("doc")?; - - cfg.browser - .map(|path_args| (path_args.path.resolve_program(ws.config()), path_args.args)) + let cfg: Option = ws.config().get("doc.browser")?; + cfg.map(|path_args| (path_args.path.resolve_program(ws.config()), path_args.args)) }; let mut shell = ws.config().shell(); diff --git a/tests/testsuite/doc.rs b/tests/testsuite/doc.rs index ecb54cf949a..cd8712425e1 100644 --- a/tests/testsuite/doc.rs +++ b/tests/testsuite/doc.rs @@ -1188,13 +1188,12 @@ fn doc_extern_map_local() { p.change_file( ".cargo/config.toml", r#" - [doc.extern-map] - std = "local" +[doc.extern-map] +std = "local" "#, ); - - p.cargo("doc -Zrustdoc-map --open") + p.cargo("doc -v --no-deps -Zrustdoc-map --open") .env("BROWSER", "echo") .masquerade_as_nightly_cargo() .with_stderr_contains("[..] Documenting foo v0.1.0 ([..])") From 950c415583443a90972ea05b72979d3b9c2b301d Mon Sep 17 00:00:00 2001 From: 5225225 <5225225@mailbox.org> Date: Mon, 28 Jun 2021 18:29:38 +0100 Subject: [PATCH 4/4] Fully match stderr, return if not nightly, shorten file --- tests/testsuite/doc.rs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/tests/testsuite/doc.rs b/tests/testsuite/doc.rs index cd8712425e1..bb949b63a9f 100644 --- a/tests/testsuite/doc.rs +++ b/tests/testsuite/doc.rs @@ -1171,7 +1171,10 @@ fn doc_workspace_open_help_message() { #[cargo_test] #[cfg(not(windows))] // `echo` may not be available fn doc_extern_map_local() { - assert!(is_nightly()); + if !is_nightly() { + // -Zextern-html-root-url is unstable + return; + } let p = project() .file( @@ -1183,21 +1186,20 @@ fn doc_extern_map_local() { "#, ) .file("src/lib.rs", "") + .file(".cargo/config.toml", "doc.extern-map.std = 'local'") .build(); - p.change_file( - ".cargo/config.toml", - r#" -[doc.extern-map] -std = "local" - "#, - ); - p.cargo("doc -v --no-deps -Zrustdoc-map --open") .env("BROWSER", "echo") .masquerade_as_nightly_cargo() - .with_stderr_contains("[..] Documenting foo v0.1.0 ([..])") - .with_stderr_does_not_contain("warning: unused config key `doc.extern-map` [..]") + .with_stderr( + "\ +[DOCUMENTING] foo v0.1.0 [..] +[RUNNING] `rustdoc --crate-type lib --crate-name foo src/lib.rs [..]--crate-version 0.1.0` +[FINISHED] [..] + Opening [CWD]/target/doc/foo/index.html +", + ) .run(); }