build_packages: Refactor chrome packages to one array.

The packages need to be treated the same and built together.
Refactor them to be listed in a single location so we can easily
add to them.

BUG=None
TEST=manual, cq

Change-Id: I600e98928103fcae9d56c946839957076189ab07
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosutils/+/2157607
Tested-by: Alex Klein <saklein@chromium.org>
Commit-Queue: Alex Klein <saklein@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Chris McDonald <cjmcdonald@chromium.org>
diff --git a/build_packages b/build_packages
index 3745f97..a3617a8 100755
--- a/build_packages
+++ b/build_packages
@@ -116,6 +116,14 @@
 # Die on any errors.
 switch_to_strict_mode
 
+# Chrome packages that need to be treated the same. These are the chrome and
+# chrome follow-on packages that share the same version as chrome and are
+# updated in lock step.
+CHROME_PACKAGES=(
+  "chromeos-base/chromeos-chrome"
+  "chromeos-base/chrome-icu"
+)
+
 # This is a temporary measure to help the goma team check the configs while
 # they transition their backend service.
 # TODO(crbug.com/1032290): Delete after the goma RBE transition is complete.
@@ -197,10 +205,9 @@
 )
 
 if [[ "${FLAGS_use_any_chrome}" -eq "${FLAGS_TRUE}" ]]; then
-  EMERGE_CMD+=(
-    "--force-remote-binary=chromeos-base/chromeos-chrome"
-    "--force-remote-binary=chromeos-base/chrome-icu"
-  )
+  for pkg in "${CHROME_PACKAGES[@]}"; do
+    EMERGE_CMD+=( "--force-remote-binary=${pkg}" )
+  done
 fi
 
 EMERGE_CMD+=( ${EXTRA_BOARD_FLAGS} )
@@ -284,7 +291,7 @@
 
   # TODO(anush): Make chrome a fake cros-workon package.
   if [[ -n "${CHROME_ORIGIN}" ]]; then
-    CROS_WORKON_PKGS+=( chromeos-base/chromeos-chrome chromeos-base/chrome-icu )
+    CROS_WORKON_PKGS+=( "${CHROME_PACKAGES[@]}" )
   fi
 fi
 
@@ -327,10 +334,11 @@
       "${BASE_INSTALL_PKGS[@]}" | sort -u ) )
     # Remove Chrome as rebuilding it is expensive and almost never makes sense.
     # Ignore grep exit status in case chromeos-chrome is the only package.
-    MOD_PKGS=( $(printf '%s\n' "${MOD_PKGS[@]}" | \
-      grep -v \
-        -e 'chromeos-base/chrome-icu' \
-        -e 'chromeos-base/chromeos-chrome' || :) )
+    grep_cmd=( grep -v )
+    for pkg in "${CHROME_PACKAGES[@]}"; do
+      grep_cmd+=( -e "${pkg}" )
+    done
+    MOD_PKGS=( $(printf '%s\n' "${MOD_PKGS[@]}" | "${grep_cmd[@]}" || :) )
   fi
 
   FORCE_LOCAL_BUILD_PKGS+=( "${MOD_PKGS[@]}" )
@@ -348,10 +356,11 @@
       # Remove Chrome as rebuilding it is expensive and almost never makes
       # sense.  Ignore grep exit status in case chromeos-chrome is the only
       # package.
-      RMOD_PKGS=( $(printf '%s\n' "${RMOD_PKGS[@]}" | \
-        grep -v \
-          -e 'chromeos-base/chrome-icu' \
-          -e 'chromeos-base/chromeos-chrome' || :) )
+      grep_cmd=( grep -v )
+      for pkg in "${CHROME_PACKAGES[@]}"; do
+        grep_cmd+=( -e "${pkg}" )
+      done
+      RMOD_PKGS=( $(printf '%s\n' "${RMOD_PKGS[@]}" | "${grep_cmd}" || :) )
       info "final reverse dependencies that will be rebuilt: ${RMOD_PKGS[*]}"
       FORCE_LOCAL_BUILD_PKGS+=( "${RMOD_PKGS[@]}" )
     fi