build_packages: install debug symbols by default

Install debug symbols at the end of build_packages if they are available. This
is turned on by default. It will be off by default once the mechanism is rolled
out to every board and is stable.

This is a copy of https://chromium-review.googlesource.com/#/c/233301/

BUG=chromium:426494
TEST=trybot run on gizmo, link, daisy, lumpy-incremental.

CQ-DEPEND=CL:234857

Change-Id: I913238d8743b2a0fef97f4a265a1e4d7d237c3bf
Reviewed-on: https://chromium-review.googlesource.com/234829
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Commit-Queue: Bertrand Simonnet <bsimonnet@chromium.org>
Tested-by: Bertrand Simonnet <bsimonnet@chromium.org>
diff --git a/build_packages b/build_packages
index 8363153..780f0c0 100755
--- a/build_packages
+++ b/build_packages
@@ -28,6 +28,8 @@
   "Don't build anything, instead only fetch what is needed."
 DEFINE_boolean unpackonly "${FLAGS_FALSE}" \
   "Don't build anything; instead only fetch and unpack what is needed."
+DEFINE_boolean withdebugsymbols "${FLAGS_TRUE}" \
+  "Install the debug symbols for all packages"
 
 # The --board_root flag specifies the environment variables ROOT and PKGDIR.
 # This allows fetching and emerging of all packages to specified board_root.
@@ -269,6 +271,13 @@
 trap - EXIT
 
 echo "Builds complete"
+
+if [[ ${FLAGS_withdebugsymbols} -eq ${FLAGS_TRUE} ]]; then
+  info "fetching the debug symbols"
+  sudo -E "${GCLIENT_ROOT}/chromite/bin/cros_install_debug_syms" \
+    "--board=${FLAGS_board}" "--all"
+fi
+
 EXTRA_COMMAND_STATS[package_count]=${package_count}
 command_completed
 echo "Done"