Depend on config rule instead of file.
The aos_config rule used to require you to depend on {name}.json to get
the output. That was weird and hid private/testonly/etc. Instead,
depend on the rule directly.
Change-Id: I1596a6c1f44b246a0db1bbc562468530a0b69614
diff --git a/aos/config.bzl b/aos/config.bzl
index d6dcf1e..8f040d6 100644
--- a/aos/config.bzl
+++ b/aos/config.bzl
@@ -5,16 +5,20 @@
"transitive_src",
])
-def aos_config(name, src, flatbuffers = [], deps = [], visibility = None):
+def aos_config(name, src, flatbuffers = [], deps = [], visibility = None, testonly = False):
_aos_config(
name = name,
src = src,
deps = deps,
flatbuffers = [expand_label(flatbuffer) + "_reflection_out" for flatbuffer in flatbuffers],
visibility = visibility,
+ testonly = testonly,
)
def _aos_config_impl(ctx):
+ config = ctx.actions.declare_file(ctx.label.name + ".json")
+ stripped_config = ctx.actions.declare_file(ctx.label.name + ".stripped.json")
+
flatbuffers_depset = depset(
ctx.files.flatbuffers,
transitive = [dep[AosConfigInfo].transitive_flatbuffers for dep in ctx.attr.deps],
@@ -27,16 +31,23 @@
all_files = flatbuffers_depset.to_list() + src_depset.to_list()
ctx.actions.run(
- outputs = [ctx.outputs.config, ctx.outputs.stripped_config],
+ outputs = [config, stripped_config],
inputs = all_files,
- arguments = [ctx.outputs.config.path, ctx.outputs.stripped_config.path, ctx.files.src[0].short_path, ctx.bin_dir.path] + [f.path for f in flatbuffers_depset.to_list()],
+ arguments = [config.path, stripped_config.path, ctx.files.src[0].short_path, ctx.bin_dir.path] + [f.path for f in flatbuffers_depset.to_list()],
progress_message = "Flattening config",
executable = ctx.executable._config_flattener,
)
- return AosConfigInfo(
- transitive_flatbuffers = flatbuffers_depset,
- transitive_src = src_depset,
- )
+ runfiles = ctx.runfiles(files = [config, stripped_config])
+ return [
+ DefaultInfo(
+ files = depset([config, stripped_config]),
+ runfiles = runfiles,
+ ),
+ AosConfigInfo(
+ transitive_flatbuffers = flatbuffers_depset,
+ transitive_src = src_depset,
+ ),
+ ]
_aos_config = rule(
attrs = {
@@ -56,9 +67,5 @@
mandatory = False,
),
},
- outputs = {
- "config": "%{name}.json",
- "stripped_config": "%{name}.stripped.json",
- },
implementation = _aos_config_impl,
)