Skip to content

Commit c22302f

Browse files
committed
Auto merge of #32773 - mitaa:rdoc-ttfn-json, r=alexcrichton
rustdoc: Remove the json-{input, output} format (for reference #32698) fixes #25108 r? @alexcrichton
2 parents 1779057 + 8bb1905 commit c22302f

File tree

7 files changed

+31
-158
lines changed

7 files changed

+31
-158
lines changed

src/librustdoc/clean/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ use doctree;
5454
use visit_ast;
5555
use html::item_type::ItemType;
5656

57-
/// A stable identifier to the particular version of JSON output.
58-
/// Increment this when the `Crate` and related structures change.
59-
pub const SCHEMA_VERSION: &'static str = "0.8.3";
60-
6157
mod inline;
6258
mod simplify;
6359

src/librustdoc/lib.rs

+7-94
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,16 @@ use std::cell::RefCell;
5454
use std::collections::HashMap;
5555
use std::default::Default;
5656
use std::env;
57-
use std::fs::File;
58-
use std::io::{self, Read, Write};
57+
use std::io::Read;
5958
use std::path::PathBuf;
6059
use std::process;
6160
use std::rc::Rc;
6261
use std::sync::mpsc::channel;
6362

6463
use externalfiles::ExternalHtml;
65-
use serialize::Decodable;
66-
use serialize::json::{self, Json};
6764
use rustc::session::search_paths::SearchPaths;
6865
use rustc::session::config::{ErrorOutputType, RustcOptGroup, nightly_options};
6966

70-
// reexported from `clean` so it can be easily updated with the mod itself
71-
pub use clean::SCHEMA_VERSION;
72-
7367
#[macro_use]
7468
pub mod externalfiles;
7569

@@ -127,7 +121,6 @@ thread_local!(pub static ANALYSISKEY: Rc<RefCell<Option<core::CrateAnalysis>>> =
127121

128122
struct Output {
129123
krate: clean::Crate,
130-
json_plugins: Vec<plugins::PluginJson>,
131124
passes: Vec<String>,
132125
}
133126

@@ -150,9 +143,9 @@ pub fn opts() -> Vec<RustcOptGroup> {
150143
stable(optflag("V", "version", "print rustdoc's version")),
151144
stable(optflag("v", "verbose", "use verbose output")),
152145
stable(optopt("r", "input-format", "the input type of the specified file",
153-
"[rust|json]")),
146+
"[rust]")),
154147
stable(optopt("w", "output-format", "the output type to write",
155-
"[html|json]")),
148+
"[html]")),
156149
stable(optopt("o", "output", "where to place the output", "PATH")),
157150
stable(optopt("", "crate-name", "specify the name of this crate", "NAME")),
158151
stable(optmulti("L", "library-path", "directory to add to crate search path",
@@ -311,7 +304,7 @@ pub fn main_args(args: &[String]) -> isize {
311304
return 1;
312305
}
313306
};
314-
let Output { krate, json_plugins, passes, } = out;
307+
let Output { krate, passes, } = out;
315308
info!("going to format");
316309
match matches.opt_str("w").as_ref().map(|s| &**s) {
317310
Some("html") | None => {
@@ -321,11 +314,6 @@ pub fn main_args(args: &[String]) -> isize {
321314
css_file_extension)
322315
.expect("failed to generate documentation")
323316
}
324-
Some("json") => {
325-
json_output(krate, json_plugins,
326-
output.unwrap_or(PathBuf::from("doc.json")))
327-
.expect("failed to write json")
328-
}
329317
Some(s) => {
330318
println!("unknown output format: {}", s);
331319
return 1;
@@ -342,14 +330,9 @@ fn acquire_input(input: &str,
342330
matches: &getopts::Matches) -> Result<Output, String> {
343331
match matches.opt_str("r").as_ref().map(|s| &**s) {
344332
Some("rust") => Ok(rust_input(input, externs, matches)),
345-
Some("json") => json_input(input),
346333
Some(s) => Err(format!("unknown input format: {}", s)),
347334
None => {
348-
if input.ends_with(".json") {
349-
json_input(input)
350-
} else {
351-
Ok(rust_input(input, externs, matches))
352-
}
335+
Ok(rust_input(input, externs, matches))
353336
}
354337
}
355338
}
@@ -461,76 +444,6 @@ fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matche
461444

462445
// Run everything!
463446
info!("Executing passes/plugins");
464-
let (krate, json) = pm.run_plugins(krate);
465-
Output { krate: krate, json_plugins: json, passes: passes }
466-
}
467-
468-
/// This input format purely deserializes the json output file. No passes are
469-
/// run over the deserialized output.
470-
fn json_input(input: &str) -> Result<Output, String> {
471-
let mut bytes = Vec::new();
472-
if let Err(e) = File::open(input).and_then(|mut f| f.read_to_end(&mut bytes)) {
473-
return Err(format!("couldn't open {}: {}", input, e))
474-
}
475-
match json::from_reader(&mut &bytes[..]) {
476-
Err(s) => Err(format!("{:?}", s)),
477-
Ok(Json::Object(obj)) => {
478-
let mut obj = obj;
479-
// Make sure the schema is what we expect
480-
match obj.remove(&"schema".to_string()) {
481-
Some(Json::String(version)) => {
482-
if version != SCHEMA_VERSION {
483-
return Err(format!(
484-
"sorry, but I only understand version {}",
485-
SCHEMA_VERSION))
486-
}
487-
}
488-
Some(..) => return Err("malformed json".to_string()),
489-
None => return Err("expected a schema version".to_string()),
490-
}
491-
let krate = match obj.remove(&"crate".to_string()) {
492-
Some(json) => {
493-
let mut d = json::Decoder::new(json);
494-
Decodable::decode(&mut d).unwrap()
495-
}
496-
None => return Err("malformed json".to_string()),
497-
};
498-
// FIXME: this should read from the "plugins" field, but currently
499-
// Json doesn't implement decodable...
500-
let plugin_output = Vec::new();
501-
Ok(Output { krate: krate, json_plugins: plugin_output, passes: Vec::new(), })
502-
}
503-
Ok(..) => {
504-
Err("malformed json input: expected an object at the \
505-
top".to_string())
506-
}
507-
}
508-
}
509-
510-
/// Outputs the crate/plugin json as a giant json blob at the specified
511-
/// destination.
512-
fn json_output(krate: clean::Crate, res: Vec<plugins::PluginJson> ,
513-
dst: PathBuf) -> io::Result<()> {
514-
// {
515-
// "schema": version,
516-
// "crate": { parsed crate ... },
517-
// "plugins": { output of plugins ... }
518-
// }
519-
let mut json = std::collections::BTreeMap::new();
520-
json.insert("schema".to_string(), Json::String(SCHEMA_VERSION.to_string()));
521-
let plugins_json = res.into_iter()
522-
.filter_map(|opt| {
523-
opt.map(|(string, json)| (string.to_string(), json))
524-
}).collect();
525-
526-
// FIXME #8335: yuck, Rust -> str -> JSON round trip! No way to .encode
527-
// straight to the Rust JSON representation.
528-
let crate_json_str = format!("{}", json::as_json(&krate));
529-
let crate_json = json::from_str(&crate_json_str).expect("Rust generated JSON is invalid");
530-
531-
json.insert("crate".to_string(), crate_json);
532-
json.insert("plugins".to_string(), Json::Object(plugins_json));
533-
534-
let mut file = File::create(&dst)?;
535-
write!(&mut file, "{}", Json::Object(json))
447+
let krate = pm.run_plugins(krate);
448+
Output { krate: krate, passes: passes }
536449
}

src/librustdoc/passes.rs

+18-19
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub fn strip_hidden(krate: clean::Crate) -> plugins::PluginResult {
5454
};
5555

5656
// strip any traits implemented on stripped items
57-
let krate = {
57+
{
5858
struct ImplStripper<'a> {
5959
stripped: &'a mut DefIdSet
6060
}
@@ -80,9 +80,7 @@ pub fn strip_hidden(krate: clean::Crate) -> plugins::PluginResult {
8080
}
8181
let mut stripper = ImplStripper{ stripped: &mut stripped };
8282
stripper.fold_crate(krate)
83-
};
84-
85-
(krate, None)
83+
}
8684
}
8785

8886
/// 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 {
107105
// strip all private implementations of traits
108106
{
109107
let mut stripper = ImplStripper(&retained);
110-
krate = stripper.fold_crate(krate);
108+
stripper.fold_crate(krate)
111109
}
112-
(krate, None)
113110
}
114111

