@@ -63,7 +63,9 @@ use std::env;
63
63
use std:: process;
64
64
65
65
use rustc_data_structures:: sync:: Lrc ;
66
+ use rustc_driver:: abort_on_err;
66
67
use rustc_errors:: ErrorReported ;
68
+ use rustc_interface:: interface;
67
69
use rustc_session:: config:: { make_crate_type_option, ErrorOutputType , RustcOptGroup } ;
68
70
use rustc_session:: getopts;
69
71
use rustc_session:: Session ;
@@ -520,34 +522,85 @@ fn main_options(options: config::Options) -> MainResult {
520
522
// then generated from the cleaned AST of the crate. This runs all the
521
523
// plug/cleaning passes.
522
524
let crate_version = options. crate_version . clone ( ) ;
525
+
526
+ let default_passes = options. default_passes ;
523
527
let output_format = options. output_format ;
524
- let ( mut krate, renderinfo, renderopts, sess) = core:: run_core ( options) ;
528
+ // TODO: fix this clone (especially render_options)
529
+ let externs = options. externs . clone ( ) ;
530
+ let manual_passes = options. manual_passes . clone ( ) ;
531
+ let render_options = options. render_options . clone ( ) ;
532
+ let config = core:: create_config ( options) ;
525
533
526
- info ! ( "finished with rustc" ) ;
534
+ interface:: create_compiler_and_run ( config, |compiler| {
535
+ compiler. enter ( |queries| {
536
+ let sess = compiler. session ( ) ;
527
537
528
- krate. version = crate_version;
538
+ // We need to hold on to the complete resolver, so we cause everything to be
539
+ // cloned for the analysis passes to use. Suboptimal, but necessary in the
540
+ // current architecture.
541
+ let resolver = core:: create_resolver ( externs, queries, & sess) ;
529
542
530
- if show_coverage {
531
- // if we ran coverage, bail early, we don't need to also generate docs at this point
532
- // (also we didn't load in any of the useful passes)
533
- return Ok ( ( ) ) ;
534
- } else if run_check {
535
- // Since we're in "check" mode, no need to generate anything beyond this point.
536
- return Ok ( ( ) ) ;
537
- }
543
+ if sess. has_errors ( ) {
544
+ sess. fatal ( "Compilation failed, aborting rustdoc" ) ;
545
+ }
538
546
539
- info ! ( "going to format" ) ;
540
- let ( error_format, edition, debugging_options) = diag_opts;
541
- let diag = core:: new_handler ( error_format, None , & debugging_options) ;
542
- let sess_time = sess. clone ( ) ;
543
- match output_format {
544
- None | Some ( config:: OutputFormat :: Html ) => sess_time. time ( "render_html" , || {
545
- run_renderer :: < html:: render:: Context > (
546
- krate, renderopts, renderinfo, & diag, edition, sess,
547
- )
548
- } ) ,
549
- Some ( config:: OutputFormat :: Json ) => sess_time. time ( "render_json" , || {
550
- run_renderer :: < json:: JsonRenderer > ( krate, renderopts, renderinfo, & diag, edition, sess)
551
- } ) ,
552
- }
547
+ let mut global_ctxt = abort_on_err ( queries. global_ctxt ( ) , sess) . take ( ) ;
548
+
549
+ global_ctxt. enter ( |tcx| {
550
+ let ( mut krate, render_info, render_opts) = sess. time ( "run_global_ctxt" , || {
551
+ core:: run_global_ctxt (
552
+ tcx,
553
+ resolver,
554
+ default_passes,
555
+ manual_passes,
556
+ render_options,
557
+ output_format,
558
+ )
559
+ } ) ;
560
+ info ! ( "finished with rustc" ) ;
561
+
562
+ if let Some ( name) = crate_name {
563
+ krate. name = name
564
+ }
565
+
566
+ krate. version = crate_version;
567
+
568
+ if show_coverage {
569
+ // if we ran coverage, bail early, we don't need to also generate docs at this point
570
+ // (also we didn't load in any of the useful passes)
571
+ return Ok ( ( ) ) ;
572
+ } else if run_check {
573
+ // Since we're in "check" mode, no need to generate anything beyond this point.
574
+ return Ok ( ( ) ) ;
575
+ }
576
+
577
+ info ! ( "going to format" ) ;
578
+ let ( error_format, edition, debugging_options) = diag_opts;
579
+ let diag = core:: new_handler ( error_format, None , & debugging_options) ;
580
+ let sess_format = sess. clone ( ) ;
581
+ match output_format {
582
+ None | Some ( config:: OutputFormat :: Html ) => sess. time ( "render_html" , || {
583
+ run_renderer :: < html:: render:: Context > (
584
+ krate,
585
+ render_opts,
586
+ render_info,
587
+ & diag,
588
+ edition,
589
+ sess_format,
590
+ )
591
+ } ) ,
592
+ Some ( config:: OutputFormat :: Json ) => sess. time ( "render_json" , || {
593
+ run_renderer :: < json:: JsonRenderer > (
594
+ krate,
595
+ render_opts,
596
+ render_info,
597
+ & diag,
598
+ edition,
599
+ sess_format,
600
+ )
601
+ } ) ,
602
+ }
603
+ } )
604
+ } )
605
+ } )
553
606
}
0 commit comments