2013-02-28 14:15:32 +01:00
|
|
|
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
|
2012-12-04 01:48:01 +01: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 23:53:12 +02:00
|
|
|
//! Rustdoc - The Rust documentation generator
|
2012-01-24 01:23:08 +01:00
|
|
|
|
2012-01-15 23:28:10 +01:00
|
|
|
#[link(name = "rustdoc",
|
2013-07-08 19:25:45 +02:00
|
|
|
vers = "0.8-pre",
|
2012-01-15 23:28:10 +01:00
|
|
|
uuid = "f8abd014-b281-484d-a0c3-26e3de8e2412",
|
2012-03-28 22:42:17 +02:00
|
|
|
url = "https://github.com/mozilla/rust/tree/master/src/rustdoc")];
|
2012-01-15 23:28:10 +01:00
|
|
|
|
2012-01-24 01:25:15 +01:00
|
|
|
#[comment = "The Rust documentation generator"];
|
2013-03-01 17:41:31 +01:00
|
|
|
#[license = "MIT/ASL2"];
|
2012-10-04 02:32:30 +02:00
|
|
|
#[crate_type = "lib"];
|
2012-01-15 23:56:58 +01:00
|
|
|
|
2013-06-29 00:32:26 +02:00
|
|
|
extern mod extra;
|
2013-05-19 06:21:41 +02:00
|
|
|
extern mod rustc;
|
|
|
|
extern mod syntax;
|
2012-04-06 02:30:26 +02:00
|
|
|
|
2013-06-29 00:32:26 +02:00
|
|
|
use std::os;
|
2013-05-18 00:28:44 +02:00
|
|
|
|
2013-03-27 03:53:33 +01:00
|
|
|
use config::Config;
|
|
|
|
use doc::Item;
|
|
|
|
use doc::ItemUtils;
|
|
|
|
|
2013-03-01 19:44:43 +01:00
|
|
|
pub mod pass;
|
|
|
|
pub mod config;
|
|
|
|
pub mod parse;
|
|
|
|
pub mod extract;
|
|
|
|
pub mod attr_parser;
|
|
|
|
pub mod doc;
|
|
|
|
pub mod markdown_index_pass;
|
|
|
|
pub mod markdown_pass;
|
|
|
|
pub mod markdown_writer;
|
|
|
|
pub mod fold;
|
|
|
|
pub mod path_pass;
|
|
|
|
pub mod attr_pass;
|
|
|
|
pub mod tystr_pass;
|
|
|
|
pub mod prune_hidden_pass;
|
|
|
|
pub mod desc_to_brief_pass;
|
|
|
|
pub mod text_pass;
|
|
|
|
pub mod unindent_pass;
|
|
|
|
pub mod trim_pass;
|
|
|
|
pub mod astsrv;
|
|
|
|
pub mod demo;
|
|
|
|
pub mod sort_pass;
|
|
|
|
pub mod sort_item_name_pass;
|
|
|
|
pub mod sort_item_type_pass;
|
|
|
|
pub mod page_pass;
|
|
|
|
pub mod sectionalize_pass;
|
|
|
|
pub mod escape_pass;
|
|
|
|
pub mod prune_private_pass;
|
2012-11-19 02:56:50 +01:00
|
|
|
|
2013-03-01 19:44:43 +01:00
|
|
|
pub fn main() {
|
2012-11-19 02:56:50 +01:00
|
|
|
let args = os::args();
|
2013-08-22 11:41:33 +02:00
|
|
|
main_args(args);
|
|
|
|
}
|
2012-11-19 02:56:50 +01:00
|
|
|
|
2013-08-22 11:41:33 +02:00
|
|
|
pub fn main_args(args: &[~str]) {
|
2013-07-05 04:13:26 +02:00
|
|
|
if args.iter().any(|x| "-h" == *x) || args.iter().any(|x| "--help" == *x) {
|
2012-11-19 02:56:50 +01:00
|
|
|
config::usage();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let config = match config::parse_config(args) {
|
|
|
|
Ok(config) => config,
|
|
|
|
Err(err) => {
|
2013-07-22 18:03:39 +02:00
|
|
|
printfln!("error: %s", err);
|
2012-11-19 02:56:50 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
run(config);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Runs rustdoc over the given file
|
2013-01-31 04:32:36 +01:00
|
|
|
fn run(config: Config) {
|
2012-11-19 02:56:50 +01:00
|
|
|
|
2013-07-02 21:47:32 +02:00
|
|
|
let source_file = config.input_crate.clone();
|
2012-11-19 02:56:50 +01: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-02-01 05:24:03 +01:00
|
|
|
do astsrv::exec(srv.clone()) |_ctxt| { }
|
2012-11-19 02:56:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// Extract the initial doc tree from the AST. This contains
|
|
|
|
// just names and node ids.
|
|
|
|
let doc = time(~"extract", || {
|
2013-07-02 21:47:32 +02:00
|
|
|
let default_name = source_file.clone();
|
2013-02-01 05:24:03 +01:00
|
|
|
extract::from_srv(srv.clone(), default_name.to_str())
|
2012-11-19 02:56:50 +01: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
|
2013-03-14 08:21:48 +01:00
|
|
|
prune_private_pass::mk_pass(),
|
2012-11-19 02:56:50 +01:00
|
|
|
// 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-07-02 21:47:32 +02:00
|
|
|
markdown_index_pass::mk_pass(config.clone()),
|
2012-11-19 02:56:50 +01: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-07-02 21:47:32 +02:00
|
|
|
markdown_writer::make_writer_factory(config.clone())
|
2012-11-19 02:56:50 +01:00
|
|
|
)
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-07 23:38:38 +01:00
|
|
|
pub fn time<T>(what: ~str, f: &fn() -> T) -> T {
|
2013-05-19 20:17:49 +02:00
|
|
|
let start = extra::time::precise_time_s();
|
2012-11-19 02:56:50 +01:00
|
|
|
let rv = f();
|
2013-05-19 20:17:49 +02:00
|
|
|
let end = extra::time::precise_time_s();
|
2012-11-19 02:56:50 +01:00
|
|
|
info!("time: %3.3f s %s", end - start, what);
|
2013-02-15 09:37:08 +01:00
|
|
|
rv
|
2012-11-19 02:56:50 +01:00
|
|
|
}
|