Rule fuzzing_dictionary() (#52)

Rule fuzzing_dictionary()

Invokes validate_dict to validate and merge dictionaries

Signed-off-by: tengpeng <tengpeng.li2020@gmail.com>

	modified:   fuzzing/common.bzl
diff --git a/fuzzing/common.bzl b/fuzzing/common.bzl
index 9306a32..04d079a 100644
--- a/fuzzing/common.bzl
+++ b/fuzzing/common.bzl
@@ -99,3 +99,48 @@
         ),
     },
 )
+
+def _fuzzing_dictionary_impl(ctx):
+    output_dict = ctx.actions.declare_file(ctx.attr.output)
+    args = ctx.actions.args()
+    args.add_joined("--dict_list", ctx.files.dicts, join_with = ",")
+    args.add("--output_file=" + output_dict.path)
+
+    ctx.actions.run(
+        inputs = ctx.files.dicts,
+        outputs = [output_dict],
+        arguments = [args],
+        executable = ctx.executable._validation_tool,
+    )
+
+    runfiles = ctx.runfiles(files = [output_dict])
+    runfiles.merge(ctx.attr._validation_tool[DefaultInfo].default_runfiles)
+
+    return [DefaultInfo(
+        runfiles = runfiles,
+        files = depset([output_dict]),
+    )]
+
+fuzzing_dictionary = rule(
+    implementation = _fuzzing_dictionary_impl,
+    doc = """
+Rule to validate the fuzzing dictionaries and output a merged dictionary.
+""",
+    attrs = {
+        "_validation_tool": attr.label(
+            default = Label("//fuzzing/tools:validate_dict"),
+            doc = "The tool script to validate and merge the dictionaries.",
+            executable = True,
+            cfg = "host",
+        ),
+        "dicts": attr.label_list(
+            doc = "The fuzzing dictionaries.",
+            allow_files = True,
+            mandatory = True,
+        ),
+        "output": attr.string(
+            doc = "The name of the merged dictionary.",
+            mandatory = True,
+        ),
+    },
+)