@@ -54,22 +54,16 @@ use std::cell::RefCell;
5454use std:: collections:: HashMap ;
5555use std:: default:: Default ;
5656use std:: env;
57- use std:: fs:: File ;
58- use std:: io:: { self , Read , Write } ;
57+ use std:: io:: Read ;
5958use std:: path:: PathBuf ;
6059use std:: process;
6160use std:: rc:: Rc ;
6261use std:: sync:: mpsc:: channel;
6362
6463use externalfiles:: ExternalHtml ;
65- use serialize:: Decodable ;
66- use serialize:: json:: { self , Json } ;
6764use rustc:: session:: search_paths:: SearchPaths ;
6865use 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]
7468pub mod externalfiles;
7569
@@ -127,7 +121,6 @@ thread_local!(pub static ANALYSISKEY: Rc<RefCell<Option<core::CrateAnalysis>>> =
127121
128122struct 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}
0 commit comments