Move board overlay calculation into chromite (part 1 of 5).

Currently cros_overlay_list lives in a shell script. Moving this into a
Python module simplifies the code while speeding up any Python scripts
that need to check what overlays are in use.

This saves ~100ms off of every call to cros_overlay_list.

This CL adds the Python logic for calculating board overlays, and moves
updates all callers in the Chromite repository to use it. Thorough unit
tests for this functionality are added, and useless unit tests for the
GetBoardOverlay function in upload_prebuilts are removed.

BUG=chromium-os:35514
TEST=New unit test. Trybot runs with all callers adjusted to use
     cros_list_overlays instead of cros_overlay_list.

Change-Id: I2ba2af5b19c71130e65588bdc9dfee5f3ff990e1
Reviewed-on: https://gerrit.chromium.org/gerrit/36191
Reviewed-by: Chris Sosa <sosa@chromium.org>
Commit-Ready: David James <davidjames@chromium.org>
Tested-by: David James <davidjames@chromium.org>
diff --git a/scripts/cros_setup_toolchains.py b/scripts/cros_setup_toolchains.py
index 459cff4..fbb5cff 100644
--- a/scripts/cros_setup_toolchains.py
+++ b/scripts/cros_setup_toolchains.py
@@ -7,13 +7,13 @@
 """
 
 import copy
-import errno
 import json
 import optparse
 import os
 import sys
 
 from chromite.buildbot import constants
+from chromite.buildbot import portage_utilities
 from chromite.lib import cros_build_lib
 from chromite.lib import osutils
 
@@ -27,8 +27,6 @@
 
 
 EMERGE_CMD = os.path.join(constants.CHROMITE_BIN_DIR, 'parallel_emerge')
-CROS_OVERLAY_LIST_CMD = os.path.join(
-    constants.SOURCE_ROOT, 'src/platform/dev/host/cros_overlay_list')
 PACKAGE_STABLE = '[stable]'
 PACKAGE_NONE = '[none]'
 SRC_ROOT = os.path.realpath(constants.SOURCE_ROOT)
@@ -227,21 +225,8 @@
 
   returns the list of toolchain tuples for the given board
   """
-  cmd = [CROS_OVERLAY_LIST_CMD]
-  if board == 'all' or board == 'sdk':
-    cmd.append('--all_boards')
-  else:
-    # TODO(vapier):
-    # Some tools will give us the base board name ('tegra2') while others will
-    # give us the board+variant ('tegra2_kaen').  The cros_overlay_list does
-    # not like getting variant names, so strip that off.  Not entirely clear
-    # if this is what we want to do, or if the cros_overlay_list should give
-    # us back the overlays (including variants).  I'm inclined to go with the
-    # latter, but that requires more testing to prevent fallout.
-    cmd.append('--board=' + board.split('_')[0])
-  overlays = cros_build_lib.RunCommand(
-      cmd, print_cmd=False, redirect_stdout=True).output.splitlines()
-
+  overlays = portage_utilities.FindOverlays(
+      constants.BOTH_OVERLAYS, None if board in ('all', 'sdk') else board)
   toolchains = GetTuplesForOverlays(overlays)
   if board == 'sdk':
     toolchains = FilterToolchains(toolchains, 'sdk', True)