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/BUILD b/aos/BUILD
index a7d691b..286882f 100644
--- a/aos/BUILD
+++ b/aos/BUILD
@@ -466,7 +466,7 @@
         "configuration_test.cc",
     ],
     data = [
-        "//aos/events:pingpong_config.json",
+        "//aos/events:pingpong_config",
         "//aos/events:pong.bfbs",
         "//aos/testdata:test_configs",
     ],
diff --git a/aos/actions/BUILD b/aos/actions/BUILD
index 6276105..14592cf 100644
--- a/aos/actions/BUILD
+++ b/aos/actions/BUILD
@@ -58,7 +58,7 @@
     srcs = [
         "action_test.cc",
     ],
-    data = ["action_test_config.json"],
+    data = [":action_test_config"],
     deps = [
         ":action_lib",
         ":actions_fbs",
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,
 )
diff --git a/aos/events/BUILD b/aos/events/BUILD
index 5346647..902ca76 100644
--- a/aos/events/BUILD
+++ b/aos/events/BUILD
@@ -106,7 +106,7 @@
     srcs = [
         "ping.cc",
     ],
-    data = ["pingpong_config.json"],
+    data = [":pingpong_config"],
     deps = [
         ":ping_lib",
         ":shm_event_loop",
@@ -170,7 +170,7 @@
     srcs = [
         "pong.cc",
     ],
-    data = ["pingpong_config.json"],
+    data = [":pingpong_config"],
     deps = [
         ":ping_fbs",
         ":pong_fbs",
@@ -186,7 +186,7 @@
 cc_test(
     name = "pingpong_test",
     srcs = ["pingpong_test.cc"],
-    data = [":pingpong_config.json"],
+    data = [":pingpong_config"],
     deps = [
         ":ping_lib",
         ":pong_lib",
@@ -266,7 +266,7 @@
 cc_test(
     name = "simulated_event_loop_test",
     srcs = ["simulated_event_loop_test.cc"],
-    data = ["multinode_pingpong_config.json"],
+    data = [":multinode_pingpong_config"],
     shard_count = 4,
     deps = [
         ":event_loop_param_test",
diff --git a/aos/events/logging/BUILD b/aos/events/logging/BUILD
index c3af9e2..0fb4708 100644
--- a/aos/events/logging/BUILD
+++ b/aos/events/logging/BUILD
@@ -142,8 +142,8 @@
     name = "logger_test",
     srcs = ["logger_test.cc"],
     data = [
-        ":multinode_pingpong_config.json",
-        "//aos/events:pingpong_config.json",
+        ":multinode_pingpong_config",
+        "//aos/events:pingpong_config",
     ],
     deps = [
         ":logger",
diff --git a/aos/network/BUILD b/aos/network/BUILD
index f9fe7ea..65aff91 100644
--- a/aos/network/BUILD
+++ b/aos/network/BUILD
@@ -295,8 +295,8 @@
         "message_bridge_test.cc",
     ],
     data = [
-        ":message_bridge_test_client_config.json",
-        ":message_bridge_test_server_config.json",
+        ":message_bridge_test_client_config",
+        ":message_bridge_test_server_config",
     ],
     shard_count = 3,
     deps = [
diff --git a/aos/network/www/BUILD b/aos/network/www/BUILD
index 33291b2..60bea09 100644
--- a/aos/network/www/BUILD
+++ b/aos/network/www/BUILD
@@ -106,8 +106,8 @@
         ":flatbuffers",
         ":reflection_test.html",
         ":reflection_test_bundle",
-        ":test_config.json",
+        ":test_config",
         "//aos/network:web_proxy_main",
-        "//y2020:config.json",
+        "//y2020:config",
     ],
 )