compiler_wrapper: fix a bug where we won't log rusage on compilation
env.exec, outside of tests and "print command" configurations, never
returns if it executed successfully (since it turns into an actual call
to execve()). Since we want to write rusage logs after the compiler is
finished, we need to not exec in that case.
BUG=None
TEST=CQ
Change-Id: If19ffb5c590868bc03431301514de875d60f7af5
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/2648089
Reviewed-by: Ryan Beltran <ryanbeltran@chromium.org>
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
Tested-by: George Burgess <gbiv@chromium.org>
diff --git a/compiler_wrapper/compiler_wrapper.go b/compiler_wrapper/compiler_wrapper.go
index 0574f3c..f47b09c 100644
--- a/compiler_wrapper/compiler_wrapper.go
+++ b/compiler_wrapper/compiler_wrapper.go
@@ -174,10 +174,16 @@
}
}
- commitRusage, err := maybeCaptureRusage(env, rusageLogfileName, compilerCmd, func() error {
- // Note: We return an exit code only if the underlying env is not
- // really doing an exec, e.g. commandRecordingEnv.
- exitCode, err = wrapSubprocessErrorWithSourceLoc(compilerCmd, env.exec(compilerCmd))
+ commitRusage, err := maybeCaptureRusage(env, rusageLogfileName, compilerCmd, func(willLogRusage bool) error {
+ var err error
+ if willLogRusage {
+ err = env.run(compilerCmd, env.stdin(), env.stdout(), env.stderr())
+ } else {
+ // Note: We return from this in non-fatal circumstances only if the
+ // underlying env is not really doing an exec, e.g. commandRecordingEnv.
+ err = env.exec(compilerCmd)
+ }
+ exitCode, err = wrapSubprocessErrorWithSourceLoc(compilerCmd, err)
return err
})
if err != nil {