diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 4895022cfac29..d1134b81e674e 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -54,10 +54,6 @@ use doctree; use visit_ast; use html::item_type::ItemType; -/// A stable identifier to the particular version of JSON output. -/// Increment this when the `Crate` and related structures change. -pub const SCHEMA_VERSION: &'static str = "0.8.3"; - mod inline; mod simplify; diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 9953fd4b5d8aa..34c0edd8ee1e4 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -54,22 +54,16 @@ use std::cell::RefCell; use std::collections::HashMap; use std::default::Default; use std::env; -use std::fs::File; -use std::io::{self, Read, Write}; +use std::io::Read; use std::path::PathBuf; use std::process; use std::rc::Rc; use std::sync::mpsc::channel; use externalfiles::ExternalHtml; -use serialize::Decodable; -use serialize::json::{self, Json}; use rustc::session::search_paths::SearchPaths; use rustc::session::config::{ErrorOutputType, RustcOptGroup, nightly_options}; -// reexported from `clean` so it can be easily updated with the mod itself -pub use clean::SCHEMA_VERSION; - #[macro_use] pub mod externalfiles; @@ -127,7 +121,6 @@ thread_local!(pub static ANALYSISKEY: Rc>> = struct Output { krate: clean::Crate, - json_plugins: Vec, passes: Vec, } @@ -150,9 +143,9 @@ pub fn opts() -> Vec { stable(optflag("V", "version", "print rustdoc's version")), stable(optflag("v", "verbose", "use verbose output")), stable(optopt("r", "input-format", "the input type of the specified file", - "[rust|json]")), + "[rust]")), stable(optopt("w", "output-format", "the output type to write", - "[html|json]")), + "[html]")), stable(optopt("o", "output", "where to place the output", "PATH")), stable(optopt("", "crate-name", "specify the name of this crate", "NAME")), stable(optmulti("L", "library-path", "directory to add to crate search path", @@ -311,7 +304,7 @@ pub fn main_args(args: &[String]) -> isize { return 1; } }; - let Output { krate, json_plugins, passes, } = out; + let Output { krate, passes, } = out; info!("going to format"); match matches.opt_str("w").as_ref().map(|s| &**s) { Some("html") | None => { @@ -321,11 +314,6 @@ pub fn main_args(args: &[String]) -> isize { css_file_extension) .expect("failed to generate documentation") } - Some("json") => { - json_output(krate, json_plugins, - output.unwrap_or(PathBuf::from("doc.json"))) - .expect("failed to write json") - } Some(s) => { println!("unknown output format: {}", s); return 1; @@ -342,14 +330,9 @@ fn acquire_input(input: &str, matches: &getopts::Matches) -> Result { match matches.opt_str("r").as_ref().map(|s| &**s) { Some("rust") => Ok(rust_input(input, externs, matches)), - Some("json") => json_input(input), Some(s) => Err(format!("unknown input format: {}", s)), None => { - if input.ends_with(".json") { - json_input(input) - } else { - Ok(rust_input(input, externs, matches)) - } + Ok(rust_input(input, externs, matches)) } } } @@ -461,76 +444,6 @@ fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matche // Run everything! info!("Executing passes/plugins"); - let (krate, json) = pm.run_plugins(krate); - Output { krate: krate, json_plugins: json, passes: passes } -} - -/// This input format purely deserializes the json output file. No passes are -/// run over the deserialized output. -fn json_input(input: &str) -> Result { - let mut bytes = Vec::new(); - if let Err(e) = File::open(input).and_then(|mut f| f.read_to_end(&mut bytes)) { - return Err(format!("couldn't open {}: {}", input, e)) - } - match json::from_reader(&mut &bytes[..]) { - Err(s) => Err(format!("{:?}", s)), - Ok(Json::Object(obj)) => { - let mut obj = obj; - // Make sure the schema is what we expect - match obj.remove(&"schema".to_string()) { - Some(Json::String(version)) => { - if version != SCHEMA_VERSION { - return Err(format!( - "sorry, but I only understand version {}", - SCHEMA_VERSION)) - } - } - Some(..) => return Err("malformed json".to_string()), - None => return Err("expected a schema version".to_string()), - } - let krate = match obj.remove(&"crate".to_string()) { - Some(json) => { - let mut d = json::Decoder::new(json); - Decodable::decode(&mut d).unwrap() - } - None => return Err("malformed json".to_string()), - }; - // FIXME: this should read from the "plugins" field, but currently - // Json doesn't implement decodable... - let plugin_output = Vec::new(); - Ok(Output { krate: krate, json_plugins: plugin_output, passes: Vec::new(), }) - } - Ok(..) => { - Err("malformed json input: expected an object at the \ - top".to_string()) - } - } -} - -/// Outputs the crate/plugin json as a giant json blob at the specified -/// destination. -fn json_output(krate: clean::Crate, res: Vec , - dst: PathBuf) -> io::Result<()> { - // { - // "schema": version, - // "crate": { parsed crate ... }, - // "plugins": { output of plugins ... } - // } - let mut json = std::collections::BTreeMap::new(); - json.insert("schema".to_string(), Json::String(SCHEMA_VERSION.to_string())); - let plugins_json = res.into_iter() - .filter_map(|opt| { - opt.map(|(string, json)| (string.to_string(), json)) - }).collect(); - - // FIXME #8335: yuck, Rust -> str -> JSON round trip! No way to .encode - // straight to the Rust JSON representation. - let crate_json_str = format!("{}", json::as_json(&krate)); - let crate_json = json::from_str(&crate_json_str).expect("Rust generated JSON is invalid"); - - json.insert("crate".to_string(), crate_json); - json.insert("plugins".to_string(), Json::Object(plugins_json)); - - let mut file = File::create(&dst)?; - write!(&mut file, "{}", Json::Object(json)) + let krate = pm.run_plugins(krate); + Output { krate: krate, passes: passes } } diff --git a/src/librustdoc/passes.rs b/src/librustdoc/passes.rs index ff2a9f13e8a12..adc39b69986d6 100644 --- a/src/librustdoc/passes.rs +++ b/src/librustdoc/passes.rs @@ -54,7 +54,7 @@ pub fn strip_hidden(krate: clean::Crate) -> plugins::PluginResult { }; // strip any traits implemented on stripped items - let krate = { + { struct ImplStripper<'a> { stripped: &'a mut DefIdSet } @@ -80,9 +80,7 @@ pub fn strip_hidden(krate: clean::Crate) -> plugins::PluginResult { } let mut stripper = ImplStripper{ stripped: &mut stripped }; stripper.fold_crate(krate) - }; - - (krate, None) + } } /// Strip private items from the point of view of a crate or externally from a @@ -107,9 +105,8 @@ pub fn strip_private(mut krate: clean::Crate) -> plugins::PluginResult { // strip all private implementations of traits { let mut stripper = ImplStripper(&retained); - krate = stripper.fold_crate(krate); + stripper.fold_crate(krate) } - (krate, None) } struct Stripper<'a> { @@ -192,17 +189,19 @@ impl<'a> fold::DocFolder for Stripper<'a> { self.fold_item_recur(i) }; - i.and_then(|i| { match i.inner { - // emptied modules/impls have no need to exist - clean::ModuleItem(ref m) - if m.items.is_empty() && - i.doc_value().is_none() => None, - clean::ImplItem(ref i) if i.items.is_empty() => None, - _ => { - self.retained.insert(i.def_id); - Some(i) + i.and_then(|i| { + match i.inner { + // emptied modules/impls have no need to exist + clean::ModuleItem(ref m) + if m.items.is_empty() && + i.doc_value().is_none() => None, + clean::ImplItem(ref i) if i.items.is_empty() => None, + _ => { + self.retained.insert(i.def_id); + Some(i) + } } - }}) + }) } } @@ -234,7 +233,7 @@ impl fold::DocFolder for ImportStripper { } pub fn strip_priv_imports(krate: clean::Crate) -> plugins::PluginResult { - (ImportStripper.fold_crate(krate), None) + ImportStripper.fold_crate(krate) } pub fn unindent_comments(krate: clean::Crate) -> plugins::PluginResult { @@ -258,7 +257,7 @@ pub fn unindent_comments(krate: clean::Crate) -> plugins::PluginResult { } let mut cleaner = CommentCleaner; let krate = cleaner.fold_crate(krate); - (krate, None) + krate } pub fn collapse_docs(krate: clean::Crate) -> plugins::PluginResult { @@ -287,7 +286,7 @@ pub fn collapse_docs(krate: clean::Crate) -> plugins::PluginResult { } let mut collapser = Collapser; let krate = collapser.fold_crate(krate); - (krate, None) + krate } pub fn unindent(s: &str) -> String { diff --git a/src/librustdoc/plugins.rs b/src/librustdoc/plugins.rs index 83ce3e61ab281..b8be84825c9cc 100644 --- a/src/librustdoc/plugins.rs +++ b/src/librustdoc/plugins.rs @@ -12,15 +12,13 @@ use clean; -use serialize::json; use std::mem; use std::string::String; use std::path::PathBuf; use rustc_back::dynamic_lib as dl; -pub type PluginJson = Option<(String, json::Json)>; -pub type PluginResult = (clean::Crate, PluginJson); +pub type PluginResult = clean::Crate; pub type PluginCallback = fn (clean::Crate) -> PluginResult; /// Manages loading and running of plugins @@ -65,15 +63,11 @@ impl PluginManager { self.callbacks.push(plugin); } /// Run all the loaded plugins over the crate, returning their results - pub fn run_plugins(&self, krate: clean::Crate) -> (clean::Crate, Vec ) { - let mut out_json = Vec::new(); - let mut krate = krate; + pub fn run_plugins(&self, mut krate: clean::Crate) -> clean::Crate { for &callback in &self.callbacks { - let (c, res) = callback(krate); - krate = c; - out_json.push(res); + krate = callback(krate); } - (krate, out_json) + krate } } diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 3810fb87acf6a..1fe9a8240fa80 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -122,8 +122,8 @@ pub fn run(input: &str, if let Some(name) = crate_name { krate.name = name; } - let (krate, _) = passes::collapse_docs(krate); - let (krate, _) = passes::unindent_comments(krate); + let krate = passes::collapse_docs(krate); + let krate = passes::unindent_comments(krate); let mut collector = Collector::new(krate.name.to_string(), cfgs, diff --git a/src/test/run-make/rustdoc-json/Makefile b/src/test/run-make/rustdoc-json/Makefile deleted file mode 100644 index e49ab64b6958a..0000000000000 --- a/src/test/run-make/rustdoc-json/Makefile +++ /dev/null @@ -1,4 +0,0 @@ --include ../tools.mk -all: - $(HOST_RPATH_ENV) $(RUSTDOC) -w json -o $(TMPDIR)/doc.json foo.rs - $(HOST_RPATH_ENV) $(RUSTDOC) -o $(TMPDIR)/doc $(TMPDIR)/doc.json diff --git a/src/test/run-make/rustdoc-json/foo.rs b/src/test/run-make/rustdoc-json/foo.rs deleted file mode 100644 index 3bd56c14193a8..0000000000000 --- a/src/test/run-make/rustdoc-json/foo.rs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![crate_name = "foo"] - -//! Very docs - -pub mod bar { - - /// So correct - pub mod baz { - /// Much detail - pub fn baz() { } - } - - /// *wow* - pub trait Doge { fn dummy(&self) { } } -}