dev-install: filter out root bdepends

With the increase of BDEPENDS in ebuilds, the emerge output here has
changed to include both deps for the board & the SDK.  We need to
filter out the SDK deps as there are some that only show up there
and will never work for boards.

BUG=chromium:1072761, chromium:1108379, chromium:1170187
TEST=devinstall_test.py passes

Change-Id: I1ec3e120191a1a72de9fadfaee11e3fb22a66830
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosutils/+/2648863
Tested-by: Mike Frysinger <vapier@chromium.org>
Auto-Submit: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Ricky Liang <jcliang@chromium.org>
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
diff --git a/build_library/base_image_util.sh b/build_library/base_image_util.sh
index 4b3a9de..638be6b 100755
--- a/build_library/base_image_util.sh
+++ b/build_library/base_image_util.sh
@@ -104,9 +104,13 @@
       if [[ "${pkg}" == "virtual/target-os" ]]; then
         usepkg="--usepkgonly"
       fi
+      # Need to filter out BDEPENDS installed into the /.  We rely on the output
+      # from portage to look like:
+      #   R    sys-libs/zlib 1.2.11
+      #   R    virtual/rust 1.47.0-r6 to /build/betty/
       emerge-${BOARD} --color n --pretend --quiet --emptytree --cols \
         --root-deps=rdeps --with-bdeps=n ${usepkg} ${pkg} | \
-        awk '$2 ~ /\// {print $2 "-" $3}' | \
+        awk '($2 ~ /\// && $4 == "to") {print $2 "-" $3}' | \
         sort > "${pkgs_out}/${pkg##*/}.packages"
       pipestatus=${PIPESTATUS[*]}
       [[ ${pipestatus// } -eq 0 ]]