mirror of
https://github.com/intel/llvm.git
synced 2026-01-20 01:58:44 +08:00
[bazel] Add support for multiple tblgen outputs (#168158)
Required after https://github.com/llvm/llvm-project/pull/167700 This adds yet another format for `tbl_outs` where you pass the list of opts, and a list of outputs (where previously you could only have 1 output). In that case all outputs must be produced, but the first is used for the `-o` arg since tblgen is generating the other names based on that single argument.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -153,7 +153,7 @@ def _gentbl_rule_impl(ctx):
|
||||
args.add("-o", ctx.outputs.out)
|
||||
|
||||
ctx.actions.run(
|
||||
outputs = [ctx.outputs.out],
|
||||
outputs = [ctx.outputs.out] + ctx.outputs.additional_outputs,
|
||||
inputs = trans_srcs,
|
||||
executable = ctx.executable.tblgen,
|
||||
execution_requirements = {"supports-path-mapping": "1"},
|
||||
@@ -195,6 +195,9 @@ gentbl_rule = rule(
|
||||
doc = "The output file for the TableGen invocation.",
|
||||
mandatory = True,
|
||||
),
|
||||
"additional_outputs": attr.output_list(
|
||||
doc = "Extra output files from the TableGen invocation. The primary 'out' is used for the -o argument.",
|
||||
),
|
||||
"opts": attr.string_list(
|
||||
doc = "Additional command line options to add to the TableGen" +
|
||||
" invocation. For include arguments, prefer to use" +
|
||||
@@ -313,9 +316,12 @@ def gentbl_filegroup(
|
||||
name: The name of the generated filegroup rule for use in dependencies.
|
||||
tblgen: The binary used to produce the output.
|
||||
td_file: The primary table definitions file.
|
||||
tbl_outs: Either a dict {out: [opts]} or a list of tuples ([opts], out),
|
||||
where each 'opts' is a list of options passed to tblgen, each option
|
||||
being a string, and 'out' is the corresponding output file produced.
|
||||
tbl_outs: Either a dict {out: [opts]}, a list of tuples ([opts], out),
|
||||
or a list of tuples ([opts], [outs]). Each 'opts' is a list of options
|
||||
passed to tblgen, each option being a string,
|
||||
and 'out' is the corresponding output file produced. If 'outs' are used,
|
||||
the first path in the list is passed to '-o' but tblgen is expected
|
||||
to produce all listed outputs.
|
||||
td_srcs: See gentbl_rule.td_srcs
|
||||
includes: See gentbl_rule.includes
|
||||
deps: See gentbl_rule.deps
|
||||
@@ -325,9 +331,14 @@ def gentbl_filegroup(
|
||||
**kwargs: Extra keyword arguments to pass to all generated rules.
|
||||
"""
|
||||
|
||||
included_srcs = []
|
||||
if type(tbl_outs) == type({}):
|
||||
tbl_outs = [(v, k) for k, v in tbl_outs.items()]
|
||||
for (opts, out) in tbl_outs:
|
||||
for (opts, output_or_outputs) in tbl_outs:
|
||||
outs = output_or_outputs if type(output_or_outputs) == type([]) else [output_or_outputs]
|
||||
out = outs[0]
|
||||
if not any([skip_opt in opts for skip_opt in skip_opts]):
|
||||
included_srcs.extend(outs)
|
||||
first_opt = opts[0] if opts else ""
|
||||
rule_suffix = "_{}_{}".format(
|
||||
first_opt.replace("-", "_").replace("=", "_"),
|
||||
@@ -343,6 +354,7 @@ def gentbl_filegroup(
|
||||
deps = deps,
|
||||
includes = includes,
|
||||
out = out,
|
||||
additional_outputs = outs[1:],
|
||||
**kwargs
|
||||
)
|
||||
|
||||
@@ -364,7 +376,6 @@ def gentbl_filegroup(
|
||||
**kwargs
|
||||
)
|
||||
|
||||
included_srcs = [f for (opts, f) in tbl_outs if not any([skip_opt in opts for skip_opt in skip_opts])]
|
||||
native.filegroup(
|
||||
name = name,
|
||||
srcs = included_srcs,
|
||||
|
||||
Reference in New Issue
Block a user