2012-12-03 18:48:01 -06:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// 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.
|
|
|
|
|
2013-01-29 17:16:07 -06:00
|
|
|
pub use syntax::diagnostic;
|
2012-11-28 18:20:41 -06:00
|
|
|
|
2014-05-06 06:38:01 -05:00
|
|
|
use back::link;
|
|
|
|
use driver::driver::{Input, FileInput, StrInput};
|
|
|
|
use driver::session::{Session, build_session};
|
2014-06-10 16:03:19 -05:00
|
|
|
use lint::Lint;
|
2014-06-01 17:58:06 -05:00
|
|
|
use lint;
|
2014-05-06 06:38:01 -05:00
|
|
|
use metadata;
|
|
|
|
|
|
|
|
use std::any::AnyRefExt;
|
|
|
|
use std::io;
|
|
|
|
use std::os;
|
|
|
|
use std::task::TaskBuilder;
|
|
|
|
|
|
|
|
use syntax::ast;
|
|
|
|
use syntax::parse;
|
|
|
|
use syntax::diagnostic::Emitter;
|
2014-07-01 11:39:41 -05:00
|
|
|
use syntax::diagnostics;
|
2014-05-06 06:38:01 -05:00
|
|
|
|
|
|
|
use getopts;
|
|
|
|
|
|
|
|
|
2013-01-29 17:16:07 -06:00
|
|
|
pub mod driver;
|
|
|
|
pub mod session;
|
2014-05-06 06:38:01 -05:00
|
|
|
pub mod config;
|
2014-08-11 05:59:35 -05:00
|
|
|
pub mod pretty;
|
2014-05-06 06:38:01 -05:00
|
|
|
|
|
|
|
|
2014-05-22 18:57:53 -05:00
|
|
|
pub fn main_args(args: &[String]) -> int {
|
2014-07-16 15:37:28 -05:00
|
|
|
let owned_args = args.to_vec();
|
2014-06-06 12:27:49 -05:00
|
|
|
monitor(proc() run_compiler(owned_args.as_slice()));
|
2014-05-06 06:38:01 -05:00
|
|
|
0
|
|
|
|
}
|
|
|
|
|
|
|
|
static BUG_REPORT_URL: &'static str =
|
2014-05-21 21:55:39 -05:00
|
|
|
"http://doc.rust-lang.org/complement-bugreport.html";
|
2014-05-06 06:38:01 -05:00
|
|
|
|
2014-05-22 18:57:53 -05:00
|
|
|
fn run_compiler(args: &[String]) {
|
2014-05-06 06:38:01 -05:00
|
|
|
let matches = match handle_options(Vec::from_slice(args)) {
|
|
|
|
Some(matches) => matches,
|
|
|
|
None => return
|
|
|
|
};
|
2014-06-04 16:35:58 -05:00
|
|
|
|
2014-07-01 11:39:41 -05:00
|
|
|
let descriptions = diagnostics::registry::Registry::new(super::DIAGNOSTICS);
|
|
|
|
match matches.opt_str("explain") {
|
|
|
|
Some(ref code) => {
|
|
|
|
match descriptions.find_description(code.as_slice()) {
|
|
|
|
Some(ref description) => {
|
|
|
|
println!("{}", description);
|
|
|
|
}
|
|
|
|
None => {
|
|
|
|
early_error(format!("no extended information for {}", code).as_slice());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
},
|
|
|
|
None => ()
|
|
|
|
}
|
|
|
|
|
|
|
|
let sopts = config::build_session_options(&matches);
|
2014-05-06 06:38:01 -05:00
|
|
|
let (input, input_file_path) = match matches.free.len() {
|
2014-06-10 16:03:19 -05:00
|
|
|
0u => {
|
|
|
|
if sopts.describe_lints {
|
|
|
|
let mut ls = lint::LintStore::new();
|
|
|
|
ls.register_builtin(None);
|
2014-06-18 19:26:14 -05:00
|
|
|
describe_lints(&ls, false);
|
2014-06-10 16:03:19 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
early_error("no input filename given");
|
|
|
|
}
|
2014-05-06 06:38:01 -05:00
|
|
|
1u => {
|
|
|
|
let ifile = matches.free.get(0).as_slice();
|
|
|
|
if ifile == "-" {
|
|
|
|
let contents = io::stdin().read_to_end().unwrap();
|
2014-06-30 09:41:30 -05:00
|
|
|
let src = String::from_utf8(contents).unwrap();
|
2014-05-06 06:38:01 -05:00
|
|
|
(StrInput(src), None)
|
|
|
|
} else {
|
|
|
|
(FileInput(Path::new(ifile)), Some(Path::new(ifile)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => early_error("multiple input filenames provided")
|
|
|
|
};
|
|
|
|
|
2014-07-01 11:39:41 -05:00
|
|
|
let sess = build_session(sopts, input_file_path, descriptions);
|
2014-05-06 06:38:01 -05:00
|
|
|
let cfg = config::build_configuration(&sess);
|
|
|
|
let odir = matches.opt_str("out-dir").map(|o| Path::new(o));
|
|
|
|
let ofile = matches.opt_str("o").map(|o| Path::new(o));
|
|
|
|
|
|
|
|
let pretty = matches.opt_default("pretty", "normal").map(|a| {
|
2014-08-11 05:59:35 -05:00
|
|
|
pretty::parse_pretty(&sess, a.as_slice())
|
2014-05-06 06:38:01 -05:00
|
|
|
});
|
|
|
|
match pretty {
|
pretty-printer: let users choose particular items to pretty print.
With this change:
* `--pretty variant=<node-id>` will print the item associated with
`<node-id>` (where `<node-id>` is an integer for some node-id in
the AST, and `variant` means one of {`normal`,`expanded`,...}).
* `--pretty variant=<path-suffix>` will print all of the items that
match the `<path-suffix>` (where `<path-suffix>` is a suffix of a
path, and `variant` again means one of {`normal`,`expanded`,...}).
Example 1: the suffix `typeck::check::check_struct` matches the
item with the path `rustc::middle::typeck::check::check_struct`
when compiling the `rustc` crate.
Example 2: the suffix `and` matches `core::option::Option::and`
and `core::result::Result::and` when compiling the `core` crate.
Both of the `--pretty variant=...` modes will include the full path to
the item in a comment that follows the item.
Note that when multiple paths match, then either:
1. all matching items are printed, in series; this is what happens in
the usual pretty-print variants, or
2. the compiler signals an error; this is what happens in flowgraph
printing.
----
Some drive-by improvements:
Heavily refactored the pretty-printing glue in driver.rs, introducing
a couple local traits to avoid cut-and-pasting very code segments that
differed only in how they accessed the `Session` or the
`ast_map::Map`. (Note the previous code had three similar calls to
`print_crate` which have all been unified in this revision; the
addition of printing individual node-ids exacerbated the situation
beyond tolerance.) We may want to consider promoting some of these
traits, e.g. `SessionCarrier`, for use more generally elsewhere in the
compiler; right now I have to double check how to access the `Session`
depending on what context I am hacking in.
Refactored `PpMode` to make the data directly reflect the fundamental
difference in the categories (in terms of printing source-code with
various annotations, versus printing a control-flow graph).
(also, addressed review feedback.)
2014-08-07 11:22:24 -05:00
|
|
|
Some((ppm, opt_uii)) => {
|
2014-08-11 05:59:35 -05:00
|
|
|
pretty::pretty_print_input(sess, cfg, &input, ppm, opt_uii, ofile);
|
2014-05-06 06:38:01 -05:00
|
|
|
return;
|
|
|
|
}
|
pretty-printer: let users choose particular items to pretty print.
With this change:
* `--pretty variant=<node-id>` will print the item associated with
`<node-id>` (where `<node-id>` is an integer for some node-id in
the AST, and `variant` means one of {`normal`,`expanded`,...}).
* `--pretty variant=<path-suffix>` will print all of the items that
match the `<path-suffix>` (where `<path-suffix>` is a suffix of a
path, and `variant` again means one of {`normal`,`expanded`,...}).
Example 1: the suffix `typeck::check::check_struct` matches the
item with the path `rustc::middle::typeck::check::check_struct`
when compiling the `rustc` crate.
Example 2: the suffix `and` matches `core::option::Option::and`
and `core::result::Result::and` when compiling the `core` crate.
Both of the `--pretty variant=...` modes will include the full path to
the item in a comment that follows the item.
Note that when multiple paths match, then either:
1. all matching items are printed, in series; this is what happens in
the usual pretty-print variants, or
2. the compiler signals an error; this is what happens in flowgraph
printing.
----
Some drive-by improvements:
Heavily refactored the pretty-printing glue in driver.rs, introducing
a couple local traits to avoid cut-and-pasting very code segments that
differed only in how they accessed the `Session` or the
`ast_map::Map`. (Note the previous code had three similar calls to
`print_crate` which have all been unified in this revision; the
addition of printing individual node-ids exacerbated the situation
beyond tolerance.) We may want to consider promoting some of these
traits, e.g. `SessionCarrier`, for use more generally elsewhere in the
compiler; right now I have to double check how to access the `Session`
depending on what context I am hacking in.
Refactored `PpMode` to make the data directly reflect the fundamental
difference in the categories (in terms of printing source-code with
various annotations, versus printing a control-flow graph).
(also, addressed review feedback.)
2014-08-07 11:22:24 -05:00
|
|
|
None => {/* continue */ }
|
2014-05-06 06:38:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
let r = matches.opt_strs("Z");
|
2014-05-25 05:17:19 -05:00
|
|
|
if r.contains(&("ls".to_string())) {
|
2014-05-06 06:38:01 -05:00
|
|
|
match input {
|
|
|
|
FileInput(ref ifile) => {
|
|
|
|
let mut stdout = io::stdout();
|
|
|
|
list_metadata(&sess, &(*ifile), &mut stdout).unwrap();
|
|
|
|
}
|
|
|
|
StrInput(_) => {
|
|
|
|
early_error("can not list metadata for stdin");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if print_crate_info(&sess, &input, &odir, &ofile) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-07-19 23:54:37 -05:00
|
|
|
driver::compile_input(sess, cfg, &input, &odir, &ofile, None);
|
2014-05-06 06:38:01 -05:00
|
|
|
}
|
|
|
|
|
2014-05-18 22:37:07 -05:00
|
|
|
/// Prints version information and returns None on success or an error
|
|
|
|
/// message on failure.
|
|
|
|
pub fn version(binary: &str, matches: &getopts::Matches) -> Option<String> {
|
|
|
|
let verbose = match matches.opt_str("version").as_ref().map(|s| s.as_slice()) {
|
|
|
|
None => false,
|
|
|
|
Some("verbose") => true,
|
|
|
|
Some(s) => return Some(format!("Unrecognized argument: {}", s))
|
2014-05-06 06:38:01 -05:00
|
|
|
};
|
2014-05-18 22:37:07 -05:00
|
|
|
|
|
|
|
println!("{} {}", binary, env!("CFG_VERSION"));
|
|
|
|
if verbose {
|
|
|
|
println!("binary: {}", binary);
|
|
|
|
println!("commit-hash: {}", option_env!("CFG_VER_HASH").unwrap_or("unknown"));
|
|
|
|
println!("commit-date: {}", option_env!("CFG_VER_DATE").unwrap_or("unknown"));
|
|
|
|
println!("host: {}", driver::host_triple());
|
|
|
|
println!("release: {}", env!("CFG_RELEASE"));
|
|
|
|
}
|
|
|
|
None
|
2014-05-06 06:38:01 -05:00
|
|
|
}
|
|
|
|
|
2014-05-12 17:39:07 -05:00
|
|
|
fn usage() {
|
|
|
|
let message = format!("Usage: rustc [OPTIONS] INPUT");
|
2014-05-06 06:38:01 -05:00
|
|
|
println!("{}\n\
|
|
|
|
Additional help:
|
|
|
|
-C help Print codegen options
|
|
|
|
-W help Print 'lint' options and default settings
|
|
|
|
-Z help Print internal options for debugging rustc\n",
|
2014-05-16 12:45:16 -05:00
|
|
|
getopts::usage(message.as_slice(),
|
|
|
|
config::optgroups().as_slice()));
|
2014-05-06 06:38:01 -05:00
|
|
|
}
|
|
|
|
|
2014-06-18 19:26:14 -05:00
|
|
|
fn describe_lints(lint_store: &lint::LintStore, loaded_plugins: bool) {
|
2014-05-06 06:38:01 -05:00
|
|
|
println!("
|
|
|
|
Available lint options:
|
|
|
|
-W <foo> Warn about <foo>
|
|
|
|
-A <foo> Allow <foo>
|
|
|
|
-D <foo> Deny <foo>
|
|
|
|
-F <foo> Forbid <foo> (deny, and deny all overrides)
|
2014-06-10 16:03:19 -05:00
|
|
|
|
2014-05-06 06:38:01 -05:00
|
|
|
");
|
|
|
|
|
2014-06-10 16:03:19 -05:00
|
|
|
fn sort_lints(lints: Vec<(&'static Lint, bool)>) -> Vec<&'static Lint> {
|
|
|
|
let mut lints: Vec<_> = lints.move_iter().map(|(x, _)| x).collect();
|
|
|
|
lints.sort_by(|x: &&Lint, y: &&Lint| {
|
|
|
|
match x.default_level.cmp(&y.default_level) {
|
2014-06-13 15:04:52 -05:00
|
|
|
// The sort doesn't case-fold but it's doubtful we care.
|
2014-06-10 16:03:19 -05:00
|
|
|
Equal => x.name.cmp(&y.name),
|
|
|
|
r => r,
|
|
|
|
}
|
|
|
|
});
|
|
|
|
lints
|
|
|
|
}
|
2014-06-04 16:35:58 -05:00
|
|
|
|
2014-07-20 22:27:59 -05:00
|
|
|
fn sort_lint_groups(lints: Vec<(&'static str, Vec<lint::LintId>, bool)>)
|
|
|
|
-> Vec<(&'static str, Vec<lint::LintId>)> {
|
|
|
|
let mut lints: Vec<_> = lints.move_iter().map(|(x, y, _)| (x, y)).collect();
|
|
|
|
lints.sort_by(|&(x, _): &(&'static str, Vec<lint::LintId>),
|
|
|
|
&(y, _): &(&'static str, Vec<lint::LintId>)| {
|
|
|
|
x.cmp(&y)
|
|
|
|
});
|
|
|
|
lints
|
|
|
|
}
|
|
|
|
|
2014-06-18 19:26:14 -05:00
|
|
|
let (plugin, builtin) = lint_store.get_lints().partitioned(|&(_, p)| p);
|
|
|
|
let plugin = sort_lints(plugin);
|
2014-06-10 16:03:19 -05:00
|
|
|
let builtin = sort_lints(builtin);
|
|
|
|
|
2014-07-20 22:27:59 -05:00
|
|
|
let (plugin_groups, builtin_groups) = lint_store.get_lint_groups().partitioned(|&(_, _, p)| p);
|
|
|
|
let plugin_groups = sort_lint_groups(plugin_groups);
|
|
|
|
let builtin_groups = sort_lint_groups(builtin_groups);
|
|
|
|
|
2014-06-18 19:26:14 -05:00
|
|
|
let max_name_len = plugin.iter().chain(builtin.iter())
|
2014-07-20 22:27:59 -05:00
|
|
|
.map(|&s| s.name.width(true))
|
2014-06-04 16:35:58 -05:00
|
|
|
.max().unwrap_or(0);
|
|
|
|
let padded = |x: &str| {
|
2014-06-10 16:03:19 -05:00
|
|
|
" ".repeat(max_name_len - x.char_len()).append(x)
|
2014-06-04 16:35:58 -05:00
|
|
|
};
|
2014-05-06 06:38:01 -05:00
|
|
|
|
2014-06-10 16:03:19 -05:00
|
|
|
println!("Lint checks provided by rustc:\n");
|
2014-06-04 16:35:58 -05:00
|
|
|
println!(" {} {:7.7s} {}", padded("name"), "default", "meaning");
|
|
|
|
println!(" {} {:7.7s} {}", padded("----"), "-------", "-------");
|
|
|
|
|
2014-06-10 16:03:19 -05:00
|
|
|
let print_lints = |lints: Vec<&Lint>| {
|
|
|
|
for lint in lints.move_iter() {
|
2014-06-13 15:04:52 -05:00
|
|
|
let name = lint.name_lower().replace("_", "-");
|
2014-06-10 16:03:19 -05:00
|
|
|
println!(" {} {:7.7s} {}",
|
2014-06-17 19:41:50 -05:00
|
|
|
padded(name.as_slice()), lint.default_level.as_str(), lint.desc);
|
2014-06-10 16:03:19 -05:00
|
|
|
}
|
|
|
|
println!("\n");
|
|
|
|
};
|
|
|
|
|
|
|
|
print_lints(builtin);
|
|
|
|
|
2014-07-20 22:27:59 -05:00
|
|
|
|
|
|
|
|
|
|
|
let max_name_len = plugin_groups.iter().chain(builtin_groups.iter())
|
|
|
|
.map(|&(s, _)| s.width(true))
|
|
|
|
.max().unwrap_or(0);
|
|
|
|
let padded = |x: &str| {
|
|
|
|
" ".repeat(max_name_len - x.char_len()).append(x)
|
|
|
|
};
|
|
|
|
|
|
|
|
println!("Lint groups provided by rustc:\n");
|
|
|
|
println!(" {} {}", padded("name"), "sub-lints");
|
|
|
|
println!(" {} {}", padded("----"), "---------");
|
|
|
|
|
|
|
|
let print_lint_groups = |lints: Vec<(&'static str, Vec<lint::LintId>)>| {
|
|
|
|
for (name, to) in lints.move_iter() {
|
|
|
|
let name = name.chars().map(|x| x.to_lowercase())
|
|
|
|
.collect::<String>().replace("_", "-");
|
|
|
|
let desc = to.move_iter().map(|x| x.as_str()).collect::<Vec<String>>().connect(", ");
|
|
|
|
println!(" {} {}",
|
|
|
|
padded(name.as_slice()), desc);
|
2014-06-18 19:26:14 -05:00
|
|
|
}
|
2014-07-20 22:27:59 -05:00
|
|
|
println!("\n");
|
|
|
|
};
|
|
|
|
|
|
|
|
print_lint_groups(builtin_groups);
|
|
|
|
|
|
|
|
match (loaded_plugins, plugin.len(), plugin_groups.len()) {
|
|
|
|
(false, 0, _) | (false, _, 0) => {
|
|
|
|
println!("Compiler plugins can provide additional lints and lint groups. To see a \
|
|
|
|
listing of these, re-run `rustc -W help` with a crate filename.");
|
|
|
|
}
|
|
|
|
(false, _, _) => fail!("didn't load lint plugins but got them anyway!"),
|
|
|
|
(true, 0, 0) => println!("This crate does not load any lint plugins or lint groups."),
|
|
|
|
(true, l, g) => {
|
|
|
|
if l > 0 {
|
|
|
|
println!("Lint checks provided by plugins loaded by this crate:\n");
|
|
|
|
print_lints(plugin);
|
|
|
|
}
|
|
|
|
if g > 0 {
|
|
|
|
println!("Lint groups provided by plugins loaded by this crate:\n");
|
|
|
|
print_lint_groups(plugin_groups);
|
|
|
|
}
|
2014-06-18 19:26:14 -05:00
|
|
|
}
|
|
|
|
}
|
2014-05-06 06:38:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn describe_debug_flags() {
|
|
|
|
println!("\nAvailable debug options:\n");
|
|
|
|
let r = config::debugging_opts_map();
|
|
|
|
for tuple in r.iter() {
|
|
|
|
match *tuple {
|
|
|
|
(ref name, ref desc, _) => {
|
|
|
|
println!(" -Z {:>20s} -- {}", *name, *desc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn describe_codegen_flags() {
|
|
|
|
println!("\nAvailable codegen options:\n");
|
|
|
|
let mut cg = config::basic_codegen_options();
|
|
|
|
for &(name, parser, desc) in config::CG_OPTIONS.iter() {
|
|
|
|
// we invoke the parser function on `None` to see if this option needs
|
|
|
|
// an argument or not.
|
|
|
|
let (width, extra) = if parser(&mut cg, None) {
|
|
|
|
(25, "")
|
|
|
|
} else {
|
|
|
|
(21, "=val")
|
|
|
|
};
|
|
|
|
println!(" -C {:>width$s}{} -- {}", name.replace("_", "-"),
|
|
|
|
extra, desc, width=width);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-08 23:00:52 -05:00
|
|
|
/// Process command line options. Emits messages as appropriate. If compilation
|
2014-05-06 06:38:01 -05:00
|
|
|
/// should continue, returns a getopts::Matches object parsed from args, otherwise
|
|
|
|
/// returns None.
|
2014-05-22 18:57:53 -05:00
|
|
|
pub fn handle_options(mut args: Vec<String>) -> Option<getopts::Matches> {
|
2014-05-12 17:39:07 -05:00
|
|
|
// Throw away the first argument, the name of the binary
|
|
|
|
let _binary = args.shift().unwrap();
|
2014-05-06 06:38:01 -05:00
|
|
|
|
2014-05-14 23:39:11 -05:00
|
|
|
if args.is_empty() {
|
|
|
|
usage();
|
|
|
|
return None;
|
|
|
|
}
|
2014-05-06 06:38:01 -05:00
|
|
|
|
|
|
|
let matches =
|
|
|
|
match getopts::getopts(args.as_slice(), config::optgroups().as_slice()) {
|
|
|
|
Ok(m) => m,
|
|
|
|
Err(f) => {
|
2014-06-21 05:39:03 -05:00
|
|
|
early_error(f.to_string().as_slice());
|
2014-05-06 06:38:01 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if matches.opt_present("h") || matches.opt_present("help") {
|
2014-05-12 17:39:07 -05:00
|
|
|
usage();
|
2014-05-06 06:38:01 -05:00
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
2014-06-04 16:35:58 -05:00
|
|
|
// Don't handle -W help here, because we might first load plugins.
|
2014-05-06 06:38:01 -05:00
|
|
|
|
|
|
|
let r = matches.opt_strs("Z");
|
2014-05-14 23:39:11 -05:00
|
|
|
if r.iter().any(|x| x.as_slice() == "help") {
|
2014-05-06 06:38:01 -05:00
|
|
|
describe_debug_flags();
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
|
|
|
let cg_flags = matches.opt_strs("C");
|
2014-05-14 23:39:11 -05:00
|
|
|
if cg_flags.iter().any(|x| x.as_slice() == "help") {
|
2014-05-06 06:38:01 -05:00
|
|
|
describe_codegen_flags();
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
2014-05-25 05:17:19 -05:00
|
|
|
if cg_flags.contains(&"passes=list".to_string()) {
|
2014-07-07 19:58:01 -05:00
|
|
|
unsafe { ::llvm::LLVMRustPrintPasses(); }
|
2014-05-06 06:38:01 -05:00
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
2014-05-18 22:37:07 -05:00
|
|
|
if matches.opt_present("version") {
|
|
|
|
match version("rustc", &matches) {
|
|
|
|
Some(err) => early_error(err.as_slice()),
|
|
|
|
None => return None
|
|
|
|
}
|
2014-05-06 06:38:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Some(matches)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn print_crate_info(sess: &Session,
|
|
|
|
input: &Input,
|
|
|
|
odir: &Option<Path>,
|
|
|
|
ofile: &Option<Path>)
|
|
|
|
-> bool {
|
2014-06-06 15:21:18 -05:00
|
|
|
let (crate_name, crate_file_name) = sess.opts.print_metas;
|
2014-05-06 06:38:01 -05:00
|
|
|
// these nasty nested conditions are to avoid doing extra work
|
2014-06-06 15:21:18 -05:00
|
|
|
if crate_name || crate_file_name {
|
2014-05-06 06:38:01 -05:00
|
|
|
let attrs = parse_crate_attrs(sess, input);
|
2014-05-09 20:45:36 -05:00
|
|
|
let t_outputs = driver::build_output_filenames(input,
|
|
|
|
odir,
|
|
|
|
ofile,
|
|
|
|
attrs.as_slice(),
|
|
|
|
sess);
|
2014-07-05 14:37:43 -05:00
|
|
|
let id = link::find_crate_name(Some(sess), attrs.as_slice(), input);
|
2014-05-06 06:38:01 -05:00
|
|
|
|
|
|
|
if crate_name {
|
2014-06-06 15:21:18 -05:00
|
|
|
println!("{}", id);
|
2014-05-06 06:38:01 -05:00
|
|
|
}
|
|
|
|
if crate_file_name {
|
|
|
|
let crate_types = driver::collect_crate_types(sess, attrs.as_slice());
|
2014-07-01 00:52:48 -05:00
|
|
|
let metadata = driver::collect_crate_metadata(sess, attrs.as_slice());
|
|
|
|
*sess.crate_metadata.borrow_mut() = metadata;
|
2014-05-06 06:38:01 -05:00
|
|
|
for &style in crate_types.iter() {
|
2014-06-06 15:21:18 -05:00
|
|
|
let fname = link::filename_for_input(sess, style, id.as_slice(),
|
2014-05-06 06:38:01 -05:00
|
|
|
&t_outputs.with_extension(""));
|
|
|
|
println!("{}", fname.filename_display());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
true
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn parse_crate_attrs(sess: &Session, input: &Input) ->
|
|
|
|
Vec<ast::Attribute> {
|
|
|
|
let result = match *input {
|
|
|
|
FileInput(ref ifile) => {
|
|
|
|
parse::parse_crate_attrs_from_file(ifile,
|
|
|
|
Vec::new(),
|
|
|
|
&sess.parse_sess)
|
|
|
|
}
|
|
|
|
StrInput(ref src) => {
|
|
|
|
parse::parse_crate_attrs_from_source_str(
|
2014-05-25 05:17:19 -05:00
|
|
|
driver::anon_src().to_string(),
|
|
|
|
src.to_string(),
|
2014-05-06 06:38:01 -05:00
|
|
|
Vec::new(),
|
|
|
|
&sess.parse_sess)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
result.move_iter().collect()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn early_error(msg: &str) -> ! {
|
2014-07-01 11:39:41 -05:00
|
|
|
let mut emitter = diagnostic::EmitterWriter::stderr(diagnostic::Auto, None);
|
|
|
|
emitter.emit(None, msg, None, diagnostic::Fatal);
|
2014-05-06 06:38:01 -05:00
|
|
|
fail!(diagnostic::FatalError);
|
|
|
|
}
|
2014-07-01 19:07:06 -05:00
|
|
|
|
|
|
|
pub fn early_warn(msg: &str) {
|
2014-07-01 11:39:41 -05:00
|
|
|
let mut emitter = diagnostic::EmitterWriter::stderr(diagnostic::Auto, None);
|
|
|
|
emitter.emit(None, msg, None, diagnostic::Warning);
|
2014-07-01 19:07:06 -05:00
|
|
|
}
|
2014-05-06 06:38:01 -05:00
|
|
|
|
|
|
|
pub fn list_metadata(sess: &Session, path: &Path,
|
|
|
|
out: &mut io::Writer) -> io::IoResult<()> {
|
2014-06-11 02:48:17 -05:00
|
|
|
metadata::loader::list_file_metadata(sess.targ_cfg.os, path, out)
|
2014-05-06 06:38:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Run a procedure which will detect failures in the compiler and print nicer
|
|
|
|
/// error messages rather than just failing the test.
|
|
|
|
///
|
|
|
|
/// The diagnostic emitter yielded to the procedure should be used for reporting
|
|
|
|
/// errors of the compiler.
|
2014-07-19 03:29:57 -05:00
|
|
|
pub fn monitor(f: proc():Send) {
|
2014-05-06 06:38:01 -05:00
|
|
|
// FIXME: This is a hack for newsched since it doesn't support split stacks.
|
|
|
|
// rustc needs a lot of stack! When optimizations are disabled, it needs
|
|
|
|
// even *more* stack than usual as well.
|
|
|
|
#[cfg(rtopt)]
|
|
|
|
static STACK_SIZE: uint = 6000000; // 6MB
|
|
|
|
#[cfg(not(rtopt))]
|
|
|
|
static STACK_SIZE: uint = 20000000; // 20MB
|
|
|
|
|
2014-06-16 18:17:59 -05:00
|
|
|
let (tx, rx) = channel();
|
|
|
|
let w = io::ChanWriter::new(tx);
|
|
|
|
let mut r = io::ChanReader::new(rx);
|
|
|
|
|
|
|
|
let mut task = TaskBuilder::new().named("rustc").stderr(box w);
|
2014-05-06 06:38:01 -05:00
|
|
|
|
|
|
|
// FIXME: Hacks on hacks. If the env is trying to override the stack size
|
|
|
|
// then *don't* set it explicitly.
|
|
|
|
if os::getenv("RUST_MIN_STACK").is_none() {
|
2014-06-16 18:17:59 -05:00
|
|
|
task = task.stack_size(STACK_SIZE);
|
2014-05-06 06:38:01 -05:00
|
|
|
}
|
|
|
|
|
2014-06-16 18:17:59 -05:00
|
|
|
match task.try(f) {
|
2014-05-06 06:38:01 -05:00
|
|
|
Ok(()) => { /* fallthrough */ }
|
|
|
|
Err(value) => {
|
|
|
|
// Task failed without emitting a fatal diagnostic
|
|
|
|
if !value.is::<diagnostic::FatalError>() {
|
2014-07-01 11:39:41 -05:00
|
|
|
let mut emitter = diagnostic::EmitterWriter::stderr(diagnostic::Auto, None);
|
2014-05-06 06:38:01 -05:00
|
|
|
|
|
|
|
// a .span_bug or .bug call has already printed what
|
|
|
|
// it wants to print.
|
|
|
|
if !value.is::<diagnostic::ExplicitBug>() {
|
|
|
|
emitter.emit(
|
|
|
|
None,
|
|
|
|
"unexpected failure",
|
2014-07-01 11:39:41 -05:00
|
|
|
None,
|
2014-05-06 06:38:01 -05:00
|
|
|
diagnostic::Bug);
|
|
|
|
}
|
|
|
|
|
|
|
|
let xs = [
|
2014-05-25 05:10:11 -05:00
|
|
|
"the compiler hit an unexpected failure path. this is a bug.".to_string(),
|
2014-05-19 19:23:26 -05:00
|
|
|
format!("we would appreciate a bug report: {}",
|
|
|
|
BUG_REPORT_URL),
|
2014-05-25 05:10:11 -05:00
|
|
|
"run with `RUST_BACKTRACE=1` for a backtrace".to_string(),
|
2014-05-06 06:38:01 -05:00
|
|
|
];
|
|
|
|
for note in xs.iter() {
|
2014-07-01 11:39:41 -05:00
|
|
|
emitter.emit(None, note.as_slice(), None, diagnostic::Note)
|
2014-05-06 06:38:01 -05:00
|
|
|
}
|
|
|
|
|
2014-06-21 05:39:03 -05:00
|
|
|
match r.read_to_string() {
|
2014-05-06 06:38:01 -05:00
|
|
|
Ok(s) => println!("{}", s),
|
2014-05-16 12:45:16 -05:00
|
|
|
Err(e) => {
|
|
|
|
emitter.emit(None,
|
|
|
|
format!("failed to read internal \
|
|
|
|
stderr: {}",
|
|
|
|
e).as_slice(),
|
2014-07-01 11:39:41 -05:00
|
|
|
None,
|
2014-05-16 12:45:16 -05:00
|
|
|
diagnostic::Error)
|
|
|
|
}
|
2014-05-06 06:38:01 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fail so the process returns a failure code, but don't pollute the
|
|
|
|
// output with some unnecessary failure messages, we've already
|
|
|
|
// printed everything that we needed to.
|
|
|
|
io::stdio::set_stderr(box io::util::NullWriter);
|
|
|
|
fail!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|