Skip to content

Commit

Permalink
pw_bluetooth_sapphire: Audit Bazel and GN files for host/ subdirectories
Browse files Browse the repository at this point in the history
This CL examines and cleans up the BUILD.bazel and BUILD.gn files under
//pw_bluetooth_sapphire/host/... to fit match each other more closely
and follow Pigweed's best practices more closely. This includes:

1. Reorganizing GN targets to match the order in the GN style guide,
   then the order of corresponding Bazel targets.
2. Reduce the number of public dependencies.
3. Reduce the number of transitive dependencies. #IWYU
4. Add fuzzers from the GN build to the Bazel build.

Change-Id: Ie10021a83d9ab949163a1aa0b4e744b61e9ca44b
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/253892
Docs-Not-Needed: Aaron Green <[email protected]>
Reviewed-by: Ben Lawson <[email protected]>
Lint: Lint 🤖 <[email protected]>
Commit-Queue: Aaron Green <[email protected]>
  • Loading branch information
nopsledder authored and CQ Bot Account committed Jan 10, 2025
1 parent 224e2e3 commit a8c17c9
Show file tree
Hide file tree
Showing 38 changed files with 775 additions and 516 deletions.
11 changes: 3 additions & 8 deletions pw_bluetooth_sapphire/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,17 @@ package(default_visibility = ["//pw_bluetooth_sapphire:__subpackages__"])
cc_library(
name = "config",
srcs = [],
hdrs = [
"public/pw_bluetooth_sapphire/config.h",
],
defines = select({
"@platforms//os:fuchsia": [
"PW_BLUETOOTH_SAPPHIRE_INSPECT_ENABLED",
"PW_BLUETOOTH_SAPPHIRE_TRACE_ENABLED",
],
"//conditions:default": [],
}),
)

cc_library(
name = "public",
hdrs = [
"public/pw_bluetooth_sapphire/config.h",
],
strip_include_prefix = "public",
tags = ["manual"],
)

cc_library(
Expand Down
1 change: 1 addition & 0 deletions pw_bluetooth_sapphire/fuchsia/bt_hci_virtual/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ fuchsia_cc_test(
deps = [
":common",
"//pw_bluetooth_sapphire/host/testing:gtest_main",
"//pw_unit_test",
"@fuchsia_sdk//pkg/driver_testing_cpp",
],
)
Expand Down
1 change: 1 addition & 0 deletions pw_bluetooth_sapphire/fuchsia/host/fidl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ fuchsia_cc_test(
"//pw_bluetooth_sapphire/host/testing:fake_controller",
"//pw_bluetooth_sapphire/host/testing:gtest_main",
"//pw_bluetooth_sapphire/host/testing:loop_fixture",
"//pw_bluetooth_sapphire/host/testing:test_helpers",
],
)

Expand Down
1 change: 1 addition & 0 deletions pw_bluetooth_sapphire/fuchsia/host/socket/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ fuchsia_cc_test(
"//pw_bluetooth_sapphire/host/testing",
"//pw_bluetooth_sapphire/host/testing:gtest_main",
"//pw_bluetooth_sapphire/host/testing:loop_fixture",
"//pw_bluetooth_sapphire/host/testing:test_helpers",
"//pw_bluetooth_sapphire/host/transport:testing",
"@fuchsia_sdk//pkg/async-loop-cpp",
],
Expand Down
1 change: 1 addition & 0 deletions pw_bluetooth_sapphire/fuchsia/lib/fidl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ fuchsia_cc_test(
deps = [
":fidl",
"//pw_bluetooth_sapphire/host/testing:gtest_main",
"//pw_unit_test",
"@fuchsia_sdk//pkg/fidl_cpp",
],
)
Expand Down
12 changes: 9 additions & 3 deletions pw_bluetooth_sapphire/host/att/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
# License for the specific language governing permissions and limitations under
# the License.

load("@pigweed//pw_unit_test:pw_cc_test.bzl", "pw_cc_test")
load("//pw_unit_test:pw_cc_test.bzl", "pw_cc_test")

package(default_visibility = ["//visibility:public"])

