Add flag in setup_board and build_packages for only using the Chrome binhost.

This is needed so that the commit queue can compile everything from
source except for Chrome itself.

BUG=chromium:257167
TEST=setup_board --help
TEST=setup_board --board=link --force --chrome_binhost_only
TEST=setup_board --board=link --force

Change-Id: I9ab7cd2e81a52c4579cb7a41cb47370c85619338
Reviewed-on: https://gerrit.chromium.org/gerrit/60944
Reviewed-by: Matt Tennant <mtennant@chromium.org>
Commit-Queue: David James <davidjames@chromium.org>
Tested-by: David James <davidjames@chromium.org>
diff --git a/build_packages b/build_packages
index 3261981..d8aa7f1 100755
--- a/build_packages
+++ b/build_packages
@@ -62,6 +62,8 @@
   "Build factory installer."
 DEFINE_boolean withtest "${FLAGS_TRUE}" \
   "Build packages required for testing."
+DEFINE_boolean chrome_binhost_only $FLAGS_FALSE \
+  "Only fetch packages from the Chrome binhost."
 
 # The --reuse_pkgs_from_local_boards flag tells Portage to share binary
 # packages between boards that are built locally, so that the total time
@@ -106,6 +108,9 @@
 if [[ "${FLAGS_jobs}" -ne -1 ]]; then
   UPDATE_ARGS+=( --jobs=${FLAGS_jobs} )
 fi
+if [ "${FLAGS_chrome_binhost_only}" -eq "${FLAGS_TRUE}" ]; then
+  UPDATE_ARGS+=( --chrome_binhost_only )
+fi
 if [ "${FLAGS_reuse_pkgs_from_local_boards}" -eq "${FLAGS_TRUE}" ]; then
   UPDATE_ARGS+=( --reuse_pkgs_from_local_boards )
 fi
diff --git a/setup_board b/setup_board
index 1f0c258..efd85f9 100755
--- a/setup_board
+++ b/setup_board
@@ -59,6 +59,8 @@
   "Board variant."
 DEFINE_boolean regen_configs ${FLAGS_FALSE} \
   "Regenerate all config files (useful for modifying profiles w/out rebuild)."
+DEFINE_boolean chrome_binhost_only $FLAGS_FALSE \
+  "Only fetch packages from the Chrome binhost."
 
 # The --reuse_pkgs_from_local_boards flag tells Portage to share binary
 # packages between boards that are built locally, so that the total time
@@ -183,13 +185,12 @@
   fi
 }
 
-print_binhost_config() {
-  if [ "$1" == "--local" ]; then
+# Print the PORTAGE_BINHOST variable, suitable for inclusion in make.conf.board.
+print_board_binhost_config() {
+  if [ "${FLAGS_reuse_pkgs_from_local_boards}" -eq "${FLAGS_TRUE}" ]; then
     cros_generate_local_binhosts --board "${BOARD_VARIANT}"
     echo 'PORTAGE_BINHOST="$LOCAL_BINHOST"'
     return 0
-  elif [ $# -ne 0 ]; then
-    die "Invalid arguments for print_binhost_config: $@"
   fi
 
   local binhost_dir="$CHROMIUMOS_OVERLAY/chromeos/binhost/target"
@@ -231,7 +232,11 @@
     fi
   done
 
-  cat <<'EOF'
+  if [ "${FLAGS_chrome_binhost_only}" -eq "${FLAGS_TRUE}" ]; then
+    echo source "$chrome_binhost"
+    echo 'PORTAGE_BINHOST="$LATEST_RELEASE_CHROME_BINHOST"'
+  else
+    cat <<'EOF'
 # FULL_BINHOST is populated by the full builders. It is listed first because it
 # is the lowest priority binhost. It is better to download packages from the
 # preflight binhost because they are fresher packages.
@@ -239,41 +244,34 @@
 
 EOF
 
-  if [[ -f "$preflight_binhost" && -z "$IGNORE_PREFLIGHT_BINHOST" ]]; then
-    cat <<'EOF'
+    if [[ -f "$preflight_binhost" && -z "$IGNORE_PREFLIGHT_BINHOST" ]]; then
+      cat <<'EOF'
 # PREFLIGHT_BINHOST is populated by the preflight builders. If the same
 # package is provided by both the preflight and full binhosts, the package is
 # downloaded from the preflight binhost.
 EOF
-    echo source "$preflight_binhost"
-    echo 'PORTAGE_BINHOST="$PORTAGE_BINHOST $PREFLIGHT_BINHOST"'
-    echo
-  fi
+      echo source "$preflight_binhost"
+      echo 'PORTAGE_BINHOST="$PORTAGE_BINHOST $PREFLIGHT_BINHOST"'
+      echo
+    fi
 
-  if [[ -f "$internal_binhost"  && -z "$IGNORE_PREFLIGHT_BINHOST" ]]; then
-    cat <<'EOF'
+    if [[ -f "$internal_binhost"  && -z "$IGNORE_PREFLIGHT_BINHOST" ]]; then
+      cat <<'EOF'
 # The internal PREFLIGHT_BINHOST is populated by the internal preflight
 # builders. It takes priority over the public preflight binhost.
 EOF
-    echo source "$internal_binhost"
-    echo 'PORTAGE_BINHOST="$PORTAGE_BINHOST $PREFLIGHT_BINHOST"'
-    echo
-  fi
+      echo source "$internal_binhost"
+      echo 'PORTAGE_BINHOST="$PORTAGE_BINHOST $PREFLIGHT_BINHOST"'
+      echo
+    fi
 
-  if [[ -f "$chrome_binhost" ]]; then
-    cat <<'EOF'
+    if [[ -f "$chrome_binhost" ]]; then
+      cat <<'EOF'
 # LATEST_RELEASE_CHROME_BINHOST provides prebuilts for chromeos-chrome only.
 EOF
-    echo source "$chrome_binhost"
-    echo 'PORTAGE_BINHOST="$PORTAGE_BINHOST $LATEST_RELEASE_CHROME_BINHOST"'
-  fi
-}
-
-print_board_binhost_config() {
-  if [ "${FLAGS_reuse_pkgs_from_local_boards}" -eq "${FLAGS_TRUE}" ]; then
-    print_binhost_config --local
-  else
-    print_binhost_config
+      echo source "$chrome_binhost"
+      echo 'PORTAGE_BINHOST="$PORTAGE_BINHOST $LATEST_RELEASE_CHROME_BINHOST"'
+    fi
   fi
 }