2013-02-28 07:15:32 -06:00
|
|
|
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
|
2012-12-03 18:48:01 -06:00
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2012-07-04 16:53:12 -05:00
|
|
|
//! Rustdoc - The Rust documentation generator
|
2012-01-23 18:23:08 -06:00
|
|
|
|
2012-01-15 16:28:10 -06:00
|
|
|
#[link(name = "rustdoc",
|
2012-12-21 17:35:15 -06:00
|
|
|
vers = "0.6",
|
2012-01-15 16:28:10 -06:00
|
|
|
uuid = "f8abd014-b281-484d-a0c3-26e3de8e2412",
|
2012-03-28 15:42:17 -05:00
|
|
|
url = "https://github.com/mozilla/rust/tree/master/src/rustdoc")];
|
2012-01-15 16:28:10 -06:00
|
|
|
|
2012-01-23 18:25:15 -06:00
|
|
|
#[comment = "The Rust documentation generator"];
|
2013-02-28 07:15:32 -06:00
|
|
|
#[license = "MIT/APL2"];
|
2012-10-03 19:32:30 -05:00
|
|
|
#[crate_type = "lib"];
|
2012-01-15 16:56:58 -06:00
|
|
|
|
2012-04-05 19:30:26 -05:00
|
|
|
#[no_core];
|
2012-09-18 17:52:21 -05:00
|
|
|
|
2012-09-21 19:10:46 -05:00
|
|
|
#[allow(non_implicitly_copyable_typarams)];
|
2012-06-04 20:34:24 -05:00
|
|
|
|
2012-12-21 17:35:15 -06:00
|
|
|
extern mod core(vers = "0.6");
|
|
|
|
extern mod std(vers = "0.6");
|
|
|
|
extern mod rustc(vers = "0.6");
|
|
|
|
extern mod syntax(vers = "0.6");
|
2012-04-05 19:30:26 -05:00
|
|
|
|
2012-09-07 20:08:21 -05:00
|
|
|
use core::*;
|
|
|
|
use std::par;
|
2012-01-17 19:22:03 -06:00
|
|
|
|
2012-09-21 19:10:46 -05:00
|
|
|
mod pass;
|
2012-02-26 18:32:57 -06:00
|
|
|
mod config;
|
2012-01-15 17:06:59 -06:00
|
|
|
mod parse;
|
2012-01-15 19:23:19 -06:00
|
|
|
mod extract;
|
2012-01-15 23:50:55 -06:00
|
|
|
mod attr_parser;
|
2012-01-15 17:23:07 -06:00
|
|
|
mod doc;
|
2012-03-02 17:17:13 -06:00
|
|
|
mod markdown_index_pass;
|
2012-01-24 20:18:14 -06:00
|
|
|
mod markdown_pass;
|
2012-03-01 00:26:28 -06:00
|
|
|
mod markdown_writer;
|
2012-01-16 17:33:06 -06:00
|
|
|
mod fold;
|
2012-01-19 01:48:25 -06:00
|
|
|
mod path_pass;
|
2012-01-16 18:05:59 -06:00
|
|
|
mod attr_pass;
|
2012-01-16 18:55:26 -06:00
|
|
|
mod tystr_pass;
|
2012-03-07 16:49:52 -06:00
|
|
|
mod prune_hidden_pass;
|
2012-01-24 19:19:27 -06:00
|
|
|
mod desc_to_brief_pass;
|
2012-03-08 19:00:03 -06:00
|
|
|
mod text_pass;
|
2012-01-25 00:02:36 -06:00
|
|
|
mod unindent_pass;
|
2012-01-24 19:40:22 -06:00
|
|
|
mod trim_pass;
|
2012-01-16 18:55:26 -06:00
|
|
|
mod astsrv;
|
2012-01-24 22:29:59 -06:00
|
|
|
mod demo;
|
2012-02-03 14:00:49 -06:00
|
|
|
mod sort_pass;
|
|
|
|
mod sort_item_name_pass;
|
2012-02-20 18:10:54 -06:00
|
|
|
mod sort_item_type_pass;
|
2012-03-06 15:56:33 -06:00
|
|
|
mod page_pass;
|
2012-03-16 14:20:29 -05:00
|
|
|
mod sectionalize_pass;
|
|
|
|
mod escape_pass;
|
2012-09-21 20:10:45 -05:00
|
|
|
mod prune_private_pass;
|
2012-11-28 14:38:53 -06:00
|
|
|
mod util;
|
2012-11-18 19:56:50 -06:00
|
|
|
|
|
|
|
use doc::ItemUtils;
|
|
|
|
use doc::Item;
|
|
|
|
use pass::Pass;
|
|
|
|
use config::Config;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let args = os::args();
|
|
|
|
|
|
|
|
if args.contains(&~"-h") || args.contains(&~"--help") {
|
|
|
|
config::usage();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let config = match config::parse_config(args) {
|
|
|
|
Ok(config) => config,
|
|
|
|
Err(err) => {
|
|
|
|
io::println(fmt!("error: %s", err));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
run(config);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Runs rustdoc over the given file
|
2013-01-30 21:32:36 -06:00
|
|
|
fn run(config: Config) {
|
2012-11-18 19:56:50 -06:00
|
|
|
|
2013-01-30 15:14:35 -06:00
|
|
|
let source_file = copy config.input_crate;
|
2012-11-18 19:56:50 -06:00
|
|
|
|
|
|
|
// Create an AST service from the source code
|
|
|
|
do astsrv::from_file(source_file.to_str()) |srv| {
|
|
|
|
|
|
|
|
// Just time how long it takes for the AST to become available
|
|
|
|
do time(~"wait_ast") {
|
2013-01-31 22:24:03 -06:00
|
|
|
do astsrv::exec(srv.clone()) |_ctxt| { }
|
2012-11-18 19:56:50 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
// Extract the initial doc tree from the AST. This contains
|
|
|
|
// just names and node ids.
|
|
|
|
let doc = time(~"extract", || {
|
2013-01-30 15:14:35 -06:00
|
|
|
let default_name = copy source_file;
|
2013-01-31 22:24:03 -06:00
|
|
|
extract::from_srv(srv.clone(), default_name.to_str())
|
2012-11-18 19:56:50 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
// Refine and publish the document
|
|
|
|
pass::run_passes(srv, doc, ~[
|
|
|
|
// Generate type and signature strings
|
|
|
|
tystr_pass::mk_pass(),
|
|
|
|
// Record the full paths to various nodes
|
|
|
|
path_pass::mk_pass(),
|
|
|
|
// Extract the docs attributes and attach them to doc nodes
|
|
|
|
attr_pass::mk_pass(),
|
|
|
|
// Perform various text escaping
|
|
|
|
escape_pass::mk_pass(),
|
|
|
|
// Remove things marked doc(hidden)
|
|
|
|
prune_hidden_pass::mk_pass(),
|
|
|
|
// Remove things that are private
|
|
|
|
// XXX enable this after 'export' is removed in favor of 'pub'
|
|
|
|
// prune_private_pass::mk_pass(),
|
|
|
|
// Extract brief documentation from the full descriptions
|
|
|
|
desc_to_brief_pass::mk_pass(),
|
|
|
|
// Massage the text to remove extra indentation
|
|
|
|
unindent_pass::mk_pass(),
|
|
|
|
// Split text into multiple sections according to headers
|
|
|
|
sectionalize_pass::mk_pass(),
|
|
|
|
// Trim extra spaces from text
|
|
|
|
trim_pass::mk_pass(),
|
|
|
|
// Sort items by name
|
|
|
|
sort_item_name_pass::mk_pass(),
|
|
|
|
// Sort items again by kind
|
|
|
|
sort_item_type_pass::mk_pass(),
|
|
|
|
// Create indexes appropriate for markdown
|
2013-01-30 15:14:35 -06:00
|
|
|
markdown_index_pass::mk_pass(copy config),
|
2012-11-18 19:56:50 -06:00
|
|
|
// Break the document into pages if required by the
|
|
|
|
// output format
|
|
|
|
page_pass::mk_pass(config.output_style),
|
|
|
|
// Render
|
|
|
|
markdown_pass::mk_pass(
|
2013-01-30 15:14:35 -06:00
|
|
|
markdown_writer::make_writer_factory(copy config)
|
2012-11-18 19:56:50 -06:00
|
|
|
)
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-30 21:32:36 -06:00
|
|
|
fn time<T>(what: ~str, f: fn() -> T) -> T {
|
2012-11-18 19:56:50 -06:00
|
|
|
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);
|
2013-02-15 02:37:08 -06:00
|
|
|
rv
|
2012-11-18 19:56:50 -06:00
|
|
|
}
|