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.
|
|
|
|
|
2012-12-13 15:05:22 -06:00
|
|
|
use back::link;
|
|
|
|
use back::target_strs;
|
2012-12-23 16:41:37 -06:00
|
|
|
use back;
|
2013-03-01 12:44:43 -06:00
|
|
|
use driver::driver::host_triple;
|
2012-12-23 16:41:37 -06:00
|
|
|
use driver::session;
|
2012-12-13 15:05:22 -06:00
|
|
|
use metadata::filesearch;
|
2012-12-23 16:41:37 -06:00
|
|
|
use metadata;
|
2012-12-13 15:05:22 -06:00
|
|
|
use middle::lint;
|
|
|
|
|
2012-09-04 13:54:36 -05:00
|
|
|
use syntax::ast::node_id;
|
|
|
|
use syntax::ast::{int_ty, uint_ty, float_ty};
|
2012-12-13 15:05:22 -06:00
|
|
|
use syntax::codemap::span;
|
2012-12-23 16:41:37 -06:00
|
|
|
use syntax::diagnostic;
|
2013-02-21 02:16:31 -06:00
|
|
|
use syntax::parse::ParseSess;
|
2012-12-13 15:05:22 -06:00
|
|
|
use syntax::{ast, codemap};
|
2013-03-13 21:25:28 -05:00
|
|
|
use syntax::abi;
|
2012-12-23 16:41:37 -06:00
|
|
|
use syntax;
|
2012-06-04 18:07:54 -05:00
|
|
|
|
2013-03-20 10:40:02 -05:00
|
|
|
#[deriving(Eq)]
|
2013-01-29 17:16:07 -06:00
|
|
|
pub enum os { os_win32, os_macos, os_linux, os_android, os_freebsd, }
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2013-01-29 17:16:07 -06:00
|
|
|
pub enum crate_type { bin_crate, lib_crate, unknown_crate, }
|
2011-12-08 22:08:00 -06:00
|
|
|
|
2013-02-19 01:40:42 -06:00
|
|
|
pub struct config {
|
|
|
|
os: os,
|
2013-03-13 21:25:28 -05:00
|
|
|
arch: abi::Architecture,
|
2013-02-19 01:40:42 -06:00
|
|
|
target_strs: target_strs::t,
|
|
|
|
int_type: int_ty,
|
|
|
|
uint_type: uint_ty,
|
|
|
|
float_type: float_ty
|
|
|
|
}
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2013-03-22 16:00:15 -05:00
|
|
|
pub static verbose: uint = 1 << 0;
|
|
|
|
pub static time_passes: uint = 1 << 1;
|
|
|
|
pub static count_llvm_insns: uint = 1 << 2;
|
|
|
|
pub static time_llvm_passes: uint = 1 << 3;
|
|
|
|
pub static trans_stats: uint = 1 << 4;
|
|
|
|
pub static no_asm_comments: uint = 1 << 5;
|
|
|
|
pub static no_verify: uint = 1 << 6;
|
|
|
|
pub static trace: uint = 1 << 7;
|
|
|
|
pub static coherence: uint = 1 << 8;
|
|
|
|
pub static borrowck_stats: uint = 1 << 9;
|
|
|
|
pub static borrowck_note_pure: uint = 1 << 10;
|
|
|
|
pub static borrowck_note_loan: uint = 1 << 11;
|
|
|
|
pub static no_landing_pads: uint = 1 << 12;
|
|
|
|
pub static debug_llvm: uint = 1 << 13;
|
|
|
|
pub static count_type_sizes: uint = 1 << 14;
|
|
|
|
pub static meta_stats: uint = 1 << 15;
|
|
|
|
pub static no_opt: uint = 1 << 16;
|
|
|
|
pub static no_monomorphic_collapse: uint = 1 << 17;
|
|
|
|
pub static gc: uint = 1 << 18;
|
|
|
|
pub static jit: uint = 1 << 19;
|
|
|
|
pub static debug_info: uint = 1 << 20;
|
|
|
|
pub static extra_debug_info: uint = 1 << 21;
|
|
|
|
pub static static: uint = 1 << 22;
|
2013-01-29 17:16:07 -06:00
|
|
|
|
|
|
|
pub fn debugging_opts_map() -> ~[(~str, ~str, uint)] {
|
2012-09-12 19:06:36 -05:00
|
|
|
~[(~"verbose", ~"in general, enable more debug printouts", verbose),
|
2012-07-14 00:57:48 -05:00
|
|
|
(~"time-passes", ~"measure time of each rustc pass", time_passes),
|
|
|
|
(~"count-llvm-insns", ~"count where LLVM \
|
2012-05-17 23:53:49 -05:00
|
|
|
instrs originate", count_llvm_insns),
|
2012-07-14 00:57:48 -05:00
|
|
|
(~"time-llvm-passes", ~"measure time of each LLVM pass",
|
|
|
|
time_llvm_passes),
|
|
|
|
(~"trans-stats", ~"gather trans statistics", trans_stats),
|
|
|
|
(~"no-asm-comments", ~"omit comments when using -S", no_asm_comments),
|
|
|
|
(~"no-verify", ~"skip LLVM verification", no_verify),
|
|
|
|
(~"trace", ~"emit trace logs", trace),
|
|
|
|
(~"coherence", ~"perform coherence checking", coherence),
|
|
|
|
(~"borrowck-stats", ~"gather borrowck statistics", borrowck_stats),
|
|
|
|
(~"borrowck-note-pure", ~"note where purity is req'd",
|
2012-07-11 12:28:30 -05:00
|
|
|
borrowck_note_pure),
|
2012-07-14 00:57:48 -05:00
|
|
|
(~"borrowck-note-loan", ~"note where loans are req'd",
|
2012-06-29 14:31:23 -05:00
|
|
|
borrowck_note_loan),
|
|
|
|
(~"no-landing-pads", ~"omit landing pads for unwinding",
|
2012-07-25 14:06:03 -05:00
|
|
|
no_landing_pads),
|
2012-08-07 20:39:41 -05:00
|
|
|
(~"debug-llvm", ~"enable debug output from LLVM", debug_llvm),
|
|
|
|
(~"count-type-sizes", ~"count the sizes of aggregate types",
|
2012-08-27 18:53:54 -05:00
|
|
|
count_type_sizes),
|
2012-09-07 14:06:42 -05:00
|
|
|
(~"meta-stats", ~"gather metadata statistics", meta_stats),
|
|
|
|
(~"no-opt", ~"do not optimize, even if -O is passed", no_opt),
|
2012-12-05 22:45:58 -06:00
|
|
|
(~"no-monomorphic-collapse", ~"do not collapse template instantiations",
|
|
|
|
no_monomorphic_collapse),
|
2013-02-07 17:14:17 -06:00
|
|
|
(~"gc", ~"Garbage collect shared data (experimental)", gc),
|
|
|
|
(~"jit", ~"Execute using JIT (experimental)", jit),
|
|
|
|
(~"extra-debug-info", ~"Extra debugging info (experimental)",
|
|
|
|
extra_debug_info),
|
|
|
|
(~"debug-info", ~"Produce debug info (experimental)", debug_info),
|
|
|
|
(~"static", ~"Use or produce static libraries or binaries " +
|
|
|
|
"(experimental)", static)
|
2012-06-29 18:26:56 -05:00
|
|
|
]
|
2012-05-17 23:53:49 -05:00
|
|
|
}
|
|
|
|
|
2013-04-28 21:54:41 -05:00
|
|
|
// Information output flags
|
|
|
|
pub static out_link_args : uint = 1 << 0;
|
|
|
|
|
2013-03-20 10:40:02 -05:00
|
|
|
#[deriving(Eq)]
|
2013-01-29 17:16:07 -06:00
|
|
|
pub enum OptLevel {
|
2012-08-21 19:22:45 -05:00
|
|
|
No, // -O0
|
|
|
|
Less, // -O1
|
|
|
|
Default, // -O2
|
|
|
|
Aggressive // -O3
|
|
|
|
}
|
|
|
|
|
2013-02-19 01:40:42 -06:00
|
|
|
pub struct options {
|
2011-07-27 07:19:39 -05:00
|
|
|
// The crate config requested for the session, which may be combined
|
|
|
|
// with additional crate configurations during the compile process
|
2013-02-19 01:40:42 -06:00
|
|
|
crate_type: crate_type,
|
|
|
|
is_static: bool,
|
|
|
|
gc: bool,
|
|
|
|
optimize: OptLevel,
|
|
|
|
debuginfo: bool,
|
|
|
|
extra_debuginfo: bool,
|
|
|
|
lint_opts: ~[(lint::lint, lint::level)],
|
|
|
|
save_temps: bool,
|
|
|
|
jit: bool,
|
|
|
|
output_type: back::link::output_type,
|
|
|
|
addl_lib_search_paths: ~[Path],
|
2013-04-28 19:57:49 -05:00
|
|
|
linker_args: ~[~str],
|
2013-02-19 01:40:42 -06:00
|
|
|
maybe_sysroot: Option<Path>,
|
|
|
|
target_triple: ~str,
|
2013-04-22 06:54:12 -05:00
|
|
|
target_feature: ~str,
|
2013-02-19 01:40:42 -06:00
|
|
|
// User-specified cfg meta items. The compiler itself will add additional
|
|
|
|
// items to the crate config, and during parsing the entire crate config
|
|
|
|
// will be added to the crate AST node. This should not be used for
|
|
|
|
// anything except building the full crate config prior to parsing.
|
|
|
|
cfg: ast::crate_cfg,
|
2013-04-16 18:10:21 -05:00
|
|
|
binary: @~str,
|
2013-02-19 01:40:42 -06:00
|
|
|
test: bool,
|
|
|
|
parse_only: bool,
|
|
|
|
no_trans: bool,
|
|
|
|
debugging_opts: uint,
|
2013-04-28 21:54:41 -05:00
|
|
|
output_info: uint,
|
2013-03-04 22:12:23 -06:00
|
|
|
android_cross_path: Option<~str>
|
2013-02-19 01:40:42 -06:00
|
|
|
}
|
2011-06-15 13:19:50 -05:00
|
|
|
|
2013-02-19 01:40:42 -06:00
|
|
|
pub struct crate_metadata {
|
|
|
|
name: ~str,
|
|
|
|
data: ~[u8]
|
|
|
|
}
|
2013-01-29 17:16:07 -06:00
|
|
|
|
2013-04-09 03:16:06 -05:00
|
|
|
// The type of entry function, so
|
|
|
|
// users can have their own entry
|
|
|
|
// functions that don't start a
|
|
|
|
// scheduler
|
|
|
|
#[deriving(Eq)]
|
|
|
|
pub enum EntryFnType {
|
|
|
|
EntryMain,
|
|
|
|
EntryStart
|
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub struct Session_ {
|
|
|
|
targ_cfg: @config,
|
|
|
|
opts: @options,
|
|
|
|
cstore: @mut metadata::cstore::CStore,
|
2013-02-21 02:16:31 -06:00
|
|
|
parse_sess: @mut ParseSess,
|
2013-02-04 16:02:01 -06:00
|
|
|
codemap: @codemap::CodeMap,
|
|
|
|
// For a library crate, this is always none
|
2013-04-09 03:16:06 -05:00
|
|
|
entry_fn: @mut Option<(node_id, codemap::span)>,
|
|
|
|
entry_type: @mut Option<EntryFnType>,
|
2013-03-12 15:00:50 -05:00
|
|
|
span_diagnostic: @diagnostic::span_handler,
|
|
|
|
filesearch: @filesearch::FileSearch,
|
2013-02-04 16:02:01 -06:00
|
|
|
building_library: @mut bool,
|
|
|
|
working_dir: Path,
|
2013-02-19 01:40:42 -06:00
|
|
|
lint_settings: lint::LintSettings
|
2012-07-11 17:00:40 -05:00
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub type Session = @Session_;
|
|
|
|
|
2013-03-12 19:33:54 -05:00
|
|
|
pub impl Session_ {
|
|
|
|
fn span_fatal(@self, sp: span, msg: ~str) -> ! {
|
2012-01-24 23:42:54 -06:00
|
|
|
self.span_diagnostic.span_fatal(sp, msg)
|
2010-09-01 15:24:14 -05:00
|
|
|
}
|
2013-03-12 19:33:54 -05:00
|
|
|
fn fatal(@self, msg: ~str) -> ! {
|
2012-01-24 23:42:54 -06:00
|
|
|
self.span_diagnostic.handler().fatal(msg)
|
2010-09-01 15:24:14 -05:00
|
|
|
}
|
2013-03-12 19:33:54 -05:00
|
|
|
fn span_err(@self, sp: span, msg: ~str) {
|
2012-01-24 23:42:54 -06:00
|
|
|
self.span_diagnostic.span_err(sp, msg)
|
2011-06-19 00:55:53 -05:00
|
|
|
}
|
2013-03-12 19:33:54 -05:00
|
|
|
fn err(@self, msg: ~str) {
|
2012-01-24 23:42:54 -06:00
|
|
|
self.span_diagnostic.handler().err(msg)
|
2012-01-13 19:08:47 -06:00
|
|
|
}
|
2013-03-12 19:33:54 -05:00
|
|
|
fn has_errors(@self) -> bool {
|
2012-01-24 23:42:54 -06:00
|
|
|
self.span_diagnostic.handler().has_errors()
|
2011-06-19 00:55:53 -05:00
|
|
|
}
|
2013-03-12 19:33:54 -05:00
|
|
|
fn abort_if_errors(@self) {
|
2012-01-24 23:42:54 -06:00
|
|
|
self.span_diagnostic.handler().abort_if_errors()
|
2011-06-19 00:55:53 -05:00
|
|
|
}
|
2013-03-12 19:33:54 -05:00
|
|
|
fn span_warn(@self, sp: span, msg: ~str) {
|
2012-01-24 23:42:54 -06:00
|
|
|
self.span_diagnostic.span_warn(sp, msg)
|
2012-01-12 10:59:49 -06:00
|
|
|
}
|
2013-03-12 19:33:54 -05:00
|
|
|
fn warn(@self, msg: ~str) {
|
2012-01-24 23:42:54 -06:00
|
|
|
self.span_diagnostic.handler().warn(msg)
|
2011-08-27 16:57:47 -05:00
|
|
|
}
|
2013-03-12 19:33:54 -05:00
|
|
|
fn span_note(@self, sp: span, msg: ~str) {
|
2012-01-24 23:42:54 -06:00
|
|
|
self.span_diagnostic.span_note(sp, msg)
|
2012-01-12 10:59:49 -06:00
|
|
|
}
|
2013-03-12 19:33:54 -05:00
|
|
|
fn note(@self, msg: ~str) {
|
2012-01-24 23:42:54 -06:00
|
|
|
self.span_diagnostic.handler().note(msg)
|
2011-08-27 16:57:47 -05:00
|
|
|
}
|
2013-03-12 19:33:54 -05:00
|
|
|
fn span_bug(@self, sp: span, msg: ~str) -> ! {
|
2012-01-24 23:42:54 -06:00
|
|
|
self.span_diagnostic.span_bug(sp, msg)
|
2011-05-17 16:12:49 -05:00
|
|
|
}
|
2013-03-12 19:33:54 -05:00
|
|
|
fn bug(@self, msg: ~str) -> ! {
|
2012-01-24 23:42:54 -06:00
|
|
|
self.span_diagnostic.handler().bug(msg)
|
2010-11-22 18:27:00 -06:00
|
|
|
}
|
2013-03-12 19:33:54 -05:00
|
|
|
fn span_unimpl(@self, sp: span, msg: ~str) -> ! {
|
2012-01-24 23:42:54 -06:00
|
|
|
self.span_diagnostic.span_unimpl(sp, msg)
|
2012-01-13 19:08:47 -06:00
|
|
|
}
|
2013-03-12 19:33:54 -05:00
|
|
|
fn unimpl(@self, msg: ~str) -> ! {
|
2012-01-24 23:42:54 -06:00
|
|
|
self.span_diagnostic.handler().unimpl(msg)
|
2011-03-18 14:30:44 -05:00
|
|
|
}
|
2013-04-17 11:15:37 -05:00
|
|
|
fn span_lint_level(@self, level: lint::level, sp: span, msg: ~str) {
|
2012-08-06 14:34:08 -05:00
|
|
|
match level {
|
2012-08-03 21:59:04 -05:00
|
|
|
lint::allow => { },
|
|
|
|
lint::warn => self.span_warn(sp, msg),
|
|
|
|
lint::deny | lint::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 19:08:21 -05:00
|
|
|
self.span_err(sp, msg);
|
|
|
|
}
|
2012-06-04 18:07:54 -05:00
|
|
|
}
|
|
|
|
}
|
2013-03-12 19:33:54 -05:00
|
|
|
fn span_lint(@self, lint_mode: lint::lint,
|
2013-01-07 16:16:52 -06:00
|
|
|
expr_id: ast::node_id,
|
|
|
|
item_id: ast::node_id,
|
|
|
|
span: span,
|
2013-04-17 11:15:37 -05:00
|
|
|
msg: ~str) {
|
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 19:08:21 -05:00
|
|
|
let level = lint::get_lint_settings_level(
|
|
|
|
self.lint_settings, lint_mode, expr_id, item_id);
|
2012-06-04 18:07:54 -05:00
|
|
|
self.span_lint_level(level, span, msg);
|
|
|
|
}
|
2013-03-12 19:33:54 -05:00
|
|
|
fn next_node_id(@self) -> ast::node_id {
|
2012-08-01 19:30:05 -05:00
|
|
|
return syntax::parse::next_node_id(self.parse_sess);
|
2011-12-19 02:42:58 -06:00
|
|
|
}
|
2013-03-12 19:33:54 -05:00
|
|
|
fn diagnostic(@self) -> @diagnostic::span_handler {
|
2012-03-22 19:39:45 -05:00
|
|
|
self.span_diagnostic
|
|
|
|
}
|
2013-03-12 19:33:54 -05:00
|
|
|
fn debugging_opt(@self, opt: uint) -> bool {
|
2012-05-17 23:53:49 -05:00
|
|
|
(self.opts.debugging_opts & opt) != 0u
|
|
|
|
}
|
2012-08-21 19:22:45 -05:00
|
|
|
// This exists to help with refactoring to eliminate impossible
|
|
|
|
// cases later on
|
2013-03-12 19:33:54 -05:00
|
|
|
fn impossible_case(@self, sp: span, msg: &str) -> ! {
|
2012-10-12 14:32:36 -05:00
|
|
|
self.span_bug(sp, fmt!("Impossible case reached: %s", msg));
|
2012-08-21 19:22:45 -05:00
|
|
|
}
|
2013-03-12 19:33:54 -05:00
|
|
|
fn verbose(@self) -> bool { self.debugging_opt(verbose) }
|
|
|
|
fn time_passes(@self) -> bool { self.debugging_opt(time_passes) }
|
|
|
|
fn count_llvm_insns(@self) -> bool {
|
2013-02-22 00:41:37 -06:00
|
|
|
self.debugging_opt(count_llvm_insns)
|
|
|
|
}
|
2013-03-12 19:33:54 -05:00
|
|
|
fn count_type_sizes(@self) -> bool {
|
2013-02-22 00:41:37 -06:00
|
|
|
self.debugging_opt(count_type_sizes)
|
|
|
|
}
|
2013-03-12 19:33:54 -05:00
|
|
|
fn time_llvm_passes(@self) -> bool {
|
2013-02-22 00:41:37 -06:00
|
|
|
self.debugging_opt(time_llvm_passes)
|
|
|
|
}
|
2013-03-12 19:33:54 -05:00
|
|
|
fn trans_stats(@self) -> bool { self.debugging_opt(trans_stats) }
|
|
|
|
fn meta_stats(@self) -> bool { self.debugging_opt(meta_stats) }
|
|
|
|
fn no_asm_comments(@self) -> bool { self.debugging_opt(no_asm_comments) }
|
|
|
|
fn no_verify(@self) -> bool { self.debugging_opt(no_verify) }
|
|
|
|
fn trace(@self) -> bool { self.debugging_opt(trace) }
|
|
|
|
fn coherence(@self) -> bool { self.debugging_opt(coherence) }
|
|
|
|
fn borrowck_stats(@self) -> bool { self.debugging_opt(borrowck_stats) }
|
|
|
|
fn borrowck_note_pure(@self) -> bool {
|
2013-02-22 00:41:37 -06:00
|
|
|
self.debugging_opt(borrowck_note_pure)
|
|
|
|
}
|
2013-03-12 19:33:54 -05:00
|
|
|
fn borrowck_note_loan(@self) -> bool {
|
2013-02-22 00:41:37 -06:00
|
|
|
self.debugging_opt(borrowck_note_loan)
|
|
|
|
}
|
2013-03-12 19:33:54 -05:00
|
|
|
fn no_monomorphic_collapse(@self) -> bool {
|
2012-12-06 21:45:32 -06:00
|
|
|
self.debugging_opt(no_monomorphic_collapse)
|
2012-12-05 22:45:58 -06:00
|
|
|
}
|
2012-07-18 18:18:02 -05:00
|
|
|
|
2013-03-12 19:33:54 -05:00
|
|
|
fn str_of(@self, id: ast::ident) -> @~str {
|
2013-02-10 18:33:16 -06:00
|
|
|
self.parse_sess.interner.get(id)
|
2012-07-18 18:18:02 -05:00
|
|
|
}
|
2013-04-17 11:15:37 -05:00
|
|
|
fn ident_of(@self, st: ~str) -> ast::ident {
|
2012-07-18 18:18:02 -05:00
|
|
|
self.parse_sess.interner.intern(@st)
|
|
|
|
}
|
2013-03-12 19:33:54 -05:00
|
|
|
fn intr(@self) -> @syntax::parse::token::ident_interner {
|
2012-07-18 18:18:02 -05:00
|
|
|
self.parse_sess.interner
|
|
|
|
}
|
2010-09-01 15:24:14 -05:00
|
|
|
}
|
2011-12-08 23:05:44 -06:00
|
|
|
|
2012-07-04 16:53:12 -05:00
|
|
|
/// Some reasonable defaults
|
2013-01-29 17:16:07 -06:00
|
|
|
pub fn basic_options() -> @options {
|
2013-02-19 01:40:42 -06:00
|
|
|
@options {
|
2012-05-09 00:25:22 -05:00
|
|
|
crate_type: session::lib_crate,
|
2013-02-19 01:40:42 -06:00
|
|
|
is_static: false,
|
2012-06-26 16:27:09 -05:00
|
|
|
gc: false,
|
2012-08-21 19:22:45 -05:00
|
|
|
optimize: No,
|
2012-05-09 00:25:22 -05:00
|
|
|
debuginfo: false,
|
|
|
|
extra_debuginfo: false,
|
2012-06-29 18:26:56 -05:00
|
|
|
lint_opts: ~[],
|
2012-05-09 00:25:22 -05:00
|
|
|
save_temps: false,
|
2012-08-24 23:54:30 -05:00
|
|
|
jit: false,
|
2012-09-18 13:46:39 -05:00
|
|
|
output_type: link::output_type_exe,
|
2012-06-29 18:26:56 -05:00
|
|
|
addl_lib_search_paths: ~[],
|
2013-04-28 19:57:49 -05:00
|
|
|
linker_args:~[],
|
2012-08-20 14:23:37 -05:00
|
|
|
maybe_sysroot: None,
|
2013-03-01 12:44:43 -06:00
|
|
|
target_triple: host_triple(),
|
2013-04-22 06:54:12 -05:00
|
|
|
target_feature: ~"",
|
2012-06-29 18:26:56 -05:00
|
|
|
cfg: ~[],
|
2013-04-16 18:10:21 -05:00
|
|
|
binary: @~"rustc",
|
2012-05-09 00:25:22 -05:00
|
|
|
test: false,
|
|
|
|
parse_only: false,
|
|
|
|
no_trans: false,
|
2013-03-04 22:12:23 -06:00
|
|
|
debugging_opts: 0u,
|
2013-04-28 21:54:41 -05:00
|
|
|
output_info: 0u,
|
2013-03-04 22:12:23 -06:00
|
|
|
android_cross_path: None
|
2012-05-09 00:25:22 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-19 12:19:00 -05:00
|
|
|
// Seems out of place, but it uses session, so I'm putting it here
|
2013-02-20 19:07:17 -06:00
|
|
|
pub fn expect<T:Copy>(sess: Session,
|
2013-01-29 17:16:07 -06:00
|
|
|
opt: Option<T>,
|
2013-03-07 16:38:38 -06:00
|
|
|
msg: &fn() -> ~str)
|
2013-01-29 17:16:07 -06:00
|
|
|
-> T {
|
2012-05-22 16:55:39 -05:00
|
|
|
diagnostic::expect(sess.diagnostic(), opt, msg)
|
2012-03-19 12:19:00 -05:00
|
|
|
}
|
|
|
|
|
2013-02-04 16:02:01 -06:00
|
|
|
pub fn building_library(req_crate_type: crate_type,
|
|
|
|
crate: @ast::crate,
|
2013-01-29 17:16:07 -06:00
|
|
|
testing: bool) -> bool {
|
2012-08-06 14:34:08 -05:00
|
|
|
match req_crate_type {
|
2012-08-03 21:59:04 -05:00
|
|
|
bin_crate => false,
|
|
|
|
lib_crate => true,
|
|
|
|
unknown_crate => {
|
2012-01-17 16:37:39 -06:00
|
|
|
if testing {
|
|
|
|
false
|
|
|
|
} else {
|
2012-08-06 14:34:08 -05:00
|
|
|
match syntax::attr::first_attr_value_str_by_name(
|
2012-01-17 16:37:39 -06:00
|
|
|
crate.node.attrs,
|
2012-07-14 00:57:48 -05:00
|
|
|
~"crate_type") {
|
2013-02-14 22:19:27 -06:00
|
|
|
Some(@~"lib") => true,
|
2012-08-03 21:59:04 -05:00
|
|
|
_ => false
|
2012-01-17 16:37:39 -06:00
|
|
|
}
|
2011-12-08 23:05:44 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-29 17:16:07 -06:00
|
|
|
pub fn sess_os_to_meta_os(os: os) -> metadata::loader::os {
|
2012-09-07 20:08:21 -05:00
|
|
|
use metadata::loader;
|
2012-05-22 19:16:26 -05:00
|
|
|
|
2012-08-06 14:34:08 -05:00
|
|
|
match os {
|
2012-08-03 21:59:04 -05:00
|
|
|
os_win32 => loader::os_win32,
|
|
|
|
os_linux => loader::os_linux,
|
2012-11-29 18:21:49 -06:00
|
|
|
os_android => loader::os_android,
|
2012-08-03 21:59:04 -05:00
|
|
|
os_macos => loader::os_macos,
|
|
|
|
os_freebsd => loader::os_freebsd
|
2012-05-22 19:16:26 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-08 23:05:44 -06:00
|
|
|
#[cfg(test)]
|
2013-04-15 10:08:52 -05:00
|
|
|
mod test {
|
2013-01-08 21:37:25 -06:00
|
|
|
use driver::session::{bin_crate, building_library, lib_crate};
|
|
|
|
use driver::session::{unknown_crate};
|
|
|
|
|
2012-12-27 17:49:26 -06:00
|
|
|
use syntax::ast;
|
2013-01-31 20:14:27 -06:00
|
|
|
use syntax::codemap;
|
2011-12-08 23:05:44 -06:00
|
|
|
|
2013-04-17 11:15:37 -05:00
|
|
|
fn make_crate_type_attr(t: ~str) -> ast::attribute {
|
2013-01-31 20:14:27 -06:00
|
|
|
codemap::respan(codemap::dummy_sp(), ast::attribute_ {
|
2011-12-08 23:05:44 -06:00
|
|
|
style: ast::attr_outer,
|
2013-02-25 08:19:44 -06:00
|
|
|
value: @codemap::respan(codemap::dummy_sp(),
|
2011-12-08 23:05:44 -06:00
|
|
|
ast::meta_name_value(
|
2013-02-14 09:34:21 -06:00
|
|
|
@~"crate_type",
|
2013-01-31 20:14:27 -06:00
|
|
|
codemap::respan(codemap::dummy_sp(),
|
2012-06-30 05:54:54 -05:00
|
|
|
ast::lit_str(@t)))),
|
|
|
|
is_sugared_doc: false
|
2011-12-08 23:05:44 -06:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2013-04-15 10:08:52 -05:00
|
|
|
fn make_crate(with_bin: bool, with_lib: bool) -> @ast::crate {
|
2012-06-29 18:26:56 -05:00
|
|
|
let mut attrs = ~[];
|
2012-07-14 00:57:48 -05:00
|
|
|
if with_bin { attrs += ~[make_crate_type_attr(~"bin")]; }
|
|
|
|
if with_lib { attrs += ~[make_crate_type_attr(~"lib")]; }
|
2013-01-31 20:14:27 -06:00
|
|
|
@codemap::respan(codemap::dummy_sp(), ast::crate_ {
|
2013-01-15 18:05:20 -06:00
|
|
|
module: ast::_mod { view_items: ~[], items: ~[] },
|
2011-12-08 23:05:44 -06:00
|
|
|
attrs: attrs,
|
2012-06-29 18:26:56 -05:00
|
|
|
config: ~[]
|
2011-12-08 23:05:44 -06:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2013-04-15 10:08:52 -05:00
|
|
|
fn bin_crate_type_attr_results_in_bin_output() {
|
2011-12-08 23:05:44 -06:00
|
|
|
let crate = make_crate(true, false);
|
2013-03-28 20:39:09 -05:00
|
|
|
assert!(!building_library(unknown_crate, crate, false));
|
2011-12-08 23:05:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2013-04-15 10:08:52 -05:00
|
|
|
fn lib_crate_type_attr_results_in_lib_output() {
|
2011-12-08 23:05:44 -06:00
|
|
|
let crate = make_crate(false, true);
|
2013-03-28 20:39:09 -05:00
|
|
|
assert!(building_library(unknown_crate, crate, false));
|
2011-12-08 23:05:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2013-04-15 10:08:52 -05:00
|
|
|
fn bin_option_overrides_lib_crate_type() {
|
2011-12-08 23:05:44 -06:00
|
|
|
let crate = make_crate(false, true);
|
2013-03-28 20:39:09 -05:00
|
|
|
assert!(!building_library(bin_crate, crate, false));
|
2011-12-08 23:05:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2013-04-15 10:08:52 -05:00
|
|
|
fn lib_option_overrides_bin_crate_type() {
|
2011-12-08 23:05:44 -06:00
|
|
|
let crate = make_crate(true, false);
|
2013-03-28 20:39:09 -05:00
|
|
|
assert!(building_library(lib_crate, crate, false));
|
2011-12-08 23:05:44 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2013-04-15 10:08:52 -05:00
|
|
|
fn bin_crate_type_is_default() {
|
2011-12-08 23:05:44 -06:00
|
|
|
let crate = make_crate(false, false);
|
2013-03-28 20:39:09 -05:00
|
|
|
assert!(!building_library(unknown_crate, crate, false));
|
2012-01-17 16:37:39 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2013-04-15 10:08:52 -05:00
|
|
|
fn test_option_overrides_lib_crate_type() {
|
2012-01-17 16:37:39 -06:00
|
|
|
let crate = make_crate(false, true);
|
2013-03-28 20:39:09 -05:00
|
|
|
assert!(!building_library(unknown_crate, crate, true));
|
2012-01-17 16:37:39 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2013-04-15 10:08:52 -05:00
|
|
|
fn test_option_does_not_override_requested_lib_type() {
|
2012-01-17 16:37:39 -06:00
|
|
|
let crate = make_crate(false, false);
|
2013-03-28 20:39:09 -05:00
|
|
|
assert!(building_library(lib_crate, crate, true));
|
2011-12-08 23:05:44 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-01 15:24:14 -05:00
|
|
|
// Local Variables:
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// End:
|