File tree Expand file tree Collapse file tree 3 files changed +27
-12
lines changed
tools/build_helper/src/drop_bomb Expand file tree Collapse file tree 3 files changed +27
-12
lines changed Original file line number Diff line number Diff line change @@ -937,13 +937,19 @@ impl Build {
937
937
938
938
/// Execute a command and return its output.
939
939
/// This method should be used for all command executions in bootstrap.
940
+ #[ track_caller]
940
941
fn run ( & self , command : & mut BootstrapCommand ) -> CommandOutput {
941
942
command. mark_as_executed ( ) ;
942
943
if self . config . dry_run ( ) && !command. run_always {
943
944
return CommandOutput :: default ( ) ;
944
945
}
945
946
946
- self . verbose ( || println ! ( "running: {command:?}" ) ) ;
947
+ let created_at = command. get_created_location ( ) ;
948
+ let executed_at = std:: panic:: Location :: caller ( ) ;
949
+
950
+ self . verbose ( || {
951
+ println ! ( "running: {command:?} (created at {created_at}, executed at {executed_at})" )
952
+ } ) ;
947
953
948
954
let stdout = command. stdout . stdio ( ) ;
949
955
command. as_command_mut ( ) . stdout ( stdout) ;
@@ -962,8 +968,11 @@ impl Build {
962
968
Ok ( output) => {
963
969
writeln ! (
964
970
message,
965
- "\n \n Command {command:?} did not execute successfully.\
966
- \n Expected success, got: {}",
971
+ r#"
972
+ Command {command:?} did not execute successfully.
973
+ Expected success, got {}
974
+ Created at: {created_at}
975
+ Executed at: {executed_at}"# ,
967
976
output. status,
968
977
)
969
978
. unwrap ( ) ;
Original file line number Diff line number Diff line change @@ -160,24 +160,31 @@ impl BootstrapCommand {
160
160
& mut self . command
161
161
}
162
162
163
- /// Mark the command as being executd , disarming the drop bomb.
163
+ /// Mark the command as being executed , disarming the drop bomb.
164
164
/// If this method is not called before the command is dropped, its drop will panic.
165
165
pub fn mark_as_executed ( & mut self ) {
166
166
self . drop_bomb . defuse ( ) ;
167
167
}
168
+
169
+ /// Returns the source code location where this command was created.
170
+ pub fn get_created_location ( & self ) -> std:: panic:: Location < ' static > {
171
+ self . drop_bomb . get_created_location ( )
172
+ }
168
173
}
169
174
170
175
impl From < Command > for BootstrapCommand {
171
176
#[ track_caller]
172
177
fn from ( command : Command ) -> Self {
173
178
let program = command. get_program ( ) . to_owned ( ) ;
179
+ let created_at = std:: panic:: Location :: caller ( ) ;
180
+
174
181
Self {
175
182
command,
176
183
failure_behavior : BehaviorOnFailure :: Exit ,
177
184
stdout : OutputMode :: Print ,
178
185
stderr : OutputMode :: Print ,
179
186
run_always : false ,
180
- drop_bomb : DropBomb :: arm ( program) ,
187
+ drop_bomb : DropBomb :: arm ( program, * created_at ) ,
181
188
}
182
189
}
183
190
}
Original file line number Diff line number Diff line change @@ -22,13 +22,12 @@ impl DropBomb {
22
22
/// Arm a [`DropBomb`]. If the value is dropped without being [`defused`][Self::defused], then
23
23
/// it will panic. It is expected that the command wrapper uses `#[track_caller]` to help
24
24
/// propagate the caller location.
25
- #[ track_caller]
26
- pub fn arm < S : AsRef < OsStr > > ( command : S ) -> DropBomb {
27
- DropBomb {
28
- command : command. as_ref ( ) . into ( ) ,
29
- defused : false ,
30
- armed_location : * panic:: Location :: caller ( ) ,
31
- }
25
+ pub fn arm < S : AsRef < OsStr > > ( command : S , armed_location : panic:: Location < ' static > ) -> DropBomb {
26
+ DropBomb { command : command. as_ref ( ) . into ( ) , defused : false , armed_location }
27
+ }
28
+
29
+ pub fn get_created_location ( & self ) -> panic:: Location < ' static > {
30
+ self . armed_location
32
31
}
33
32
34
33
/// Defuse the [`DropBomb`]. This will prevent the drop bomb from panicking when dropped.
You can’t perform that action at this time.
0 commit comments