115112
struct Stripper<'a> {
@@ -192,17 +189,19 @@ impl<'a> fold::DocFolder for Stripper<'a> {
192189
self.fold_item_recur(i)
193190
};
194191

195-
i.and_then(|i| { match i.inner {
196-
// emptied modules/impls have no need to exist
197-
clean::ModuleItem(ref m)
198-
if m.items.is_empty() &&
199-
i.doc_value().is_none() => None,
200-
clean::ImplItem(ref i) if i.items.is_empty() => None,
201-
_ => {
202-
self.retained.insert(i.def_id);
203-
Some(i)
192+
i.and_then(|i| {
193+
match i.inner {
194+
// emptied modules/impls have no need to exist
195+
clean::ModuleItem(ref m)
196+
if m.items.is_empty() &&
197+
i.doc_value().is_none() => None,
198+
clean::ImplItem(ref i) if i.items.is_empty() => None,
199+
_ => {
200+
self.retained.insert(i.def_id);
201+
Some(i)
202+
}
204203
}
205-
}})
204+
})
206205
}
207206
}
208207

@@ -234,7 +233,7 @@ impl fold::DocFolder for ImportStripper {
234233
}
235234

236235
pub fn strip_priv_imports(krate: clean::Crate) -> plugins::PluginResult {
237-
(ImportStripper.fold_crate(krate), None)
236+
ImportStripper.fold_crate(krate)
238237
}
239238

