Make use of cros_setup_toolchains, take 2

Resubmit of If62b4f3973f02fd8e1deed35864c824a02ab0c22
This will be safe to land after
I2c4e21ec7e8c0c0cf58947e2b0a3a9edf7617a09
The breakage was a timing issue paired with people not always syncing
the complete tree. No changes to the CL are needed.

It is now used for:
- make_chroot (cros_sdk --bootstrap)
- update_chroot

setup_board is stripped of redundant code which was deprecated by this.

Also stripped is some usepkg logic in make_chroot, as that is now
exclusively source-only.

BUG=chromium-os:23032
TEST=trybot chromiumos-sdk

Change-Id: Ib888cf2886218622d9cfeebb17b9cd4462d06c89
Reviewed-on: https://gerrit.chromium.org/gerrit/22578
Tested-by: Zdenek Behan <zbehan@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: asharif <asharif@chromium.org>
Commit-Ready: Zdenek Behan <zbehan@chromium.org>
diff --git a/sdk_lib/make_chroot.sh b/sdk_lib/make_chroot.sh
index d99eca9..c0512bc 100755
--- a/sdk_lib/make_chroot.sh
+++ b/sdk_lib/make_chroot.sh
@@ -396,19 +396,15 @@
 info "Updating portage"
 early_enter_chroot emerge -uNv --quiet portage
 
-info "Updating toolchain"
-early_enter_chroot emerge -uNv --quiet $USEPKG '>=sys-devel/gcc-4.4' \
-  sys-libs/glibc sys-devel/binutils sys-kernel/linux-headers
-
-# HACK: Select the latest toolchain. We're assuming that when this is
-# ran, the chroot has no experimental versions of new toolchains, just
-# one that is very old, and one that was just emerged.
-GCC_ATOM="$(early_enter_chroot portageq best_version / sys-devel/gcc)"
-early_enter_chroot emerge --unmerge "<${GCC_ATOM}"
-CHOST="$(early_enter_chroot portageq envvar CHOST)"
-LATEST="$(early_enter_chroot gcc-config -l | grep "${CHOST}" | tail -n1 | \
-          cut -f3 -d' ')"
-early_enter_chroot gcc-config "${LATEST}"
+info "Updating host toolchain"
+early_enter_chroot emerge -uNv --quiet crossdev
+TOOLCHAIN_ARGS=( --deleteold )
+if [[ ${FLAGS_usepkg} -eq ${FLAGS_FALSE} ]]; then
+  TOOLCHAIN_ARGS+=( --nousepkg )
+fi
+# Note: early_enter_chroot executes as root.
+early_enter_chroot "${CHROOT_TRUNK}/chromite/bin/cros_setup_toolchains" \
+    --hostonly "${TOOLCHAIN_ARGS[@]}"
 
 # dhcpcd is included in 'world' by the stage3 that we pull in for some reason.
 # We have no need to install it in our host environment, so pull it out here.
@@ -427,8 +423,10 @@
 fi
 
 # Update chroot.
-UPDATE_ARGS=()
-if [[ $FLAGS_usepkg -eq $FLAGS_TRUE ]]; then
+# Skip toolchain update because it already happened above, and the chroot is
+# not ready to emerge all cross toolchains.
+UPDATE_ARGS=( --skip_toolchain_update )
+if [[ ${FLAGS_usepkg} -eq ${FLAGS_TRUE} ]]; then
   UPDATE_ARGS+=( --usepkg )
 else
   UPDATE_ARGS+=( --nousepkg )
@@ -448,6 +446,11 @@
   CHROOT_EXAMPLE_OPT="--chroot=$FLAGS_chroot"
 fi
 
+# As a final pass, build all desired cross-toolchains.
+info "Updating toolchains"
+enter_chroot sudo "${CHROOT_TRUNK}/chromite/bin/cros_setup_toolchains" \
+    "${TOOLCHAIN_ARGS[@]}"
+
 print_time_elapsed
 
 cat <<EOF