@@ -199,6 +199,8 @@ def read_git_state():
199199def run_wrapped (make_target , config ):
200200 """
201201 Runs specified make shell target and collects performance data.
202+
203+ Return exit code of process (negative for signals).
202204 """
203205 # Do as much as possible inside try blocks
204206 do_collect = True
@@ -219,16 +221,16 @@ def run_wrapped(make_target, config):
219221 file = sys .stderr )
220222
221223 completed_process = run_target (make_target )
224+ subprocess_exit_code = completed_process .returncode
222225
223226 # Do as much as possible inside try blocks
224227 try :
225228 # Skip metrics reporting if setup failed
226229 if not do_collect :
227- return
230+ return subprocess_exit_code
228231
229232 signal (SIGINT , SIG_DFL ) # stop trapping SIGINT (if haven't already)
230233 end_time = datetime .now (timezone .utc )
231- exit_code = completed_process .returncode
232234 time_diff_millis = (end_time - start_time ).microseconds // 1000
233235 # Must be compatible with our Segment schema, and must not be
234236 # expanded to include additional attributes without an
@@ -244,7 +246,7 @@ def run_wrapped(make_target, config):
244246 # https://docs.python.org/3.8/library/subprocess.html#subprocess.CompletedProcess
245247 #
246248 # If a make subprocess exits non-zero, make exits with code 2.
247- 'exit_status' : exit_code ,
249+ 'exit_status' : subprocess_exit_code ,
248250 ** read_git_state ()
249251 }
250252 send_metrics_to_segment ('devstack.command.run' , event_properties , config )
@@ -258,16 +260,24 @@ def run_wrapped(make_target, config):
258260 "(This should not have affected the outcome of your make command.)" ,
259261 file = sys .stderr )
260262
263+ return subprocess_exit_code
264+
261265
262266def run_target (make_target ):
263- """Just run make on the given target."""
267+ """
268+ Just run make on the given target.
269+
270+ Return exit code of process (negative for signals).
271+ """
264272 return subprocess .run (["make" , "impl-%s" % make_target ], check = False )
265273
266274
267275def do_wrap (make_target ):
268276 """
269277 Run the given make target, and collect and report data if and only if
270278 the user has consented to data collection.
279+
280+ Return exit code to exit with (signals become 128 + signal value).
271281 """
272282 try :
273283 consent_state = check_consent ()
@@ -277,9 +287,9 @@ def do_wrap(make_target):
277287 consent_state = {}
278288
279289 if consent_state .get ('ok_to_collect' ):
280- run_wrapped (make_target , consent_state .get ('config' ))
290+ subprocess_exit_code = run_wrapped (make_target , consent_state .get ('config' ))
281291 else :
282- run_target (make_target )
292+ subprocess_exit_code = run_target (make_target ). returncode
283293 if consent_state .get ('print_invitation' ):
284294 print (
285295 "Would you like to assist devstack development by sending "
@@ -288,6 +298,12 @@ def do_wrap(make_target):
288298 file = sys .stderr
289299 )
290300
301+ if subprocess_exit_code < 0 :
302+ # Translate to shell convention.
303+ return 128 + - subprocess_exit_code
304+ else :
305+ return subprocess_exit_code
306+
291307
292308def do_opt_in ():
293309 """
@@ -435,7 +451,8 @@ def main(args):
435451 if len (action_args ) != 1 :
436452 print ("send-metrics wrap takes one argument" , file = sys .stderr )
437453 sys .exit (1 )
438- do_wrap (action_args [0 ])
454+ conveyed_exit_code = do_wrap (action_args [0 ])
455+ sys .exit (conveyed_exit_code )
439456 elif action == 'opt-in' :
440457 if len (action_args ) != 0 :
441458 print ("send-metrics opt-in takes zero arguments" , file = sys .stderr )
0 commit comments