update_chroot/build_packages: log long running commands

Add a log line showing the exact command we ran so it's easier to
triage builders.  These normally output 100's of log lines, so one
more shouldn't be a problem.

BUG=chromium:1168210
TEST=CQ passes

Change-Id: I276052b19aac2b60e6f79894593093817c32e34b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosutils/+/2649358
Commit-Queue: Michael Mortensen <mmortensen@google.com>
Tested-by: Mike Frysinger <vapier@chromium.org>
Auto-Submit: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Michael Mortensen <mmortensen@google.com>
diff --git a/build_packages b/build_packages
index 4dfd889..1190ea9 100755
--- a/build_packages
+++ b/build_packages
@@ -276,7 +276,7 @@
 info "Rebuilding Portage cache"
 # Before running any emerge operations, regenerate the Portage dependency cache
 # in parallel.
-"${EMERGE_CMD[@]}" --regen --quiet
+info_run "${EMERGE_CMD[@]}" --regen --quiet
 
 # Verify that all packages can be emerged from scratch, without any
 # backtracking. Only print the output if this step fails.
@@ -460,7 +460,7 @@
     trap "'${goma_ctl}' stop" EXIT
   fi
 
-  sudo -E "${EMERGE_CMD[@]}" "${EMERGE_FLAGS[@]}" "${PACKAGES[@]}" \
+  info_run sudo -E "${EMERGE_CMD[@]}" "${EMERGE_FLAGS[@]}" "${PACKAGES[@]}" \
     --useoldpkg-atoms="${CRITICAL_SDK_PACKAGES[*]}" \
     --rebuild-exclude="${CRITICAL_SDK_PACKAGES[*]}"
 )
@@ -469,7 +469,7 @@
 
 if [[ ${FLAGS_withdebugsymbols} -eq ${FLAGS_TRUE} ]]; then
   info "fetching the debug symbols"
-  sudo -E "${CHROMITE_BIN}/cros_install_debug_syms" \
+  info_run sudo -E "${CHROMITE_BIN}/cros_install_debug_syms" \
     "--board=${FLAGS_board}" "--all"
 fi
 
diff --git a/build_sdk_board b/build_sdk_board
index 418e8a1..cb54c47 100755
--- a/build_sdk_board
+++ b/build_sdk_board
@@ -126,9 +126,7 @@
 PACKAGES=( system virtual/target-sdk world )
 
 run_emerge() {
-  local cmd=( ${EMERGE_CMD} "$@" )
-  info "Running: ${cmd[*]}"
-  sudo -E "${cmd[@]}"
+  info_run sudo -E ${EMERGE_CMD} "$@"
 }
 
 # First, rebuild all packages from scratch. This is needed to make sure
diff --git a/common.sh b/common.sh
index 27978b0..31f75d2 100644
--- a/common.sh
+++ b/common.sh
@@ -122,6 +122,12 @@
   _message "${V_BOLD_RED}ERROR   " "$*"
 }
 
+# Log the command we're about to run, then run it.
+# Useful for long running commands that often need debugging from builders.
+info_run() {
+  info "Running: $*"
+  "$@"
+}
 
 # For all die functions, they must explicitly force set +eu;
 # no reason to have them cause their own crash if we're in the middle
diff --git a/update_chroot b/update_chroot
index f9b5faf..39cb16e 100755
--- a/update_chroot
+++ b/update_chroot
@@ -81,7 +81,7 @@
     TOOLCHAIN_FLAGS+=( --nousepkg )
   fi
   # Expand the path before sudo, as root doesn't have the same path magic.
-  sudo -E $(type -p cros_setup_toolchains) "${TOOLCHAIN_FLAGS[@]}"
+  info_run sudo -E $(type -p cros_setup_toolchains) "${TOOLCHAIN_FLAGS[@]}"
 fi
 
 # Make sure depot_tools is bootstrapped, so that it can build chromeos-chrome.
@@ -96,7 +96,7 @@
 info "Rebuilding Portage cache"
 # Before running any emerge operations, regenerate the Portage dependency cache
 # in parallel.
-"${EMERGE_CMD[@]}" --regen --quiet
+info_run "${EMERGE_CMD[@]}" --regen --quiet
 
 info "Updating the SDK"
 
@@ -131,14 +131,15 @@
 
 # Second pass, update everything else.
 EMERGE_FLAGS+=( --deep )
-sudo -E ${EMERGE_CMD} "${EMERGE_FLAGS[@]}" virtual/target-sdk world
+info_run sudo -E ${EMERGE_CMD} "${EMERGE_FLAGS[@]}" virtual/target-sdk world
 
 # Install post cross packages if binary pkgs are available.
 if [ "${FLAGS_usepkg}" -eq "${FLAGS_TRUE}" ]; then
   # Install nobdeps packages only when binary pkgs are available, since we don't
   # want to accidentally pull in build deps for a rebuild.
   EMERGE_FLAGS=( -uNv --with-bdeps=n --oneshot --getbinpkg --deep --usepkgonly )
-  sudo -E "${EMERGE_CMD}" "${EMERGE_FLAGS[@]}" virtual/target-sdk-nobdeps
+  info_run sudo -E "${EMERGE_CMD}" "${EMERGE_FLAGS[@]}" \
+    virtual/target-sdk-nobdeps
 fi
 
 # Automatically discard all CONFIG_PROTECT'ed files. Those that are
@@ -151,8 +152,8 @@
 
 # Finally clean out any stale binpkgs we've accumulated.
 if [[ ${FLAGS_eclean} -eq ${FLAGS_TRUE} ]]; then
-  info "Running 'eclean -d packages' to clean up stale binpkgs"
-  sudo eclean -d packages
+  info "Cleaning stale binpkgs"
+  info_run sudo eclean -d packages
 fi
 
 command_completed