diff --git a/mk/docs.mk b/mk/docs.mk index a7ffe928940f5..412981add6c62 100644 --- a/mk/docs.mk +++ b/mk/docs.mk @@ -215,10 +215,12 @@ RUSTDOC = $(HBIN2_H_$(CFG_BUILD))/rustdoc$(X_$(CFG_BUILD)) # $(1) - The crate name (std/extra) # $(2) - The crate file # $(3) - The relevant host build triple (to depend on libstd) +# +# Passes --cfg stage2 to rustdoc because it uses the stage2 librustc. define libdoc doc/$(1)/index.html: $$(RUSTDOC) $$(TLIB2_T_$(3)_H_$(3))/$(CFG_STDLIB_$(3)) @$$(call E, rustdoc: $$@) - $(Q)$(RUSTDOC) $(2) + $(Q)$(RUSTDOC) --cfg stage2 $(2) DOCS += doc/$(1)/index.html endef diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index c802d41bcee13..79aba0f1320e9 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -37,7 +37,7 @@ pub struct CrateAnalysis { /// Parses, resolves, and typechecks the given crate fn get_ast_and_resolve(cpath: &Path, - libs: HashSet) -> (DocContext, CrateAnalysis) { + libs: HashSet, cfgs: ~[~str]) -> (DocContext, CrateAnalysis) { use syntax::codemap::dummy_spanned; use rustc::driver::driver::{file_input, build_configuration, phase_1_parse_input, @@ -66,7 +66,9 @@ fn get_ast_and_resolve(cpath: &Path, span_diagnostic_handler); let mut cfg = build_configuration(sess); - cfg.push(@dummy_spanned(ast::MetaWord(@"stage2"))); + for cfg_ in cfgs.move_iter() { + cfg.push(@dummy_spanned(ast::MetaWord(cfg_.to_managed()))); + } let mut crate = phase_1_parse_input(sess, cfg.clone(), &input); crate = phase_2_configure_and_expand(sess, cfg, crate); @@ -79,8 +81,8 @@ fn get_ast_and_resolve(cpath: &Path, CrateAnalysis { exported_items: exported_items }); } -pub fn run_core (libs: HashSet, path: &Path) -> (clean::Crate, CrateAnalysis) { - let (ctxt, analysis) = get_ast_and_resolve(path, libs); +pub fn run_core (libs: HashSet, cfgs: ~[~str], path: &Path) -> (clean::Crate, CrateAnalysis) { + let (ctxt, analysis) = get_ast_and_resolve(path, libs, cfgs); let ctxt = @ctxt; debug!("defmap:"); for (k, v) in ctxt.tycx.def_map.iter() { diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 12a79aa545e80..1ed1b79a628cf 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -96,6 +96,7 @@ pub fn opts() -> ~[groups::OptGroup] { optopt("o", "output", "where to place the output", "PATH"), optmulti("L", "library-path", "directory to add to crate search path", "DIR"), + optmulti("", "cfg", "pass a --cfg to rustc", ""), optmulti("", "plugin-path", "directory to load plugins from", "DIR"), optmulti("", "passes", "space separated list of passes to also run, a \ value of `list` will print available passes", @@ -194,11 +195,12 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output { // First, parse the crate and extract all relevant information. let libs = Cell::new(matches.opt_strs("L").map(|s| Path::new(s.as_slice()))); + let cfgs = Cell::new(matches.opt_strs("cfg")); let cr = Cell::new(Path::new(cratefile)); info!("starting to run rustc"); let (crate, analysis) = do std::task::try { let cr = cr.take(); - core::run_core(libs.take().move_iter().collect(), &cr) + core::run_core(libs.take().move_iter().collect(), cfgs.take(), &cr) }.unwrap(); info!("finished with rustc"); local_data::set(analysiskey, analysis);