Skip to content

Commit 5820991

Browse files
committed
auto merge of #5433 : lucab/rust/lucab/cfgspec, r=graydon
All current meta items types (word, name-value, list) are now properly parsed by rustc --cfg command line. Fixes #2399
2 parents 3c84bac + 0a34a3f commit 5820991

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

src/librustc/driver/driver.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,15 @@ pub fn build_configuration(sess: Session, +argv0: ~str, input: input) ->
132132
}
133133

134134
// Convert strings provided as --cfg [cfgspec] into a crate_cfg
135-
pub fn parse_cfgspecs(cfgspecs: ~[~str]) -> ast::crate_cfg {
136-
// FIXME (#2399): It would be nice to use the parser to parse all
137-
// varieties of meta_item here. At the moment we just support the
138-
// meta_word variant.
139-
let mut words = ~[];
135+
fn parse_cfgspecs(cfgspecs: ~[~str],
136+
demitter: diagnostic::Emitter) -> ast::crate_cfg {
137+
let mut meta = ~[];
140138
for cfgspecs.each |s| {
141-
words.push(attr::mk_word_item(@/*bad*/copy *s));
139+
let sess = parse::new_parse_sess(Some(demitter));
140+
let m = parse::parse_meta_from_source_str(~"cfgspec", @/*bad*/ copy *s, ~[], sess);
141+
meta.push(m)
142142
}
143-
return words;
143+
return meta;
144144
}
145145

146146
pub enum input {
@@ -639,7 +639,7 @@ pub fn build_session_options(+binary: ~str,
639639
let addl_lib_search_paths =
640640
getopts::opt_strs(matches, ~"L")
641641
.map(|s| Path(*s));
642-
let cfg = parse_cfgspecs(getopts::opt_strs(matches, ~"cfg"));
642+
let cfg = parse_cfgspecs(getopts::opt_strs(matches, ~"cfg"), demitter);
643643
let test = opt_present(matches, ~"test");
644644
let android_cross_path = getopts::opt_maybe_str(
645645
matches, ~"android-cross-path");

src/libsyntax/parse/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,22 @@ pub fn parse_item_from_source_str(
139139
maybe_aborted(p.parse_item(attrs),p)
140140
}
141141

142+
pub fn parse_meta_from_source_str(
143+
name: ~str,
144+
source: @~str,
145+
+cfg: ast::crate_cfg,
146+
sess: @mut ParseSess
147+
) -> @ast::meta_item {
148+
let p = new_parser_from_source_str(
149+
sess,
150+
cfg,
151+
/*bad*/ copy name,
152+
codemap::FssNone,
153+
source
154+
);
155+
maybe_aborted(p.parse_meta_item(),p)
156+
}
157+
142158
pub fn parse_stmt_from_source_str(
143159
name: ~str,
144160
source: @~str,

0 commit comments

Comments
 (0)