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.
This commit is contained in:
parent
aaf595eab9
commit
e930aeb32b
4 changed files with 23 additions and 13 deletions
|
@ -45,7 +45,6 @@ use rustc::middle::def;
|
|||
use rustc::middle::subst::{self, ParamSpace, VecPerParamSpace};
|
||||
use rustc::middle::ty;
|
||||
use rustc::middle::stability;
|
||||
use rustc::session::config;
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::u32;
|
||||
|
@ -127,6 +126,8 @@ pub struct Crate {
|
|||
|
||||
impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> {
|
||||
fn clean(&self, cx: &DocContext) -> Crate {
|
||||
use rustc::session::config::Input;
|
||||
|
||||
let mut externs = Vec::new();
|
||||
cx.sess().cstore.iter_crate_data(|n, meta| {
|
||||
externs.push((n, meta.clean(cx)));
|
||||
|
@ -134,8 +135,8 @@ impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> {
|
|||
externs.sort_by(|&(a, _), &(b, _)| a.cmp(&b));
|
||||
|
||||
// Figure out the name of this crate
|
||||
let input = config::Input::File(cx.src.clone());
|
||||
let name = link::find_crate_name(None, self.attrs.as_slice(), &input);
|
||||
let input = &cx.input;
|
||||
let name = link::find_crate_name(None, self.attrs.as_slice(), input);
|
||||
|
||||
// Clean the crate, translating the entire libsyntax AST to one that is
|
||||
// understood by rustdoc.
|
||||
|
@ -188,9 +189,14 @@ impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> {
|
|||
m.items.extend(tmp.into_iter());
|
||||
}
|
||||
|
||||
let src = match cx.input {
|
||||
Input::File(ref path) => path.clone(),
|
||||
Input::Str(_) => FsPath::new("") // FIXME: this is wrong
|
||||
};
|
||||
|
||||
Crate {
|
||||
name: name.to_string(),
|
||||
src: cx.src.clone(),
|
||||
src: src,
|
||||
module: Some(module),
|
||||
externs: externs,
|
||||
primitives: primitives,
|
||||
|
|
|
@ -11,7 +11,7 @@ pub use self::MaybeTyped::*;
|
|||
|
||||
use rustc_driver::driver;
|
||||
use rustc::session::{self, config};
|
||||
use rustc::session::config::UnstableFeatures;
|
||||
use rustc::session::config::{Input, UnstableFeatures};
|
||||
use rustc::session::search_paths::SearchPaths;
|
||||
use rustc::middle::{privacy, ty};
|
||||
use rustc::lint;
|
||||
|
@ -39,7 +39,7 @@ pub type ExternalPaths = RefCell<Option<HashMap<ast::DefId,
|
|||
pub struct DocContext<'tcx> {
|
||||
pub krate: &'tcx ast::Crate,
|
||||
pub maybe_typed: MaybeTyped<'tcx>,
|
||||
pub src: Path,
|
||||
pub input: Input,
|
||||
pub external_paths: ExternalPaths,
|
||||
pub external_traits: RefCell<Option<HashMap<ast::DefId, clean::Trait>>>,
|
||||
pub external_typarams: RefCell<Option<HashMap<ast::DefId, String>>>,
|
||||
|
@ -80,12 +80,15 @@ pub struct CrateAnalysis {
|
|||
pub type Externs = HashMap<String, Vec<String>>;
|
||||
|
||||
pub fn run_core(search_paths: SearchPaths, cfgs: Vec<String>, externs: Externs,
|
||||
cpath: &Path, triple: Option<String>)
|
||||
input: Input, triple: Option<String>)
|
||||
-> (clean::Crate, CrateAnalysis) {
|
||||
|
||||
// Parse, resolve, and typecheck the given crate.
|
||||
|
||||
let input = config::Input::File(cpath.clone());
|
||||
let cpath = match input {
|
||||
Input::File(ref p) => Some(p.clone()),
|
||||
_ => None
|
||||
};
|
||||
|
||||
let warning_lint = lint::builtin::WARNINGS.name_lower();
|
||||
|
||||
|
@ -107,8 +110,7 @@ pub fn run_core(search_paths: SearchPaths, cfgs: Vec<String>, externs: Externs,
|
|||
let span_diagnostic_handler =
|
||||
diagnostic::mk_span_handler(diagnostic_handler, codemap);
|
||||
|
||||
let sess = session::build_session_(sessopts,
|
||||
Some(cpath.clone()),
|
||||
let sess = session::build_session_(sessopts, cpath,
|
||||
span_diagnostic_handler);
|
||||
|
||||
let cfg = config::build_configuration(&sess);
|
||||
|
@ -136,7 +138,7 @@ pub fn run_core(search_paths: SearchPaths, cfgs: Vec<String>, externs: Externs,
|
|||
let ctxt = DocContext {
|
||||
krate: ty_cx.map.krate(),
|
||||
maybe_typed: Typed(ty_cx),
|
||||
src: cpath.clone(),
|
||||
input: input,
|
||||
external_traits: RefCell::new(Some(HashMap::new())),
|
||||
external_typarams: RefCell::new(Some(HashMap::new())),
|
||||
external_paths: RefCell::new(Some(HashMap::new())),
|
||||
|
|
|
@ -350,8 +350,10 @@ fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matche
|
|||
info!("starting to run rustc");
|
||||
|
||||
let (mut krate, analysis) = std::thread::Thread::scoped(move |:| {
|
||||
use rustc::session::config::Input;
|
||||
|
||||
let cr = cr;
|
||||
core::run_core(paths, cfgs, externs, &cr, triple)
|
||||
core::run_core(paths, cfgs, externs, Input::File(cr), triple)
|
||||
}).join().map_err(|_| "rustc failed").unwrap();
|
||||
info!("finished with rustc");
|
||||
let mut analysis = Some(analysis);
|
||||
|
|
|
@ -79,7 +79,7 @@ pub fn run(input: &str,
|
|||
let ctx = core::DocContext {
|
||||
krate: &krate,
|
||||
maybe_typed: core::NotTyped(sess),
|
||||
src: input_path,
|
||||
input: input,
|
||||
external_paths: RefCell::new(Some(HashMap::new())),
|
||||
external_traits: RefCell::new(None),
|
||||
external_typarams: RefCell::new(None),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue