Skip to content

Commit

Permalink
Rollup merge of rust-lang#36729 - frewsxcv:rustdoc, r=alexcrichton
Browse files Browse the repository at this point in the history
librustdoc refactoring and cleanup.

See each commit for more information. Biggest changes here is the addition of a `passes` module and each pass now lives in its own submodule.
  • Loading branch information
Jonathan Turner authored Sep 27, 2016
2 parents df52628 + 99e1b9c commit ee2e115
Show file tree
Hide file tree
Showing 8 changed files with 552 additions and 451 deletions.
46 changes: 11 additions & 35 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,39 +91,14 @@ pub mod test;

use clean::Attributes;

type Pass = (&'static str, // name
fn(clean::Crate) -> plugins::PluginResult, // fn
&'static str); // description

const PASSES: &'static [Pass] = &[
("strip-hidden", passes::strip_hidden,
"strips all doc(hidden) items from the output"),
("unindent-comments", passes::unindent_comments,
"removes excess indentation on comments in order for markdown to like it"),
("collapse-docs", passes::collapse_docs,
"concatenates all document attributes into one document attribute"),
("strip-private", passes::strip_private,
"strips all private items from a crate which cannot be seen externally, \
implies strip-priv-imports"),
("strip-priv-imports", passes::strip_priv_imports,
"strips all private import statements (`use`, `extern crate`) from a crate"),
];

const DEFAULT_PASSES: &'static [&'static str] = &[
"strip-hidden",
"strip-private",
"collapse-docs",
"unindent-comments",
];

struct Output {
krate: clean::Crate,
renderinfo: html::render::RenderInfo,
passes: Vec<String>,
}

pub fn main() {
const STACK_SIZE: usize = 32000000; // 32MB
const STACK_SIZE: usize = 32_000_000; // 32MB
let res = std::thread::Builder::new().stack_size(STACK_SIZE).spawn(move || {
let s = env::args().collect::<Vec<_>>();
main_args(&s)
Expand Down Expand Up @@ -223,11 +198,11 @@ pub fn main_args(args: &[String]) -> isize {

if matches.opt_strs("passes") == ["list"] {
println!("Available passes for running rustdoc:");
for &(name, _, description) in PASSES {
for &(name, _, description) in passes::PASSES {
println!("{:>20} - {}", name, description);
}
println!("\nDefault passes for rustdoc:");
for &name in DEFAULT_PASSES {
for &name in passes::DEFAULT_PASSES {
println!("{:>20}", name);
}
return 0;
Expand All @@ -236,7 +211,8 @@ pub fn main_args(args: &[String]) -> isize {
if matches.free.is_empty() {
println!("expected an input file to act on");
return 1;
} if matches.free.len() > 1 {
}
if matches.free.len() > 1 {
println!("only one input file may be specified");
return 1;
}
Expand Down Expand Up @@ -412,7 +388,7 @@ fn rust_input(cratefile: &str, externs: Externs, matches: &getopts::Matches) ->
}

if default_passes {
for name in DEFAULT_PASSES.iter().rev() {
for name in passes::DEFAULT_PASSES.iter().rev() {
passes.insert(0, name.to_string());
}
}
Expand All @@ -422,11 +398,11 @@ fn rust_input(cratefile: &str, externs: Externs, matches: &getopts::Matches) ->
.unwrap_or("/tmp/rustdoc/plugins".to_string());
let mut pm = plugins::PluginManager::new(PathBuf::from(path));
for pass in &passes {
let plugin = match PASSES.iter()
.position(|&(p, ..)| {
p == *pass
}) {
Some(i) => PASSES[i].1,
let plugin = match passes::PASSES.iter()
.position(|&(p, ..)| {
p == *pass
}) {
Some(i) => passes::PASSES[i].1,
None => {
error!("unknown pass {}, skipping", *pass);
continue
Expand Down
Loading

0 comments on commit ee2e115

Please sign in to comment.