Skip to content

rustdoc: pass through --cfg to rustc #10644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 25, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion mk/docs.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub struct CrateAnalysis {

/// Parses, resolves, and typechecks the given crate
fn get_ast_and_resolve(cpath: &Path,
libs: HashSet<Path>) -> (DocContext, CrateAnalysis) {
libs: HashSet<Path>, cfgs: ~[~str]) -> (DocContext, CrateAnalysis) {
use syntax::codemap::dummy_spanned;
use rustc::driver::driver::{file_input, build_configuration,
phase_1_parse_input,
Expand Down Expand Up @@ -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);
Expand All @@ -79,8 +81,8 @@ fn get_ast_and_resolve(cpath: &Path,
CrateAnalysis { exported_items: exported_items });
}

pub fn run_core (libs: HashSet<Path>, path: &Path) -> (clean::Crate, CrateAnalysis) {
let (ctxt, analysis) = get_ast_and_resolve(path, libs);
pub fn run_core (libs: HashSet<Path>, 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() {
Expand Down
4 changes: 3 additions & 1 deletion src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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);
Expand Down