Skip to content

Commit

Permalink
pw_thread: Fix support for multiple facades in the same module
Browse files Browse the repository at this point in the history
Change-Id: I754ecb9a8f0c6ad6ba23c7fe362e33a17882798d
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/114770
Reviewed-by: Wyatt Hepler <hepler@google.com>
Commit-Queue: Yvonne Yip <ykyyip@google.com>
  • Loading branch information
Yvonne Yip authored and CQ Bot Account committed Oct 14, 2022
1 parent 043d70a commit 8ff95d1
Show file tree
Hide file tree
Showing 35 changed files with 197 additions and 110 deletions.
22 changes: 22 additions & 0 deletions docs/module_structure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,28 @@ The GN build system provides the
:ref:`pw_facade template<module-pw_build-facade>` as a convenient way to declare
facades.

Multiple Facades
~~~~~~~~~~~~~~~~
A module may contain multiple facades. Each facade's public override headers
must be contained in separate folders in the backend implementation, so that
it's possible to use multiple backends for a module.

.. code-block::
# pw_foo contains 2 facades, foo and bar
pw_foo/...
# Public headers
# public/pw_foo/foo.h #includes pw_foo_backend/foo.h
# public/pw_foo/bar.h #includes pw_foo_backend/bar.h
public/pw_foo/foo.h
public/pw_foo/bar.h
pw_foo_backend/...
# Public override headers for facade1 and facade2 go in separate folders
foo_public_overrides/pw_foo_backend/foo.h
bar_public_overrides/pw_foo_backend/bar.h
Documentation
-------------
Documentation should go in the root module folder, typically in the
Expand Down
20 changes: 10 additions & 10 deletions pw_thread_embos/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ licenses(["notice"])
pw_cc_library(
name = "id_headers",
hdrs = [
"id_public_overrides/pw_thread_backend/id_inline.h",
"id_public_overrides/pw_thread_backend/id_native.h",
"public/pw_thread_embos/id_inline.h",
"public/pw_thread_embos/id_native.h",
"public_overrides/pw_thread_backend/id_inline.h",
"public_overrides/pw_thread_backend/id_native.h",
],
includes = [
"id_public_overrides",
"public",
"public_overrides",
],
)