# Basic target with protocol definitions and no logic, suitable for test
# emulation.
cc_library(
name = "definitions",
srcs = [
Expand Down Expand Up @@ -52,14 +54,17 @@ cc_library(
"public/pw_bluetooth_sapphire/internal/host/att/write_queue.h",
],
implementation_deps = [
"@pigweed//pw_string",
"//pw_preprocessor",
"//pw_string",
],
strip_include_prefix = "public",
deps = [
":definitions",
"//pw_async:dispatcher",
"//pw_bluetooth_sapphire/host/common",
"//pw_bluetooth_sapphire/host/l2cap",
"//pw_bluetooth_sapphire/host/sm:definitions",
"@pigweed//third_party/fuchsia:fit",
"//third_party/fuchsia:fit",
],
)

Expand All @@ -76,5 +81,6 @@ pw_cc_test(
deps = [
":att",
"//pw_bluetooth_sapphire/host/l2cap:testing",
"//pw_bluetooth_sapphire/host/testing:test_helpers",
],
)
37 changes: 22 additions & 15 deletions pw_bluetooth_sapphire/host/att/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,20 @@ config("public_include_path") {
# Basic target with protocol definitions and no logic, suitable for test
# emulation.
pw_source_set("definitions") {
sources = [ "packet.cc" ]
public = [
"public/pw_bluetooth_sapphire/internal/host/att/att.h",
"public/pw_bluetooth_sapphire/internal/host/att/packet.h",
]
sources = [ "packet.cc" ]
public_configs = [ ":public_include_path" ]
public_deps = [
"$dir_pw_bluetooth_sapphire/host/common",
"$dir_pw_bluetooth_sapphire/host/hci-spec",
"$dir_pw_bluetooth_sapphire/host/l2cap:definitions",
]
public_configs = [ ":public_include_path" ]
}

pw_source_set("att") {
public = [
"public/pw_bluetooth_sapphire/internal/host/att/attribute.h",
"public/pw_bluetooth_sapphire/internal/host/att/bearer.h",
"public/pw_bluetooth_sapphire/internal/host/att/database.h",
"public/pw_bluetooth_sapphire/internal/host/att/error.h",
"public/pw_bluetooth_sapphire/internal/host/att/permissions.h",
"public/pw_bluetooth_sapphire/internal/host/att/write_queue.h",
]
sources = [
"attribute.cc",
"bearer.cc",
Expand All @@ -52,30 +44,45 @@ pw_source_set("att") {
"permissions.cc",
"write_queue.cc",
]
public = [
"public/pw_bluetooth_sapphire/internal/host/att/attribute.h",
"public/pw_bluetooth_sapphire/internal/host/att/bearer.h",
"public/pw_bluetooth_sapphire/internal/host/att/database.h",
"public/pw_bluetooth_sapphire/internal/host/att/error.h",
"public/pw_bluetooth_sapphire/internal/host/att/permissions.h",
"public/pw_bluetooth_sapphire/internal/host/att/write_queue.h",
]
public_configs = [ ":public_include_path" ]
public_deps = [
":definitions",
"$dir_pw_async:dispatcher",
"$dir_pw_bluetooth_sapphire/host/common",
"$dir_pw_bluetooth_sapphire/host/l2cap",
"$dir_pw_bluetooth_sapphire/host/sm:definitions",
"$dir_pw_third_party/fuchsia:fit",
]
deps = [
"$dir_pw_preprocessor",
"$dir_pw_string",
dir_pw_preprocessor,
dir_pw_string,
]
public_configs = [ ":public_include_path" ]
}

pw_test("tests") {
pw_test("att_test") {
sources = [
"attribute_test.cc",
"bearer_test.cc",
"database_test.cc",
"error_test.cc",
"permissions_test.cc",
]
test_main = "$dir_pw_bluetooth_sapphire/host/testing:gtest_main"
deps = [
":att",
"$dir_pw_bluetooth_sapphire/host/l2cap:testing",
"$dir_pw_bluetooth_sapphire/host/testing:test_helpers",
]
test_main = "$dir_pw_bluetooth_sapphire/host/testing:gtest_main"
}

pw_test_group("tests") {
tests = [ ":att_test" ]
}
41 changes: 26 additions & 15 deletions pw_bluetooth_sapphire/host/common/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
# License for the specific language governing permissions and limitations under
# the License.

load("@pigweed//pw_unit_test:pw_cc_test.bzl", "pw_cc_test")
load("//pw_fuzzer:fuzzer.bzl", "pw_cc_fuzz_test")
load("//pw_unit_test:pw_cc_test.bzl", "pw_cc_test")

package(default_visibility = ["//visibility:public"])

Expand Down Expand Up @@ -69,6 +70,10 @@ cc_library(
"public/pw_bluetooth_sapphire/internal/host/common/weak_self.h",
"public/pw_bluetooth_sapphire/internal/host/common/windowed_inspect_numeric_property.h",
],
implementation_deps = [
"//pw_string",
"//pw_string:utf_codecs",
],
strip_include_prefix = "public",
# This library is not compatible with --config=rp2040.
target_compatible_with = select({
Expand All @@ -78,21 +83,20 @@ cc_library(
"//conditions:default": ["@platforms//:incompatible"],
}),
deps = [
"//pw_assert",
"//pw_async:dispatcher",
"//pw_async:task",
"//pw_bluetooth:emboss_hci",
"//pw_bluetooth_sapphire:config",
"//pw_bluetooth_sapphire:public",
"//pw_bluetooth_sapphire/lib/cpp-string",
"//pw_bluetooth_sapphire/lib/cpp-type",
"@pigweed//pw_assert",
"@pigweed//pw_async:dispatcher",
"@pigweed//pw_async:task",
"@pigweed//pw_bluetooth:emboss_hci",
"@pigweed//pw_intrusive_ptr",
"@pigweed//pw_log",
"@pigweed//pw_random",
"@pigweed//pw_span",
"@pigweed//pw_string",
"@pigweed//pw_string:utf_codecs",
"@pigweed//third_party/fuchsia:fit",
"//pw_chrono:system_clock",
"//pw_intrusive_ptr",
"//pw_log",
"//pw_preprocessor",
"//pw_random",
"//pw_span",
"//third_party/fuchsia:fit",
] + select({
"@platforms//os:fuchsia": [
"@fuchsia_sdk//pkg/inspect_component_cpp",
Expand All @@ -105,7 +109,7 @@ cc_library(
cc_library(
name = "uuid_string_util",
srcs = ["uuid_string_util.cc"],
deps = [":common"],
implementation_deps = [":common"],
)

pw_cc_test(
Expand Down Expand Up @@ -135,7 +139,14 @@ pw_cc_test(
deps = [
":common",
":uuid_string_util",
"//pw_async:fake_dispatcher_fixture",
"//pw_bluetooth_sapphire/host/testing",
"@pigweed//pw_async:fake_dispatcher_fixture",
"//pw_bluetooth_sapphire/host/testing:test_helpers",
],
)

pw_cc_fuzz_test(
name = "advertising_data_fuzzer",
srcs = ["advertising_data_fuzztest.cc"],
deps = [":common"],
)
64 changes: 34 additions & 30 deletions pw_bluetooth_sapphire/host/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@ config("public_include_path") {
}

pw_source_set("common") {
sources = [
"advertising_data.cc",
"bounded_inspect_list_node.cc",
"byte_buffer.cc",
"device_address.cc",
"device_class.cc",
"host_error.cc",
"identifier.cc",
"log.cc",
"manufacturer_names.cc",
"metrics.cc",
"random.cc",
"retire_log.cc",
"slab_allocator.cc",
"supplement_data.cc",
"uuid.cc",
]
public = [
"public/pw_bluetooth_sapphire/internal/host/common/advertising_data.h",
"public/pw_bluetooth_sapphire/internal/host/common/assert.h",
Expand Down Expand Up @@ -55,55 +72,41 @@ pw_source_set("common") {
"public/pw_bluetooth_sapphire/internal/host/common/weak_self.h",
"public/pw_bluetooth_sapphire/internal/host/common/windowed_inspect_numeric_property.h",
]
sources = [
"advertising_data.cc",
"bounded_inspect_list_node.cc",
"byte_buffer.cc",
"device_address.cc",
"device_class.cc",
"host_error.cc",
"identifier.cc",
"log.cc",
"manufacturer_names.cc",
"metrics.cc",
"random.cc",
"retire_log.cc",
"slab_allocator.cc",
"supplement_data.cc",
"uuid.cc",
]
public_configs = [ ":public_include_path" ]
public_deps = [
"$dir_pw_assert",
"$dir_pw_async:dispatcher",
"$dir_pw_async:task",
"$dir_pw_bluetooth:emboss_hci_group",
"$dir_pw_bluetooth_sapphire:config",
"$dir_pw_bluetooth_sapphire/lib/cpp-string",
"$dir_pw_bluetooth_sapphire/lib/cpp-type",
"$dir_pw_intrusive_ptr",
"$dir_pw_log",
"$dir_pw_random",
"$dir_pw_span",
"$dir_pw_string",
"$dir_pw_string:utf_codecs",
"$dir_pw_chrono:system_clock",
"$dir_pw_third_party/fuchsia:fit",
dir_pw_assert,
dir_pw_intrusive_ptr,
dir_pw_log,
dir_pw_preprocessor,
dir_pw_random,
dir_pw_span,
]
if (current_os == "fuchsia") {
public_deps += [
"//sdk/lib/sys/inspect/cpp",
"//zircon/system/ulib/trace",
]
}
public_configs = [ ":public_include_path" ]
deps = [ "$dir_pw_preprocessor" ]
deps = [
"$dir_pw_string:utf_codecs",
dir_pw_preprocessor,
]
}

pw_source_set("uuid_string_util") {
sources = [ "uuid_string_util.cc" ]
public_deps = [ ":common" ]
deps = [ ":common" ]
}

pw_test("common_tests") {
pw_test("common_test") {
sources = [
"advertising_data_test.cc",
"bounded_inspect_list_node_test.cc",
Expand All @@ -125,13 +128,14 @@ pw_test("common_tests") {
"weak_self_test.cc",
"windowed_inspect_numeric_property_test.cc",
]
test_main = "$dir_pw_bluetooth_sapphire/host/testing:gtest_main"
deps = [
":common",
":uuid_string_util",
"$dir_pw_async:fake_dispatcher_fixture",
"$dir_pw_bluetooth_sapphire/host/testing",
"$dir_pw_bluetooth_sapphire/host/testing:test_helpers",
]
test_main = "$dir_pw_bluetooth_sapphire/host/testing:gtest_main"
}

pw_fuzzer("advertising_data_fuzzer") {
Expand All @@ -141,7 +145,7 @@ pw_fuzzer("advertising_data_fuzzer") {

pw_test_group("tests") {
tests = [
":common_tests",
":common_test",
":advertising_data_fuzzer_test",
]
}
Loading

0 comments on commit a8c17c9

Please sign in to comment.