make_chroot: Pass $USEPKG and $USEPKGONLY when building glibc/binutils.

Toolchain packages like glibc, binutils etc. should only be built
from source when "--nousepkg" is passed. Linux-headers is also
in this list as it matches the exisiting behavior of crossdev's
cross-* packages.

Define a new USEPKGONLY variable and use it to force toolchain
packages from being built from source.
This fixes the reported issue of glibc being built from source when
entering a newly created chroot.

BUG=chromium:976914
TEST=glibc not built when entering a new chroot.

Change-Id: I0cf0456ffafd117dbb571999352acf46b4406ca6
Reviewed-on: https://chromium-review.googlesource.com/1668010
Tested-by: Manoj Gupta <manojgupta@chromium.org>
Commit-Ready: Manoj Gupta <manojgupta@chromium.org>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/sdk_lib/make_chroot.sh b/sdk_lib/make_chroot.sh
index 09bca08..d9d011c 100755
--- a/sdk_lib/make_chroot.sh
+++ b/sdk_lib/make_chroot.sh
@@ -74,11 +74,14 @@
 DEFGROUPS="${PRIMARY_GROUP},adm,cdrom,floppy,audio,video,portage"
 
 USEPKG=""
+USEPKGONLY=""
 if [[ $FLAGS_usepkg -eq $FLAGS_TRUE ]]; then
   # Use binary packages. Include all build-time dependencies,
   # so as to avoid unnecessary differences between source
   # and binary builds.
   USEPKG="--getbinpkg --usepkg --with-bdeps y"
+  # Use --usepkgonly to avoid building toolchain packages from source.
+  USEPKGONLY="--usepkgonly"
 fi
 
 EMERGE_CMD="${CHROOT_TRUNK_DIR}/chromite/bin/parallel_emerge"
@@ -638,11 +641,11 @@
 fi
 # First the low level compiler tools.  These should be fairly independent of
 # the C library, so we can do it first.
-early_enter_chroot ${EMERGE_CMD} -uNv ${EMERGE_JOBS} \
+early_enter_chroot ${EMERGE_CMD} -uNv ${USEPKG} ${USEPKGONLY} ${EMERGE_JOBS} \
   sys-devel/binutils
 # Next the C library.  The compilers often use newer features, but the C library
 # is often designed to work with older compilers.
-early_enter_chroot ${EMERGE_CMD} -uNv ${EMERGE_JOBS} \
+early_enter_chroot ${EMERGE_CMD} -uNv ${USEPKG} ${USEPKGONLY} ${EMERGE_JOBS} \
   sys-kernel/linux-headers sys-libs/glibc
 # Now we can let the rest of the compiler packages build in parallel as they
 # don't generally rely on each other.