2011-12-20 04:17:13 -06:00
|
|
|
// -*- rust -*-
|
2012-05-29 22:38:46 -05:00
|
|
|
import metadata::{creader, cstore, filesearch};
|
2012-01-12 10:59:49 -06:00
|
|
|
import session::session;
|
2012-04-18 01:34:48 -05:00
|
|
|
import syntax::parse;
|
2011-12-20 04:17:13 -06:00
|
|
|
import syntax::{ast, codemap};
|
2012-03-22 20:16:22 -05:00
|
|
|
import syntax::attr;
|
2012-05-25 02:14:40 -05:00
|
|
|
import middle::{trans, resolve, freevars, kind, ty, typeck, lint};
|
2011-12-20 04:17:13 -06:00
|
|
|
import syntax::print::{pp, pprust};
|
2012-05-29 22:38:46 -05:00
|
|
|
import util::ppaux;
|
2011-12-20 04:17:13 -06:00
|
|
|
import back::link;
|
|
|
|
import result::{ok, err};
|
2012-03-12 22:04:27 -05:00
|
|
|
import std::getopts;
|
2012-01-19 12:53:20 -06:00
|
|
|
import io::{reader_util, writer_util};
|
2011-12-20 04:17:13 -06:00
|
|
|
import getopts::{optopt, optmulti, optflag, optflagopt, opt_present};
|
|
|
|
import back::{x86, x86_64};
|
2012-05-22 12:54:12 -05:00
|
|
|
import std::map::hashmap;
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2012-03-12 12:19:35 -05:00
|
|
|
enum pp_mode {ppm_normal, ppm_expanded, ppm_typed, ppm_identified,
|
|
|
|
ppm_expanded_identified }
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2012-07-04 16:53:12 -05:00
|
|
|
/**
|
|
|
|
* The name used for source code that doesn't originate in a file
|
|
|
|
* (e.g. source from stdin or a string)
|
|
|
|
*/
|
2012-05-09 21:41:24 -05:00
|
|
|
fn anon_src() -> str { "<anon>" }
|
|
|
|
|
|
|
|
fn source_name(input: input) -> str {
|
|
|
|
alt input {
|
|
|
|
file_input(ifile) { ifile }
|
|
|
|
str_input(_) { anon_src() }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn default_configuration(sess: session, argv0: str, input: input) ->
|
2011-12-20 04:17:13 -06:00
|
|
|
ast::crate_cfg {
|
2012-01-26 03:52:08 -06:00
|
|
|
let libc = alt sess.targ_cfg.os {
|
|
|
|
session::os_win32 { "msvcrt.dll" }
|
|
|
|
session::os_macos { "libc.dylib" }
|
|
|
|
session::os_linux { "libc.so.6" }
|
|
|
|
session::os_freebsd { "libc.so.7" }
|
2012-04-24 04:13:25 -05:00
|
|
|
// _ { "libc.so" }
|
2012-01-26 03:52:08 -06:00
|
|
|
};
|
2011-12-20 04:17:13 -06:00
|
|
|
|
|
|
|
let mk = attr::mk_name_value_item_str;
|
|
|
|
|
2012-01-12 10:59:49 -06:00
|
|
|
let arch = alt sess.targ_cfg.arch {
|
2012-01-19 03:03:57 -06:00
|
|
|
session::arch_x86 { "x86" }
|
|
|
|
session::arch_x86_64 { "x86_64" }
|
|
|
|
session::arch_arm { "arm" }
|
2011-12-20 04:17:13 -06:00
|
|
|
};
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
ret ~[ // Target bindings.
|
2012-06-10 02:49:59 -05:00
|
|
|
attr::mk_word_item(@os::family()),
|
|
|
|
mk(@"target_os", os::sysname()),
|
|
|
|
mk(@"target_family", os::family()),
|
|
|
|
mk(@"target_arch", arch),
|
|
|
|
mk(@"target_libc", libc),
|
2011-12-20 04:17:13 -06:00
|
|
|
// Build bindings.
|
2012-06-10 02:49:59 -05:00
|
|
|
mk(@"build_compiler", argv0),
|
2012-06-29 18:26:56 -05:00
|
|
|
mk(@"build_input", source_name(input))];
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
2012-05-09 21:41:24 -05:00
|
|
|
fn build_configuration(sess: session, argv0: str, input: input) ->
|
2011-12-20 04:17:13 -06:00
|
|
|
ast::crate_cfg {
|
|
|
|
// Combine the configuration requested by the session (command line) with
|
|
|
|
// some default and generated configuration items
|
|
|
|
let default_cfg = default_configuration(sess, argv0, input);
|
2012-01-12 10:59:49 -06:00
|
|
|
let user_cfg = sess.opts.cfg;
|
2011-12-20 04:17:13 -06:00
|
|
|
// If the user wants a test runner, then add the test cfg
|
|
|
|
let gen_cfg =
|
|
|
|
{
|
2012-01-12 10:59:49 -06:00
|
|
|
if sess.opts.test && !attr::contains_name(user_cfg, "test")
|
2011-12-20 04:17:13 -06:00
|
|
|
{
|
2012-06-29 18:26:56 -05:00
|
|
|
~[attr::mk_word_item(@"test")]
|
|
|
|
} else { ~[] }
|
2011-12-20 04:17:13 -06:00
|
|
|
};
|
2012-06-28 17:00:03 -05:00
|
|
|
ret vec::append(vec::append(user_cfg, gen_cfg), default_cfg);
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Convert strings provided as --cfg [cfgspec] into a crate_cfg
|
2012-06-29 18:26:56 -05:00
|
|
|
fn parse_cfgspecs(cfgspecs: ~[str]) -> ast::crate_cfg {
|
2012-06-21 18:44:10 -05:00
|
|
|
// FIXME (#2399): It would be nice to use the parser to parse all
|
|
|
|
// varieties of meta_item here. At the moment we just support the
|
|
|
|
// meta_word variant.
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut words = ~[];
|
2012-06-30 18:19:07 -05:00
|
|
|
for cfgspecs.each |s| { vec::push(words, attr::mk_word_item(@s)); }
|
2011-12-20 04:17:13 -06:00
|
|
|
ret words;
|
|
|
|
}
|
|
|
|
|
2012-05-09 21:41:24 -05:00
|
|
|
enum input {
|
2012-07-04 16:53:12 -05:00
|
|
|
/// Load source from file
|
2012-05-09 21:41:24 -05:00
|
|
|
file_input(str),
|
2012-07-04 16:53:12 -05:00
|
|
|
/// The string is the source
|
2012-05-09 21:41:24 -05:00
|
|
|
str_input(str)
|
|
|
|
}
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2012-05-09 21:41:24 -05:00
|
|
|
fn parse_input(sess: session, cfg: ast::crate_cfg, input: input)
|
2012-01-26 03:52:08 -06:00
|
|
|
-> @ast::crate {
|
2012-05-09 21:41:24 -05:00
|
|
|
alt input {
|
|
|
|
file_input(file) {
|
|
|
|
parse::parse_crate_from_file(file, cfg, sess.parse_sess)
|
|
|
|
}
|
|
|
|
str_input(src) {
|
2012-06-21 18:44:10 -05:00
|
|
|
// FIXME (#2319): Don't really want to box the source string
|
2012-05-09 21:41:24 -05:00
|
|
|
parse::parse_crate_from_source_str(
|
|
|
|
anon_src(), @src, cfg, sess.parse_sess)
|
|
|
|
}
|
2012-01-26 03:52:08 -06:00
|
|
|
}
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
2012-05-22 12:54:12 -05:00
|
|
|
fn time<T>(do_it: bool, what: str, thunk: fn() -> T) -> T {
|
2011-12-20 04:17:13 -06:00
|
|
|
if !do_it { ret thunk(); }
|
|
|
|
let start = std::time::precise_time_s();
|
|
|
|
let rv = thunk();
|
|
|
|
let end = std::time::precise_time_s();
|
2012-01-19 12:53:20 -06:00
|
|
|
io::stdout().write_str(#fmt("time: %3.3f s\t%s\n",
|
|
|
|
end - start, what));
|
2011-12-20 04:17:13 -06:00
|
|
|
ret rv;
|
|
|
|
}
|
|
|
|
|
2012-01-17 09:42:45 -06:00
|
|
|
enum compile_upto {
|
2012-01-19 19:56:05 -06:00
|
|
|
cu_parse,
|
|
|
|
cu_expand,
|
|
|
|
cu_typeck,
|
|
|
|
cu_no_trans,
|
|
|
|
cu_everything,
|
2012-01-17 09:42:45 -06:00
|
|
|
}
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2012-01-17 09:42:45 -06:00
|
|
|
fn compile_upto(sess: session, cfg: ast::crate_cfg,
|
2012-05-09 21:41:24 -05:00
|
|
|
input: input, upto: compile_upto,
|
2012-01-31 19:05:20 -06:00
|
|
|
outputs: option<output_filenames>)
|
|
|
|
-> {crate: @ast::crate, tcx: option<ty::ctxt>} {
|
2012-05-17 23:53:49 -05:00
|
|
|
let time_passes = sess.time_passes();
|
2012-03-15 08:47:03 -05:00
|
|
|
let mut crate = time(time_passes, "parsing",
|
2012-06-30 18:19:07 -05:00
|
|
|
||parse_input(sess, cfg, input) );
|
2012-01-26 03:52:08 -06:00
|
|
|
if upto == cu_parse { ret {crate: crate, tcx: none}; }
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2012-01-17 16:37:39 -06:00
|
|
|
sess.building_library = session::building_library(
|
|
|
|
sess.opts.crate_type, crate, sess.opts.test);
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2012-05-22 12:54:12 -05:00
|
|
|
crate = time(time_passes, "configuration", ||
|
|
|
|
front::config::strip_unconfigured_items(crate));
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2012-05-22 12:54:12 -05:00
|
|
|
crate = time(time_passes, "maybe building test harness", ||
|
|
|
|
front::test::modify_for_testing(sess, crate));
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2012-05-22 12:54:12 -05:00
|
|
|
crate = time(time_passes, "expansion", ||
|
|
|
|
syntax::ext::expand::expand_crate(sess.parse_sess, sess.opts.cfg,
|
|
|
|
crate));
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2012-01-26 03:52:08 -06:00
|
|
|
if upto == cu_expand { ret {crate: crate, tcx: none}; }
|
2012-01-26 17:20:29 -06:00
|
|
|
|
2012-05-22 12:54:12 -05:00
|
|
|
crate = time(time_passes, "intrinsic injection", ||
|
|
|
|
front::intrinsic_inject::inject_intrinsic(sess, crate));
|
|
|
|
|
|
|
|
crate = time(time_passes, "core injection", ||
|
|
|
|
front::core_inject::maybe_inject_libcore_ref(sess, crate));
|
|
|
|
|
|
|
|
time(time_passes, "building warning settings table", ||
|
|
|
|
lint::build_settings_crate(sess, crate));
|
|
|
|
|
|
|
|
let ast_map = time(time_passes, "ast indexing", ||
|
|
|
|
syntax::ast_map::map_crate(sess.diagnostic(), *crate));
|
|
|
|
|
|
|
|
time(time_passes, "external crate/lib resolution", ||
|
|
|
|
creader::read_crates(sess.diagnostic(), *crate, sess.cstore,
|
|
|
|
sess.filesearch,
|
|
|
|
session::sess_os_to_meta_os(sess.targ_cfg.os),
|
|
|
|
sess.opts.static));
|
|
|
|
|
2012-07-09 18:48:15 -05:00
|
|
|
let mut def_map;
|
|
|
|
let mut impl_map;
|
|
|
|
let mut exp_map;
|
|
|
|
if sess.fast_resolve() {
|
|
|
|
let { def_map: fast_dm, exp_map: fast_em, impl_map: fast_im } =
|
|
|
|
time(time_passes, "fast resolution", ||
|
|
|
|
middle::resolve3::resolve_crate(sess, ast_map, crate));
|
|
|
|
|
|
|
|
def_map = fast_dm;
|
|
|
|
impl_map = fast_im;
|
|
|
|
exp_map = fast_em;
|
|
|
|
} else {
|
|
|
|
let { def_map: normal_dm, exp_map: normal_em, impl_map: normal_im } =
|
|
|
|
time(time_passes, "resolution", ||
|
|
|
|
resolve::resolve_crate(sess, ast_map, crate));
|
|
|
|
|
|
|
|
def_map = normal_dm;
|
|
|
|
impl_map = normal_im;
|
|
|
|
exp_map = normal_em;
|
|
|
|
}
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2012-05-22 12:54:12 -05:00
|
|
|
let freevars = time(time_passes, "freevar finding", ||
|
|
|
|
freevars::annotate_freevars(def_map, crate));
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2012-05-22 12:54:12 -05:00
|
|
|
let region_map = time(time_passes, "region resolution", ||
|
|
|
|
middle::region::resolve_crate(sess, def_map, crate));
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2012-03-09 18:39:54 -06:00
|
|
|
let ty_cx = ty::mk_ctxt(sess, def_map, ast_map, freevars, region_map);
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2012-05-22 12:54:12 -05:00
|
|
|
let (method_map, vtable_map) = time(time_passes, "typechecking", ||
|
|
|
|
typeck::check_crate(ty_cx,
|
|
|
|
impl_map,
|
|
|
|
crate));
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2012-05-22 12:54:12 -05:00
|
|
|
time(time_passes, "const checking", ||
|
|
|
|
middle::check_const::check_crate(sess, crate, ast_map, def_map,
|
|
|
|
method_map, ty_cx));
|
2012-01-17 09:42:45 -06:00
|
|
|
|
2012-01-26 03:52:08 -06:00
|
|
|
if upto == cu_typeck { ret {crate: crate, tcx: some(ty_cx)}; }
|
2012-01-17 09:42:45 -06:00
|
|
|
|
2012-05-22 12:54:12 -05:00
|
|
|
time(time_passes, "block-use checking", ||
|
|
|
|
middle::block_use::check_crate(ty_cx, crate));
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2012-05-22 12:54:12 -05:00
|
|
|
time(time_passes, "loop checking", ||
|
|
|
|
middle::check_loop::check_crate(ty_cx, crate));
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2012-05-22 12:54:12 -05:00
|
|
|
time(time_passes, "alt checking", ||
|
|
|
|
middle::check_alt::check_crate(ty_cx, crate));
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2012-05-22 12:54:12 -05:00
|
|
|
let last_use_map = time(time_passes, "liveness checking", ||
|
|
|
|
middle::liveness::check_crate(ty_cx, method_map, crate));
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2012-05-22 12:54:12 -05:00
|
|
|
time(time_passes, "typestate checking", ||
|
|
|
|
middle::tstate::ck::check_crate(ty_cx, crate));
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2012-05-22 12:54:12 -05:00
|
|
|
let (root_map, mutbl_map) = time(time_passes, "borrow checking", ||
|
2012-06-30 18:19:07 -05:00
|
|
|
middle::borrowck::check_crate(ty_cx, method_map,
|
2012-05-22 12:54:12 -05:00
|
|
|
last_use_map, crate));
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2012-05-22 12:54:12 -05:00
|
|
|
time(time_passes, "kind checking", ||
|
|
|
|
kind::check_crate(ty_cx, method_map, last_use_map, crate));
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2012-05-22 12:54:12 -05:00
|
|
|
time(time_passes, "lint checking", || lint::check_crate(ty_cx, crate));
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2012-01-26 03:52:08 -06:00
|
|
|
if upto == cu_no_trans { ret {crate: crate, tcx: some(ty_cx)}; }
|
2012-01-17 09:42:45 -06:00
|
|
|
let outputs = option::get(outputs);
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2012-05-14 22:32:29 -05:00
|
|
|
let maps = {mutbl_map: mutbl_map, root_map: root_map,
|
2012-06-08 09:46:14 -05:00
|
|
|
last_use_map: last_use_map,
|
2012-05-14 22:32:29 -05:00
|
|
|
impl_map: impl_map, method_map: method_map,
|
2012-06-06 16:19:52 -05:00
|
|
|
vtable_map: vtable_map};
|
2012-02-14 17:21:53 -06:00
|
|
|
|
2012-05-22 12:54:12 -05:00
|
|
|
let (llmod, link_meta) = time(time_passes, "translation", ||
|
2012-06-30 18:19:07 -05:00
|
|
|
trans::base::trans_crate(sess, crate, ty_cx, outputs.obj_filename,
|
2012-05-22 12:54:12 -05:00
|
|
|
exp_map, maps));
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2012-05-22 12:54:12 -05:00
|
|
|
time(time_passes, "LLVM passes", ||
|
|
|
|
link::write::run_passes(sess, llmod, outputs.obj_filename));
|
2011-12-20 04:17:13 -06:00
|
|
|
|
|
|
|
let stop_after_codegen =
|
2012-01-12 10:59:49 -06:00
|
|
|
sess.opts.output_type != link::output_type_exe ||
|
|
|
|
sess.opts.static && sess.building_library;
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2012-01-26 03:52:08 -06:00
|
|
|
if stop_after_codegen { ret {crate: crate, tcx: some(ty_cx)}; }
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2012-05-22 12:54:12 -05:00
|
|
|
time(time_passes, "linking", ||
|
|
|
|
link::link_binary(sess, outputs.obj_filename,
|
|
|
|
outputs.out_filename, link_meta));
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2012-01-26 03:52:08 -06:00
|
|
|
ret {crate: crate, tcx: some(ty_cx)};
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
2012-05-09 21:41:24 -05:00
|
|
|
fn compile_input(sess: session, cfg: ast::crate_cfg, input: input,
|
2012-01-31 19:05:20 -06:00
|
|
|
outdir: option<str>, output: option<str>) {
|
2012-01-17 09:42:45 -06:00
|
|
|
|
|
|
|
let upto = if sess.opts.parse_only { cu_parse }
|
|
|
|
else if sess.opts.no_trans { cu_no_trans }
|
|
|
|
else { cu_everything };
|
|
|
|
let outputs = build_output_filenames(input, outdir, output, sess);
|
|
|
|
compile_upto(sess, cfg, input, upto, some(outputs));
|
|
|
|
}
|
|
|
|
|
2012-05-09 21:41:24 -05:00
|
|
|
fn pretty_print_input(sess: session, cfg: ast::crate_cfg, input: input,
|
2011-12-20 04:17:13 -06:00
|
|
|
ppm: pp_mode) {
|
|
|
|
fn ann_paren_for_expr(node: pprust::ann_node) {
|
|
|
|
alt node { pprust::node_expr(s, expr) { pprust::popen(s); } _ { } }
|
|
|
|
}
|
|
|
|
fn ann_typed_post(tcx: ty::ctxt, node: pprust::ann_node) {
|
|
|
|
alt node {
|
|
|
|
pprust::node_expr(s, expr) {
|
|
|
|
pp::space(s.s);
|
|
|
|
pp::word(s.s, "as");
|
|
|
|
pp::space(s.s);
|
|
|
|
pp::word(s.s, ppaux::ty_to_str(tcx, ty::expr_ty(tcx, expr)));
|
|
|
|
pprust::pclose(s);
|
|
|
|
}
|
|
|
|
_ { }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn ann_identified_post(node: pprust::ann_node) {
|
|
|
|
alt node {
|
|
|
|
pprust::node_item(s, item) {
|
|
|
|
pp::space(s.s);
|
|
|
|
pprust::synth_comment(s, int::to_str(item.id, 10u));
|
|
|
|
}
|
|
|
|
pprust::node_block(s, blk) {
|
|
|
|
pp::space(s.s);
|
|
|
|
pprust::synth_comment(s,
|
|
|
|
"block " + int::to_str(blk.node.id, 10u));
|
|
|
|
}
|
|
|
|
pprust::node_expr(s, expr) {
|
|
|
|
pp::space(s.s);
|
|
|
|
pprust::synth_comment(s, int::to_str(expr.id, 10u));
|
|
|
|
pprust::pclose(s);
|
|
|
|
}
|
2012-05-18 21:06:56 -05:00
|
|
|
pprust::node_pat(s, pat) {
|
|
|
|
pp::space(s.s);
|
|
|
|
pprust::synth_comment(s, "pat " + int::to_str(pat.id, 10u));
|
|
|
|
}
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Because the pretty printer needs to make a pass over the source
|
|
|
|
// to collect comments and literals, and we need to support reading
|
|
|
|
// from stdin, we're going to just suck the source into a string
|
|
|
|
// so both the parser and pretty-printer can use it.
|
2012-01-17 09:42:45 -06:00
|
|
|
let upto = alt ppm {
|
2012-03-12 12:19:35 -05:00
|
|
|
ppm_expanded | ppm_expanded_identified { cu_expand }
|
2012-01-19 00:37:22 -06:00
|
|
|
ppm_typed { cu_typeck }
|
2012-01-17 09:42:45 -06:00
|
|
|
_ { cu_parse }
|
|
|
|
};
|
2012-01-26 03:52:08 -06:00
|
|
|
let {crate, tcx} = compile_upto(sess, cfg, input, upto, none);
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2012-06-28 17:29:15 -05:00
|
|
|
let ann = alt ppm {
|
2012-01-19 00:37:22 -06:00
|
|
|
ppm_typed {
|
2012-06-28 17:29:15 -05:00
|
|
|
{pre: ann_paren_for_expr,
|
2012-06-30 18:19:07 -05:00
|
|
|
post: |a| ann_typed_post(option::get(tcx), a) }
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
2012-03-12 12:19:35 -05:00
|
|
|
ppm_identified | ppm_expanded_identified {
|
2012-06-28 17:29:15 -05:00
|
|
|
{pre: ann_paren_for_expr, post: ann_identified_post}
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
2012-06-28 17:29:15 -05:00
|
|
|
ppm_expanded | ppm_normal { pprust::no_ann() }
|
|
|
|
};
|
|
|
|
let is_expanded = upto != cu_parse;
|
2012-05-09 21:41:24 -05:00
|
|
|
let src = codemap::get_filemap(sess.codemap, source_name(input)).src;
|
2012-06-30 18:19:07 -05:00
|
|
|
do io::with_str_reader(*src) |rdr| {
|
2012-05-09 21:41:24 -05:00
|
|
|
pprust::print_crate(sess.codemap, sess.span_diagnostic, crate,
|
|
|
|
source_name(input),
|
2012-06-28 17:29:15 -05:00
|
|
|
rdr, io::stdout(), ann, is_expanded);
|
2012-02-29 23:23:50 -06:00
|
|
|
}
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
2012-01-14 01:03:37 -06:00
|
|
|
fn get_os(triple: str) -> option<session::os> {
|
2012-02-13 00:00:56 -06:00
|
|
|
ret if str::contains(triple, "win32") ||
|
|
|
|
str::contains(triple, "mingw32") {
|
2012-01-14 01:03:37 -06:00
|
|
|
some(session::os_win32)
|
2012-02-13 00:00:56 -06:00
|
|
|
} else if str::contains(triple, "darwin") {
|
2012-01-14 01:03:37 -06:00
|
|
|
some(session::os_macos)
|
2012-02-13 00:00:56 -06:00
|
|
|
} else if str::contains(triple, "linux") {
|
2012-01-14 01:03:37 -06:00
|
|
|
some(session::os_linux)
|
2012-02-13 00:00:56 -06:00
|
|
|
} else if str::contains(triple, "freebsd") {
|
2012-01-14 01:03:37 -06:00
|
|
|
some(session::os_freebsd)
|
|
|
|
} else { none };
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
2012-01-14 01:03:37 -06:00
|
|
|
fn get_arch(triple: str) -> option<session::arch> {
|
2012-02-13 00:00:56 -06:00
|
|
|
ret if str::contains(triple, "i386") || str::contains(triple, "i486") ||
|
|
|
|
str::contains(triple, "i586") ||
|
|
|
|
str::contains(triple, "i686") ||
|
|
|
|
str::contains(triple, "i786") {
|
2012-01-14 01:03:37 -06:00
|
|
|
some(session::arch_x86)
|
2012-02-13 00:00:56 -06:00
|
|
|
} else if str::contains(triple, "x86_64") {
|
2012-01-14 01:03:37 -06:00
|
|
|
some(session::arch_x86_64)
|
2012-02-13 00:00:56 -06:00
|
|
|
} else if str::contains(triple, "arm") ||
|
|
|
|
str::contains(triple, "xscale") {
|
2012-01-14 01:03:37 -06:00
|
|
|
some(session::arch_arm)
|
|
|
|
} else { none };
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
2012-01-14 01:18:01 -06:00
|
|
|
fn build_target_config(sopts: @session::options,
|
|
|
|
demitter: diagnostic::emitter) -> @session::config {
|
2012-01-14 01:03:37 -06:00
|
|
|
let os = alt get_os(sopts.target_triple) {
|
|
|
|
some(os) { os }
|
2012-03-05 18:27:27 -06:00
|
|
|
none { early_error(demitter, "unknown operating system") }
|
2012-01-14 01:03:37 -06:00
|
|
|
};
|
|
|
|
let arch = alt get_arch(sopts.target_triple) {
|
|
|
|
some(arch) { arch }
|
2012-01-19 00:37:22 -06:00
|
|
|
none { early_error(demitter,
|
2012-03-05 18:27:27 -06:00
|
|
|
"unknown architecture: " + sopts.target_triple) }
|
2012-01-14 01:03:37 -06:00
|
|
|
};
|
2011-12-20 04:17:13 -06:00
|
|
|
let (int_type, uint_type, float_type) = alt arch {
|
2012-01-19 03:03:57 -06:00
|
|
|
session::arch_x86 {(ast::ty_i32, ast::ty_u32, ast::ty_f64)}
|
|
|
|
session::arch_x86_64 {(ast::ty_i64, ast::ty_u64, ast::ty_f64)}
|
|
|
|
session::arch_arm {(ast::ty_i32, ast::ty_u32, ast::ty_f64)}
|
2011-12-20 04:17:13 -06:00
|
|
|
};
|
|
|
|
let target_strs = alt arch {
|
2012-01-19 03:03:57 -06:00
|
|
|
session::arch_x86 {x86::get_target_strs(os)}
|
|
|
|
session::arch_x86_64 {x86_64::get_target_strs(os)}
|
|
|
|
session::arch_arm {x86::get_target_strs(os)}
|
2011-12-20 04:17:13 -06:00
|
|
|
};
|
|
|
|
let target_cfg: @session::config =
|
|
|
|
@{os: os, arch: arch, target_strs: target_strs, int_type: int_type,
|
|
|
|
uint_type: uint_type, float_type: float_type};
|
|
|
|
ret target_cfg;
|
|
|
|
}
|
|
|
|
|
|
|
|
fn host_triple() -> str {
|
|
|
|
// Get the host triple out of the build environment. This ensures that our
|
|
|
|
// idea of the host triple is the same as for the set of libraries we've
|
|
|
|
// actually built. We can't just take LLVM's host triple because they
|
|
|
|
// normalize all ix86 architectures to i386.
|
2012-06-21 18:44:10 -05:00
|
|
|
|
|
|
|
// FIXME (#2400): Instead of grabbing the host triple we really should
|
|
|
|
// be grabbing (at compile time) the target triple that this rustc is
|
|
|
|
// built with and calling that (at runtime) the host triple.
|
2011-12-20 04:17:13 -06:00
|
|
|
let ht = #env("CFG_HOST_TRIPLE");
|
2012-01-29 20:33:08 -06:00
|
|
|
ret if ht != "" {
|
|
|
|
ht
|
|
|
|
} else {
|
|
|
|
fail "rustc built without CFG_HOST_TRIPLE"
|
|
|
|
};
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
2012-01-14 01:18:01 -06:00
|
|
|
fn build_session_options(match: getopts::match,
|
|
|
|
demitter: diagnostic::emitter) -> @session::options {
|
2011-12-20 04:17:13 -06:00
|
|
|
let crate_type = if opt_present(match, "lib") {
|
|
|
|
session::lib_crate
|
|
|
|
} else if opt_present(match, "bin") {
|
|
|
|
session::bin_crate
|
|
|
|
} else {
|
|
|
|
session::unknown_crate
|
|
|
|
};
|
|
|
|
let static = opt_present(match, "static");
|
|
|
|
|
|
|
|
let parse_only = opt_present(match, "parse-only");
|
|
|
|
let no_trans = opt_present(match, "no-trans");
|
2012-04-12 19:30:52 -05:00
|
|
|
|
2012-06-28 17:00:03 -05:00
|
|
|
let lint_flags = vec::append(getopts::opt_strs(match, "W"),
|
|
|
|
getopts::opt_strs(match, "warn"));
|
2012-04-12 19:30:52 -05:00
|
|
|
let lint_dict = lint::get_lint_dict();
|
2012-06-30 18:19:07 -05:00
|
|
|
let lint_opts = do vec::map(lint_flags) |flag| {
|
2012-04-12 19:30:52 -05:00
|
|
|
alt lint::lookup_lint(lint_dict, flag) {
|
2012-06-01 17:58:04 -05:00
|
|
|
(flag, none) {
|
|
|
|
early_error(demitter, #fmt("unknown warning: %s", flag))
|
|
|
|
}
|
|
|
|
(_, some(x)) { x }
|
2012-04-12 19:30:52 -05:00
|
|
|
}
|
|
|
|
};
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2012-05-17 23:53:49 -05:00
|
|
|
let mut debugging_opts = 0u;
|
|
|
|
let debug_flags = getopts::opt_strs(match, "Z");
|
|
|
|
let debug_map = session::debugging_opts_map();
|
2012-06-30 18:19:07 -05:00
|
|
|
for debug_flags.each |debug_flag| {
|
2012-05-17 23:53:49 -05:00
|
|
|
let mut this_bit = 0u;
|
2012-06-30 18:19:07 -05:00
|
|
|
for debug_map.each |pair| {
|
2012-05-17 23:53:49 -05:00
|
|
|
let (name, _, bit) = pair;
|
|
|
|
if name == debug_flag { this_bit = bit; break; }
|
|
|
|
}
|
|
|
|
if this_bit == 0u {
|
|
|
|
early_error(demitter, #fmt("unknown debug flag: %s", debug_flag))
|
|
|
|
}
|
|
|
|
debugging_opts |= this_bit;
|
|
|
|
}
|
|
|
|
|
2011-12-20 04:17:13 -06:00
|
|
|
let output_type =
|
|
|
|
if parse_only || no_trans {
|
|
|
|
link::output_type_none
|
|
|
|
} else if opt_present(match, "S") && opt_present(match, "emit-llvm") {
|
|
|
|
link::output_type_llvm_assembly
|
|
|
|
} else if opt_present(match, "S") {
|
|
|
|
link::output_type_assembly
|
|
|
|
} else if opt_present(match, "c") {
|
|
|
|
link::output_type_object
|
|
|
|
} else if opt_present(match, "emit-llvm") {
|
|
|
|
link::output_type_bitcode
|
|
|
|
} else { link::output_type_exe };
|
|
|
|
let extra_debuginfo = opt_present(match, "xg");
|
|
|
|
let debuginfo = opt_present(match, "g") || extra_debuginfo;
|
|
|
|
let sysroot_opt = getopts::opt_maybe_str(match, "sysroot");
|
|
|
|
let target_opt = getopts::opt_maybe_str(match, "target");
|
2012-05-17 23:53:49 -05:00
|
|
|
let save_temps = getopts::opt_present(match, "save-temps");
|
2011-12-20 04:17:13 -06:00
|
|
|
alt output_type {
|
|
|
|
// unless we're emitting huamn-readable assembly, omit comments.
|
2012-01-19 03:03:57 -06:00
|
|
|
link::output_type_llvm_assembly | link::output_type_assembly {}
|
2012-05-17 23:53:49 -05:00
|
|
|
_ { debugging_opts |= session::no_asm_comments; }
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
let opt_level: uint =
|
|
|
|
if opt_present(match, "O") {
|
|
|
|
if opt_present(match, "opt-level") {
|
2012-01-14 01:18:01 -06:00
|
|
|
early_error(demitter, "-O and --opt-level both provided");
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
2u
|
|
|
|
} else if opt_present(match, "opt-level") {
|
|
|
|
alt getopts::opt_str(match, "opt-level") {
|
|
|
|
"0" { 0u }
|
|
|
|
"1" { 1u }
|
|
|
|
"2" { 2u }
|
|
|
|
"3" { 3u }
|
|
|
|
_ {
|
2012-01-14 01:18:01 -06:00
|
|
|
early_error(demitter, "optimization level needs " +
|
2011-12-20 04:17:13 -06:00
|
|
|
"to be between 0-3")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else { 0u };
|
|
|
|
let target =
|
|
|
|
alt target_opt {
|
2012-01-19 00:37:22 -06:00
|
|
|
none { host_triple() }
|
2011-12-20 04:17:13 -06:00
|
|
|
some(s) { s }
|
|
|
|
};
|
|
|
|
|
|
|
|
let addl_lib_search_paths = getopts::opt_strs(match, "L");
|
|
|
|
let cfg = parse_cfgspecs(getopts::opt_strs(match, "cfg"));
|
|
|
|
let test = opt_present(match, "test");
|
|
|
|
let sopts: @session::options =
|
|
|
|
@{crate_type: crate_type,
|
|
|
|
static: static,
|
|
|
|
optimize: opt_level,
|
|
|
|
debuginfo: debuginfo,
|
|
|
|
extra_debuginfo: extra_debuginfo,
|
2012-01-19 02:50:51 -06:00
|
|
|
lint_opts: lint_opts,
|
2011-12-20 04:17:13 -06:00
|
|
|
save_temps: save_temps,
|
|
|
|
output_type: output_type,
|
|
|
|
addl_lib_search_paths: addl_lib_search_paths,
|
|
|
|
maybe_sysroot: sysroot_opt,
|
|
|
|
target_triple: target,
|
|
|
|
cfg: cfg,
|
|
|
|
test: test,
|
|
|
|
parse_only: parse_only,
|
|
|
|
no_trans: no_trans,
|
2012-06-08 09:46:14 -05:00
|
|
|
debugging_opts: debugging_opts};
|
2011-12-20 04:17:13 -06:00
|
|
|
ret sopts;
|
|
|
|
}
|
|
|
|
|
2012-03-21 17:56:20 -05:00
|
|
|
fn build_session(sopts: @session::options,
|
2012-01-17 09:42:45 -06:00
|
|
|
demitter: diagnostic::emitter) -> session {
|
2012-02-17 16:15:09 -06:00
|
|
|
let codemap = codemap::new_codemap();
|
|
|
|
let diagnostic_handler =
|
|
|
|
diagnostic::mk_handler(some(demitter));
|
|
|
|
let span_diagnostic_handler =
|
|
|
|
diagnostic::mk_span_handler(diagnostic_handler, codemap);
|
2012-03-21 17:56:20 -05:00
|
|
|
build_session_(sopts, codemap, demitter, span_diagnostic_handler)
|
2012-02-17 16:15:09 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn build_session_(
|
2012-06-06 11:50:08 -05:00
|
|
|
sopts: @session::options, cm: codemap::codemap,
|
2012-02-17 16:15:09 -06:00
|
|
|
demitter: diagnostic::emitter,
|
|
|
|
span_diagnostic_handler: diagnostic::span_handler
|
|
|
|
) -> session {
|
2012-01-14 01:18:01 -06:00
|
|
|
let target_cfg = build_target_config(sopts, demitter);
|
2011-12-20 04:17:13 -06:00
|
|
|
let cstore = cstore::mk_cstore();
|
|
|
|
let filesearch = filesearch::mk_filesearch(
|
|
|
|
sopts.maybe_sysroot,
|
|
|
|
sopts.target_triple,
|
|
|
|
sopts.addl_lib_search_paths);
|
2012-06-04 18:07:54 -05:00
|
|
|
let warning_settings = lint::mk_warning_settings();
|
2012-01-12 10:59:49 -06:00
|
|
|
@{targ_cfg: target_cfg,
|
|
|
|
opts: sopts,
|
|
|
|
cstore: cstore,
|
2012-06-06 11:50:08 -05:00
|
|
|
parse_sess:
|
|
|
|
parse::new_parse_sess_special_handler(span_diagnostic_handler, cm),
|
|
|
|
codemap: cm,
|
2012-01-12 10:59:49 -06:00
|
|
|
// For a library crate, this is always none
|
2012-03-26 20:35:18 -05:00
|
|
|
mut main_fn: none,
|
2012-01-24 23:42:54 -06:00
|
|
|
span_diagnostic: span_diagnostic_handler,
|
2012-01-12 10:59:49 -06:00
|
|
|
filesearch: filesearch,
|
2012-03-26 20:35:18 -05:00
|
|
|
mut building_library: false,
|
2012-06-04 18:07:54 -05:00
|
|
|
working_dir: os::getcwd(),
|
|
|
|
warning_settings: warning_settings}
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
2012-01-17 09:42:45 -06:00
|
|
|
fn parse_pretty(sess: session, &&name: str) -> pp_mode {
|
2011-12-20 04:17:13 -06:00
|
|
|
if str::eq(name, "normal") {
|
|
|
|
ret ppm_normal;
|
|
|
|
} else if str::eq(name, "expanded") {
|
|
|
|
ret ppm_expanded;
|
|
|
|
} else if str::eq(name, "typed") {
|
|
|
|
ret ppm_typed;
|
2012-03-12 12:19:35 -05:00
|
|
|
} else if str::eq(name, "expanded,identified") {
|
|
|
|
ret ppm_expanded_identified;
|
|
|
|
} else if str::eq(name, "identified") {
|
|
|
|
ret ppm_identified;
|
|
|
|
}
|
2011-12-20 04:17:13 -06:00
|
|
|
sess.fatal("argument to `pretty` must be one of `normal`, `typed`, or " +
|
|
|
|
"`identified`");
|
|
|
|
}
|
|
|
|
|
2012-06-29 18:26:56 -05:00
|
|
|
fn opts() -> ~[getopts::opt] {
|
|
|
|
ret ~[optflag("h"), optflag("help"), optflag("v"), optflag("version"),
|
2011-12-20 04:17:13 -06:00
|
|
|
optflag("emit-llvm"), optflagopt("pretty"),
|
|
|
|
optflag("ls"), optflag("parse-only"), optflag("no-trans"),
|
|
|
|
optflag("O"), optopt("opt-level"), optmulti("L"), optflag("S"),
|
|
|
|
optopt("o"), optopt("out-dir"), optflag("xg"),
|
|
|
|
optflag("c"), optflag("g"), optflag("save-temps"),
|
2012-05-17 23:53:49 -05:00
|
|
|
optopt("sysroot"), optopt("target"),
|
2012-04-12 19:30:52 -05:00
|
|
|
|
|
|
|
optmulti("W"), optmulti("warn"),
|
|
|
|
|
2012-05-17 23:53:49 -05:00
|
|
|
optmulti("Z"),
|
|
|
|
|
2011-12-20 04:17:13 -06:00
|
|
|
optmulti("cfg"), optflag("test"),
|
2012-06-29 18:26:56 -05:00
|
|
|
optflag("lib"), optflag("bin"), optflag("static"), optflag("gc")];
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
2012-01-17 09:42:45 -06:00
|
|
|
type output_filenames = @{out_filename: str, obj_filename:str};
|
|
|
|
|
2012-05-09 21:41:24 -05:00
|
|
|
fn build_output_filenames(input: input,
|
2012-01-31 19:05:20 -06:00
|
|
|
odir: option<str>,
|
|
|
|
ofile: option<str>,
|
2012-01-17 09:42:45 -06:00
|
|
|
sess: session)
|
|
|
|
-> output_filenames {
|
2012-06-14 14:40:49 -05:00
|
|
|
let obj_path;
|
|
|
|
let out_path;
|
2012-01-12 10:59:49 -06:00
|
|
|
let sopts = sess.opts;
|
2011-12-20 04:17:13 -06:00
|
|
|
let stop_after_codegen =
|
|
|
|
sopts.output_type != link::output_type_exe ||
|
2012-01-12 10:59:49 -06:00
|
|
|
sopts.static && sess.building_library;
|
2011-12-20 04:17:13 -06:00
|
|
|
|
|
|
|
|
|
|
|
let obj_suffix =
|
|
|
|
alt sopts.output_type {
|
2012-01-19 00:37:22 -06:00
|
|
|
link::output_type_none { "none" }
|
|
|
|
link::output_type_bitcode { "bc" }
|
2012-01-19 03:03:57 -06:00
|
|
|
link::output_type_assembly { "s" }
|
|
|
|
link::output_type_llvm_assembly { "ll" }
|
2011-12-20 04:17:13 -06:00
|
|
|
// Object and exe output both use the '.o' extension here
|
2012-01-19 03:03:57 -06:00
|
|
|
link::output_type_object | link::output_type_exe {
|
2011-12-20 04:17:13 -06:00
|
|
|
"o"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
alt ofile {
|
2012-01-19 00:37:22 -06:00
|
|
|
none {
|
2011-12-20 04:17:13 -06:00
|
|
|
// "-" as input file will cause the parser to read from stdin so we
|
|
|
|
// have to make up a name
|
|
|
|
// We want to toss everything after the final '.'
|
|
|
|
let dirname = alt odir {
|
|
|
|
some(d) { d }
|
2012-01-19 00:37:22 -06:00
|
|
|
none {
|
2012-05-09 21:41:24 -05:00
|
|
|
alt input {
|
|
|
|
str_input(_) {
|
2012-03-12 22:04:27 -05:00
|
|
|
os::getcwd()
|
2012-05-09 21:41:24 -05:00
|
|
|
}
|
|
|
|
file_input(ifile) {
|
2012-03-12 22:04:27 -05:00
|
|
|
path::dirname(ifile)
|
2012-05-09 21:41:24 -05:00
|
|
|
}
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-05-09 21:41:24 -05:00
|
|
|
let base_filename = alt input {
|
|
|
|
file_input(ifile) {
|
2012-03-12 22:04:27 -05:00
|
|
|
let (path, _) = path::splitext(ifile);
|
|
|
|
path::basename(path)
|
2012-05-09 21:41:24 -05:00
|
|
|
}
|
|
|
|
str_input(_) {
|
2012-01-18 20:38:54 -06:00
|
|
|
"rust_out"
|
2012-05-09 21:41:24 -05:00
|
|
|
}
|
2011-12-20 04:17:13 -06:00
|
|
|
};
|
2012-03-12 22:04:27 -05:00
|
|
|
let base_path = path::connect(dirname, base_filename);
|
2011-12-20 04:17:13 -06:00
|
|
|
|
|
|
|
|
2012-01-12 10:59:49 -06:00
|
|
|
if sess.building_library {
|
2012-03-12 22:04:27 -05:00
|
|
|
let basename = path::basename(base_path);
|
|
|
|
let dylibname = os::dll_filename(basename);
|
|
|
|
out_path = path::connect(dirname, dylibname);
|
|
|
|
obj_path = path::connect(dirname, basename + "." + obj_suffix);
|
2011-12-20 04:17:13 -06:00
|
|
|
} else {
|
|
|
|
out_path = base_path;
|
|
|
|
obj_path = base_path + "." + obj_suffix;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
some(out_file) {
|
|
|
|
out_path = out_file;
|
|
|
|
obj_path = if stop_after_codegen {
|
|
|
|
out_file
|
|
|
|
} else {
|
2012-03-12 22:04:27 -05:00
|
|
|
let (base, _) = path::splitext(out_file);
|
2011-12-20 04:17:13 -06:00
|
|
|
let modified = base + "." + obj_suffix;
|
|
|
|
modified
|
|
|
|
};
|
|
|
|
|
2012-01-12 10:59:49 -06:00
|
|
|
if sess.building_library {
|
2012-06-21 18:44:10 -05:00
|
|
|
// FIXME (#2401): We might want to warn here; we're actually not
|
|
|
|
// going to respect the user's choice of library name when it
|
|
|
|
// comes time to link, we'll be linking to
|
|
|
|
// lib<basename>-<hash>-<version>.so no matter what.
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if odir != none {
|
2012-03-05 18:27:27 -06:00
|
|
|
sess.warn("ignoring --out-dir flag due to -o flag.");
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ret @{out_filename: out_path,
|
|
|
|
obj_filename: obj_path};
|
|
|
|
}
|
|
|
|
|
2012-01-14 01:18:01 -06:00
|
|
|
fn early_error(emitter: diagnostic::emitter, msg: str) -> ! {
|
|
|
|
emitter(none, msg, diagnostic::fatal);
|
2011-12-20 04:17:13 -06:00
|
|
|
fail;
|
|
|
|
}
|
|
|
|
|
2012-01-17 09:42:45 -06:00
|
|
|
fn list_metadata(sess: session, path: str, out: io::writer) {
|
2012-05-22 19:16:26 -05:00
|
|
|
metadata::loader::list_file_metadata(
|
|
|
|
session::sess_os_to_meta_os(sess.targ_cfg.os), path, out);
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
|
|
|
|
// When the user supplies --test we should implicitly supply --cfg test
|
|
|
|
#[test]
|
|
|
|
fn test_switch_implies_cfg_test() {
|
|
|
|
let match =
|
2012-06-29 18:26:56 -05:00
|
|
|
alt getopts::getopts(~["--test"], opts()) {
|
2011-12-20 04:17:13 -06:00
|
|
|
ok(m) { m }
|
2012-01-30 23:00:57 -06:00
|
|
|
err(f) { fail "test_switch_implies_cfg_test: " +
|
|
|
|
getopts::fail_str(f); }
|
2011-12-20 04:17:13 -06:00
|
|
|
};
|
2012-01-14 02:46:37 -06:00
|
|
|
let sessopts = build_session_options(match, diagnostic::emit);
|
2012-03-21 17:56:20 -05:00
|
|
|
let sess = build_session(sessopts, diagnostic::emit);
|
2012-05-09 21:41:24 -05:00
|
|
|
let cfg = build_configuration(sess, "whatever", str_input(""));
|
2011-12-20 04:17:13 -06:00
|
|
|
assert (attr::contains_name(cfg, "test"));
|
|
|
|
}
|
|
|
|
|
|
|
|
// When the user supplies --test and --cfg test, don't implicitly add
|
|
|
|
// another --cfg test
|
|
|
|
#[test]
|
|
|
|
fn test_switch_implies_cfg_test_unless_cfg_test() {
|
|
|
|
let match =
|
2012-06-29 18:26:56 -05:00
|
|
|
alt getopts::getopts(~["--test", "--cfg=test"], opts()) {
|
2011-12-20 04:17:13 -06:00
|
|
|
ok(m) { m }
|
2012-01-30 23:00:57 -06:00
|
|
|
err(f) { fail "test_switch_implies_cfg_test_unless_cfg_test: " +
|
|
|
|
getopts::fail_str(f); }
|
2011-12-20 04:17:13 -06:00
|
|
|
};
|
2012-01-14 02:46:37 -06:00
|
|
|
let sessopts = build_session_options(match, diagnostic::emit);
|
2012-03-21 17:56:20 -05:00
|
|
|
let sess = build_session(sessopts, diagnostic::emit);
|
2012-05-09 21:41:24 -05:00
|
|
|
let cfg = build_configuration(sess, "whatever", str_input(""));
|
2011-12-20 04:17:13 -06:00
|
|
|
let test_items = attr::find_meta_items_by_name(cfg, "test");
|
|
|
|
assert (vec::len(test_items) == 1u);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Local Variables:
|
|
|
|
// mode: rust
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// End:
|