[PATCH] D106922: [Bazel] Make td_library usable as data

Geoffrey Martin-Noble via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 29 10:48:15 PDT 2021


GMNGeoffrey updated this revision to Diff 362825.
GMNGeoffrey added a comment.
Herald added a subscriber: Chia-hungDuan.

Rebase on main


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106922/new/

https://reviews.llvm.org/D106922

Files:
  utils/bazel/llvm-project-overlay/mlir/tblgen.bzl


Index: utils/bazel/llvm-project-overlay/mlir/tblgen.bzl
===================================================================
--- utils/bazel/llvm-project-overlay/mlir/tblgen.bzl
+++ utils/bazel/llvm-project-overlay/mlir/tblgen.bzl
@@ -100,8 +100,21 @@
         _resolve_includes(ctx, ctx.attr.includes),
         ctx.attr.deps,
     )
+
+    # Note that we include srcs in runfiles. A td_library doesn't compile to
+    # produce an output: it's just a depset of source files and include
+    # directories. So if it is needed for execution of some rule (likely
+    # something running tblgen as a test action), the files needed are the same
+    # as the source files.
+    # Note: not using merge_all, as that is not available in Bazel 4.0
+    runfiles = ctx.runfiles(ctx.files.srcs)
+    for src in ctx.attr.srcs:
+        runfiles = runfiles.merge(src[DefaultInfo].default_runfiles)
+    for dep in ctx.attr.deps:
+        runfiles = runfiles.merge(dep[DefaultInfo].default_runfiles)
+
     return [
-        DefaultInfo(files = trans_srcs),
+        DefaultInfo(files = trans_srcs, runfiles = runfiles),
         TdInfo(
             transitive_sources = trans_srcs,
             transitive_includes = trans_includes,
@@ -224,11 +237,6 @@
 def _gentbl_test_impl(ctx):
     td_file = ctx.file.td_file
 
-    trans_srcs = _get_transitive_srcs(
-        ctx.files.td_srcs + [td_file],
-        ctx.attr.deps,
-    )
-
     # Note that we have two types of includes here. The deprecated ones expanded
     # only by "_prefix_roots" are already relative to the execution root, i.e.
     # may contain an `external/<workspace_name>` prefix if the current workspace
@@ -256,18 +264,26 @@
         is_executable = True,
     )
 
+    # Note: not using merge_all, as that is not available in Bazel 4.0
+    runfiles = ctx.runfiles(
+        files = [ctx.executable.tblgen],
+        transitive_files = _get_transitive_srcs(
+            ctx.files.td_srcs + [td_file],
+            ctx.attr.deps,
+        ),
+    )
+    for src in ctx.attr.td_srcs:
+        runfiles = runfiles.merge(src[DefaultInfo].default_runfiles)
+    for dep in ctx.attr.deps:
+        runfiles = runfiles.merge(dep[DefaultInfo].default_runfiles)
+
     return [
         coverage_common.instrumented_files_info(
             ctx,
             source_attributes = ["td_file", "td_srcs"],
             dependency_attributes = ["tblgen", "deps"],
         ),
-        DefaultInfo(
-            runfiles = ctx.runfiles(
-                [ctx.executable.tblgen],
-                transitive_files = trans_srcs,
-            ),
-        ),
+        DefaultInfo(runfiles = runfiles),
     ]
 
 gentbl_test = rule(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106922.362825.patch
Type: text/x-patch
Size: 2678 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210729/758930ea/attachment.bin>


More information about the llvm-commits mailing list