2014-01-10 22:05:54 +08:00
|
|
|
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
2012-12-03 16:48:01 -08: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.
|
|
|
|
|
2014-06-06 13:21:18 -07:00
|
|
|
#![crate_name = "rustdoc"]
|
2015-08-13 10:21:36 -07:00
|
|
|
#![unstable(feature = "rustdoc", issue = "27812")]
|
2014-03-21 18:05:05 -07:00
|
|
|
#![crate_type = "dylib"]
|
|
|
|
#![crate_type = "rlib"]
|
2015-08-09 14:15:05 -07:00
|
|
|
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
|
2015-12-11 13:07:11 -08:00
|
|
|
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
|
|
|
|
html_root_url = "https://doc.rust-lang.org/nightly/",
|
|
|
|
html_playground_url = "https://play.rust-lang.org/")]
|
2016-12-29 09:47:34 -08:00
|
|
|
#![deny(warnings)]
|
2015-01-30 12:26:44 -08:00
|
|
|
|
2015-02-10 22:52:44 +01:00
|
|
|
#![feature(box_patterns)]
|
2015-01-07 15:15:34 +01:00
|
|
|
#![feature(box_syntax)]
|
2015-01-22 18:22:03 -08:00
|
|
|
#![feature(libc)]
|
|
|
|
#![feature(rustc_private)]
|
2015-06-10 13:33:52 -07:00
|
|
|
#![feature(set_stdio)]
|
|
|
|
#![feature(slice_patterns)]
|
2015-01-30 12:26:44 -08:00
|
|
|
#![feature(staged_api)]
|
2015-01-22 18:22:03 -08:00
|
|
|
#![feature(test)]
|
|
|
|
#![feature(unicode)]
|
2013-10-02 18:10:16 -07:00
|
|
|
|
2014-09-06 19:13:40 +03:00
|
|
|
extern crate arena;
|
2014-05-22 11:28:01 -07:00
|
|
|
extern crate getopts;
|
|
|
|
extern crate libc;
|
2014-02-14 10:10:06 -08:00
|
|
|
extern crate rustc;
|
2016-03-30 13:43:36 +02:00
|
|
|
extern crate rustc_const_eval;
|
2016-08-12 18:22:02 -04:00
|
|
|
extern crate rustc_data_structures;
|
2014-11-15 20:30:33 -05:00
|
|
|
extern crate rustc_trans;
|
2014-11-27 09:57:47 -05:00
|
|
|
extern crate rustc_driver;
|
2015-01-11 15:03:34 +13:00
|
|
|
extern crate rustc_resolve;
|
2015-02-25 22:44:44 +11:00
|
|
|
extern crate rustc_lint;
|
std: Stabilize the `fs` module
This commit performs a stabilization pass over the `std::fs` module now that
it's had some time to bake. The change was largely just adding `#[stable]` tags,
but there are a few APIs that remain `#[unstable]`.
The following apis are now marked `#[stable]`:
* `std::fs` (the name)
* `File`
* `Metadata`
* `ReadDir`
* `DirEntry`
* `OpenOptions`
* `Permissions`
* `File::{open, create}`
* `File::{sync_all, sync_data}`
* `File::set_len`
* `File::metadata`
* Trait implementations for `File` and `&File`
* `OpenOptions::new`
* `OpenOptions::{read, write, append, truncate, create}`
* `OpenOptions::open` - this function was modified, however, to not attempt to
reject cross-platform openings of directories. This means that some platforms
will succeed in opening a directory and others will fail.
* `Metadata::{is_dir, is_file, len, permissions}`
* `Permissions::{readonly, set_readonly}`
* `Iterator for ReadDir`
* `DirEntry::path`
* `remove_file` - like with `OpenOptions::open`, the extra windows code to
remove a readonly file has been removed. This means that removing a readonly
file will succeed on some platforms but fail on others.
* `metadata`
* `rename`
* `copy`
* `hard_link`
* `soft_link`
* `read_link`
* `create_dir`
* `create_dir_all`
* `remove_dir`
* `remove_dir_all`
* `read_dir`
The following apis remain `#[unstable]`.
* `WalkDir` and `walk` - there are many methods by which a directory walk can be
constructed, and it's unclear whether the current semantics are the right
ones. For example symlinks are not handled super well currently. This is now
behind a new `fs_walk` feature.
* `File::path` - this is an extra abstraction which the standard library
provides on top of what the system offers and it's unclear whether we should
be doing so. This is now behind a new `file_path` feature.
* `Metadata::{accessed, modified}` - we do not currently have a good
abstraction for a moment in time which is what these APIs should likely be
returning, so these remain `#[unstable]` for now. These are now behind a new
`fs_time` feature
* `set_file_times` - like with `Metadata::accessed`, we do not currently have
the appropriate abstraction for the arguments here so this API remains
unstable behind the `fs_time` feature gate.
* `PathExt` - the precise set of methods on this trait may change over time and
some methods may be removed. This API remains unstable behind the `path_ext`
feature gate.
* `set_permissions` - we may wish to expose a more granular ability to set the
permissions on a file instead of just a blanket "set all permissions" method.
This function remains behind the `fs` feature.
The following apis are now `#[deprecated]`
* The `TempDir` type is now entirely deprecated and is [located on
crates.io][tempdir] as the `tempdir` crate with [its source][github] at
rust-lang/tempdir.
[tempdir]: https://crates.io/crates/tempdir
[github]: https://github.com/rust-lang/tempdir
The stability of some of these APIs has been questioned over the past few weeks
in using these APIs, and it is intentional that the majority of APIs here are
marked `#[stable]`. The `std::fs` module has a lot of room to grow and the
material is [being tracked in a RFC issue][rfc-issue].
[rfc-issue]: https://github.com/rust-lang/rfcs/issues/939
[breaking-change]
2015-03-03 19:18:29 -08:00
|
|
|
extern crate rustc_back;
|
2015-11-25 01:23:22 +02:00
|
|
|
extern crate rustc_metadata;
|
2014-02-14 10:10:06 -08:00
|
|
|
extern crate serialize;
|
2016-02-13 18:05:16 +01:00
|
|
|
#[macro_use] extern crate syntax;
|
2016-06-21 18:08:13 -04:00
|
|
|
extern crate syntax_pos;
|
2015-03-24 18:13:54 -07:00
|
|
|
extern crate test as testing;
|
2016-11-29 14:38:08 -05:00
|
|
|
extern crate std_unicode;
|
2015-01-06 09:24:46 -08:00
|
|
|
#[macro_use] extern crate log;
|
2016-06-21 18:08:13 -04:00
|
|
|
extern crate rustc_errors as errors;
|
2014-05-24 21:15:16 -07:00
|
|
|
|
2015-03-24 18:13:54 -07:00
|
|
|
extern crate serialize as rustc_serialize; // used by deriving
|
2014-12-18 22:52:48 -08:00
|
|
|
|
2016-08-02 16:53:58 -04:00
|
|
|
use std::collections::{BTreeMap, BTreeSet};
|
2016-01-05 14:35:22 +13:00
|
|
|
use std::default::Default;
|
2015-01-27 12:20:58 -08:00
|
|
|
use std::env;
|
2016-12-05 03:21:08 +01:00
|
|
|
use std::fmt::Display;
|
|
|
|
use std::io;
|
|
|
|
use std::io::Write;
|
2015-02-26 21:00:43 -08:00
|
|
|
use std::path::PathBuf;
|
2015-06-10 19:33:04 -07:00
|
|
|
use std::process;
|
2015-02-17 15:24:34 -08:00
|
|
|
use std::sync::mpsc::channel;
|
2015-02-26 21:00:43 -08:00
|
|
|
|
2014-06-28 03:35:25 -07:00
|
|
|
use externalfiles::ExternalHtml;
|
2014-12-16 14:32:02 -08:00
|
|
|
use rustc::session::search_paths::SearchPaths;
|
2016-08-02 16:53:58 -04:00
|
|
|
use rustc::session::config::{ErrorOutputType, RustcOptGroup, nightly_options,
|
|
|
|
Externs};
|
2013-09-21 23:25:48 -07:00
|
|
|
|
2015-01-06 09:24:46 -08:00
|
|
|
#[macro_use]
|
2014-12-18 20:09:57 -08:00
|
|
|
pub mod externalfiles;
|
|
|
|
|
2013-09-21 23:25:48 -07:00
|
|
|
pub mod clean;
|
|
|
|
pub mod core;
|
|
|
|
pub mod doctree;
|
2013-03-01 10:44:43 -08:00
|
|
|
pub mod fold;
|
2013-09-21 23:25:48 -07:00
|
|
|
pub mod html {
|
2014-02-20 01:14:51 -08:00
|
|
|
pub mod highlight;
|
2013-09-27 15:12:23 -07:00
|
|
|
pub mod escape;
|
2014-04-09 16:49:31 +09:00
|
|
|
pub mod item_type;
|
2013-09-27 15:12:23 -07:00
|
|
|
pub mod format;
|
2013-09-21 23:25:48 -07:00
|
|
|
pub mod layout;
|
|
|
|
pub mod markdown;
|
2013-09-27 15:12:23 -07:00
|
|
|
pub mod render;
|
2014-03-08 01:13:17 +11:00
|
|
|
pub mod toc;
|
2013-09-21 23:25:48 -07:00
|
|
|
}
|
2014-03-07 14:31:41 +11:00
|
|
|
pub mod markdown;
|
2013-09-21 23:25:48 -07:00
|
|
|
pub mod passes;
|
|
|
|
pub mod plugins;
|
|
|
|
pub mod visit_ast;
|
2016-04-15 16:34:48 +02:00
|
|
|
pub mod visit_lib;
|
2013-12-22 11:23:04 -08:00
|
|
|
pub mod test;
|
2013-09-21 23:25:48 -07:00
|
|
|
|
2016-11-24 01:40:52 +02:00
|
|
|
use clean::AttributesExt;
|
2016-02-28 10:12:41 +01:00
|
|
|
|
2014-11-09 19:09:17 -05:00
|
|
|
struct Output {
|
|
|
|
krate: clean::Crate,
|
2016-04-07 05:59:02 +02:00
|
|
|
renderinfo: html::render::RenderInfo,
|
2014-11-09 19:09:17 -05:00
|
|
|
passes: Vec<String>,
|
|
|
|
}
|
2012-11-18 17:56:50 -08:00
|
|
|
|
2013-03-01 10:44:43 -08:00
|
|
|
pub fn main() {
|
2016-09-25 13:56:54 -04:00
|
|
|
const STACK_SIZE: usize = 32_000_000; // 32MB
|
2015-04-13 15:15:32 -07:00
|
|
|
let res = std::thread::Builder::new().stack_size(STACK_SIZE).spawn(move || {
|
2015-02-11 11:47:53 -08:00
|
|
|
let s = env::args().collect::<Vec<_>>();
|
|
|
|
main_args(&s)
|
2015-07-16 15:54:15 -04:00
|
|
|
}).unwrap().join().unwrap_or(101);
|
2015-06-10 19:33:04 -07:00
|
|
|
process::exit(res as i32);
|
2013-09-21 23:25:48 -07:00
|
|
|
}
|
|
|
|
|
2016-03-15 09:09:29 +01:00
|
|
|
fn stable(g: getopts::OptGroup) -> RustcOptGroup { RustcOptGroup::stable(g) }
|
|
|
|
fn unstable(g: getopts::OptGroup) -> RustcOptGroup { RustcOptGroup::unstable(g) }
|
|
|
|
|
|
|
|
pub fn opts() -> Vec<RustcOptGroup> {
|
2014-02-03 19:14:40 -08:00
|
|
|
use getopts::*;
|
2016-10-29 22:54:04 +01:00
|
|
|
vec![
|
2016-03-15 09:09:29 +01:00
|
|
|
stable(optflag("h", "help", "show this help message")),
|
|
|
|
stable(optflag("V", "version", "print rustdoc's version")),
|
|
|
|
stable(optflag("v", "verbose", "use verbose output")),
|
|
|
|
stable(optopt("r", "input-format", "the input type of the specified file",
|
2016-04-06 20:08:28 +02:00
|
|
|
"[rust]")),
|
2016-03-15 09:09:29 +01:00
|
|
|
stable(optopt("w", "output-format", "the output type to write",
|
2016-04-06 20:08:28 +02:00
|
|
|
"[html]")),
|
2016-03-15 09:09:29 +01:00
|
|
|
stable(optopt("o", "output", "where to place the output", "PATH")),
|
|
|
|
stable(optopt("", "crate-name", "specify the name of this crate", "NAME")),
|
|
|
|
stable(optmulti("L", "library-path", "directory to add to crate search path",
|
|
|
|
"DIR")),
|
|
|
|
stable(optmulti("", "cfg", "pass a --cfg to rustc", "")),
|
|
|
|
stable(optmulti("", "extern", "pass an --extern to rustc", "NAME=PATH")),
|
|
|
|
stable(optmulti("", "plugin-path", "directory to load plugins from", "DIR")),
|
|
|
|
stable(optmulti("", "passes",
|
|
|
|
"list of passes to also run, you might want \
|
|
|
|
to pass it multiple times; a value of `list` \
|
|
|
|
will print available passes",
|
|
|
|
"PASSES")),
|
|
|
|
stable(optmulti("", "plugins", "space separated list of plugins to also load",
|
|
|
|
"PLUGINS")),
|
|
|
|
stable(optflag("", "no-defaults", "don't run the default passes")),
|
|
|
|
stable(optflag("", "test", "run code examples as tests")),
|
|
|
|
stable(optmulti("", "test-args", "arguments to pass to the test runner",
|
|
|
|
"ARGS")),
|
|
|
|
stable(optopt("", "target", "target triple to document", "TRIPLE")),
|
|
|
|
stable(optmulti("", "markdown-css",
|
|
|
|
"CSS files to include via <link> in a rendered Markdown file",
|
|
|
|
"FILES")),
|
|
|
|
stable(optmulti("", "html-in-header",
|
|
|
|
"files to include inline in the <head> section of a rendered Markdown file \
|
|
|
|
or generated documentation",
|
|
|
|
"FILES")),
|
|
|
|
stable(optmulti("", "html-before-content",
|
|
|
|
"files to include inline between <body> and the content of a rendered \
|
|
|
|
Markdown file or generated documentation",
|
|
|
|
"FILES")),
|
|
|
|
stable(optmulti("", "html-after-content",
|
|
|
|
"files to include inline between the content and </body> of a rendered \
|
|
|
|
Markdown file or generated documentation",
|
|
|
|
"FILES")),
|
|
|
|
stable(optopt("", "markdown-playground-url",
|
|
|
|
"URL to send code snippets to", "URL")),
|
|
|
|
stable(optflag("", "markdown-no-toc", "don't include table of contents")),
|
|
|
|
unstable(optopt("e", "extend-css",
|
|
|
|
"to redefine some css rules with a given file to generate doc with your \
|
|
|
|
own theme", "PATH")),
|
|
|
|
unstable(optmulti("Z", "",
|
|
|
|
"internal and debugging options (only on nightly build)", "FLAG")),
|
2016-09-19 15:56:38 -05:00
|
|
|
stable(optopt("", "sysroot", "Override the system root", "PATH")),
|
2016-11-28 12:49:33 +08:00
|
|
|
unstable(optopt("", "playground-url",
|
|
|
|
"URL to send code snippets to, may be reset by --markdown-playground-url \
|
|
|
|
or `#![doc(html_playground_url=...)]`",
|
|
|
|
"URL")),
|
2016-10-29 22:54:04 +01:00
|
|
|
]
|
2013-09-21 23:25:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn usage(argv0: &str) {
|
2014-03-05 15:28:08 -08:00
|
|
|
println!("{}",
|
2015-02-01 21:53:25 -05:00
|
|
|
getopts::usage(&format!("{} [options] <input>", argv0),
|
2016-03-15 09:09:29 +01:00
|
|
|
&opts().into_iter()
|
|
|
|
.map(|x| x.opt_group)
|
|
|
|
.collect::<Vec<getopts::OptGroup>>()));
|
2013-08-22 17:41:33 +08:00
|
|
|
}
|
2012-11-18 17:56:50 -08:00
|
|
|
|
2015-03-25 17:06:52 -07:00
|
|
|
pub fn main_args(args: &[String]) -> isize {
|
2016-03-15 09:09:29 +01:00
|
|
|
let all_groups: Vec<getopts::OptGroup> = opts()
|
|
|
|
.into_iter()
|
|
|
|
.map(|x| x.opt_group)
|
|
|
|
.collect();
|
|
|
|
let matches = match getopts::getopts(&args[1..], &all_groups) {
|
2014-01-10 22:05:54 +08:00
|
|
|
Ok(m) => m,
|
|
|
|
Err(err) => {
|
2016-12-05 03:21:08 +01:00
|
|
|
print_error(err);
|
2014-01-10 22:05:54 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
};
|
2016-03-15 09:09:29 +01:00
|
|
|
// Check for unstable options.
|
|
|
|
nightly_options::check_nightly_options(&matches, &opts());
|
|
|
|
|
2013-09-21 23:25:48 -07:00
|
|
|
if matches.opt_present("h") || matches.opt_present("help") {
|
2017-01-26 01:35:00 -05:00
|
|
|
usage("rustdoc");
|
2013-09-24 16:34:23 -07:00
|
|
|
return 0;
|
2014-01-10 10:05:26 -08:00
|
|
|
} else if matches.opt_present("version") {
|
2014-12-15 16:03:39 -08:00
|
|
|
rustc_driver::version("rustdoc", &matches);
|
|
|
|
return 0;
|
2012-11-18 17:56:50 -08:00
|
|
|
}
|
|
|
|
|
2014-11-21 01:20:04 -05:00
|
|
|
if matches.opt_strs("passes") == ["list"] {
|
2014-07-21 23:37:04 +01:00
|
|
|
println!("Available passes for running rustdoc:");
|
2016-09-25 17:59:40 -04:00
|
|
|
for &(name, _, description) in passes::PASSES {
|
2014-11-17 11:29:38 -08:00
|
|
|
println!("{:>20} - {}", name, description);
|
2014-07-21 23:37:04 +01:00
|
|
|
}
|
2015-09-20 11:35:08 +01:00
|
|
|
println!("\nDefault passes for rustdoc:");
|
2016-09-25 17:59:40 -04:00
|
|
|
for &name in passes::DEFAULT_PASSES {
|
2014-11-17 11:29:38 -08:00
|
|
|
println!("{:>20}", name);
|
2014-07-21 23:37:04 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-24 16:53:34 -07:00
|
|
|
if matches.free.is_empty() {
|
2016-12-05 03:21:08 +01:00
|
|
|
print_error("missing file operand");
|
2013-12-22 11:23:04 -08:00
|
|
|
return 1;
|
2016-09-25 13:57:12 -04:00
|
|
|
}
|
|
|
|
if matches.free.len() > 1 {
|
2016-12-05 03:21:08 +01:00
|
|
|
print_error("too many file operands");
|
2013-12-22 11:23:04 -08:00
|
|
|
return 1;
|
|
|
|
}
|
2015-02-01 21:53:25 -05:00
|
|
|
let input = &matches.free[0];
|
2013-12-22 11:23:04 -08:00
|
|
|
|
2014-12-16 14:32:02 -08:00
|
|
|
let mut libs = SearchPaths::new();
|
2015-01-31 12:20:46 -05:00
|
|
|
for s in &matches.opt_strs("L") {
|
2016-01-05 14:35:22 +13:00
|
|
|
libs.add_path(s, ErrorOutputType::default());
|
2014-12-16 14:32:02 -08:00
|
|
|
}
|
2014-07-19 23:02:14 -07:00
|
|
|
let externs = match parse_externs(&matches) {
|
|
|
|
Ok(ex) => ex,
|
|
|
|
Err(err) => {
|
2016-12-05 03:21:08 +01:00
|
|
|
print_error(err);
|
2014-07-19 23:02:14 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
};
|
2014-03-07 14:31:41 +11:00
|
|
|
|
|
|
|
let test_args = matches.opt_strs("test-args");
|
2014-05-22 16:57:53 -07:00
|
|
|
let test_args: Vec<String> = test_args.iter()
|
2015-04-18 13:49:51 -04:00
|
|
|
.flat_map(|s| s.split_whitespace())
|
2014-05-25 03:17:19 -07:00
|
|
|
.map(|s| s.to_string())
|
2014-05-12 13:44:59 -07:00
|
|
|
.collect();
|
2014-03-07 14:31:41 +11:00
|
|
|
|
|
|
|
let should_test = matches.opt_present("test");
|
|
|
|
let markdown_input = input.ends_with(".md") || input.ends_with(".markdown");
|
|
|
|
|
2015-03-18 09:14:54 -07:00
|
|
|
let output = matches.opt_str("o").map(|s| PathBuf::from(&s));
|
2016-03-13 15:36:01 +01:00
|
|
|
let css_file_extension = matches.opt_str("e").map(|s| PathBuf::from(&s));
|
2014-04-01 15:04:42 -07:00
|
|
|
let cfgs = matches.opt_strs("cfg");
|
2014-03-07 14:31:41 +11:00
|
|
|
|
2016-03-13 15:36:01 +01:00
|
|
|
if let Some(ref p) = css_file_extension {
|
|
|
|
if !p.is_file() {
|
2016-12-05 03:21:08 +01:00
|
|
|
writeln!(
|
|
|
|
&mut io::stderr(),
|
|
|
|
"rustdoc: option --extend-css argument must be a file."
|
|
|
|
).unwrap();
|
2016-03-13 15:36:01 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-28 03:35:25 -07:00
|
|
|
let external_html = match ExternalHtml::load(
|
2016-12-15 20:42:10 +02:00
|
|
|
&matches.opt_strs("html-in-header"),
|
|
|
|
&matches.opt_strs("html-before-content"),
|
2015-02-01 21:53:25 -05:00
|
|
|
&matches.opt_strs("html-after-content")) {
|
2014-06-28 03:35:25 -07:00
|
|
|
Some(eh) => eh,
|
2016-12-15 20:42:10 +02:00
|
|
|
None => return 3,
|
2014-06-28 03:35:25 -07:00
|
|
|
};
|
2014-07-31 20:14:59 -07:00
|
|
|
let crate_name = matches.opt_str("crate-name");
|
2016-11-30 10:25:08 +08:00
|
|
|
let playground_url = matches.opt_str("playground-url");
|
2016-12-24 16:04:48 +00:00
|
|
|
let maybe_sysroot = matches.opt_str("sysroot").map(PathBuf::from);
|
2014-06-28 03:35:25 -07:00
|
|
|
|
2014-03-07 14:31:41 +11:00
|
|
|
match (should_test, markdown_input) {
|
2014-03-05 15:28:08 -08:00
|
|
|
(true, true) => {
|
2016-12-24 16:04:48 +00:00
|
|
|
return markdown::test(input, cfgs, libs, externs, test_args, maybe_sysroot)
|
2014-03-05 15:28:08 -08:00
|
|
|
}
|
2014-05-12 13:44:59 -07:00
|
|
|
(true, false) => {
|
2016-12-24 16:04:48 +00:00
|
|
|
return test::run(input, cfgs, libs, externs, test_args, crate_name, maybe_sysroot)
|
2014-05-12 13:44:59 -07:00
|
|
|
}
|
2015-02-26 21:00:43 -08:00
|
|
|
(false, true) => return markdown::render(input,
|
2015-03-18 09:14:54 -07:00
|
|
|
output.unwrap_or(PathBuf::from("doc")),
|
2014-07-23 15:43:03 -07:00
|
|
|
&matches, &external_html,
|
|
|
|
!matches.opt_present("markdown-no-toc")),
|
2014-03-07 14:31:41 +11:00
|
|
|
(false, false) => {}
|
2013-12-22 11:23:04 -08:00
|
|
|
}
|
2016-11-24 01:40:52 +02:00
|
|
|
|
|
|
|
let output_format = matches.opt_str("w");
|
|
|
|
let res = acquire_input(input, externs, &matches, move |out| {
|
|
|
|
let Output { krate, passes, renderinfo } = out;
|
|
|
|
info!("going to format");
|
|
|
|
match output_format.as_ref().map(|s| &**s) {
|
|
|
|
Some("html") | None => {
|
2016-11-30 10:25:08 +08:00
|
|
|
html::render::run(krate, &external_html, playground_url,
|
2016-11-24 01:40:52 +02:00
|
|
|
output.unwrap_or(PathBuf::from("doc")),
|
|
|
|
passes.into_iter().collect(),
|
|
|
|
css_file_extension,
|
|
|
|
renderinfo)
|
|
|
|
.expect("failed to generate documentation");
|
|
|
|
0
|
|
|
|
}
|
|
|
|
Some(s) => {
|
2016-12-05 03:21:08 +01:00
|
|
|
print_error(format!("unknown output format: {}", s));
|
2016-11-24 01:40:52 +02:00
|
|
|
1
|
|
|
|
}
|
2013-09-21 23:25:48 -07:00
|
|
|
}
|
2016-11-24 01:40:52 +02:00
|
|
|
});
|
|
|
|
res.unwrap_or_else(|s| {
|
2016-12-05 03:21:08 +01:00
|
|
|
print_error(format!("input error: {}", s));
|
2016-11-24 01:40:52 +02:00
|
|
|
1
|
|
|
|
})
|
2013-09-30 12:58:18 -07:00
|
|
|
}
|
|
|
|
|
2016-12-05 03:21:08 +01:00
|
|
|
/// Prints an uniformised error message on the standard error output
|
|
|
|
fn print_error<T>(error_message: T) where T: Display {
|
|
|
|
writeln!(
|
|
|
|
&mut io::stderr(),
|
|
|
|
"rustdoc: {}\nTry 'rustdoc --help' for more information.",
|
|
|
|
error_message
|
|
|
|
).unwrap();
|
|
|
|
}
|
|
|
|
|
2013-09-30 12:58:18 -07:00
|
|
|
/// Looks inside the command line arguments to extract the relevant input format
|
|
|
|
/// and files and then generates the necessary rustdoc output for formatting.
|
2016-11-24 01:40:52 +02:00
|
|
|
fn acquire_input<R, F>(input: &str,
|
|
|
|
externs: Externs,
|
|
|
|
matches: &getopts::Matches,
|
|
|
|
f: F)
|
|
|
|
-> Result<R, String>
|
|
|
|
where R: 'static + Send, F: 'static + Send + FnOnce(Output) -> R {
|
2015-02-01 21:53:25 -05:00
|
|
|
match matches.opt_str("r").as_ref().map(|s| &**s) {
|
2016-11-24 01:40:52 +02:00
|
|
|
Some("rust") => Ok(rust_input(input, externs, matches, f)),
|
2014-05-27 20:44:58 -07:00
|
|
|
Some(s) => Err(format!("unknown input format: {}", s)),
|
2016-11-24 01:40:52 +02:00
|
|
|
None => Ok(rust_input(input, externs, matches, f))
|
2013-09-30 12:58:18 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-19 23:02:14 -07:00
|
|
|
/// Extracts `--extern CRATE=PATH` arguments from `matches` and
|
2016-08-02 16:53:58 -04:00
|
|
|
/// returns a map mapping crate names to their paths or else an
|
2014-07-19 23:02:14 -07:00
|
|
|
/// error message.
|
2016-08-02 16:53:58 -04:00
|
|
|
fn parse_externs(matches: &getopts::Matches) -> Result<Externs, String> {
|
|
|
|
let mut externs = BTreeMap::new();
|
2015-01-31 12:20:46 -05:00
|
|
|
for arg in &matches.opt_strs("extern") {
|
2015-04-01 11:28:34 -07:00
|
|
|
let mut parts = arg.splitn(2, '=');
|
2016-03-22 22:01:37 -05:00
|
|
|
let name = parts.next().ok_or("--extern value must not be empty".to_string())?;
|
|
|
|
let location = parts.next()
|
2016-02-28 12:11:13 +01:00
|
|
|
.ok_or("--extern value must be of the format `foo=bar`"
|
2016-03-22 22:01:37 -05:00
|
|
|
.to_string())?;
|
2015-01-04 14:07:32 -05:00
|
|
|
let name = name.to_string();
|
2016-08-02 16:53:58 -04:00
|
|
|
externs.entry(name).or_insert_with(BTreeSet::new).insert(location.to_string());
|
2014-07-19 23:02:14 -07:00
|
|
|
}
|
2016-08-02 16:53:58 -04:00
|
|
|
Ok(Externs::new(externs))
|
2014-07-19 23:02:14 -07:00
|
|
|
}
|
|
|
|
|
2013-09-30 12:58:18 -07:00
|
|
|
/// Interprets the input file as a rust source file, passing it through the
|
|
|
|
/// compiler all the way through the analysis passes. The rustdoc output is then
|
|
|
|
/// generated from the cleaned AST of the crate.
|
|
|
|
///
|
|
|
|
/// This form of input will run all of the plug/cleaning passes
|
2016-11-24 01:40:52 +02:00
|
|
|
fn rust_input<R, F>(cratefile: &str, externs: Externs, matches: &getopts::Matches, f: F) -> R
|
|
|
|
where R: 'static + Send, F: 'static + Send + FnOnce(Output) -> R {
|
2013-09-30 13:28:30 -07:00
|
|
|
let mut default_passes = !matches.opt_present("no-defaults");
|
2013-09-30 12:58:18 -07:00
|
|
|
let mut passes = matches.opt_strs("passes");
|
2014-06-26 08:15:14 +02:00
|
|
|
let mut plugins = matches.opt_strs("plugins");
|
2012-11-18 17:56:50 -08:00
|
|
|
|
2013-09-21 23:25:48 -07:00
|
|
|
// First, parse the crate and extract all relevant information.
|
2014-12-16 14:32:02 -08:00
|
|
|
let mut paths = SearchPaths::new();
|
2015-01-31 12:20:46 -05:00
|
|
|
for s in &matches.opt_strs("L") {
|
2016-01-05 14:35:22 +13:00
|
|
|
paths.add_path(s, ErrorOutputType::default());
|
2014-12-16 14:32:02 -08:00
|
|
|
}
|
2013-12-03 16:44:16 -08:00
|
|
|
let cfgs = matches.opt_strs("cfg");
|
2014-07-25 07:55:25 -07:00
|
|
|
let triple = matches.opt_str("target");
|
2016-09-19 15:56:38 -05:00
|
|
|
let maybe_sysroot = matches.opt_str("sysroot").map(PathBuf::from);
|
2016-11-24 01:40:52 +02:00
|
|
|
let crate_name = matches.opt_str("crate-name");
|
|
|
|
let plugin_path = matches.opt_str("plugin-path");
|
2014-07-19 23:02:14 -07:00
|
|
|
|
2015-03-18 09:14:54 -07:00
|
|
|
let cr = PathBuf::from(cratefile);
|
2013-10-21 13:08:31 -07:00
|
|
|
info!("starting to run rustc");
|
2014-12-06 18:34:37 -08:00
|
|
|
|
2015-02-17 15:24:34 -08:00
|
|
|
let (tx, rx) = channel();
|
2015-07-16 15:54:15 -04:00
|
|
|
rustc_driver::monitor(move || {
|
2015-01-17 21:02:31 -08:00
|
|
|
use rustc::session::config::Input;
|
|
|
|
|
2016-11-24 01:40:52 +02:00
|
|
|
let (mut krate, renderinfo) =
|
|
|
|
core::run_core(paths, cfgs, externs, Input::File(cr), triple, maybe_sysroot);
|
2013-09-21 23:25:48 -07:00
|
|
|
|
2016-11-24 01:40:52 +02:00
|
|
|
info!("finished with rustc");
|
2014-07-23 21:46:49 -07:00
|
|
|
|
2016-11-24 01:40:52 +02:00
|
|
|
if let Some(name) = crate_name {
|
|
|
|
krate.name = name
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process all of the crate attributes, extracting plugin metadata along
|
|
|
|
// with the passes which we are supposed to run.
|
|
|
|
for attr in krate.module.as_ref().unwrap().attrs.lists("doc") {
|
|
|
|
let name = attr.name().map(|s| s.as_str());
|
|
|
|
let name = name.as_ref().map(|s| &s[..]);
|
|
|
|
if attr.is_word() {
|
|
|
|
if name == Some("no_default_passes") {
|
|
|
|
default_passes = false;
|
|
|
|
}
|
|
|
|
} else if let Some(value) = attr.value_str() {
|
|
|
|
let sink = match name {
|
|
|
|
Some("passes") => &mut passes,
|
|
|
|
Some("plugins") => &mut plugins,
|
2016-02-28 10:12:41 +01:00
|
|
|
_ => continue,
|
|
|
|
};
|
2016-11-24 01:40:52 +02:00
|
|
|
for p in value.as_str().split_whitespace() {
|
2016-02-28 10:12:41 +01:00
|
|
|
sink.push(p.to_string());
|
2013-09-21 23:25:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-28 10:12:41 +01:00
|
|
|
|
2016-11-24 01:40:52 +02:00
|
|
|
if default_passes {
|
|
|
|
for name in passes::DEFAULT_PASSES.iter().rev() {
|
|
|
|
passes.insert(0, name.to_string());
|
|
|
|
}
|
2013-09-23 16:25:58 -07:00
|
|
|
}
|
2012-11-18 17:56:50 -08:00
|
|
|
|
2016-11-24 01:40:52 +02:00
|
|
|
// Load all plugins/passes into a PluginManager
|
|
|
|
let path = plugin_path.unwrap_or("/tmp/rustdoc/plugins".to_string());
|
|
|
|
let mut pm = plugins::PluginManager::new(PathBuf::from(path));
|
|
|
|
for pass in &passes {
|
|
|
|
let plugin = match passes::PASSES.iter()
|
|
|
|
.position(|&(p, ..)| {
|
|
|
|
p == *pass
|
|
|
|
}) {
|
|
|
|
Some(i) => passes::PASSES[i].1,
|
|
|
|
None => {
|
|
|
|
error!("unknown pass {}, skipping", *pass);
|
|
|
|
continue
|
|
|
|
},
|
|
|
|
};
|
|
|
|
pm.add_plugin(plugin);
|
|
|
|
}
|
|
|
|
info!("loading plugins...");
|
|
|
|
for pname in plugins {
|
|
|
|
pm.load_plugin(pname);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run everything!
|
|
|
|
info!("Executing passes/plugins");
|
|
|
|
let krate = pm.run_plugins(krate);
|
2012-11-18 17:56:50 -08:00
|
|
|
|
2016-11-24 01:40:52 +02:00
|
|
|
tx.send(f(Output { krate: krate, renderinfo: renderinfo, passes: passes })).unwrap();
|
|
|
|
});
|
|
|
|
rx.recv().unwrap()
|
2012-11-18 17:56:50 -08:00
|
|
|
}
|