Path: blob/trunk/java/rules_jvm_external_javadoc.patch
2864 views
diff --git a/private/rules/javadoc.bzl b/private/rules/javadoc.bzl1index 9b90570..c9b6f09 1006442--- a/private/rules/javadoc.bzl3+++ b/private/rules/javadoc.bzl4@@ -12,10 +12,43 @@ def generate_javadoc(ctx, javadoc, source_jars, classpath, javadocopts, output):5arguments = [args],6)78+def _get_prefix_strings(third_party_prefixes):9+ path_prefixes = []10+ for prefix in third_party_prefixes:11+ if prefix.find(":") != -1:12+ fail("Target prefixes may only contain paths, not specific targets: %s" % prefix)13+14+ if prefix.startswith("@"):15+ if len(prefix) > 1:16+ path_prefixes.append("external/%s" % prefix[1:].replace("//", "/"))17+ else:18+ # Allow all external dependencies to be ignored19+ path_prefixes.append("external/")20+ elif prefix.startswith("//"):21+ if len(prefix) < 3:22+ fail("Prefixes for targets within this workspace must contain a path")23+ path_prefixes.append(prefix[2:])24+25+ # Now we have the prefixes, ensure that they do not end with a slash26+ return [path[:-1] if path.endswith("/") else path for path in path_prefixes]27+28+def _path_match(file, prefixes):29+ short_path = file.dirname[len(file.root.path) + 1:]30+31+ for prefix in prefixes:32+ if short_path.startswith(prefix):33+ return True34+ return False35+36def _javadoc_impl(ctx):37+ path_prefixes = _get_prefix_strings(ctx.attr.third_party_prefixes)38sources = []39+40for dep in ctx.attr.deps:41- sources.extend(dep[JavaInfo].source_jars)42+ dep_srcs = dep[JavaInfo].transitive_source_jars.to_list() if ctx.attr.transitive else dep[JavaInfo].source_jars43+ for jar in dep_srcs:44+ if not _path_match(jar, path_prefixes):45+ sources.append(jar)4647jar_file = ctx.actions.declare_file("%s.jar" % ctx.attr.name)4849@@ -41,13 +74,23 @@ javadoc = rule(50doc = """The java libraries to generate javadocs for.5152The source jars of each dep will be used to generate the javadocs.53- Currently docs for transitive dependencies are not generated.54+ By default docs for transitive dependencies are not generated.55""",56mandatory = True,57providers = [58[JavaInfo],59],60),61+ "transitive": attr.bool(62+ doc = "Whether to generate docs for transitive dependencies too.",63+ default = False,64+ ),65+ "third_party_prefixes": attr.string_list(66+ doc = """Label prefixes to exclude from javadoc generation. This designed67+ to allow merging of all first party javadocs into a single jar whilst not68+ including any javadocs for third party packages the code may depend on.""",69+ default = ["@maven//"],70+ ),71"javadocopts": attr.string_list(72doc = """javadoc options.73Note sources and classpath are derived from the deps. Any additional747576