rust/src/rustdoc/rustdoc.rs

88 lines
2.7 KiB
Rust
Raw Normal View History

2012-09-18 18:48:40 -05:00
use doc::ItemUtils;
use doc::Item;
2012-09-21 19:10:46 -05:00
use pass::Pass;
use config::Config;
fn main(args: ~[~str]) {
2012-09-20 17:39:23 -05:00
if args.contains(~"-h") || args.contains(~"--help") {
2012-02-28 23:27:38 -06:00
config::usage();
2012-08-01 19:30:05 -05:00
return;
2012-02-28 23:27:38 -06:00
}
2012-08-06 14:34:08 -05:00
let config = match config::parse_config(args) {
2012-09-21 19:10:46 -05:00
Ok(config) => config,
Err(err) => {
2012-08-22 19:24:52 -05:00
io::println(fmt!("error: %s", err));
2012-08-01 19:30:05 -05:00
return;
2012-02-28 23:31:55 -06:00
}
};
2012-02-29 20:10:40 -06:00
run(config);
}
/// Runs rustdoc over the given file
2012-09-21 19:10:46 -05:00
fn run(config: Config) {
2012-02-29 20:10:40 -06:00
let source_file = config.input_crate;
2012-09-21 19:10:46 -05:00
// Create an AST service from the source code
do astsrv::from_file(source_file.to_str()) |srv| {
2012-09-21 19:10:46 -05:00
// Just time how long it takes for the AST to become available
do time(~"wait_ast") {
2012-06-30 18:19:07 -05:00
do astsrv::exec(srv) |_ctxt| { }
2012-02-27 20:07:16 -06:00
};
2012-09-21 19:10:46 -05:00
// Extract the initial doc tree from the AST. This contains
// just names and node ids.
let doc = time(~"extract", || {
2012-02-29 20:10:40 -06:00
let default_name = source_file;
extract::from_srv(srv, default_name.to_str())
});
2012-09-21 19:10:46 -05:00
// Refine and publish the document
pass::run_passes(srv, doc, ~[
// Generate type and signature strings
tystr_pass::mk_pass(),
2012-09-21 19:10:46 -05:00
// Record the full paths to various nodes
path_pass::mk_pass(),
2012-09-21 19:10:46 -05:00
// Extract the docs attributes and attach them to doc nodes
attr_pass::mk_pass(),
2012-09-21 19:10:46 -05:00
// Perform various text escaping
2012-03-16 14:20:29 -05:00
escape_pass::mk_pass(),
2012-09-21 19:10:46 -05:00
// Remove things marked doc(hidden)
2012-03-07 16:49:52 -06:00
prune_hidden_pass::mk_pass(),
2012-09-21 19:10:46 -05:00
// Extract brief documentation from the full descriptions
desc_to_brief_pass::mk_pass(),
2012-09-21 19:10:46 -05:00
// Massage the text to remove extra indentation
unindent_pass::mk_pass(),
2012-09-21 19:10:46 -05:00
// Split text into multiple sections according to headers
2012-03-09 13:47:31 -06:00
sectionalize_pass::mk_pass(),
2012-09-21 19:10:46 -05:00
// Trim extra spaces from text
2012-03-09 13:47:31 -06:00
trim_pass::mk_pass(),
2012-09-21 19:10:46 -05:00
// Sort items by name
sort_item_name_pass::mk_pass(),
2012-09-21 19:10:46 -05:00
// Sort items again by kind
sort_item_type_pass::mk_pass(),
2012-09-21 19:10:46 -05:00
// Create indexes appropriate for markdown
markdown_index_pass::mk_pass(config),
2012-09-21 19:10:46 -05:00
// Break the document into pages if required by the
// output format
page_pass::mk_pass(config.output_style),
2012-09-21 19:10:46 -05:00
// Render
markdown_pass::mk_pass(
markdown_writer::make_writer_factory(config)
)
]);
}
}
2012-09-21 19:10:46 -05:00
fn time<T>(what: ~str, f: fn() -> T) -> T {
let start = std::time::precise_time_s();
let rv = f();
let end = std::time::precise_time_s();
info!("time: %3.3f s %s", end - start, what);
return rv;
}