@@ -54,22 +54,16 @@ use std::cell::RefCell;
54
54
use std:: collections:: HashMap ;
55
55
use std:: default:: Default ;
56
56
use std:: env;
57
- use std:: fs:: File ;
58
- use std:: io:: { self , Read , Write } ;
57
+ use std:: io:: Read ;
59
58
use std:: path:: PathBuf ;
60
59
use std:: process;
61
60
use std:: rc:: Rc ;
62
61
use std:: sync:: mpsc:: channel;
63
62
64
63
use externalfiles:: ExternalHtml ;
65
- use serialize:: Decodable ;
66
- use serialize:: json:: { self , Json } ;
67
64
use rustc:: session:: search_paths:: SearchPaths ;
68
65
use rustc:: session:: config:: { ErrorOutputType , RustcOptGroup , nightly_options} ;
69
66
70
- // reexported from `clean` so it can be easily updated with the mod itself
71
- pub use clean:: SCHEMA_VERSION ;
72
-
73
67
#[ macro_use]
74
68
pub mod externalfiles;
75
69
@@ -127,7 +121,6 @@ thread_local!(pub static ANALYSISKEY: Rc<RefCell<Option<core::CrateAnalysis>>> =
127
121
128
122
struct Output {
129
123
krate : clean:: Crate ,
130
- json_plugins : Vec < plugins:: PluginJson > ,
131
124
passes : Vec < String > ,
132
125
}
133
126
@@ -150,9 +143,9 @@ pub fn opts() -> Vec<RustcOptGroup> {
150
143
stable( optflag( "V" , "version" , "print rustdoc's version" ) ) ,
151
144
stable( optflag( "v" , "verbose" , "use verbose output" ) ) ,
152
145
stable( optopt( "r" , "input-format" , "the input type of the specified file" ,
153
- "[rust|json ]" ) ) ,
146
+ "[rust]" ) ) ,
154
147
stable( optopt( "w" , "output-format" , "the output type to write" ,
155
- "[html|json ]" ) ) ,
148
+ "[html]" ) ) ,
156
149
stable( optopt( "o" , "output" , "where to place the output" , "PATH" ) ) ,
157
150
stable( optopt( "" , "crate-name" , "specify the name of this crate" , "NAME" ) ) ,
158
151
stable( optmulti( "L" , "library-path" , "directory to add to crate search path" ,
@@ -311,7 +304,7 @@ pub fn main_args(args: &[String]) -> isize {
311
304
return 1 ;
312
305
}
313
306
} ;
314
- let Output { krate, json_plugins , passes, } = out;
307
+ let Output { krate, passes, } = out;
315
308
info ! ( "going to format" ) ;
316
309
match matches. opt_str ( "w" ) . as_ref ( ) . map ( |s| & * * s) {
317
310
Some ( "html" ) | None => {
@@ -321,11 +314,6 @@ pub fn main_args(args: &[String]) -> isize {
321
314
css_file_extension)
322
315
. expect ( "failed to generate documentation" )
323
316
}
324
- Some ( "json" ) => {
325
- json_output ( krate, json_plugins,
326
- output. unwrap_or ( PathBuf :: from ( "doc.json" ) ) )
327
- . expect ( "failed to write json" )
328
- }
329
317
Some ( s) => {
330
318
println ! ( "unknown output format: {}" , s) ;
331
319
return 1 ;
@@ -342,14 +330,9 @@ fn acquire_input(input: &str,
342
330
matches : & getopts:: Matches ) -> Result < Output , String > {
343
331
match matches. opt_str ( "r" ) . as_ref ( ) . map ( |s| & * * s) {
344
332
Some ( "rust" ) => Ok ( rust_input ( input, externs, matches) ) ,
345
- Some ( "json" ) => json_input ( input) ,
346
333
Some ( s) => Err ( format ! ( "unknown input format: {}" , s) ) ,
347
334
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) )
353
336
}
354
337
}
355
338
}
@@ -461,76 +444,6 @@ fn rust_input(cratefile: &str, externs: core::Externs, matches: &getopts::Matche
461
444
462
445
// Run everything!
463
446
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 }
536
449
}
0 commit comments