From 7af59d46b1e5caab21ce29da744ac295bad875a2 Mon Sep 17 00:00:00 2001 From: Ted Pudlik Date: Mon, 10 Feb 2025 13:29:05 -0800 Subject: [PATCH] pw_unit_test: Standardize Bazel interface MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Use only //pw_unit_test:pw_unit_test to expose framework.h. * Provide a dependency on this target automatically to any pw_cc_test. The latter change is made via an alias, to avoid breaking any users who already have an explicit dep on this target in their pw_cc_test. (Trying to remove this dep from the list of deps is unreliable, because the deps may include select statements.) In subsequent CLs, I'll remove all explicit deps on //pw_unit_test:pw_unit_test, and clean up the alias. Bug: 390709187 Change-Id: Id3d18ddfd94e69cb51a4f7ff3485c237b85a0dbf Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/261395 Lint: Lint 🤖 Reviewed-by: Armando Montanez Presubmit-Verified: CQ Bot Account Commit-Queue: Ted Pudlik Docs-Not-Needed: Ted Pudlik --- pw_unit_test/BUILD.bazel | 14 ++++++++------ pw_unit_test/pw_cc_test.bzl | 8 ++++---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/pw_unit_test/BUILD.bazel b/pw_unit_test/BUILD.bazel index bfea61359..17f1e099b 100644 --- a/pw_unit_test/BUILD.bazel +++ b/pw_unit_test/BUILD.bazel @@ -63,6 +63,13 @@ pw_facade( deps = [":status_macros"], ) +# TODO: https://pwbug.dev/390709187 - Remove this alias once no pw_cc_test has +# an explicit direct dependency on //pw_unit_test. +alias( + name = "pw_unit_test_alias_for_migration_only", + actual = "pw_unit_test", +) + label_flag( name = "backend", build_setting_default = ":light", @@ -89,21 +96,16 @@ cc_library( srcs = ["framework_light.cc"], hdrs = [ "light_public_overrides/pw_unit_test/framework_backend.h", - # The facade header is included here since - # public_overrides/gtest/gtest.h includes it. This avoids a circular - # dependency in the build system. - "public/pw_unit_test/framework.h", "public_overrides/gtest/gtest.h", ], includes = [ "light_public_overrides", - "public", "public_overrides", ], deps = [ ":config", ":event_handler", - ":status_macros", + ":pw_unit_test.facade", "//pw_assert", "//pw_bytes:alignment", "//pw_polyfill", diff --git a/pw_unit_test/pw_cc_test.bzl b/pw_unit_test/pw_cc_test.bzl index 1c04a8563..17ac22842 100644 --- a/pw_unit_test/pw_cc_test.bzl +++ b/pw_unit_test/pw_cc_test.bzl @@ -34,10 +34,10 @@ def pw_cc_test(**kwargs): Args: **kwargs: Passed to cc_test. """ - kwargs["deps"] = kwargs.get("deps", []) + [str(Label("//pw_build:default_link_extra_lib"))] - - # Depend on the backend. E.g. to pull in gtest.h include paths. - kwargs["deps"] = kwargs["deps"] + [str(Label("//pw_unit_test:backend"))] + kwargs["deps"] = kwargs.get("deps", []) + [ + str(Label("//pw_build:default_link_extra_lib")), + str(Label("//pw_unit_test:pw_unit_test_alias_for_migration_only")), + ] # Save the base set of deps minus pw_unit_test:main for the .lib target. original_deps = kwargs["deps"]