Update CQ config to use only toolchain trybots when appropriate

When PNaCl-related (or common) files are changed, use PNaCl trybots.
When no PNaCl-related files are change, exclude them.

Change-Id: Ia7957852059f73b04cde94e28a9213f6767d881c
Reviewed-on: https://chromium-review.googlesource.com/c/1419457
Reviewed-by: Derek Schuff <dschuff@chromium.org>
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index 90b3b06..5b52052 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -189,41 +189,3 @@
     'nacl-toolchain-precise64-newlib-arm',
     'nacl-toolchain-mac-newlib-arm',
     ] + PNACL_TOOLCHAIN_TRYBOTS
-
-
-def GetPreferredTryMasters(_, change):
-
-  has_pnacl = False
-  has_toolchain_build = False
-  has_others = False
-
-  for file in change.AffectedFiles():
-    if IsFileInDirectories(file.AbsoluteLocalPath(),
-                           [os.path.join(NACL_TOP_DIR, 'build'),
-                            os.path.join(NACL_TOP_DIR, 'buildbot'),
-                            os.path.join(NACL_TOP_DIR, 'pynacl')]):
-      # Buildbot and infrastructure changes should trigger all the try bots.
-      has_pnacl = True
-      has_toolchain_build = True
-      has_others = True
-      break
-    elif IsFileInDirectories(file.AbsoluteLocalPath(),
-                           [os.path.join(NACL_TOP_DIR, 'pnacl')]):
-      has_pnacl = True
-    elif IsFileInDirectories(file.AbsoluteLocalPath(),
-                             [os.path.join(NACL_TOP_DIR, 'toolchain_build')]):
-      has_toolchain_build = True
-    else:
-      has_others = True
-
-  trybots = []
-  if has_pnacl:
-    trybots += PNACL_TOOLCHAIN_TRYBOTS
-  if has_toolchain_build:
-    trybots += TOOLCHAIN_BUILD_TRYBOTS
-  if has_others:
-    trybots += DEFAULT_TRYBOTS
-
-  return {
-    'tryserver.nacl': { t: set(['defaulttests']) for t in set(trybots) },
-  }
diff --git a/infra/config/cq.cfg b/infra/config/cq.cfg
index 7fe77c1..c957e1d 100644
--- a/infra/config/cq.cfg
+++ b/infra/config/cq.cfg
@@ -20,36 +20,180 @@
   try_job {
     buckets {
       name: "luci.nacl.try"
-      builders { name: "nacl-arm_opt_panda" }
-      builders { name: "nacl-arm_perf_panda" }
-      builders { name: "nacl-mac_arm_newlib_opt" }
-      builders { name: "nacl-mac_glibc_dbg" }
-      builders { name: "nacl-mac_glibc_opt" }
-      builders { name: "nacl-mac_newlib_dbg" }
-      builders { name: "nacl-mac_newlib_opt" }
-      builders { name: "nacl-precise32_glibc_opt" }
-      builders { name: "nacl-precise32_newlib_dbg" }
-      builders { name: "nacl-precise32_newlib_opt" }
-      builders { name: "nacl-precise64_arm_newlib_opt" }
-      builders { name: "nacl-precise64_arm_glibc_opt" }
-      builders { name: "nacl-precise64_glibc_opt" }
-      builders { name: "nacl-precise64_newlib_dbg" }
-      builders { name: "nacl-precise64_newlib_opt" }
-      builders { name: "nacl-precise_64-newlib-arm_qemu-pnacl" }
-      builders { name: "nacl-precise_64-newlib-x86_32-pnacl" }
-      builders { name: "nacl-precise_64-newlib-x86_32-pnacl-spec" }
-      builders { name: "nacl-precise_64-newlib-x86_64-pnacl" }
-      builders { name: "nacl-precise_64-newlib-x86_64-pnacl-spec" }
-      builders { name: "nacl-presubmit" }
-      builders { name: "nacl-win32_glibc_opt" }
-      builders { name: "nacl-win32_newlib_opt" }
-      builders { name: "nacl-win64_glibc_opt" }
-      builders { name: "nacl-win64_newlib_dbg" }
-      builders { name: "nacl-win64_newlib_opt" }
-      builders { name: "nacl-win7_64_arm_newlib_opt" }
-      builders { name: "nacl-win7_64_newlib_opt_pnacl" }
-      builders { name: "nacl-win8-64_newlib_dbg" }
-      builders { name: "nacl-win8-64_newlib_opt" }
+      builders {
+        name: "nacl-arm_opt_panda"
+        path_regexp_exclude: "pnacl/.+"
+        path_regexp_exclude: "toolchain_build/.+"
+      }
+      builders {
+        name: "nacl-arm_perf_panda"
+        path_regexp_exclude: "pnacl/.+"
+        path_regexp_exclude: "toolchain_build/.+"
+      }
+      builders {
+        name: "nacl-mac_arm_newlib_opt"
+        path_regexp_exclude: "pnacl/.+"
+        path_regexp_exclude: "toolchain_build/.+"
+      }
+      builders {
+        name: "nacl-mac_glibc_dbg"
+        path_regexp_exclude: "pnacl/.+"
+        path_regexp_exclude: "toolchain_build/.+"
+      }
+      builders {
+        name: "nacl-mac_glibc_opt"
+        path_regexp_exclude: "pnacl/.+"
+        path_regexp_exclude: "toolchain_build/.+"
+      }
+      builders {
+        name: "nacl-mac_newlib_dbg"
+        path_regexp_exclude: "pnacl/.+"
+        path_regexp_exclude: "toolchain_build/.+"
+      }
+      builders {
+        name: "nacl-mac_newlib_opt"
+        path_regexp_exclude: "pnacl/.+"
+        path_regexp_exclude: "toolchain_build/.+"
+      }
+      builders {
+        name: "nacl-precise32_glibc_opt"
+        path_regexp_exclude: "pnacl/.+"
+        path_regexp_exclude: "toolchain_build/.+"
+      }
+      builders {
+        name: "nacl-precise32_newlib_dbg"
+        path_regexp_exclude: "pnacl/.+"
+        path_regexp_exclude: "toolchain_build/.+"
+      }
+      builders {
+        name: "nacl-precise32_newlib_opt"
+        path_regexp_exclude: "pnacl/.+"
+        path_regexp_exclude: "toolchain_build/.+"
+      }
+      builders {
+        name: "nacl-precise64_arm_newlib_opt"
+        path_regexp_exclude: "pnacl/.+"
+        path_regexp_exclude: "toolchain_build/.+"
+      }
+      builders {
+        name: "nacl-precise64_arm_glibc_opt"
+        path_regexp_exclude: "pnacl/.+"
+        path_regexp_exclude: "toolchain_build/.+"
+      }
+      builders {
+        name: "nacl-precise64_glibc_opt"
+        path_regexp_exclude: "pnacl/.+"
+        path_regexp_exclude: "toolchain_build/.+"
+      }
+      builders {
+        name: "nacl-precise64_newlib_dbg"
+        path_regexp_exclude: "pnacl/.+"
+        path_regexp_exclude: "toolchain_build/.+"
+      }
+      builders {
+        name: "nacl-precise64_newlib_opt"
+        path_regexp_exclude: "pnacl/.+"
+        path_regexp_exclude: "toolchain_build/.+"
+      }
+      builders {
+        name: "nacl-precise_64-newlib-arm_qemu-pnacl"
+        path_regexp_exclude: "pnacl/.+"
+        path_regexp_exclude: "toolchain_build/.+"
+      }
+      builders {
+        name: "nacl-precise_64-newlib-x86_32-pnacl"
+        path_regexp_exclude: "pnacl/.+"
+        path_regexp_exclude: "toolchain_build/.+"
+      }
+      builders {
+        name: "nacl-precise_64-newlib-x86_32-pnacl-spec"
+        path_regexp_exclude: "pnacl/.+"
+        path_regexp_exclude: "toolchain_build/.+"
+      }
+      builders {
+        name: "nacl-precise_64-newlib-x86_64-pnacl"
+        path_regexp_exclude: "pnacl/.+"
+        path_regexp_exclude: "toolchain_build/.+"
+      }
+      builders {
+        name: "nacl-precise_64-newlib-x86_64-pnacl-spec"
+        path_regexp_exclude: "pnacl/.+"
+        path_regexp_exclude: "toolchain_build/.+"
+      }
+      builders {
+        name: "nacl-presubmit"
+        path_regexp_exclude: "pnacl/.+"
+        path_regexp_exclude: "toolchain_build/.+"
+      }
+      builders {
+        name: "nacl-win32_glibc_opt"
+        path_regexp_exclude: "pnacl/.+"
+        path_regexp_exclude: "toolchain_build/.+"
+      }
+      builders {
+        name: "nacl-win32_newlib_opt"
+        path_regexp_exclude: "pnacl/.+"
+        path_regexp_exclude: "toolchain_build/.+"
+      }
+      builders {
+        name: "nacl-win64_glibc_opt"
+        path_regexp_exclude: "pnacl/.+"
+        path_regexp_exclude: "toolchain_build/.+"
+      }
+      builders {
+        name: "nacl-win64_newlib_dbg"
+        path_regexp_exclude: "pnacl/.+"
+        path_regexp_exclude: "toolchain_build/.+"
+      }
+      builders {
+        name: "nacl-win64_newlib_opt"
+        path_regexp_exclude: "pnacl/.+"
+        path_regexp_exclude: "toolchain_build/.+"
+      }
+      builders {
+        name: "nacl-win7_64_arm_newlib_opt"
+        path_regexp_exclude: "pnacl/.+"
+        path_regexp_exclude: "toolchain_build/.+"
+      }
+      builders {
+        name: "nacl-win7_64_newlib_opt_pnacl"
+        path_regexp_exclude: "pnacl/.+"
+        path_regexp_exclude: "toolchain_build/.+"
+      }
+      builders {
+        name: "nacl-win8-64_newlib_dbg"
+        path_regexp_exclude: "pnacl/.+"
+        path_regexp_exclude: "toolchain_build/.+"
+      }
+      builders {
+        name: "nacl-win8-64_newlib_opt"
+        path_regexp_exclude: "pnacl/.+"
+        path_regexp_exclude: "toolchain_build/.+"
+      }
+      builders {
+        name: "nacl-toolchain-linux-pnacl-x86_64"
+        path_regexp: "pnacl/.+"
+        path_regexp: "toolchain_build/.+"
+        path_regexp: "buildbot/.+"
+        path_regexp: "pynacl/.+"
+        path_regexp: "build/.+"
+      }
+            builders {
+        name: "nacl-toolchain-mac-pnacl-x86_32"
+        path_regexp: "pnacl/.+"
+        path_regexp: "toolchain_build/.+"
+        path_regexp: "buildbot/.+"
+        path_regexp: "pynacl/.+"
+        path_regexp: "build/.+"
+      }
+            builders {
+        name: "nacl-toolchain-win7-pnacl-x86_64"
+        path_regexp: "pnacl/.+"
+        path_regexp: "toolchain_build/.+"
+        path_regexp: "buildbot/.+"
+        path_regexp: "pynacl/.+"
+        path_regexp: "build/.+"
+      }
     }
   }
 }