cros_setup_toolchains: take direct control of host packages

We've been relying on crossdev to provide a list of packages for the
host toolchain, and then either undoing the results (like gdb) or
inserting more results by hand (like llvm) or munging the categories
(and thus partially ignoring the crossdev results).  Since we don't
need or want crossdev to manage config files for the host sdk like
we do with target packages (e.g. /etc/portage/*/cross-$CHOST and
/usr/local/portage/crossdev/cross-$CHOST/ paths), we end up gaining
very little from this.

Instead, lets manage the list of host toolchain packages directly.
This makes the code clearer and easier to add more packages (which
we seem to be doing more of).

BUG=chromium:751852, b:162254118
TEST=precqs pass
TEST=`cros tryjob chromiumos-sdk` passes
TEST=`cros tryjob --latest-toolchain lumpy-release` passes

Change-Id: Ic61cd26cc763a600134b80da73e7144251abadc3
Reviewed-on: https://chromium-review.googlesource.com/664099
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/2478983
Tested-by: Patryk Duda <patrykd@google.com>
Commit-Queue: Patrick Georgi <pgeorgi@chromium.org>
Reviewed-by: Jett Rink <jettrink@chromium.org>
diff --git a/scripts/cros_setup_toolchains.py b/scripts/cros_setup_toolchains.py
index 047c873..f3cb01e 100644
--- a/scripts/cros_setup_toolchains.py
+++ b/scripts/cros_setup_toolchains.py
@@ -49,7 +49,6 @@
 }
 TARGET_VERSION_MAP = {
     'host' : {
-        'gdb' : PACKAGE_NONE,
         'ex_go' : PACKAGE_NONE,
         'ex_compiler-rt': PACKAGE_NONE,
         'ex_llvm-libunwind': PACKAGE_NONE,
@@ -58,6 +57,24 @@
     },
 }
 
+# The exact list of host toolchain packages we care about.  These are the
+# packages that bots/devs install only from binpkgs and rely on the SDK bot
+# (chromiumos-sdk) to validate+uprev.
+#
+# These also need to be manually kept in sync with update_chroot.
+#
+# We don't use crossdev to manage the host toolchain for us, especially since
+# we diverge significantly now (with llvm/clang/etc...), and we don't need or
+# want crossdev managing /etc/portage config files for the sdk
+HOST_PACKAGES = (
+    'dev-lang/go',
+    'sys-devel/binutils',
+    'sys-devel/clang',
+    'sys-devel/gcc',
+    'sys-devel/llvm',
+    'sys-libs/glibc',
+)
+
 # Enable the Go compiler for these targets.
 TARGET_GO_ENABLED = (
     'x86_64-cros-linux-gnu',
@@ -135,29 +152,35 @@
 
     val = cls._CACHE.setdefault(CACHE_ATTR, {})
     if not target in val:
-      # Find out the crossdev tuple.
-      target_tuple = target
       if target == 'host':
-        target_tuple = toolchain.GetHostTuple()
-      # Build the crossdev command.
-      cmd = ['crossdev', '--show-target-cfg', '--ex-gdb']
-      if target in TARGET_COMPILER_RT_ENABLED:
-        cmd.extend(CROSSDEV_COMPILER_RT_ARGS)
-      if target in TARGET_GO_ENABLED:
-        cmd.extend(CROSSDEV_GO_ARGS)
-      if target in TARGET_LLVM_PKGS_ENABLED:
-        for pkg in LLVM_PKGS_TABLE:
-          cmd.extend(LLVM_PKGS_TABLE[pkg])
-      cmd.extend(['-t', target_tuple])
-      # Catch output of crossdev.
-      out = cros_build_lib.RunCommand(cmd, print_cmd=False,
-                                      redirect_stdout=True).output.splitlines()
-      # List of tuples split at the first '=', converted into dict.
-      conf = dict((k, cros_build_lib.ShellUnquote(v))
-                  for k, v in (x.split('=', 1) for x in out))
-      conf['crosspkgs'] = conf['crosspkgs'].split()
+        conf = {
+            'crosspkgs': [],
+            'target': toolchain.GetHostTuple(),
+        }
+        manual_pkgs = dict((pkg, cat) for cat, pkg in
+                           [x.split('/') for x in HOST_PACKAGES])
+      else:
+        # Build the crossdev command.
+        cmd = ['crossdev', '--show-target-cfg', '--ex-gdb']
+        if target in TARGET_COMPILER_RT_ENABLED:
+          cmd.extend(CROSSDEV_COMPILER_RT_ARGS)
+        if target in TARGET_GO_ENABLED:
+          cmd.extend(CROSSDEV_GO_ARGS)
+        if target in TARGET_LLVM_PKGS_ENABLED:
+          for pkg in LLVM_PKGS_TABLE:
+            cmd.extend(LLVM_PKGS_TABLE[pkg])
+        cmd.extend(['-t', target])
+        # Catch output of crossdev.
+        out = cros_build_lib.RunCommand(
+            cmd, print_cmd=False, redirect_stdout=True).output.splitlines()
+        # List of tuples split at the first '=', converted into dict.
+        conf = dict((k, cros_build_lib.ShellUnquote(v))
+                    for k, v in (x.split('=', 1) for x in out))
+        conf['crosspkgs'] = conf['crosspkgs'].split()
 
-      for pkg, cat in cls.MANUAL_PKGS.iteritems():
+        manual_pkgs = cls.MANUAL_PKGS
+
+      for pkg, cat in manual_pkgs.items():
         conf[pkg + '_pn'] = pkg
         conf[pkg + '_category'] = cat
         if pkg not in conf['crosspkgs']: