Make bazel lit test suites less magic

Now that we're using the same lit runner internally and in OSS, we can get rid of a lot of the magic here. This obviates the need for a separate setup and glob rule and makes the dependencies of each target explicit, following bzl best practices. It should also make this easier to automatically translate to cmake, which I'll work on separately.

Note that this turns the recursive globs into non-recursive globs. This does not cause us to exclude tests, and in fact stops running tests under iree/compiler/Translation/Interpreter/Transforms/test/xla twice, which we were doing before. To verify, `cat ~/tmp/open_files.txt | grep "/BUILD" | sed -e 's@/BUILD@@' | xargs -I{} find {}/ -type d | grep -v "/$"`, which gives all the subdirectories of the directories containing the modified BUILD files.

PiperOrigin-RevId: 291435291
diff --git a/integrations/tensorflow/compiler/test/BUILD b/integrations/tensorflow/compiler/test/BUILD
index 60d7661..0f1a4c8 100644
--- a/integrations/tensorflow/compiler/test/BUILD
+++ b/integrations/tensorflow/compiler/test/BUILD
@@ -15,27 +15,28 @@
 load(
     "//iree:build_defs.oss.bzl",
     "INTREE_FILECHECK_TARGET",
-    "iree_glob_lit_tests",
-    "iree_setup_lit_package",
 )
 load(
     "//bindings/python:build_defs.oss.bzl",
     "INTREE_TENSORFLOW_PY_DEPS",
 )
+load("//iree:lit_test.bzl", "iree_lit_test_suite")
 
 package(
     default_visibility = ["//visibility:public"],
     licenses = ["notice"],  # Apache 2.0
 )
 
-iree_setup_lit_package(
+iree_lit_test_suite(
+    name = "lit",
+    srcs = glob(["*.mlir"]),
     data = [
         "//integrations/tensorflow/compiler:iree-tf-opt",
+        "//iree/tools:IreeFileCheck",
     ],
+    tags = ["nokokoro"],
 )
 
-iree_glob_lit_tests(tags = ["nokokoro"])
-
 py_test(
     name = "saved_model_adopt_exports",
     srcs = [
diff --git a/iree/build_defs.oss.bzl b/iree/build_defs.oss.bzl
index 4913f3c..815da09 100644
--- a/iree/build_defs.oss.bzl
+++ b/iree/build_defs.oss.bzl
@@ -17,17 +17,10 @@
 load("@com_github_google_flatbuffers//:build_defs.bzl", "flatbuffer_cc_library")
 load("@rules_cc//cc:defs.bzl", _cc_binary = "cc_binary", _cc_library = "cc_library")
 load("@iree_core//build_tools/third_party/glslang:build_defs.bzl", "glsl_vulkan")
-load("@iree_core//iree:lit_test.bzl", _iree_glob_lit_tests = "iree_glob_lit_tests", _iree_setup_lit_package = "iree_setup_lit_package")
 
 # Target to the FileCheck binary.
 INTREE_FILECHECK_TARGET = "@llvm-project//llvm:FileCheck"
 
-def iree_setup_lit_package(**kwargs):
-    _iree_setup_lit_package(**kwargs)
-
-def iree_glob_lit_tests(**kwargs):
-    _iree_glob_lit_tests(**kwargs)
-
 def platform_trampoline_deps(basename, path = "base"):
     """Produce a list of deps for the given `basename` platform target.
 
diff --git a/iree/compiler/Dialect/Flow/Analysis/test/BUILD b/iree/compiler/Dialect/Flow/Analysis/test/BUILD
index ab85666..7c58b4a 100644
--- a/iree/compiler/Dialect/Flow/Analysis/test/BUILD
+++ b/iree/compiler/Dialect/Flow/Analysis/test/BUILD
@@ -12,17 +12,18 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-load("//iree:build_defs.oss.bzl", "iree_glob_lit_tests", "iree_setup_lit_package")
+load("//iree:lit_test.bzl", "iree_lit_test_suite")
 
 package(
     default_visibility = ["//visibility:public"],
     licenses = ["notice"],  # Apache 2.0
 )
 
-iree_setup_lit_package(
+iree_lit_test_suite(
+    name = "lit",
+    srcs = glob(["*.mlir"]),
     data = [
+        "//iree/tools:IreeFileCheck",
         "//iree/tools:iree-opt",
     ],
 )
-
-iree_glob_lit_tests()
diff --git a/iree/compiler/Dialect/Flow/Conversion/HLOToFlow/test/BUILD b/iree/compiler/Dialect/Flow/Conversion/HLOToFlow/test/BUILD
index ab85666..7c58b4a 100644
--- a/iree/compiler/Dialect/Flow/Conversion/HLOToFlow/test/BUILD
+++ b/iree/compiler/Dialect/Flow/Conversion/HLOToFlow/test/BUILD
@@ -12,17 +12,18 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-load("//iree:build_defs.oss.bzl", "iree_glob_lit_tests", "iree_setup_lit_package")
+load("//iree:lit_test.bzl", "iree_lit_test_suite")
 
 package(
     default_visibility = ["//visibility:public"],
     licenses = ["notice"],  # Apache 2.0
 )
 
-iree_setup_lit_package(
+iree_lit_test_suite(
+    name = "lit",
+    srcs = glob(["*.mlir"]),
     data = [
+        "//iree/tools:IreeFileCheck",
         "//iree/tools:iree-opt",
     ],
 )
-
-iree_glob_lit_tests()
diff --git a/iree/compiler/Dialect/Flow/Conversion/StandardToFlow/test/BUILD b/iree/compiler/Dialect/Flow/Conversion/StandardToFlow/test/BUILD
index ab85666..7c58b4a 100644
--- a/iree/compiler/Dialect/Flow/Conversion/StandardToFlow/test/BUILD
+++ b/iree/compiler/Dialect/Flow/Conversion/StandardToFlow/test/BUILD
@@ -12,17 +12,18 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-load("//iree:build_defs.oss.bzl", "iree_glob_lit_tests", "iree_setup_lit_package")
+load("//iree:lit_test.bzl", "iree_lit_test_suite")
 
 package(
     default_visibility = ["//visibility:public"],
     licenses = ["notice"],  # Apache 2.0
 )
 
-iree_setup_lit_package(
+iree_lit_test_suite(
+    name = "lit",
+    srcs = glob(["*.mlir"]),
     data = [
+        "//iree/tools:IreeFileCheck",
         "//iree/tools:iree-opt",
     ],
 )
-
-iree_glob_lit_tests()
diff --git a/iree/compiler/Dialect/Flow/IR/test/BUILD b/iree/compiler/Dialect/Flow/IR/test/BUILD
index ab85666..7c58b4a 100644
--- a/iree/compiler/Dialect/Flow/IR/test/BUILD
+++ b/iree/compiler/Dialect/Flow/IR/test/BUILD
@@ -12,17 +12,18 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-load("//iree:build_defs.oss.bzl", "iree_glob_lit_tests", "iree_setup_lit_package")
+load("//iree:lit_test.bzl", "iree_lit_test_suite")
 
 package(
     default_visibility = ["//visibility:public"],
     licenses = ["notice"],  # Apache 2.0
 )
 
-iree_setup_lit_package(
+iree_lit_test_suite(
+    name = "lit",
+    srcs = glob(["*.mlir"]),
     data = [
+        "//iree/tools:IreeFileCheck",
         "//iree/tools:iree-opt",
     ],
 )
-
-iree_glob_lit_tests()
diff --git a/iree/compiler/Dialect/Flow/Transforms/test/BUILD b/iree/compiler/Dialect/Flow/Transforms/test/BUILD
index ab85666..7c58b4a 100644
--- a/iree/compiler/Dialect/Flow/Transforms/test/BUILD
+++ b/iree/compiler/Dialect/Flow/Transforms/test/BUILD
@@ -12,17 +12,18 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-load("//iree:build_defs.oss.bzl", "iree_glob_lit_tests", "iree_setup_lit_package")
+load("//iree:lit_test.bzl", "iree_lit_test_suite")
 
 package(
     default_visibility = ["//visibility:public"],
     licenses = ["notice"],  # Apache 2.0
 )
 
-iree_setup_lit_package(
+iree_lit_test_suite(
+    name = "lit",
+    srcs = glob(["*.mlir"]),
     data = [
+        "//iree/tools:IreeFileCheck",
         "//iree/tools:iree-opt",
     ],
 )
-
-iree_glob_lit_tests()
diff --git a/iree/compiler/Dialect/HAL/Conversion/FlowToHAL/test/BUILD b/iree/compiler/Dialect/HAL/Conversion/FlowToHAL/test/BUILD
index ab85666..7c58b4a 100644
--- a/iree/compiler/Dialect/HAL/Conversion/FlowToHAL/test/BUILD
+++ b/iree/compiler/Dialect/HAL/Conversion/FlowToHAL/test/BUILD
@@ -12,17 +12,18 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-load("//iree:build_defs.oss.bzl", "iree_glob_lit_tests", "iree_setup_lit_package")
+load("//iree:lit_test.bzl", "iree_lit_test_suite")
 
 package(
     default_visibility = ["//visibility:public"],
     licenses = ["notice"],  # Apache 2.0
 )
 
-iree_setup_lit_package(
+iree_lit_test_suite(
+    name = "lit",
+    srcs = glob(["*.mlir"]),
     data = [
+        "//iree/tools:IreeFileCheck",
         "//iree/tools:iree-opt",
     ],
 )
-
-iree_glob_lit_tests()
diff --git a/iree/compiler/Dialect/HAL/Conversion/HALToVM/test/BUILD b/iree/compiler/Dialect/HAL/Conversion/HALToVM/test/BUILD
index ab85666..7c58b4a 100644
--- a/iree/compiler/Dialect/HAL/Conversion/HALToVM/test/BUILD
+++ b/iree/compiler/Dialect/HAL/Conversion/HALToVM/test/BUILD
@@ -12,17 +12,18 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-load("//iree:build_defs.oss.bzl", "iree_glob_lit_tests", "iree_setup_lit_package")
+load("//iree:lit_test.bzl", "iree_lit_test_suite")
 
 package(
     default_visibility = ["//visibility:public"],
     licenses = ["notice"],  # Apache 2.0
 )
 
-iree_setup_lit_package(
+iree_lit_test_suite(
+    name = "lit",
+    srcs = glob(["*.mlir"]),
     data = [
+        "//iree/tools:IreeFileCheck",
         "//iree/tools:iree-opt",
     ],
 )
-
-iree_glob_lit_tests()
diff --git a/iree/compiler/Dialect/HAL/IR/test/BUILD b/iree/compiler/Dialect/HAL/IR/test/BUILD
index ab85666..7c58b4a 100644
--- a/iree/compiler/Dialect/HAL/IR/test/BUILD
+++ b/iree/compiler/Dialect/HAL/IR/test/BUILD
@@ -12,17 +12,18 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-load("//iree:build_defs.oss.bzl", "iree_glob_lit_tests", "iree_setup_lit_package")
+load("//iree:lit_test.bzl", "iree_lit_test_suite")
 
 package(
     default_visibility = ["//visibility:public"],
     licenses = ["notice"],  # Apache 2.0
 )
 
-iree_setup_lit_package(
+iree_lit_test_suite(
+    name = "lit",
+    srcs = glob(["*.mlir"]),
     data = [
+        "//iree/tools:IreeFileCheck",
         "//iree/tools:iree-opt",
     ],
 )
-
-iree_glob_lit_tests()
diff --git a/iree/compiler/Dialect/HAL/Target/test/BUILD b/iree/compiler/Dialect/HAL/Target/test/BUILD
index ab85666..7c58b4a 100644
--- a/iree/compiler/Dialect/HAL/Target/test/BUILD
+++ b/iree/compiler/Dialect/HAL/Target/test/BUILD
@@ -12,17 +12,18 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-load("//iree:build_defs.oss.bzl", "iree_glob_lit_tests", "iree_setup_lit_package")
+load("//iree:lit_test.bzl", "iree_lit_test_suite")
 
 package(
     default_visibility = ["//visibility:public"],
     licenses = ["notice"],  # Apache 2.0
 )
 
-iree_setup_lit_package(
+iree_lit_test_suite(
+    name = "lit",
+    srcs = glob(["*.mlir"]),
     data = [
+        "//iree/tools:IreeFileCheck",
         "//iree/tools:iree-opt",
     ],
 )
-
-iree_glob_lit_tests()
diff --git a/iree/compiler/Dialect/HAL/Transforms/test/BUILD b/iree/compiler/Dialect/HAL/Transforms/test/BUILD
index ab85666..7c58b4a 100644
--- a/iree/compiler/Dialect/HAL/Transforms/test/BUILD
+++ b/iree/compiler/Dialect/HAL/Transforms/test/BUILD
@@ -12,17 +12,18 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-load("//iree:build_defs.oss.bzl", "iree_glob_lit_tests", "iree_setup_lit_package")
+load("//iree:lit_test.bzl", "iree_lit_test_suite")
 
 package(
     default_visibility = ["//visibility:public"],
     licenses = ["notice"],  # Apache 2.0
 )
 
-iree_setup_lit_package(
+iree_lit_test_suite(
+    name = "lit",
+    srcs = glob(["*.mlir"]),
     data = [
+        "//iree/tools:IreeFileCheck",
         "//iree/tools:iree-opt",
     ],
 )
-
-iree_glob_lit_tests()
diff --git a/iree/compiler/Dialect/IREE/IR/test/BUILD b/iree/compiler/Dialect/IREE/IR/test/BUILD
index ab85666..7c58b4a 100644
--- a/iree/compiler/Dialect/IREE/IR/test/BUILD
+++ b/iree/compiler/Dialect/IREE/IR/test/BUILD
@@ -12,17 +12,18 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-load("//iree:build_defs.oss.bzl", "iree_glob_lit_tests", "iree_setup_lit_package")
+load("//iree:lit_test.bzl", "iree_lit_test_suite")
 
 package(
     default_visibility = ["//visibility:public"],
     licenses = ["notice"],  # Apache 2.0
 )
 
-iree_setup_lit_package(
+iree_lit_test_suite(
+    name = "lit",
+    srcs = glob(["*.mlir"]),
     data = [
+        "//iree/tools:IreeFileCheck",
         "//iree/tools:iree-opt",
     ],
 )
-
-iree_glob_lit_tests()
diff --git a/iree/compiler/Dialect/IREE/Transforms/test/BUILD b/iree/compiler/Dialect/IREE/Transforms/test/BUILD
index ab85666..7c58b4a 100644
--- a/iree/compiler/Dialect/IREE/Transforms/test/BUILD
+++ b/iree/compiler/Dialect/IREE/Transforms/test/BUILD
@@ -12,17 +12,18 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-load("//iree:build_defs.oss.bzl", "iree_glob_lit_tests", "iree_setup_lit_package")
+load("//iree:lit_test.bzl", "iree_lit_test_suite")
 
 package(
     default_visibility = ["//visibility:public"],
     licenses = ["notice"],  # Apache 2.0
 )
 
-iree_setup_lit_package(
+iree_lit_test_suite(
+    name = "lit",
+    srcs = glob(["*.mlir"]),
     data = [
+        "//iree/tools:IreeFileCheck",
         "//iree/tools:iree-opt",
     ],
 )
-
-iree_glob_lit_tests()
diff --git a/iree/compiler/Dialect/Shape/IR/test/BUILD b/iree/compiler/Dialect/Shape/IR/test/BUILD
index ab85666..7c58b4a 100644
--- a/iree/compiler/Dialect/Shape/IR/test/BUILD
+++ b/iree/compiler/Dialect/Shape/IR/test/BUILD
@@ -12,17 +12,18 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-load("//iree:build_defs.oss.bzl", "iree_glob_lit_tests", "iree_setup_lit_package")
+load("//iree:lit_test.bzl", "iree_lit_test_suite")
 
 package(
     default_visibility = ["//visibility:public"],
     licenses = ["notice"],  # Apache 2.0
 )
 
-iree_setup_lit_package(
+iree_lit_test_suite(
+    name = "lit",
+    srcs = glob(["*.mlir"]),
     data = [
+        "//iree/tools:IreeFileCheck",
         "//iree/tools:iree-opt",
     ],
 )
-
-iree_glob_lit_tests()
diff --git a/iree/compiler/Dialect/VM/Analysis/test/BUILD b/iree/compiler/Dialect/VM/Analysis/test/BUILD
index 7aa1dfd..7c58b4a 100644
--- a/iree/compiler/Dialect/VM/Analysis/test/BUILD
+++ b/iree/compiler/Dialect/VM/Analysis/test/BUILD
@@ -1,14 +1,29 @@
-load("//iree:build_defs.oss.bzl", "iree_glob_lit_tests", "iree_setup_lit_package")
+# Copyright 2019 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+load("//iree:lit_test.bzl", "iree_lit_test_suite")
 
 package(
     default_visibility = ["//visibility:public"],
     licenses = ["notice"],  # Apache 2.0
 )
 
-iree_setup_lit_package(
+iree_lit_test_suite(
+    name = "lit",
+    srcs = glob(["*.mlir"]),
     data = [
+        "//iree/tools:IreeFileCheck",
         "//iree/tools:iree-opt",
     ],
 )
-
-iree_glob_lit_tests()
diff --git a/iree/compiler/Dialect/VM/Conversion/StandardToVM/test/BUILD b/iree/compiler/Dialect/VM/Conversion/StandardToVM/test/BUILD
index 7aa1dfd..7c58b4a 100644
--- a/iree/compiler/Dialect/VM/Conversion/StandardToVM/test/BUILD
+++ b/iree/compiler/Dialect/VM/Conversion/StandardToVM/test/BUILD
@@ -1,14 +1,29 @@
-load("//iree:build_defs.oss.bzl", "iree_glob_lit_tests", "iree_setup_lit_package")
+# Copyright 2019 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+load("//iree:lit_test.bzl", "iree_lit_test_suite")
 
 package(
     default_visibility = ["//visibility:public"],
     licenses = ["notice"],  # Apache 2.0
 )
 
-iree_setup_lit_package(
+iree_lit_test_suite(
+    name = "lit",
+    srcs = glob(["*.mlir"]),
     data = [
+        "//iree/tools:IreeFileCheck",
         "//iree/tools:iree-opt",
     ],
 )
-
-iree_glob_lit_tests()
diff --git a/iree/compiler/Dialect/VM/IR/test/BUILD b/iree/compiler/Dialect/VM/IR/test/BUILD
index ab85666..7c58b4a 100644
--- a/iree/compiler/Dialect/VM/IR/test/BUILD
+++ b/iree/compiler/Dialect/VM/IR/test/BUILD
@@ -12,17 +12,18 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-load("//iree:build_defs.oss.bzl", "iree_glob_lit_tests", "iree_setup_lit_package")
+load("//iree:lit_test.bzl", "iree_lit_test_suite")
 
 package(
     default_visibility = ["//visibility:public"],
     licenses = ["notice"],  # Apache 2.0
 )
 
-iree_setup_lit_package(
+iree_lit_test_suite(
+    name = "lit",
+    srcs = glob(["*.mlir"]),
     data = [
+        "//iree/tools:IreeFileCheck",
         "//iree/tools:iree-opt",
     ],
 )
-
-iree_glob_lit_tests()
diff --git a/iree/compiler/Dialect/VM/Target/Bytecode/test/BUILD b/iree/compiler/Dialect/VM/Target/Bytecode/test/BUILD
index 186308f..3626929 100644
--- a/iree/compiler/Dialect/VM/Target/Bytecode/test/BUILD
+++ b/iree/compiler/Dialect/VM/Target/Bytecode/test/BUILD
@@ -1,14 +1,29 @@
-load("//iree:build_defs.oss.bzl", "iree_glob_lit_tests", "iree_setup_lit_package")
+# Copyright 2019 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+load("//iree:lit_test.bzl", "iree_lit_test_suite")
 
 package(
     default_visibility = ["//visibility:public"],
     licenses = ["notice"],  # Apache 2.0
 )
 
-iree_setup_lit_package(
+iree_lit_test_suite(
+    name = "lit",
+    srcs = glob(["*.mlir"]),
     data = [
+        "//iree/tools:IreeFileCheck",
         "//iree/tools:iree-translate",
     ],
 )
-
-iree_glob_lit_tests()
diff --git a/iree/compiler/Dialect/VM/Transforms/test/BUILD b/iree/compiler/Dialect/VM/Transforms/test/BUILD
index 7aa1dfd..7c58b4a 100644
--- a/iree/compiler/Dialect/VM/Transforms/test/BUILD
+++ b/iree/compiler/Dialect/VM/Transforms/test/BUILD
@@ -1,14 +1,29 @@
-load("//iree:build_defs.oss.bzl", "iree_glob_lit_tests", "iree_setup_lit_package")
+# Copyright 2019 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+load("//iree:lit_test.bzl", "iree_lit_test_suite")
 
 package(
     default_visibility = ["//visibility:public"],
     licenses = ["notice"],  # Apache 2.0
 )
 
-iree_setup_lit_package(
+iree_lit_test_suite(
+    name = "lit",
+    srcs = glob(["*.mlir"]),
     data = [
+        "//iree/tools:IreeFileCheck",
         "//iree/tools:iree-opt",
     ],
 )
-
-iree_glob_lit_tests()
diff --git a/iree/compiler/Translation/Interpreter/IR/test/BUILD b/iree/compiler/Translation/Interpreter/IR/test/BUILD
index ab85666..7c58b4a 100644
--- a/iree/compiler/Translation/Interpreter/IR/test/BUILD
+++ b/iree/compiler/Translation/Interpreter/IR/test/BUILD
@@ -12,17 +12,18 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-load("//iree:build_defs.oss.bzl", "iree_glob_lit_tests", "iree_setup_lit_package")
+load("//iree:lit_test.bzl", "iree_lit_test_suite")
 
 package(
     default_visibility = ["//visibility:public"],
     licenses = ["notice"],  # Apache 2.0
 )
 
-iree_setup_lit_package(
+iree_lit_test_suite(
+    name = "lit",
+    srcs = glob(["*.mlir"]),
     data = [
+        "//iree/tools:IreeFileCheck",
         "//iree/tools:iree-opt",
     ],
 )
-
-iree_glob_lit_tests()
diff --git a/iree/compiler/Translation/Interpreter/Transforms/test/BUILD b/iree/compiler/Translation/Interpreter/Transforms/test/BUILD
index a54938e..0355bd8 100644
--- a/iree/compiler/Translation/Interpreter/Transforms/test/BUILD
+++ b/iree/compiler/Translation/Interpreter/Transforms/test/BUILD
@@ -14,17 +14,18 @@
 
 # Tests for lowering MLIR in various dialects to IREE interpreter bytecode.
 
-load("//iree:build_defs.oss.bzl", "iree_glob_lit_tests", "iree_setup_lit_package")
+load("//iree:lit_test.bzl", "iree_lit_test_suite")
 
 package(
     default_visibility = ["//visibility:public"],
     licenses = ["notice"],  # Apache 2.0
 )
 
-iree_setup_lit_package(
+iree_lit_test_suite(
+    name = "lit",
+    srcs = glob(["*.mlir"]),
     data = [
+        "//iree/tools:IreeFileCheck",
         "//iree/tools:iree-opt",
     ],
 )
-
-iree_glob_lit_tests()
diff --git a/iree/compiler/Translation/Interpreter/Transforms/test/xla/BUILD b/iree/compiler/Translation/Interpreter/Transforms/test/xla/BUILD
index 4aa96ef..5e5d5d3 100644
--- a/iree/compiler/Translation/Interpreter/Transforms/test/xla/BUILD
+++ b/iree/compiler/Translation/Interpreter/Transforms/test/xla/BUILD
@@ -14,17 +14,18 @@
 
 # Tests specific to lowering XLA to IREE.
 
-load("//iree:build_defs.oss.bzl", "iree_glob_lit_tests", "iree_setup_lit_package")
+load("//iree:lit_test.bzl", "iree_lit_test_suite")
 
 package(
     default_visibility = ["//visibility:public"],
     licenses = ["notice"],  # Apache 2.0
 )
 
-iree_setup_lit_package(
+iree_lit_test_suite(
+    name = "lit",
+    srcs = glob(["*.mlir"]),
     data = [
+        "//iree/tools:IreeFileCheck",
         "//iree/tools:iree-opt",
     ],
 )
-
-iree_glob_lit_tests()
diff --git a/iree/compiler/Translation/SPIRV/IndexComputation/test/BUILD b/iree/compiler/Translation/SPIRV/IndexComputation/test/BUILD
index 4d99e77..1d8d07c 100644
--- a/iree/compiler/Translation/SPIRV/IndexComputation/test/BUILD
+++ b/iree/compiler/Translation/SPIRV/IndexComputation/test/BUILD
@@ -1,16 +1,31 @@
+# Copyright 2019 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
 # Tests for common transforms.
 
-load("//iree:build_defs.oss.bzl", "iree_glob_lit_tests", "iree_setup_lit_package")
+load("//iree:lit_test.bzl", "iree_lit_test_suite")
 
 package(
     default_visibility = ["//visibility:public"],
     licenses = ["notice"],  # Apache 2.0
 )
 
-iree_setup_lit_package(
+iree_lit_test_suite(
+    name = "lit",
+    srcs = glob(["*.mlir"]),
     data = [
+        "//iree/tools:IreeFileCheck",
         "//iree/tools:iree-opt",
     ],
 )
-
-iree_glob_lit_tests()
diff --git a/iree/compiler/Translation/SPIRV/LinalgToSPIRV/test/BUILD b/iree/compiler/Translation/SPIRV/LinalgToSPIRV/test/BUILD
index 4d99e77..1d8d07c 100644
--- a/iree/compiler/Translation/SPIRV/LinalgToSPIRV/test/BUILD
+++ b/iree/compiler/Translation/SPIRV/LinalgToSPIRV/test/BUILD
@@ -1,16 +1,31 @@
+# Copyright 2019 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
 # Tests for common transforms.
 
-load("//iree:build_defs.oss.bzl", "iree_glob_lit_tests", "iree_setup_lit_package")
+load("//iree:lit_test.bzl", "iree_lit_test_suite")
 
 package(
     default_visibility = ["//visibility:public"],
     licenses = ["notice"],  # Apache 2.0
 )
 
-iree_setup_lit_package(
+iree_lit_test_suite(
+    name = "lit",
+    srcs = glob(["*.mlir"]),
     data = [
+        "//iree/tools:IreeFileCheck",
         "//iree/tools:iree-opt",
     ],
 )
-
-iree_glob_lit_tests()
diff --git a/iree/compiler/Translation/SPIRV/ReductionCodegen/test/BUILD b/iree/compiler/Translation/SPIRV/ReductionCodegen/test/BUILD
index 78aa224..1d8d07c 100644
--- a/iree/compiler/Translation/SPIRV/ReductionCodegen/test/BUILD
+++ b/iree/compiler/Translation/SPIRV/ReductionCodegen/test/BUILD
@@ -14,17 +14,18 @@
 
 # Tests for common transforms.
 
-load("//iree:build_defs.oss.bzl", "iree_glob_lit_tests", "iree_setup_lit_package")
+load("//iree:lit_test.bzl", "iree_lit_test_suite")
 
 package(
     default_visibility = ["//visibility:public"],
     licenses = ["notice"],  # Apache 2.0
 )
 
-iree_setup_lit_package(
+iree_lit_test_suite(
+    name = "lit",
+    srcs = glob(["*.mlir"]),
     data = [
+        "//iree/tools:IreeFileCheck",
         "//iree/tools:iree-opt",
     ],
 )
-
-iree_glob_lit_tests()
diff --git a/iree/compiler/Translation/SPIRV/XLAToSPIRV/test/BUILD b/iree/compiler/Translation/SPIRV/XLAToSPIRV/test/BUILD
index 78aa224..1d8d07c 100644
--- a/iree/compiler/Translation/SPIRV/XLAToSPIRV/test/BUILD
+++ b/iree/compiler/Translation/SPIRV/XLAToSPIRV/test/BUILD
@@ -14,17 +14,18 @@
 
 # Tests for common transforms.
 
-load("//iree:build_defs.oss.bzl", "iree_glob_lit_tests", "iree_setup_lit_package")
+load("//iree:lit_test.bzl", "iree_lit_test_suite")
 
 package(
     default_visibility = ["//visibility:public"],
     licenses = ["notice"],  # Apache 2.0
 )
 
-iree_setup_lit_package(
+iree_lit_test_suite(
+    name = "lit",
+    srcs = glob(["*.mlir"]),
     data = [
+        "//iree/tools:IreeFileCheck",
         "//iree/tools:iree-opt",
     ],
 )
-
-iree_glob_lit_tests()
diff --git a/iree/compiler/Translation/XLAToLinalg/test/BUILD b/iree/compiler/Translation/XLAToLinalg/test/BUILD
index 0717701..19d9c45 100644
--- a/iree/compiler/Translation/XLAToLinalg/test/BUILD
+++ b/iree/compiler/Translation/XLAToLinalg/test/BUILD
@@ -1,17 +1,32 @@
+# Copyright 2019 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
 # Tests for common transforms.
 
-load("//iree:build_defs.oss.bzl", "iree_glob_lit_tests", "iree_setup_lit_package")
+load("//iree:lit_test.bzl", "iree_lit_test_suite")
 
 package(
     default_visibility = ["//visibility:public"],
     licenses = ["notice"],  # Apache 2.0
 )
 
-iree_setup_lit_package(
+iree_lit_test_suite(
+    name = "lit",
+    srcs = glob(["*.mlir"]),
     data = [
+        "//iree/tools:IreeFileCheck",
         "//iree/tools:iree-opt",
         "@llvm-project//mlir:mlir-translate",
     ],
 )
-
-iree_glob_lit_tests()
diff --git a/iree/compiler/Translation/test/BUILD b/iree/compiler/Translation/test/BUILD
index 723ac8c..950ea5a 100644
--- a/iree/compiler/Translation/test/BUILD
+++ b/iree/compiler/Translation/test/BUILD
@@ -14,18 +14,19 @@
 
 # Tests for common transforms.
 
-load("//iree:build_defs.oss.bzl", "iree_glob_lit_tests", "iree_setup_lit_package")
+load("//iree:lit_test.bzl", "iree_lit_test_suite")
 
 package(
     default_visibility = ["//visibility:public"],
     licenses = ["notice"],  # Apache 2.0
 )
 
-iree_setup_lit_package(
+iree_lit_test_suite(
+    name = "lit",
+    srcs = glob(["*.mlir"]),
     data = [
+        "//iree/tools:IreeFileCheck",
         "//iree/tools:iree-opt",
         "//iree/tools:iree-translate",
     ],
 )
-
-iree_glob_lit_tests()
diff --git a/iree/lit_test.bzl b/iree/lit_test.bzl
index e06e2fb..a3153a7 100644
--- a/iree/lit_test.bzl
+++ b/iree/lit_test.bzl
@@ -14,52 +14,69 @@
 
 """Bazel macros for running lit tests."""
 
-def iree_setup_lit_package(data, **kwargs):
-    """Should be called once per test package that contains globbed lit tests.
+def iree_lit_test(
+        name,
+        test_file,
+        data,
+        size = "small",
+        driver = "//iree/tools:run_lit.sh",
+        **kwargs):
+    """Creates a lit test from the specified source file.
 
     Args:
-      data: Additional, project specific data deps to add.
-      **kwargs: Any additional arguments to the underlying filegroup.
+      name: name of the generated test suite.
+      test_file: the test file with the lit test
+      data: binaries used in the lit tests.
+      size: size of the tests.
+      driver: the shell runner for the lit tests.
+      **kwargs: Any additional arguments that will be passed to the underlying sh_test.
     """
-
-    # Bundle together all of the test utilities that are used by tests.
-    native.filegroup(
-        name = "lit_test_utilities",
-        testonly = True,
-        data = data + [
-            "//iree/tools:IreeFileCheck",
-        ],
+    native.sh_test(
+        name = name,
+        srcs = [driver],
+        size = size,
+        data = data + [test_file],
+        args = ["$(location %s)" % (test_file,)],
         **kwargs
     )
 
-def iree_glob_lit_tests(
-        data = [":lit_test_utilities"],
+def iree_lit_test_suite(
+        name,
+        data,
+        srcs,
+        size = "small",
         driver = "//iree/tools:run_lit.sh",
-        test_file_exts = ["mlir"],
+        tags = [],
         **kwargs):
-    """Globs lit test files into tests for a package.
-
-    For most packages, the defaults suffice. Packages that include this must
-    also include a call to iree_setup_lit_package().
+    """Creates one lit test per source file and a test suite that bundles them.
 
     Args:
-      data: Data files to include/build.
-      driver: Test driver.
-      test_file_exts: File extensions to glob.
-      **kwargs: Any additional arguments to the underlying sh_test.
+      name: name of the generated test suite.
+      data: binaries used in the lit tests.
+      srcs: test file sources.
+      size: size of the tests.
+      driver: the shell runner for the lit tests.
+      tags: tags to apply to the test. Note that as in standard test suites, manual
+            is treated specially and will also apply to the test suite itself.
+      **kwargs: Any additional arguments that will be passed to the underlying tests.
     """
-    for test_file_ext in test_file_exts:
-        test_files = native.glob([
-            "*.%s" % (test_file_ext,),
-            "**/*.%s" % (test_file_ext,),
-        ])
-        for test_file in test_files:
-            test_file_location = "$(location %s)" % (test_file,)
-            native.sh_test(
-                name = "%s.test" % (test_file,),
-                size = "small",
-                srcs = [driver],
-                data = data + [test_file],
-                args = [test_file_location],
-                **kwargs
-            )
+    tests = []
+    for test_file in srcs:
+        test_name = "%s_%s_test" % (name, test_file)
+        iree_lit_test(
+            name = test_name,
+            test_file = test_file,
+            size = size,
+            data = data,
+            driver = driver,
+            **kwargs
+        )
+        tests.append(test_name)
+
+    native.test_suite(
+        name = name,
+        tests = tests,
+        # Note that only the manual tag really has any effect here. Others are
+        # used for test suite filtering, but all tests are passed the same tags.
+        tags = tags,
+    )
diff --git a/iree/modules/check/dialect/test/BUILD b/iree/modules/check/dialect/test/BUILD
index 429826c..544a942 100644
--- a/iree/modules/check/dialect/test/BUILD
+++ b/iree/modules/check/dialect/test/BUILD
@@ -12,17 +12,18 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-load("//iree:build_defs.oss.bzl", "iree_glob_lit_tests", "iree_setup_lit_package")
+load("//iree:lit_test.bzl", "iree_lit_test_suite")
 
 package(
     default_visibility = ["//visibility:public"],
     licenses = ["notice"],  # Apache 2.0
 )
 
-iree_setup_lit_package(
+iree_lit_test_suite(
+    name = "lit",
+    srcs = glob(["*.mlir"]),
     data = [
         "//iree/modules/check/dialect:check-opt",
+        "//iree/tools:IreeFileCheck",
     ],
 )
-
-iree_glob_lit_tests()
diff --git a/iree/samples/custom_modules/dialect/test/BUILD b/iree/samples/custom_modules/dialect/test/BUILD
index 9aabd15..9b910cf 100644
--- a/iree/samples/custom_modules/dialect/test/BUILD
+++ b/iree/samples/custom_modules/dialect/test/BUILD
@@ -12,17 +12,27 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-load("//iree:build_defs.oss.bzl", "iree_glob_lit_tests", "iree_setup_lit_package")
+load("//iree:lit_test.bzl", "iree_lit_test_suite")
 
 package(
     default_visibility = ["//visibility:public"],
     licenses = ["notice"],  # Apache 2.0
 )
 
-iree_setup_lit_package(
+iree_lit_test_suite(
+    name = "lit",
+    srcs = glob(["*.mlir"]),
     data = [
         "//iree/samples/custom_modules/dialect:custom-opt",
+        "//iree/tools:IreeFileCheck",
     ],
 )
-
-iree_glob_lit_tests()
+# load("//iree:lit_test.bzl", "iree_lit_test_suite")
+# iree_lit_test_suite(
+#     name = "lit",
+#     srcs = glob(["*.mlir"]),
+#     data = [
+#         "//iree/tools:IreeFileCheck",
+#         "//iree/samples/custom_modules/dialect:custom-opt",
+#     ],
+# )
diff --git a/test/e2e/xla/BUILD b/test/e2e/xla/BUILD
index ba1a3e4..f110356 100644
--- a/test/e2e/xla/BUILD
+++ b/test/e2e/xla/BUILD
@@ -14,17 +14,18 @@
 
 # Tests for end-to-end IREE support starting from the XLA HLO dialect.
 
-load("//iree:build_defs.oss.bzl", "iree_glob_lit_tests", "iree_setup_lit_package")
+load("//iree:lit_test.bzl", "iree_lit_test_suite")
 
 package(
     default_visibility = ["//visibility:public"],
     licenses = ["notice"],  # Apache 2.0
 )
 
-iree_setup_lit_package(
+iree_lit_test_suite(
+    name = "lit",
+    srcs = glob(["*.mlir"]),
     data = [
+        "//iree/tools:IreeFileCheck",
         "//iree/tools:iree-run-mlir",
     ],
 )
-
-iree_glob_lit_tests()