aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYifan Hong <elsk@google.com>2023-12-13 01:55:20 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-12-13 01:55:20 +0000
commit024cd9ef4e4648ba32eca318043b289753769f32 (patch)
tree6fb7c09527a3029ea70f70e60f50be247eaee558
parent6cc67207794dc1aa61995030b740a85541ea9bb8 (diff)
parent922646c2d60f55d42f456638536dd309c7a98e51 (diff)
downloadbazel_common_rules-024cd9ef4e4648ba32eca318043b289753769f32.tar.gz
docs: Allow srcs in a different pkg am: af2a7a2f0d am: a1af63aa98 am: 922646c2d6
Original change: https://android-review.googlesource.com/c/platform/build/bazel_common_rules/+/2865912 Change-Id: Ifc6e226ee6f203e4b69adeec6bd29f71889f27fd Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--docs/docs.bzl23
1 files changed, 17 insertions, 6 deletions
diff --git a/docs/docs.bzl b/docs/docs.bzl
index e770fb6..50097d2 100644
--- a/docs/docs.bzl
+++ b/docs/docs.bzl
@@ -12,9 +12,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-load("//build/bazel_common_rules/dist:dist.bzl", "copy_to_dist_dir")
-load("@io_bazel_stardoc//stardoc:stardoc.bzl", "stardoc")
+"""Generate bare-bones docs with Stardoc"""
+
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
+load("@io_bazel_stardoc//stardoc:stardoc.bzl", "stardoc")
+load("//build/bazel_common_rules/dist:dist.bzl", "copy_to_dist_dir")
+
+def _sanitize_label_as_filename(label):
+ """Sanitize a Bazel label so it is safe to be used as a filename."""
+ label_text = str(label)
+ return _normalize(label_text)
+
+def _normalize(s):
+ """Returns a normalized string by replacing non-letters / non-numbers as underscores."""
+ return "".join([c if c.isalnum() else "_" for c in s.elems()])
# TODO: Add aspect_template when necessary
def docs(
@@ -68,15 +79,15 @@ def docs(
all_markdown_files = []
for src in srcs:
stardoc(
- name = name + "-" + src,
- out = name + "/" + src,
+ name = name + "-" + _sanitize_label_as_filename(src),
+ out = name + "/" + _sanitize_label_as_filename(src),
input = src,
deps = [":" + name + "_deps"],
func_template = func_template,
provider_template = provider_template,
rule_template = rule_template,
)
- all_markdown_files.append((name + "/" + src, src))
+ all_markdown_files.append((name + "/" + _sanitize_label_as_filename(src), src))
native.filegroup(
name = name + "_markdown_files",
@@ -84,7 +95,7 @@ def docs(
)
default_file_cmd = """touch $@ && """
- for target, src in all_markdown_files:
+ for src in srcs:
if default == src:
default_file_cmd += """echo '<div hidden><a href="#{src}" id="default_file">{src}</a></div>' >> $@ &&""".format(
src = src,