Skip to content

Commit e930aeb

Browse files
committed
rustdoc: Accept string source in core::run_core
This is wanted by external tooling that uses rustdoc. There are likely some bugs when actually generating HTML output (which may expect to be able to read the source) but all I need for now is the cleaned crate and analysis.
1 parent aaf595e commit e930aeb

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ use rustc::middle::def;
4545
use rustc::middle::subst::{self, ParamSpace, VecPerParamSpace};
4646
use rustc::middle::ty;
4747
use rustc::middle::stability;
48-
use rustc::session::config;
4948

5049
use std::rc::Rc;
5150
use std::u32;
@@ -127,15 +126,17 @@ pub struct Crate {
127126

128127
impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> {
129128
fn clean(&self, cx: &DocContext) -> Crate {
129+
use rustc::session::config::Input;
130+
130131
let mut externs = Vec::new();
131132
cx.sess().cstore.iter_crate_data(|n, meta| {
132133
externs.push((n, meta.clean(cx)));
133134
});
134135
externs.sort_by(|&(a, _), &(b, _)| a.cmp(&b));
135136

136137
// Figure out the name of this crate
137-
let input = config::Input::File(cx.src.clone());
138-
let name = link::find_crate_name(None, self.attrs.as_slice(), &input);
138+
let input = &cx.input;
139+
let name = link::find_crate_name(None, self.attrs.as_slice(), input);
139140

140141
// Clean the crate, translating the entire libsyntax AST to one that is
141142
// understood by rustdoc.
@@ -188,9 +189,14 @@ impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> {
188189
m.items.extend(tmp.into_iter());
189190
}
190191

192+
let src = match cx.input {
193+
Input::File(ref path) => path.clone(),
194+
Input::Str(_) => FsPath::new("") // FIXME: this is wrong
195+
};
196+
191197
Crate {
192198
name: name.to_string(),
193-
src: cx.src.clone(),
199+
src: src,
194200
module: Some(module),
195201
externs: externs,
196202
primitives: primitives,

src/librustdoc/core.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub use self::MaybeTyped::*;
1111

1212
use rustc_driver::driver;
1313
use rustc::session::{self, config};
14-
use rustc::session::config::UnstableFeatures;
14+
use rustc::session::config::{Input, UnstableFeatures};
1515
use rustc::session::search_paths::SearchPaths;
1616
use rustc::middle::{privacy, ty};
1717
use rustc::lint;
@@ -39,7 +39,7 @@ pub type ExternalPaths = RefCell<Option<HashMap<ast::DefId,
3939
pub struct DocContext<'tcx> {
4040
pub krate: &'tcx ast::Crate,
4141
pub maybe_typed: MaybeTyped<'tcx>,
42-
pub src: Path,
42+
pub input: Input,
4343
pub external_paths: ExternalPaths,
4444
pub external_traits: RefCell<Option<HashMap<ast::DefId, clean::Trait>>>,
4545
pub external_typarams: RefCell<Option<HashMap<ast::DefId, String>>>,
@@ -80,12 +80,15 @@ pub struct CrateAnalysis {
8080
pub type Externs = HashMap<String, Vec<String>>;
8181

8282
pub fn run_core(search_paths: SearchPaths, cfgs: Vec<String>, externs: Externs,
83-
cpath: &Path, triple: Option<String>)
83+
input: Input, triple: Option<String>)
8484
-> (clean::Crate, CrateAnalysis) {
8585

8686
// Parse, resolve, and typecheck the given crate.
8787

88-
let input = config::Input::File(cpath.clone());
88+
let cpath = match input {
89+
Input::File(ref p) => Some(p.clone()),
90+
_ => None
91+
};
8992

9093
let warning_lint = lint::builtin::WARNINGS.name_lower();
9194

@@ -107,8 +110,7 @@ pub fn run_core(search_paths: SearchPaths, cfgs: Vec<String>, externs: Externs,
107110
let span_diagnostic_handler =
108111
diagnostic::mk_span_handler(diagnostic_handler, codemap);
109112

110-
let sess = session::build_session_(sessopts,
111-
Some(cpath.clone()),
113+
let sess = session::build_session_(sessopts, cpath,
112114
span_diagnostic_handler);
113115

114116
let cfg = config::build_configuration(&sess);
@@ -136,7 +138,7 @@ pub fn run_core(search_paths: SearchPaths, cfgs: Vec<String>, externs: Externs,
136138
let ctxt = DocContext {
137139
krate: ty_cx.map.krate(),
138140
maybe_typed: Typed(ty_cx),
139-
src: cpath.clone(),
141+
input: input,
140142
external_traits: RefCell::new(Some(HashMap::new())),
141143
external_typarams: RefCell::new(Some(HashMap::new())),
142144
external_paths: RefCell::new(Some(HashMap::new())),

src/librustdoc/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,10 @@ fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matche
350350
info!("starting to run rustc");
351351

352352
let (mut krate, analysis) = std::thread::Thread::scoped(move |:| {
353+
use rustc::session::config::Input;
354+
353355
let cr = cr;
354-
core::run_core(paths, cfgs, externs, &cr, triple)
356+
core::run_core(paths, cfgs, externs, Input::File(cr), triple)
355357
}).join().map_err(|_| "rustc failed").unwrap();
356358
info!("finished with rustc");
357359
let mut analysis = Some(analysis);

src/librustdoc/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub fn run(input: &str,
7979
let ctx = core::DocContext {
8080
krate: &krate,
8181
maybe_typed: core::NotTyped(sess),
82-
src: input_path,
82+
input: input,
8383
external_paths: RefCell::new(Some(HashMap::new())),
8484
external_traits: RefCell::new(None),
8585
external_typarams: RefCell::new(None),

0 commit comments

Comments
 (0)