setup_board: Use virtual/target-sdk-nobdeps on host

virtual/target-sdk-nobdeps pulls in ebuilds that should be installed
without their build-deps.  This gets built as normal during the first
pass of rebuilding the chroot, then gets pulled into the new board root
with --with-bdeps=n to ensure that build-time dependencies are not
present in the final chroot image.  The initial use case is to make
shellcheck available in the chroot without bringing in all the Haskell
compiler dependencies.

BUG=chromium:844166
TEST=chromiumos-sdk-tryjob
CQ-DEPEND=CL:1070324

Change-Id: I536d7da844ecd29a09e4b3a7fb8e922328bcb465
Reviewed-on: https://chromium-review.googlesource.com/1260045
Commit-Ready: Benjamin Gordon <bmgordon@chromium.org>
Tested-by: Benjamin Gordon <bmgordon@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Alex Klein <saklein@chromium.org>
diff --git a/setup_board b/setup_board
index 9c97ce0..7447b02 100755
--- a/setup_board
+++ b/setup_board
@@ -227,13 +227,20 @@
   # First, rebuild all packages from scratch. This is needed to make sure
   # we rebuild all chroot packages.
   sudo -E $EMERGE_CMD --emptytree --with-bdeps=y \
-    "${TOOLCHAIN_PACKAGES[@]}" "${PACKAGES[@]}"
+    "${TOOLCHAIN_PACKAGES[@]}" "${PACKAGES[@]}" \
+    virtual/target-sdk-nobdeps
   sudo eclean -d packages
 
   # Next, install our rebuilt packages into our separate root.
   HOST_FLAGS="--root=$BOARD_ROOT --update --verbose --deep --root-deps"
-  HOST_FLAGS+=" --with-bdeps=y --newuse --jobs=$NUM_JOBS --usepkgonly"
-  sudo -E $EMERGE_CMD $HOST_FLAGS --select=y "${PACKAGES[@]}"
+  HOST_FLAGS+=" --newuse --jobs=$NUM_JOBS --usepkgonly"
+  sudo -E $EMERGE_CMD $HOST_FLAGS --with-bdeps=y --select=y "${PACKAGES[@]}"
+  # Install our rebuilt packages from the nobdeps target into our separate root
+  # without their build-time deps.  We also avoid adding this target to the
+  # world set so that subsequent update_chroot commands won't re-import the
+  # build deps.
+  sudo -E $EMERGE_CMD $HOST_FLAGS --with-bdeps=n --oneshot \
+    virtual/target-sdk-nobdeps
   sudo cp -a "${PKGDIR}" $BOARD_ROOT/packages
 
   # Copy our chroot version into the newly packaged chroot.