2012-04-05 17:30:26 -07:00
|
|
|
#[no_core];
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 17:08:21 -07:00
|
|
|
#[allow(vecs_implicitly_copyable)];
|
2012-09-18 11:20:57 -07:00
|
|
|
#[allow(non_camel_case_types)];
|
2012-09-18 15:52:21 -07:00
|
|
|
#[legacy_modes];
|
2012-04-05 17:30:26 -07:00
|
|
|
|
2012-10-12 16:41:25 -07:00
|
|
|
extern mod core(vers = "0.5");
|
|
|
|
|
extern mod std(vers = "0.5");
|
|
|
|
|
extern mod rustc(vers = "0.5");
|
|
|
|
|
extern mod syntax(vers = "0.5");
|
2012-04-05 17:30:26 -07:00
|
|
|
|
2012-09-04 11:54:36 -07:00
|
|
|
use core::*;
|
2011-06-15 11:19:50 -07:00
|
|
|
|
|
|
|
|
// -*- rust -*-
|
2012-09-04 11:54:36 -07:00
|
|
|
use result::{Ok, Err};
|
2012-09-25 13:16:43 -04:00
|
|
|
use io::ReaderUtil;
|
2012-09-04 11:54:36 -07:00
|
|
|
use std::getopts;
|
2012-09-10 15:38:28 -07:00
|
|
|
use std::map::HashMap;
|
2012-09-04 11:54:36 -07:00
|
|
|
use getopts::{opt_present};
|
2012-10-11 16:54:31 -07:00
|
|
|
use getopts::groups;
|
2012-09-04 11:54:36 -07:00
|
|
|
use rustc::driver::driver::*;
|
|
|
|
|
use syntax::codemap;
|
|
|
|
|
use syntax::diagnostic;
|
|
|
|
|
use rustc::driver::session;
|
|
|
|
|
use rustc::middle::lint;
|
2011-03-04 07:22:43 +01:00
|
|
|
|
2012-10-04 19:58:31 -07:00
|
|
|
fn version(argv0: &str) {
|
2012-07-13 22:57:48 -07:00
|
|
|
let mut vers = ~"unknown version";
|
2012-08-22 17:24:52 -07:00
|
|
|
let env_vers = env!("CFG_VERSION");
|
2012-10-04 19:58:31 -07:00
|
|
|
if env_vers.len() != 0 { vers = env_vers; }
|
2012-08-22 17:24:52 -07:00
|
|
|
io::println(fmt!("%s %s", argv0, vers));
|
|
|
|
|
io::println(fmt!("host: %s", host_triple()));
|
2011-05-05 12:03:23 -07:00
|
|
|
}
|
|
|
|
|
|
2012-10-04 19:58:31 -07:00
|
|
|
fn usage(argv0: &str) {
|
2012-10-11 16:54:31 -07:00
|
|
|
let message = fmt!("Usage: %s [OPTIONS] INPUT", argv0);
|
|
|
|
|
io::println(groups::usage(message, optgroups()) +
|
|
|
|
|
~"Additional help:
|
|
|
|
|
-W help Print 'lint' options and default settings
|
|
|
|
|
-Z help Print internal options for debugging rustc
|
2011-08-28 00:24:28 -07:00
|
|
|
");
|
2010-10-22 11:47:28 -07:00
|
|
|
}
|
|
|
|
|
|
2012-04-26 13:26:45 -07:00
|
|
|
fn describe_warnings() {
|
2012-10-10 16:35:52 -07:00
|
|
|
io::println(fmt!("
|
|
|
|
|
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)
|
|
|
|
|
"));
|
|
|
|
|
|
2012-04-26 13:26:45 -07:00
|
|
|
let lint_dict = lint::get_lint_dict();
|
2012-08-30 12:54:50 -07:00
|
|
|
let mut max_key = 0;
|
|
|
|
|
for lint_dict.each_key |k| { max_key = uint::max(k.len(), max_key); }
|
2012-10-04 19:58:31 -07:00
|
|
|
fn padded(max: uint, s: &str) -> ~str {
|
2012-04-26 13:26:45 -07:00
|
|
|
str::from_bytes(vec::from_elem(max - s.len(), ' ' as u8)) + s
|
|
|
|
|
}
|
2012-08-22 17:24:52 -07:00
|
|
|
io::println(fmt!("\nAvailable lint checks:\n"));
|
|
|
|
|
io::println(fmt!(" %s %7.7s %s",
|
|
|
|
|
padded(max_key, ~"name"), ~"default", ~"meaning"));
|
|
|
|
|
io::println(fmt!(" %s %7.7s %s\n",
|
|
|
|
|
padded(max_key, ~"----"), ~"-------", ~"-------"));
|
2012-06-30 16:19:07 -07:00
|
|
|
for lint_dict.each |k, v| {
|
2012-07-13 22:57:48 -07:00
|
|
|
let k = str::replace(k, ~"_", ~"-");
|
2012-08-22 17:24:52 -07:00
|
|
|
io::println(fmt!(" %s %7.7s %s",
|
2012-04-26 13:26:45 -07:00
|
|
|
padded(max_key, k),
|
2012-08-06 12:34:08 -07:00
|
|
|
match v.default {
|
2012-08-03 19:59:04 -07:00
|
|
|
lint::allow => ~"allow",
|
|
|
|
|
lint::warn => ~"warn",
|
|
|
|
|
lint::deny => ~"deny",
|
|
|
|
|
lint::forbid => ~"forbid"
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 17:08:21 -07:00
|
|
|
},
|
2012-08-22 17:24:52 -07:00
|
|
|
v.desc));
|
2012-04-26 13:26:45 -07:00
|
|
|
}
|
2012-07-13 22:57:48 -07:00
|
|
|
io::println(~"");
|
2012-04-26 13:26:45 -07:00
|
|
|
}
|
|
|
|
|
|
2012-05-17 21:53:49 -07:00
|
|
|
fn describe_debug_flags() {
|
2012-08-22 17:24:52 -07:00
|
|
|
io::println(fmt!("\nAvailable debug options:\n"));
|
2012-06-30 16:19:07 -07:00
|
|
|
for session::debugging_opts_map().each |pair| {
|
2012-09-19 16:55:01 -07:00
|
|
|
let (name, desc, _) = *pair;
|
2012-10-10 15:45:33 -07:00
|
|
|
io::println(fmt!(" -Z %-20s -- %s", name, desc));
|
2012-05-17 21:53:49 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-04 19:58:31 -07:00
|
|
|
fn run_compiler(args: &~[~str], demitter: diagnostic::emitter) {
|
2012-01-13 13:21:19 -08:00
|
|
|
// Don't display log spew by default. Can override with RUST_LOG.
|
|
|
|
|
logging::console_off();
|
|
|
|
|
|
2012-10-04 19:58:31 -07:00
|
|
|
let mut args = *args;
|
2012-09-27 22:20:47 -07:00
|
|
|
let binary = args.shift();
|
2011-12-30 15:26:49 -08:00
|
|
|
|
2012-10-04 19:58:31 -07:00
|
|
|
if args.is_empty() { usage(binary); return; }
|
2011-12-30 15:26:49 -08:00
|
|
|
|
2012-07-31 16:38:41 -07:00
|
|
|
let matches =
|
2012-10-11 16:54:31 -07:00
|
|
|
match getopts::groups::getopts(args, optgroups()) {
|
2012-08-26 16:54:31 -07:00
|
|
|
Ok(m) => m,
|
|
|
|
|
Err(f) => {
|
2012-01-13 23:18:01 -08:00
|
|
|
early_error(demitter, getopts::fail_str(f))
|
2011-07-27 14:19:39 +02:00
|
|
|
}
|
2011-06-15 11:19:50 -07:00
|
|
|
};
|
2012-04-26 13:26:45 -07:00
|
|
|
|
2012-07-31 16:38:41 -07:00
|
|
|
if opt_present(matches, ~"h") || opt_present(matches, ~"help") {
|
2011-05-22 16:41:32 -04:00
|
|
|
usage(binary);
|
2012-08-01 17:30:05 -07:00
|
|
|
return;
|
2011-05-22 16:41:32 -04:00
|
|
|
}
|
2012-04-26 13:26:45 -07:00
|
|
|
|
2012-07-31 16:38:41 -07:00
|
|
|
let lint_flags = vec::append(getopts::opt_strs(matches, ~"W"),
|
|
|
|
|
getopts::opt_strs(matches, ~"warn"));
|
2012-09-25 17:39:22 -07:00
|
|
|
if lint_flags.contains(&~"help") {
|
2012-04-26 13:26:45 -07:00
|
|
|
describe_warnings();
|
2012-08-01 17:30:05 -07:00
|
|
|
return;
|
2012-04-26 13:26:45 -07:00
|
|
|
}
|
|
|
|
|
|
2012-09-25 17:39:22 -07:00
|
|
|
if getopts::opt_strs(matches, ~"Z").contains(&~"help") {
|
2012-05-17 21:53:49 -07:00
|
|
|
describe_debug_flags();
|
2012-08-01 17:30:05 -07:00
|
|
|
return;
|
2012-05-17 21:53:49 -07:00
|
|
|
}
|
|
|
|
|
|
2012-07-31 16:38:41 -07:00
|
|
|
if opt_present(matches, ~"v") || opt_present(matches, ~"version") {
|
2011-05-22 16:41:32 -04:00
|
|
|
version(binary);
|
2012-08-01 17:30:05 -07:00
|
|
|
return;
|
2011-05-22 16:41:32 -04:00
|
|
|
}
|
2012-08-06 12:34:08 -07:00
|
|
|
let input = match vec::len(matches.free) {
|
2012-08-03 19:59:04 -07:00
|
|
|
0u => early_error(demitter, ~"no input filename given"),
|
|
|
|
|
1u => {
|
2012-07-31 16:38:41 -07:00
|
|
|
let ifile = matches.free[0];
|
2012-07-13 22:57:48 -07:00
|
|
|
if ifile == ~"-" {
|
2012-05-09 19:41:24 -07:00
|
|
|
let src = str::from_bytes(io::stdin().read_whole_stream());
|
|
|
|
|
str_input(src)
|
|
|
|
|
} else {
|
2012-08-24 15:28:43 -07:00
|
|
|
file_input(Path(ifile))
|
2012-05-09 19:41:24 -07:00
|
|
|
}
|
|
|
|
|
}
|
2012-08-03 19:59:04 -07:00
|
|
|
_ => early_error(demitter, ~"multiple input filenames provided")
|
2011-10-28 11:57:01 -07:00
|
|
|
};
|
|
|
|
|
|
2012-08-30 12:24:43 +10:00
|
|
|
let sopts = build_session_options(binary, matches, demitter);
|
2012-03-21 18:56:20 -04:00
|
|
|
let sess = build_session(sopts, demitter);
|
2012-07-31 16:38:41 -07:00
|
|
|
let odir = getopts::opt_maybe_str(matches, ~"out-dir");
|
2012-09-26 16:27:12 -07:00
|
|
|
let odir = odir.map(|o| Path(*o));
|
2012-07-31 16:38:41 -07:00
|
|
|
let ofile = getopts::opt_maybe_str(matches, ~"o");
|
2012-09-26 16:27:12 -07:00
|
|
|
let ofile = ofile.map(|o| Path(*o));
|
2012-05-09 19:41:24 -07:00
|
|
|
let cfg = build_configuration(sess, binary, input);
|
2011-07-27 14:19:39 +02:00
|
|
|
let pretty =
|
2012-09-21 19:37:57 -07:00
|
|
|
option::map(&getopts::opt_default(matches, ~"pretty",
|
2012-07-13 22:57:48 -07:00
|
|
|
~"normal"),
|
2012-09-26 16:27:12 -07:00
|
|
|
|a| parse_pretty(sess, *a) );
|
2012-08-06 12:34:08 -07:00
|
|
|
match pretty {
|
2012-08-20 12:23:37 -07:00
|
|
|
Some::<pp_mode>(ppm) => {
|
2012-08-01 17:30:05 -07:00
|
|
|
pretty_print_input(sess, cfg, input, ppm);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-08-20 12:23:37 -07:00
|
|
|
None::<pp_mode> => {/* continue */ }
|
2011-06-01 18:31:31 -07:00
|
|
|
}
|
2012-07-31 16:38:41 -07:00
|
|
|
let ls = opt_present(matches, ~"ls");
|
2011-10-12 12:29:08 -07:00
|
|
|
if ls {
|
2012-08-06 12:34:08 -07:00
|
|
|
match input {
|
2012-08-03 19:59:04 -07:00
|
|
|
file_input(ifile) => {
|
2012-08-24 15:28:43 -07:00
|
|
|
list_metadata(sess, &ifile, io::stdout());
|
2012-05-09 19:41:24 -07:00
|
|
|
}
|
2012-08-03 19:59:04 -07:00
|
|
|
str_input(_) => {
|
2012-07-13 22:57:48 -07:00
|
|
|
early_error(demitter, ~"can not list metadata for stdin");
|
2012-05-09 19:41:24 -07:00
|
|
|
}
|
|
|
|
|
}
|
2012-08-01 17:30:05 -07:00
|
|
|
return;
|
2011-10-12 12:29:08 -07:00
|
|
|
}
|
2011-07-08 15:03:48 -04:00
|
|
|
|
2012-08-24 15:28:43 -07:00
|
|
|
compile_input(sess, cfg, input, &odir, &ofile);
|
2010-06-23 21:03:09 -07:00
|
|
|
}
|
2011-07-13 18:13:19 -07:00
|
|
|
|
2012-08-27 16:26:35 -07:00
|
|
|
enum monitor_msg {
|
|
|
|
|
fatal,
|
|
|
|
|
done,
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-19 18:00:26 -07:00
|
|
|
impl monitor_msg : cmp::Eq {
|
|
|
|
|
pure fn eq(other: &monitor_msg) -> bool {
|
|
|
|
|
(self as uint) == ((*other) as uint)
|
|
|
|
|
}
|
|
|
|
|
pure fn ne(other: &monitor_msg) -> bool { !self.eq(other) }
|
|
|
|
|
}
|
2012-08-27 16:26:35 -07:00
|
|
|
|
2012-01-14 00:35:46 -08:00
|
|
|
/*
|
|
|
|
|
This is a sanity check that any failure of the compiler is performed
|
|
|
|
|
through the diagnostic module and reported properly - we shouldn't be calling
|
|
|
|
|
plain-old-fail on any execution path that might be taken. Since we have
|
|
|
|
|
console logging off by default, hitting a plain fail statement would make the
|
|
|
|
|
compiler silently exit, which would be terrible.
|
|
|
|
|
|
|
|
|
|
This method wraps the compiler in a subtask and injects a function into the
|
|
|
|
|
diagnostic emitter which records when we hit a fatal error. If the task
|
|
|
|
|
fails without recording a fatal error then we've encountered a compiler
|
|
|
|
|
bug and need to present an error.
|
|
|
|
|
*/
|
2012-05-24 14:49:39 -07:00
|
|
|
fn monitor(+f: fn~(diagnostic::emitter)) {
|
2012-08-27 14:22:25 -07:00
|
|
|
let p = comm::Port();
|
2012-10-03 14:38:01 -07:00
|
|
|
let ch = comm::Chan(&p);
|
2012-01-14 00:35:46 -08:00
|
|
|
|
2012-09-12 11:15:39 -07:00
|
|
|
match do task::try |move f| {
|
2012-01-14 00:35:46 -08:00
|
|
|
|
|
|
|
|
// The 'diagnostics emitter'. Every error, warning, etc. should
|
|
|
|
|
// go through this function.
|
2012-10-15 14:56:42 -07:00
|
|
|
let demitter = fn@(cmsp: Option<(codemap::CodeMap, codemap::span)>,
|
2012-09-28 12:22:33 -07:00
|
|
|
msg: &str, lvl: diagnostic::level) {
|
2012-01-14 00:35:46 -08:00
|
|
|
if lvl == diagnostic::fatal {
|
|
|
|
|
comm::send(ch, fatal);
|
|
|
|
|
}
|
|
|
|
|
diagnostic::emit(cmsp, msg, lvl);
|
|
|
|
|
};
|
|
|
|
|
|
2012-08-15 18:46:55 -07:00
|
|
|
struct finally {
|
2012-09-06 19:40:15 -07:00
|
|
|
ch: comm::Chan<monitor_msg>,
|
2012-06-22 11:53:25 -07:00
|
|
|
drop { comm::send(self.ch, done); }
|
2012-01-14 00:35:46 -08:00
|
|
|
}
|
|
|
|
|
|
2012-09-05 15:58:43 -07:00
|
|
|
let _finally = finally { ch: ch };
|
2012-01-14 00:35:46 -08:00
|
|
|
|
|
|
|
|
f(demitter)
|
|
|
|
|
} {
|
2012-08-26 16:54:31 -07:00
|
|
|
result::Ok(_) => { /* fallthrough */ }
|
|
|
|
|
result::Err(_) => {
|
2012-01-14 00:35:46 -08:00
|
|
|
// Task failed without emitting a fatal diagnostic
|
|
|
|
|
if comm::recv(p) == done {
|
|
|
|
|
diagnostic::emit(
|
2012-08-20 12:23:37 -07:00
|
|
|
None,
|
2012-07-13 22:57:48 -07:00
|
|
|
diagnostic::ice_msg(~"unexpected failure"),
|
2012-01-14 00:35:46 -08:00
|
|
|
diagnostic::error);
|
2012-04-28 16:38:06 -07:00
|
|
|
|
|
|
|
|
for [
|
2012-07-13 22:57:48 -07:00
|
|
|
~"the compiler hit an unexpected failure path. \
|
2012-04-28 16:38:06 -07:00
|
|
|
this is a bug",
|
2012-07-13 22:57:48 -07:00
|
|
|
~"try running with RUST_LOG=rustc=0,::rt::backtrace \
|
2012-04-28 16:38:06 -07:00
|
|
|
to get further details and report the results \
|
|
|
|
|
to github.com/mozilla/rust/issues"
|
2012-06-30 16:19:07 -07:00
|
|
|
]/_.each |note| {
|
2012-09-19 16:55:01 -07:00
|
|
|
diagnostic::emit(None, *note, diagnostic::note)
|
2012-04-28 16:38:06 -07:00
|
|
|
}
|
2012-01-14 00:35:46 -08:00
|
|
|
}
|
|
|
|
|
// Fail so the process returns a failure code
|
|
|
|
|
fail;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-03 19:16:27 -07:00
|
|
|
fn main() {
|
2012-10-04 19:58:31 -07:00
|
|
|
let mut args = os::args();
|
|
|
|
|
do monitor |move args, demitter| {
|
|
|
|
|
run_compiler(&args, demitter);
|
2012-01-14 00:35:46 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-12 10:29:23 -07:00
|
|
|
// Local Variables:
|
|
|
|
|
// mode: rust
|
|
|
|
|
// fill-column: 78;
|
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
|
// c-basic-offset: 4
|
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
|
// End:
|