Expand All @@ -49,11 +49,11 @@ pw_cc_library(
name = "sleep_headers",
hdrs = [
"public/pw_thread_embos/sleep_inline.h",
"public_overrides/pw_thread_backend/sleep_inline.h",
"sleep_public_overrides/pw_thread_backend/sleep_inline.h",
],
includes = [
"public",
"public_overrides",
"sleep_public_overrides",
],
deps = [
"//pw_chrono:system_clock",
Expand Down Expand Up @@ -85,12 +85,12 @@ pw_cc_library(
"public/pw_thread_embos/options.h",
"public/pw_thread_embos/thread_inline.h",
"public/pw_thread_embos/thread_native.h",
"public_overrides/pw_thread_backend/thread_inline.h",
"public_overrides/pw_thread_backend/thread_native.h",
"thread_public_overrides/pw_thread_backend/thread_inline.h",
"thread_public_overrides/pw_thread_backend/thread_native.h",
],
includes = [
"public",
"public_overrides",
"thread_public_overrides",
],
deps = [
":id",
Expand Down Expand Up @@ -133,11 +133,11 @@ pw_cc_library(
name = "yield_headers",
hdrs = [
"public/pw_thread_embos/yield_inline.h",
"public_overrides/pw_thread_backend/yield_inline.h",
"yield_public_overrides/pw_thread_backend/yield_inline.h",
],
includes = [
"public",
"public_overrides",
"yield_public_overrides",
],
# TODO(b/234876414): This should depend on embOS but our third parties
# currently do not have Bazel support.
Expand Down
39 changes: 27 additions & 12 deletions pw_thread_embos/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ config("public_include_path") {
visibility = [ ":*" ]
}

config("backend_config") {
include_dirs = [ "public_overrides" ]
config("id_public_overrides") {
include_dirs = [ "id_public_overrides" ]
visibility = [ ":*" ]
}

Expand All @@ -52,18 +52,18 @@ pw_source_set("config") {
pw_source_set("id") {
public_configs = [
":public_include_path",
":backend_config",
":id_public_overrides",
]
public_deps = [
"$dir_pw_assert",
"$dir_pw_interrupt:context",
"$dir_pw_third_party/embos",
]
public = [
"id_public_overrides/pw_thread_backend/id_inline.h",
"id_public_overrides/pw_thread_backend/id_native.h",
"public/pw_thread_embos/id_inline.h",
"public/pw_thread_embos/id_native.h",
"public_overrides/pw_thread_backend/id_inline.h",
"public_overrides/pw_thread_backend/id_native.h",
]
deps = [ "$dir_pw_thread:id.facade" ]
}
Expand All @@ -78,15 +78,20 @@ pw_build_assert("check_system_clock_backend") {
}

if (pw_chrono_SYSTEM_CLOCK_BACKEND != "" && pw_thread_SLEEP_BACKEND != "") {
config("sleep_public_overrides") {
include_dirs = [ "sleep_public_overrides" ]
visibility = [ ":*" ]
}

# This target provides the backend for pw::thread::sleep_{for,until}.
pw_source_set("sleep") {
public_configs = [
":public_include_path",
":backend_config",
":sleep_public_overrides",
]
public = [
"public/pw_thread_embos/sleep_inline.h",
"public_overrides/pw_thread_backend/sleep_inline.h",
"sleep_public_overrides/pw_thread_backend/sleep_inline.h",
]
public_deps = [ "$dir_pw_chrono:system_clock" ]
sources = [ "sleep.cc" ]
Expand All @@ -101,12 +106,17 @@ if (pw_chrono_SYSTEM_CLOCK_BACKEND != "" && pw_thread_SLEEP_BACKEND != "") {
}
}

config("thread_public_overrides") {
include_dirs = [ "thread_public_overrides" ]
visibility = [ ":*" ]
}

# This target provides the backend for pw::thread::Thread and the headers needed
# for thread creation.
pw_source_set("thread") {
public_configs = [
":public_include_path",
":backend_config",
":thread_public_overrides",
]
public_deps = [
":config",
Expand All @@ -122,22 +132,27 @@ pw_source_set("thread") {
"public/pw_thread_embos/options.h",
"public/pw_thread_embos/thread_inline.h",
"public/pw_thread_embos/thread_native.h",
"public_overrides/pw_thread_backend/thread_inline.h",
"public_overrides/pw_thread_backend/thread_native.h",
"thread_public_overrides/pw_thread_backend/thread_inline.h",
"thread_public_overrides/pw_thread_backend/thread_native.h",
]
allow_circular_includes_from = [ "$dir_pw_thread:thread.facade" ]
sources = [ "thread.cc" ]
}

config("yield_public_overrides") {
include_dirs = [ "yield_public_overrides" ]
visibility = [ ":*" ]
}

# This target provides the backend for pw::thread::yield.
pw_source_set("yield") {
public_configs = [
":public_include_path",
":backend_config",
":yield_public_overrides",
]
public = [
"public/pw_thread_embos/yield_inline.h",
"public_overrides/pw_thread_backend/yield_inline.h",
"yield_public_overrides/pw_thread_backend/yield_inline.h",
]
public_deps = [
"$dir_pw_assert",
Expand Down
20 changes: 10 additions & 10 deletions pw_thread_freertos/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ licenses(["notice"])
pw_cc_library(
name = "id_headers",
hdrs = [
"id_public_overrides/pw_thread_backend/id_inline.h",
"id_public_overrides/pw_thread_backend/id_native.h",
"public/pw_thread_freertos/id_inline.h",
"public/pw_thread_freertos/id_native.h",
"public_overrides/pw_thread_backend/id_inline.h",
"public_overrides/pw_thread_backend/id_native.h",
],
includes = [
"id_public_overrides",
"public",
"public_overrides",
],
)

Expand All @@ -51,11 +51,11 @@ pw_cc_library(
name = "sleep_headers",
hdrs = [
"public/pw_thread_freertos/sleep_inline.h",
"public_overrides/pw_thread_backend/sleep_inline.h",
"sleep_public_overrides/pw_thread_backend/sleep_inline.h",
],
includes = [
"public",
"public_overrides",
"sleep_public_overrides",
],
deps = [
"//pw_chrono:system_clock",
Expand Down Expand Up @@ -87,12 +87,12 @@ pw_cc_library(
"public/pw_thread_freertos/options.h",
"public/pw_thread_freertos/thread_inline.h",
"public/pw_thread_freertos/thread_native.h",
"public_overrides/pw_thread_backend/thread_inline.h",
"public_overrides/pw_thread_backend/thread_native.h",
"thread_public_overrides/pw_thread_backend/thread_inline.h",
"thread_public_overrides/pw_thread_backend/thread_native.h",
],
includes = [
"public",
"public_overrides",
"thread_public_overrides",
],
deps = [
":id",
Expand Down Expand Up @@ -165,11 +165,11 @@ pw_cc_library(
name = "yield_headers",
hdrs = [
"public/pw_thread_freertos/yield_inline.h",
"public_overrides/pw_thread_backend/yield_inline.h",
"yield_public_overrides/pw_thread_backend/yield_inline.h",
],
includes = [
"public",
"public_overrides",
"yield_public_overrides",
],
# TODO(b/234876414): This should depend on FreeRTOS but our third parties
# currently do not have Bazel support.
Expand Down
47 changes: 31 additions & 16 deletions pw_thread_freertos/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ config("public_include_path") {
visibility = [ ":*" ]
}

config("backend_config") {
include_dirs = [ "public_overrides" ]
visibility = [ ":*" ]
}

pw_source_set("config") {
public = [ "public/pw_thread_freertos/config.h" ]
public_configs = [ ":public_include_path" ]
Expand All @@ -51,22 +46,27 @@ pw_source_set("config") {
]
}

config("id_public_overrides") {
include_dirs = [ "id_public_overrides" ]
visibility = [ ":*" ]
}

# This target provides the backend for pw::thread::Id & pw::this_thread::get_id.
pw_source_set("id") {
public_configs = [
":public_include_path",
":backend_config",
":id_public_overrides",
]
public_deps = [
"$dir_pw_assert",
"$dir_pw_interrupt:context",
"$dir_pw_third_party/freertos",
]
public = [
"id_public_overrides/pw_thread_backend/id_inline.h",
"id_public_overrides/pw_thread_backend/id_native.h",
"public/pw_thread_freertos/id_inline.h",
"public/pw_thread_freertos/id_native.h",
"public_overrides/pw_thread_backend/id_inline.h",
"public_overrides/pw_thread_backend/id_native.h",
]
deps = [ "$dir_pw_thread:id.facade" ]
}
Expand All @@ -82,15 +82,20 @@ pw_build_assert("check_system_clock_backend") {
visibility = [ ":*" ]
}

config("sleep_public_overrides") {
include_dirs = [ "sleep_public_overrides" ]
visibility = [ ":*" ]
}

# This target provides the backend for pw::this_thread::sleep_{for,until}.
pw_source_set("sleep") {
public_configs = [
":public_include_path",
":backend_config",
":sleep_public_overrides",
]
public = [
"public/pw_thread_freertos/sleep_inline.h",
"public_overrides/pw_thread_backend/sleep_inline.h",
"sleep_public_overrides/pw_thread_backend/sleep_inline.h",
]
public_deps = [ "$dir_pw_chrono:system_clock" ]
sources = [ "sleep.cc" ]
Expand All @@ -104,12 +109,17 @@ pw_source_set("sleep") {
]
}

config("thread_public_overrides") {
include_dirs = [ "thread_public_overrides" ]
visibility = [ ":*" ]
}

# This target provides the backend for pw::thread::Thread and the headers needed
# for thread creation.
pw_source_set("thread") {
public_configs = [
":public_include_path",
":backend_config",
":thread_public_overrides",
]
public_deps = [
":config",
Expand All @@ -125,8 +135,8 @@ pw_source_set("thread") {
"public/pw_thread_freertos/options.h",
"public/pw_thread_freertos/thread_inline.h",
"public/pw_thread_freertos/thread_native.h",
"public_overrides/pw_thread_backend/thread_inline.h",
"public_overrides/pw_thread_backend/thread_native.h",
"thread_public_overrides/pw_thread_backend/thread_inline.h",
"thread_public_overrides/pw_thread_backend/thread_native.h",
]
allow_circular_includes_from = [ "$dir_pw_thread:thread.facade" ]
sources = [ "thread.cc" ]
Expand All @@ -135,7 +145,7 @@ pw_source_set("thread") {
# This target provides the backend for pw::thread::thread_iteration.
if (pw_thread_freertos_FREERTOS_TSKTCB_BACKEND != "") {
pw_source_set("thread_iteration") {
public_configs = [ ":backend_config" ]
public_configs = [ ":thread_public_overrides" ]
deps = [
":freertos_tsktcb",
"$dir_pw_third_party/freertos",
Expand All @@ -153,15 +163,20 @@ if (pw_thread_freertos_FREERTOS_TSKTCB_BACKEND != "") {
}
}

config("yield_public_overrides") {
include_dirs = [ "yield_public_overrides" ]
visibility = [ ":*" ]
}

# This target provides the backend for pw::this_thread::yield.
pw_source_set("yield") {
public_configs = [
":public_include_path",
":backend_config",
":yield_public_overrides",
]
public = [
"public/pw_thread_freertos/yield_inline.h",
"public_overrides/pw_thread_backend/yield_inline.h",
"yield_public_overrides/pw_thread_backend/yield_inline.h",
]
public_deps = [
"$dir_pw_assert",
Expand Down
Loading

0 comments on commit 8ff95d1

Please sign in to comment.