Skip to content

Commit 1746c02

Browse files
committed
auto merge of #10644 : cmr/rust/rustdoc_cfg, r=alexcrichton
Closes #10623
2 parents 4043951 + 6fbe2a0 commit 1746c02

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

mk/docs.mk

+3-1
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,12 @@ RUSTDOC = $(HBIN2_H_$(CFG_BUILD))/rustdoc$(X_$(CFG_BUILD))
215215
# $(1) - The crate name (std/extra)
216216
# $(2) - The crate file
217217
# $(3) - The relevant host build triple (to depend on libstd)
218+
#
219+
# Passes --cfg stage2 to rustdoc because it uses the stage2 librustc.
218220
define libdoc
219221
doc/$(1)/index.html: $$(RUSTDOC) $$(TLIB2_T_$(3)_H_$(3))/$(CFG_STDLIB_$(3))
220222
@$$(call E, rustdoc: $$@)
221-
$(Q)$(RUSTDOC) $(2)
223+
$(Q)$(RUSTDOC) --cfg stage2 $(2)
222224

223225
DOCS += doc/$(1)/index.html
224226
endef

src/librustdoc/core.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub struct CrateAnalysis {
3737

3838
/// Parses, resolves, and typechecks the given crate
3939
fn get_ast_and_resolve(cpath: &Path,
40-
libs: HashSet<Path>) -> (DocContext, CrateAnalysis) {
40+
libs: HashSet<Path>, cfgs: ~[~str]) -> (DocContext, CrateAnalysis) {
4141
use syntax::codemap::dummy_spanned;
4242
use rustc::driver::driver::{file_input, build_configuration,
4343
phase_1_parse_input,
@@ -66,7 +66,9 @@ fn get_ast_and_resolve(cpath: &Path,
6666
span_diagnostic_handler);
6767

6868
let mut cfg = build_configuration(sess);
69-
cfg.push(@dummy_spanned(ast::MetaWord(@"stage2")));
69+
for cfg_ in cfgs.move_iter() {
70+
cfg.push(@dummy_spanned(ast::MetaWord(cfg_.to_managed())));
71+
}
7072

7173
let mut crate = phase_1_parse_input(sess, cfg.clone(), &input);
7274
crate = phase_2_configure_and_expand(sess, cfg, crate);
@@ -79,8 +81,8 @@ fn get_ast_and_resolve(cpath: &Path,
7981
CrateAnalysis { exported_items: exported_items });
8082
}
8183

82-
pub fn run_core (libs: HashSet<Path>, path: &Path) -> (clean::Crate, CrateAnalysis) {
83-
let (ctxt, analysis) = get_ast_and_resolve(path, libs);
84+
pub fn run_core (libs: HashSet<Path>, cfgs: ~[~str], path: &Path) -> (clean::Crate, CrateAnalysis) {
85+
let (ctxt, analysis) = get_ast_and_resolve(path, libs, cfgs);
8486
let ctxt = @ctxt;
8587
debug!("defmap:");
8688
for (k, v) in ctxt.tycx.def_map.iter() {

src/librustdoc/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ pub fn opts() -> ~[groups::OptGroup] {
9696
optopt("o", "output", "where to place the output", "PATH"),
9797
optmulti("L", "library-path", "directory to add to crate search path",
9898
"DIR"),
99+
optmulti("", "cfg", "pass a --cfg to rustc", ""),
99100
optmulti("", "plugin-path", "directory to load plugins from", "DIR"),
100101
optmulti("", "passes", "space separated list of passes to also run, a \
101102
value of `list` will print available passes",
@@ -194,11 +195,12 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output {
194195

195196
// First, parse the crate and extract all relevant information.
196197
let libs = Cell::new(matches.opt_strs("L").map(|s| Path::new(s.as_slice())));
198+
let cfgs = Cell::new(matches.opt_strs("cfg"));
197199
let cr = Cell::new(Path::new(cratefile));
198200
info!("starting to run rustc");
199201
let (crate, analysis) = do std::task::try {
200202
let cr = cr.take();
201-
core::run_core(libs.take().move_iter().collect(), &cr)
203+
core::run_core(libs.take().move_iter().collect(), cfgs.take(), &cr)
202204
}.unwrap();
203205
info!("finished with rustc");
204206
local_data::set(analysiskey, analysis);

0 commit comments

Comments
 (0)