@@ -28,8 +28,6 @@ use std::{env, fs, io, str};
2828use build_helper:: ci:: gha;
2929use build_helper:: exit;
3030use termcolor:: { ColorChoice , StandardStream , WriteColor } ;
31- #[ cfg( feature = "tracing" ) ]
32- use tracing:: { debug, instrument, span, trace} ;
3331use utils:: build_stamp:: BuildStamp ;
3432use utils:: channel:: GitInfo ;
3533
@@ -46,6 +44,8 @@ pub use core::builder::PathSet;
4644pub use core:: config:: Config ;
4745pub use core:: config:: flags:: { Flags , Subcommand } ;
4846
47+ #[ cfg( feature = "tracing" ) ]
48+ use tracing:: { instrument, span} ;
4949pub use utils:: change_tracker:: {
5050 CONFIG_CHANGE_HISTORY , find_recent_config_change_ids, human_readable_changes,
5151} ;
@@ -541,72 +541,71 @@ impl Build {
541541 /// Executes the entire build, as configured by the flags and configuration.
542542 #[ cfg_attr( feature = "tracing" , instrument( level = "debug" , name = "Build::build" , skip_all) ) ]
543543 pub fn build ( & mut self ) {
544- #[ cfg( feature = "tracing" ) ]
545544 trace ! ( "setting up job management" ) ;
546545 unsafe {
547546 crate :: utils:: job:: setup ( self ) ;
548547 }
549548
550- #[ cfg( feature = "tracing" ) ]
551- trace ! ( "downloading rustfmt early" ) ;
552-
553549 // Download rustfmt early so that it can be used in rust-analyzer configs.
550+ trace ! ( "downloading rustfmt early" ) ;
554551 let _ = & builder:: Builder :: new ( self ) . initial_rustfmt ( ) ;
555552
556- #[ cfg( feature = "tracing" ) ]
557- let hardcoded_span =
558- span ! ( tracing:: Level :: DEBUG , "handling hardcoded subcommands (Format, Suggest, Perf)" )
559- . entered ( ) ;
560-
561- // hardcoded subcommands
562- match & self . config . cmd {
563- Subcommand :: Format { check, all } => {
564- return core:: build_steps:: format:: format (
565- & builder:: Builder :: new ( self ) ,
566- * check,
567- * all,
568- & self . config . paths ,
569- ) ;
570- }
571- Subcommand :: Suggest { run } => {
572- return core:: build_steps:: suggest:: suggest ( & builder:: Builder :: new ( self ) , * run) ;
573- }
574- Subcommand :: Perf { .. } => {
575- return core:: build_steps:: perf:: perf ( & builder:: Builder :: new ( self ) ) ;
576- }
577- _cmd => {
578- #[ cfg( feature = "tracing" ) ]
579- debug ! ( cmd = ?_cmd, "not a hardcoded subcommand; returning to normal handling" ) ;
553+ // Handle hard-coded subcommands.
554+ {
555+ #[ cfg( feature = "tracing" ) ]
556+ let _hardcoded_span = span ! (
557+ tracing:: Level :: DEBUG ,
558+ "handling hardcoded subcommands (Format, Suggest, Perf)"
559+ )
560+ . entered ( ) ;
561+
562+ match & self . config . cmd {
563+ Subcommand :: Format { check, all } => {
564+ return core:: build_steps:: format:: format (
565+ & builder:: Builder :: new ( self ) ,
566+ * check,
567+ * all,
568+ & self . config . paths ,
569+ ) ;
570+ }
571+ Subcommand :: Suggest { run } => {
572+ return core:: build_steps:: suggest:: suggest ( & builder:: Builder :: new ( self ) , * run) ;
573+ }
574+ Subcommand :: Perf { .. } => {
575+ return core:: build_steps:: perf:: perf ( & builder:: Builder :: new ( self ) ) ;
576+ }
577+ _cmd => {
578+ debug ! ( cmd = ?_cmd, "not a hardcoded subcommand; returning to normal handling" ) ;
579+ }
580580 }
581- }
582581
583- #[ cfg( feature = "tracing" ) ]
584- drop ( hardcoded_span) ;
585- #[ cfg( feature = "tracing" ) ]
586- debug ! ( "handling subcommand normally" ) ;
582+ debug ! ( "handling subcommand normally" ) ;
583+ }
587584
588585 if !self . config . dry_run ( ) {
589586 #[ cfg( feature = "tracing" ) ]
590587 let _real_run_span = span ! ( tracing:: Level :: DEBUG , "executing real run" ) . entered ( ) ;
591588
589+ // We first do a dry-run. This is a sanity-check to ensure that
590+ // steps don't do anything expensive in the dry-run.
592591 {
593592 #[ cfg( feature = "tracing" ) ]
594593 let _sanity_check_span =
595594 span ! ( tracing:: Level :: DEBUG , "(1) executing dry-run sanity-check" ) . entered ( ) ;
596-
597- // We first do a dry-run. This is a sanity-check to ensure that
598- // steps don't do anything expensive in the dry-run.
599595 self . config . dry_run = DryRun :: SelfCheck ;
600596 let builder = builder:: Builder :: new ( self ) ;
601597 builder. execute_cli ( ) ;
602598 }
603599
604- #[ cfg( feature = "tracing" ) ]
605- let _actual_run_span =
606- span ! ( tracing:: Level :: DEBUG , "(2) executing actual run" ) . entered ( ) ;
607- self . config . dry_run = DryRun :: Disabled ;
608- let builder = builder:: Builder :: new ( self ) ;
609- builder. execute_cli ( ) ;
600+ // Actual run.
601+ {
602+ #[ cfg( feature = "tracing" ) ]
603+ let _actual_run_span =
604+ span ! ( tracing:: Level :: DEBUG , "(2) executing actual run" ) . entered ( ) ;
605+ self . config . dry_run = DryRun :: Disabled ;
606+ let builder = builder:: Builder :: new ( self ) ;
607+ builder. execute_cli ( ) ;
608+ }
610609 } else {
611610 #[ cfg( feature = "tracing" ) ]
612611 let _dry_run_span = span ! ( tracing:: Level :: DEBUG , "executing dry run" ) . entered ( ) ;
0 commit comments