bazel: Add platform-printing aspect
Change-Id: I3923b5bfcca1b4d840be25721250b2a89f5ff8af
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/122974
Reviewed-by: Erik Gilling <konkers@google.com>
Presubmit-Verified: CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed-service-accounts.iam.gserviceaccount.com>
Pigweed-Auto-Submit: Ted Pudlik <tpudlik@google.com>
diff --git a/pw_build/bazel_internal/pigweed_internal.bzl b/pw_build/bazel_internal/pigweed_internal.bzl
index ecfa834..6d1233c 100644
--- a/pw_build/bazel_internal/pigweed_internal.bzl
+++ b/pw_build/bazel_internal/pigweed_internal.bzl
@@ -153,3 +153,26 @@
toolchains = use_cpp_toolchain(),
fragments = ["cpp"],
)
+
+def _print_platform_impl(_, ctx):
+ if hasattr(ctx.rule.attr, "constraint_values"):
+ for cv in ctx.rule.attr.constraint_values:
+ # buildifier: disable=print
+ print(str(ctx.rule.attr.name) + " specifies " + str(cv))
+ return []
+
+print_platform = aspect(
+ implementation = _print_platform_impl,
+ attr_aspects = ["parents"],
+ doc = """
+ This is a little debug utility that traverses the platform inheritance
+ hierarchy and prints all the constraint values.
+
+ Example usage:
+
+ bazel build \
+ //pw_build/platforms:lm3s6965evb \
+ --aspects \
+ pw_build/bazel_internal/pigweed_internal.bzl%print_platform
+ """,
+)