240239
pub fn unindent_comments(krate: clean::Crate) -> plugins::PluginResult {
@@ -258,7 +257,7 @@ pub fn unindent_comments(krate: clean::Crate) -> plugins::PluginResult {
258257
}
259258
let mut cleaner = CommentCleaner;
260259
let krate = cleaner.fold_crate(krate);
261-
(krate, None)
260+
krate
262261
}
263262

264263
pub fn collapse_docs(krate: clean::Crate) -> plugins::PluginResult {
@@ -287,7 +286,7 @@ pub fn collapse_docs(krate: clean::Crate) -> plugins::PluginResult {
287286
}
288287
let mut collapser = Collapser;
289288
let krate = collapser.fold_crate(krate);
290-
(krate, None)
289+
krate
291290
}
292291

293292
pub fn unindent(s: &str) -> String {

src/librustdoc/plugins.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@
1212

1313
use clean;
1414

15-
use serialize::json;
1615
use std::mem;
1716
use std::string::String;
1817
use std::path::PathBuf;
1918

2019
use rustc_back::dynamic_lib as dl;
2120

22-
pub type PluginJson = Option<(String, json::Json)>;
23-
pub type PluginResult = (clean::Crate, PluginJson);
21+
pub type PluginResult = clean::Crate;
2422
pub type PluginCallback = fn (clean::Crate) -> PluginResult;
2523

2624
/// Manages loading and running of plugins
@@ -65,15 +63,11 @@ impl PluginManager {
6563
self.callbacks.push(plugin);
6664
}
6765
/// Run all the loaded plugins over the crate, returning their results
68-
pub fn run_plugins(&self, krate: clean::Crate) -> (clean::Crate, Vec<PluginJson> ) {
69-
let mut out_json = Vec::new();
70-
let mut krate = krate;
66+
pub fn run_plugins(&self, mut krate: clean::Crate) -> clean::Crate {
7167
for &callback in &self.callbacks {
72-
let (c, res) = callback(krate);
73-
krate = c;
74-
out_json.push(res);
68+
krate = callback(krate);
7569
}
76-
(krate, out_json)
70+
krate
7771
}
7872
}
7973

src/librustdoc/test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ pub fn run(input: &str,
122122
if let Some(name) = crate_name {
123123
krate.name = name;
124124
}
125-
let (krate, _) = passes::collapse_docs(krate);
126-
let (krate, _) = passes::unindent_comments(krate);
125+
let krate = passes::collapse_docs(krate);
126+
let krate = passes::unindent_comments(krate);
127127

128128
let mut collector = Collector::new(krate.name.to_string(),
129129
cfgs,

src/test/run-make/rustdoc-json/Makefile

-4
This file was deleted.

src/test/run-make/rustdoc-json/foo.rs

-25
This file was deleted.

0 commit comments

Comments
 (0)