[PATCH] D106922: [Bazel] Make td_library usable as data
Geoffrey Martin-Noble via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 27 15:43:00 PDT 2021
GMNGeoffrey created this revision.
Herald added subscribers: dcaballe, cota, teijeong, rdzhabarov, tatianashp, msifontes, jurahul, Kayjukh, grosul1, Joonsoo, liufengdb, aartbik, lucyrfox, mgester, arpith-jacob, antiagainst, shauheen, rriddle, mehdi_amini.
GMNGeoffrey requested review of this revision.
Herald added subscribers: llvm-commits, stephenneuendorffer, nicolasvasilache.
Herald added a project: LLVM.
This patch makes it possible to list a td_library as a rule's data
attribute and get its source files and all its transitive dependencies
at runtime. This is useful for, e.g. shell tests running tblgen.
Note that this is a bit different from how a "normal" (e.g. C++) library
rule would work because those have actual library outputs because the
td_library rule just bundles some source files and includes. If someone
wanted to make use of the includes, they would have to access the TdInfo
provider, but this keeps simple things simple.
Repository:
rG LLVM Github Monorepo
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 on the 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.362207.patch
Type: text/x-patch
Size: 2682 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210727/92830754/attachment-0001.bin>
More information about the llvm-commits
mailing list