Skip to content

Commit 134e00b

Browse files
committed
Auto merge of #21876 - nick29581:driver-args, r=huonw
This allows people to write tools which are drop-in replacements for rustc by implementing `CompilerCalls` and three lines of code, rather than having to copy+paste a bunch of args parsing code. r? @alexcrichton
2 parents 0ba9e1f + f0e1e09 commit 134e00b

File tree

6 files changed

+431
-180
lines changed

6 files changed

+431
-180
lines changed

src/librustc/session/config.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ use syntax::diagnostic::{ColorConfig, Auto, Always, Never, SpanHandler};
3333
use syntax::parse;
3434
use syntax::parse::token::InternedString;
3535

36+
use getopts;
3637
use std::collections::HashMap;
3738
use std::collections::hash_map::Entry::{Occupied, Vacant};
38-
use getopts;
39+
use std::env;
3940
use std::fmt;
4041

4142
use llvm;
@@ -821,7 +822,6 @@ pub fn parse_cfgspecs(cfgspecs: Vec<String> ) -> ast::CrateConfig {
821822
}
822823

823824
pub fn build_session_options(matches: &getopts::Matches) -> Options {
824-
825825
let unparsed_crate_types = matches.opt_strs("crate-type");
826826
let crate_types = parse_crate_types_from_list(unparsed_crate_types)
827827
.unwrap_or_else(|e| early_error(&e[]));
@@ -1041,7 +1041,22 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
10411041
crate_name: crate_name,
10421042
alt_std_name: None,
10431043
libs: libs,
1044-
unstable_features: UnstableFeatures::Disallow
1044+
unstable_features: get_unstable_features_setting(),
1045+
}
1046+
}
1047+
1048+
pub fn get_unstable_features_setting() -> UnstableFeatures {
1049+
// Whether this is a feature-staged build, i.e. on the beta or stable channel
1050+
let disable_unstable_features = option_env!("CFG_DISABLE_UNSTABLE_FEATURES").is_some();
1051+
// The secret key needed to get through the rustc build itself by
1052+
// subverting the unstable features lints
1053+
let bootstrap_secret_key = option_env!("CFG_BOOTSTRAP_KEY");
1054+
// The matching key to the above, only known by the build system
1055+
let bootstrap_provided_key = env::var_string("RUSTC_BOOTSTRAP_KEY").ok();
1056+
match (disable_unstable_features, bootstrap_secret_key, bootstrap_provided_key) {
1057+
(_, Some(ref s), Some(ref p)) if s == p => UnstableFeatures::Cheat,
1058+
(true, _, _) => UnstableFeatures::Disallow,
1059+
(false, _, _) => UnstableFeatures::Default
10451060
}
10461061
}
10471062

src/librustc_driver/driver.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -27,6 +27,7 @@ use rustc_trans::back::write;
2727
use rustc_trans::trans;
2828
use rustc_typeck as typeck;
2929
use rustc_privacy;
30+
use super::Compilation;
3031

3132
use serialize::json;
3233

@@ -55,7 +56,7 @@ pub fn compile_input(sess: Session,
5556
let state = $make_state;
5657
(control.$point.callback)(state);
5758
}
58-
if control.$point.stop {
59+
if control.$point.stop == Compilation::Stop {
5960
return;
6061
}
6162
})}
@@ -206,14 +207,14 @@ impl<'a> CompileController<'a> {
206207
}
207208

208209
pub struct PhaseController<'a> {
209-
pub stop: bool,
210+
pub stop: Compilation,
210211
pub callback: Box<Fn(CompileState) -> () + 'a>,
211212
}
212213

213214
impl<'a> PhaseController<'a> {
214215
pub fn basic() -> PhaseController<'a> {
215216
PhaseController {
216-
stop: false,
217+
stop: Compilation::Continue,
217218
callback: box |_| {},
218219
}
219220
}

0 commit comments

Comments
 (0)