Rollup merge of #57929 - GuillaumeGomez:rustodc-remove-old-style-files, r=ollie27

Rustdoc remove old style files

Reopening of #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.
This commit is contained in:
kennytm 2019-02-16 14:15:04 +08:00
commit f8ccdeb0d4
No known key found for this signature in database
GPG Key ID: FEF6C8051D0E013C
13 changed files with 64 additions and 23 deletions

View File

@ -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;
@ -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 {

View File

@ -517,6 +517,7 @@ fn run(self, builder: &Builder) {
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);
@ -581,7 +582,9 @@ fn run(self, builder: &Builder) {
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);
@ -650,9 +653,9 @@ fn run(self, builder: &Builder) {
// 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);

View File

@ -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 {
@ -436,6 +438,7 @@ pub fn from_matches(matches: &getopts::Matches) -> Result<Options, isize> {
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);
@ -480,6 +483,7 @@ pub fn from_matches(matches: &getopts::Matches) -> Result<Options, isize> {
markdown_css,
markdown_playground_url,
generate_search_filter,
generate_redirect_pages,
}
})
}

View File

@ -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 {
@ -516,6 +518,7 @@ pub fn run(mut krate: clean::Crate,
resource_suffix,
static_root_path,
generate_search_filter,
generate_redirect_pages,
..
} = options;
@ -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
@ -2246,17 +2250,18 @@ fn item<F>(&mut self, item: clean::Item, all: &mut AllTypes, mut f: F) -> Result
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 {

View File

@ -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")
}),
]
}

View File

@ -1,3 +1,5 @@
// compile-flags:-Z unstable-options --generate-redirect-pages
use std::ops::Deref;
pub struct Foo;

View File

@ -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};

View File

@ -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)'

View File

@ -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)'

View File

@ -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 {
() => [];

View File

@ -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) { } }

View File

@ -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

View File

@ -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;