Skip to content

Commit

Permalink
Rollup merge of rust-lang#57929 - GuillaumeGomez:rustodc-remove-old-s…
Browse files Browse the repository at this point in the history
…tyle-files, r=ollie27

Rustdoc remove old style files

Reopening of rust-lang#56577 (which I can't seem to reopen...).

I made the flag unstable so with this change, what was blocking the PR is now gone I assume.
  • Loading branch information
kennytm committed Feb 17, 2019
2 parents 4739cd8 + d264755 commit f8ccdeb
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 23 deletions.
20 changes: 17 additions & 3 deletions src/bootstrap/bin/rustdoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ fn main() {
let libdir = env::var_os("RUSTDOC_LIBDIR").expect("RUSTDOC_LIBDIR was not set");
let stage = env::var("RUSTC_STAGE").expect("RUSTC_STAGE was not set");
let sysroot = env::var_os("RUSTC_SYSROOT").expect("RUSTC_SYSROOT was not set");
let mut has_unstable = false;

use std::str::FromStr;

Expand Down Expand Up @@ -54,9 +55,22 @@ fn main() {
// it up so we can make rustdoc print this into the docs
if let Some(version) = env::var_os("RUSTDOC_CRATE_VERSION") {
// This "unstable-options" can be removed when `--crate-version` is stabilized
cmd.arg("-Z")
.arg("unstable-options")
.arg("--crate-version").arg(version);
if !has_unstable {
cmd.arg("-Z")
.arg("unstable-options");
}
cmd.arg("--crate-version").arg(version);
has_unstable = true;
}

// Needed to be able to run all rustdoc tests.
if let Some(_) = env::var_os("RUSTDOC_GENERATE_REDIRECT_PAGES") {
// This "unstable-options" can be removed when `--generate-redirect-pages` is stabilized
if !has_unstable {
cmd.arg("-Z")
.arg("unstable-options");
}
cmd.arg("--generate-redirect-pages");
}

if verbose > 1 {
Expand Down
9 changes: 6 additions & 3 deletions src/bootstrap/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ impl Step for Std {
cargo.arg("--")
.arg("--markdown-css").arg("rust.css")
.arg("--markdown-no-toc")
.arg("--generate-redirect-pages")
.arg("--index-page").arg(&builder.src.join("src/doc/index.md"));

builder.run(&mut cargo);
Expand Down Expand Up @@ -581,7 +582,9 @@ impl Step for Test {
let mut cargo = builder.cargo(compiler, Mode::Test, target, "doc");
compile::test_cargo(builder, &compiler, target, &mut cargo);

cargo.arg("--no-deps").arg("-p").arg("test");
cargo.arg("--no-deps")
.arg("-p").arg("test")
.env("RUSTDOC_GENERATE_REDIRECT_PAGES", "1");

builder.run(&mut cargo);
builder.cp_r(&my_out, &out);
Expand Down Expand Up @@ -650,9 +653,9 @@ impl Step for WhitelistedRustc {
// We don't want to build docs for internal compiler dependencies in this
// step (there is another step for that). Therefore, we whitelist the crates
// for which docs must be built.
cargo.arg("--no-deps");
for krate in &["proc_macro"] {
cargo.arg("-p").arg(krate);
cargo.arg("-p").arg(krate)
.env("RUSTDOC_GENERATE_REDIRECT_PAGES", "1");
}

builder.run(&mut cargo);
Expand Down
4 changes: 4 additions & 0 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ pub struct RenderOptions {
/// If false, the `select` element to have search filtering by crates on rendered docs
/// won't be generated.
pub generate_search_filter: bool,
/// Option (disabled by default) to generate files used by RLS and some other tools.
pub generate_redirect_pages: bool,
}

impl Options {
Expand Down Expand Up @@ -436,6 +438,7 @@ impl Options {
let static_root_path = matches.opt_str("static-root-path");
let generate_search_filter = !matches.opt_present("disable-per-crate-search");
let persist_doctests = matches.opt_str("persist-doctests").map(PathBuf::from);
let generate_redirect_pages = matches.opt_present("generate-redirect-pages");

let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format);

Expand Down Expand Up @@ -480,6 +483,7 @@ impl Options {
markdown_css,
markdown_playground_url,
generate_search_filter,
generate_redirect_pages,
}
})
}
Expand Down
25 changes: 15 additions & 10 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ struct SharedContext {
/// If false, the `select` element to have search filtering by crates on rendered docs
/// won't be generated.
pub generate_search_filter: bool,
/// Option disabled by default to generate files used by RLS and some other tools.
pub generate_redirect_pages: bool,
}

impl SharedContext {
Expand Down Expand Up @@ -516,6 +518,7 @@ pub fn run(mut krate: clean::Crate,
resource_suffix,
static_root_path,
generate_search_filter,
generate_redirect_pages,
..
} = options;

Expand Down Expand Up @@ -545,6 +548,7 @@ pub fn run(mut krate: clean::Crate,
resource_suffix,
static_root_path,
generate_search_filter,
generate_redirect_pages,
};

// If user passed in `--playground-url` arg, we fill in crate name here
Expand Down Expand Up @@ -2246,17 +2250,18 @@ impl Context {
if !self.render_redirect_pages {
all.append(full_path(self, &item), &item_type);
}
// Redirect from a sane URL using the namespace to Rustdoc's
// URL for the page.
let redir_name = format!("{}.{}.html", name, item_type.name_space());
let redir_dst = self.dst.join(redir_name);
if let Ok(redirect_out) = OpenOptions::new().create_new(true)
.write(true)
.open(&redir_dst) {
let mut redirect_out = BufWriter::new(redirect_out);
try_err!(layout::redirect(&mut redirect_out, file_name), &redir_dst);
if self.shared.generate_redirect_pages {
// Redirect from a sane URL using the namespace to Rustdoc's
// URL for the page.
let redir_name = format!("{}.{}.html", name, item_type.name_space());
let redir_dst = self.dst.join(redir_name);
if let Ok(redirect_out) = OpenOptions::new().create_new(true)
.write(true)
.open(&redir_dst) {
let mut redirect_out = BufWriter::new(redirect_out);
try_err!(layout::redirect(&mut redirect_out, file_name), &redir_dst);
}
}

// If the item is a macro, redirect from the old macro URL (with !)
// to the new one (without).
if item_type == ItemType::Macro {
Expand Down
5 changes: 5 additions & 0 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,11 @@ fn opts() -> Vec<RustcOptGroup> {
"Directory to persist doctest executables into",
"PATH")
}),
unstable("generate-redirect-pages", |o| {
o.optflag("",
"generate-redirect-pages",
"Generate extra pages to support legacy URLs and tool links")
}),
]
}

Expand Down
2 changes: 2 additions & 0 deletions src/test/rustdoc/issue-19190.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// compile-flags:-Z unstable-options --generate-redirect-pages

use std::ops::Deref;

pub struct Foo;
Expand Down
1 change: 0 additions & 1 deletion src/test/rustdoc/issue-21092.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

extern crate issue_21092;

// @has issue_21092/Bar.t.html
// @has issue_21092/struct.Bar.html
// @has - '//*[@id="associatedtype.Bar"]' 'type Bar = i32'
pub use issue_21092::{Foo, Bar};
1 change: 0 additions & 1 deletion src/test/rustdoc/issue-35169-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ impl DerefMut for Bar {
fn deref_mut(&mut self) -> &mut Foo { loop {} }
}

// @has issue_35169_2/Bar.t.html
// @has issue_35169_2/struct.Bar.html
// @has - '//*[@id="by_ref.v"]' 'fn by_ref(&self)'
// @has - '//*[@id="method.by_ref"]' 'fn by_ref(&self)'
Expand Down
1 change: 0 additions & 1 deletion src/test/rustdoc/issue-35169.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ impl Deref for Bar {
fn deref(&self) -> &Foo { loop {} }
}

// @has issue_35169/Bar.t.html
// @has issue_35169/struct.Bar.html
// @has - '//*[@id="by_ref.v"]' 'fn by_ref(&self)'
// @has - '//*[@id="method.by_ref"]' 'fn by_ref(&self)'
Expand Down
2 changes: 0 additions & 2 deletions src/test/rustdoc/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// @has - //pre '() => { ... };'
// @has - //pre '($a:tt) => { ... };'
// @has - //pre '($e:expr) => { ... };'
// @has macros/macro.my_macro!.html
// @has - //a 'macro.my_macro.html'
#[macro_export]
macro_rules! my_macro {
() => [];
Expand Down
2 changes: 0 additions & 2 deletions src/test/rustdoc/src-links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ pub mod bar {
// @has foo/bar/baz/index.html '//a/@href' '../../../src/foo/src-links.rs.html'
pub mod baz {
/// Dox
// @has foo/bar/baz/baz.v.html
// @has foo/bar/baz/fn.baz.html '//a/@href' '../../../src/foo/src-links.rs.html'
pub fn baz() { }
}

/// Dox
// @has foo/bar/Foobar.t.html
// @has foo/bar/trait.Foobar.html '//a/@href' '../../src/foo/src-links.rs.html'
pub trait Foobar { fn dummy(&self) { } }

Expand Down
2 changes: 2 additions & 0 deletions src/test/rustdoc/structfields.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// compile-flags:-Z unstable-options --generate-redirect-pages

// @has structfields/Foo.t.html
// @has - struct.Foo.html
// @has structfields/struct.Foo.html
Expand Down
13 changes: 13 additions & 0 deletions src/test/rustdoc/without-redirect.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#![crate_name = "foo"]

// @has foo/macro.bar.html
// @has foo/macro.bar!.html
// @!has foo/bar.m.html
#[macro_export]
macro_rules! bar {
() => {}
}

// @has foo/struct.Bar.html
// @!has foo/Bar.t.html
pub struct Bar;

0 comments on commit f8ccdeb

Please sign in to comment.