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;
|
2012-01-16 20:08:17 -06:00
|
|
|
|
2012-07-14 00:57:48 -05:00
|
|
|
fn main(args: ~[~str]) {
|
2011-12-30 17:26:49 -06:00
|
|
|
|
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
|
|
|
}
|
|
|
|
};
|
2011-12-30 17:26:49 -06:00
|
|
|
|
2012-02-29 20:10:40 -06:00
|
|
|
run(config);
|
2012-01-16 20:21:34 -06:00
|
|
|
}
|
|
|
|
|
2012-07-04 16:53:12 -05:00
|
|
|
/// Runs rustdoc over the given file
|
2012-09-21 19:10:46 -05:00
|
|
|
fn run(config: Config) {
|
2012-01-16 20:21:34 -06:00
|
|
|
|
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
|
2012-08-24 17:28:43 -05:00
|
|
|
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
|
2012-07-14 00:57:48 -05:00
|
|
|
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.
|
2012-07-14 00:57:48 -05:00
|
|
|
let doc = time(~"extract", || {
|
2012-02-29 20:10:40 -06:00
|
|
|
let default_name = source_file;
|
2012-08-24 17:28:43 -05:00
|
|
|
extract::from_srv(srv, default_name.to_str())
|
2012-06-26 15:55:56 -05:00
|
|
|
});
|
2012-09-21 19:10:46 -05:00
|
|
|
|
|
|
|
// Refine and publish the document
|
|
|
|
pass::run_passes(srv, doc, ~[
|
|
|
|
// Generate type and signature strings
|
2012-02-20 23:08:19 -06:00
|
|
|
tystr_pass::mk_pass(),
|
2012-09-21 19:10:46 -05:00
|
|
|
// Record the full paths to various nodes
|
2012-02-20 23:08:19 -06:00
|
|
|
path_pass::mk_pass(),
|
2012-09-21 19:10:46 -05:00
|
|
|
// Extract the docs attributes and attach them to doc nodes
|
2012-02-20 23:08:19 -06:00
|
|
|
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 20:07:17 -05:00
|
|
|
// Remove things that are private
|
|
|
|
// XXX enable this after 'export' is removed in favor of 'pub'
|
|
|
|
// prune_private_pass::mk_pass(),
|
2012-09-21 19:10:46 -05:00
|
|
|
// Extract brief documentation from the full descriptions
|
2012-02-20 23:08:19 -06:00
|
|
|
desc_to_brief_pass::mk_pass(),
|
2012-09-21 19:10:46 -05:00
|
|
|
// Massage the text to remove extra indentation
|
2012-02-20 23:08:19 -06:00
|
|
|
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
|
2012-02-20 23:08:19 -06:00
|
|
|
sort_item_name_pass::mk_pass(),
|
2012-09-21 19:10:46 -05:00
|
|
|
// Sort items again by kind
|
2012-02-20 23:08:19 -06:00
|
|
|
sort_item_type_pass::mk_pass(),
|
2012-09-21 19:10:46 -05:00
|
|
|
// Create indexes appropriate for markdown
|
2012-03-06 17:57:36 -06:00
|
|
|
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
|
2012-03-06 16:07:34 -06:00
|
|
|
page_pass::mk_pass(config.output_style),
|
2012-09-21 19:10:46 -05:00
|
|
|
// Render
|
2012-03-04 01:20:40 -06:00
|
|
|
markdown_pass::mk_pass(
|
2012-03-04 01:56:38 -06:00
|
|
|
markdown_writer::make_writer_factory(config)
|
2012-03-04 01:20:40 -06:00
|
|
|
)
|
2012-06-29 18:26:56 -05:00
|
|
|
]);
|
2012-02-20 23:08:19 -06:00
|
|
|
}
|
2012-06-25 22:00:46 -05:00
|
|
|
}
|
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;
|
|
|
|
}
|