Skip to content

Commit cacd6b6

Browse files
committed
Refactor compilation to make it easier to use for tools
1 parent 0ba9e1f commit cacd6b6

File tree

5 files changed

+404
-175
lines changed

5 files changed

+404
-175
lines changed

src/librustc/session/config.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ 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;
3939
use std::fmt;
40+
use std::os;
4041

4142
use llvm;
4243

@@ -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

0 commit comments

Comments
 (0)