initial checkin of skydoc skylark rule
diff --git a/BUILD b/BUILD index a8f9c00..70f0b5b 100644 --- a/BUILD +++ b/BUILD
@@ -3,6 +3,7 @@ package(default_visibility = ["//visibility:public"]) load("//:skylark_library.bzl", "skylark_library") +load("//:skydoc.bzl", "skydoc") exports_files([ "LICENSE", @@ -41,3 +42,12 @@ name = "skylark_library", srcs = ["skylark_library.bzl"], ) + +skydoc( + name = "skydoc_doc", + target_file = ":skydoc.bzl", + deps = [":skylark_library"], + rule_names = ["skydoc"], + out = "skydoc_doc.txt", +) +
diff --git a/WORKSPACE b/WORKSPACE index 5458cd5..9a3d36d 100644 --- a/WORKSPACE +++ b/WORKSPACE
@@ -1 +1,13 @@ workspace(name = "bazel_skylib") + +git_repository( + name = "io_bazel", + remote = "https://github.com/bazelbuild/bazel.git", + commit = "6964a0b68444333ed13a355a7f6799adb931b4aa", +) + +http_archive( + name = "com_google_protobuf", + strip_prefix = "protobuf-3.5.1", + urls = ["https://github.com/google/protobuf/archive/v3.5.1.zip"], +)
diff --git a/skydoc.bzl b/skydoc.bzl new file mode 100644 index 0000000..f53e209 --- /dev/null +++ b/skydoc.bzl
@@ -0,0 +1,64 @@ +"""Rules for generating skylark documentation""" + +load(":skylark_library.bzl", "SkylarkLibraryInfo") + +def _skydoc_impl(ctx): + """Implementation of the skydoc rule.""" + out_file = ctx.outputs.out + input_files = depset(order = "postorder", direct = [ctx.files.target_file[0]], transitive = [ + dep[SkylarkLibraryInfo].transitive_srcs + for dep in ctx.attr.deps + ]) + args = [ + str(ctx.files.target_file[0].owner), + ctx.outputs.out.path, + ] + ctx.attr.rule_names + skydoc = ctx.executable.skydoc + + ctx.actions.run( + outputs = [out_file], + inputs = input_files, + executable = skydoc, + arguments = args, + mnemonic = "Skydoc", + progress_message = ("Generating Skylark doc for %s" % + (ctx.label.name)), + ) + +skydoc = rule( + _skydoc_impl, + doc = """ +Generates documentation for exported skylark rule definitions in a target skylark file. +""", + attrs = { + "target_file": attr.label( + doc = "The skylark file to generate documentation for.", + allow_files = [".bzl"], + ), + "deps": attr.label_list( + doc = "A list of skylark_library dependencies which target_file depends on.", + providers = [SkylarkLibraryInfo], + allow_files = False, + ), + "out": attr.output( + doc = "The file to which documentation will be output.", + mandatory = True, + ), + "rule_names": attr.string_list( + doc = """ +A list of rule names to generate documentation for. These should correspond to +the names of exported symbols for rule definitions in the target file. If this list +is empty, then documentation for all exported rule definitions will be generated. +""", + default = [], + ), + "skydoc": attr.label( + doc = "The location of the skydoc tool.", + allow_files = True, + default = Label("@io_bazel//src/main/java/com/google/devtools/build/skydoc"), + cfg = "host", + executable = True, + ), + }, +) +