Skip to content

Commit

Permalink
pw_allocator: Reorganize examples for copybara
Browse files Browse the repository at this point in the history
Bug: 390192992
Change-Id: Iface66205cb60fe7e5e15d94c37bc57627ed3286
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/260613
Pigweed-Auto-Submit: Aaron Green <[email protected]>
Commit-Queue: Aaron Green <[email protected]>
Lint: Lint 🤖 <[email protected]>
Reviewed-by: Wyatt Hepler <[email protected]>
  • Loading branch information
nopsledder authored and CQ Bot Account committed Jan 15, 2025
1 parent 5ba5ba2 commit adf609f
Show file tree
Hide file tree
Showing 17 changed files with 38 additions and 28 deletions.
4 changes: 2 additions & 2 deletions pw_allocator/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -792,13 +792,13 @@ pw_doc_group("docs") {
"examples/basic.cc",
"examples/block_allocator.cc",
"examples/custom_allocator_perf_test.cc",
"examples/custom_allocator_test_harness.h",
"examples/custom_allocator_test.cc",
"examples/custom_allocator.cc",
"examples/custom_allocator.h",
"examples/linker_sections.cc",
"examples/metrics.cc",
"examples/pmr.cc",
"examples/public/examples/custom_allocator.h",
"examples/public/examples/custom_allocator_test_harness.h",
"examples/size_report.cc",
"examples/spin_lock.cc",
]
Expand Down
13 changes: 8 additions & 5 deletions pw_allocator/examples/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ licenses(["notice"])
cc_library(
name = "named_u32",
testonly = True,
hdrs = ["named_u32.h"],
hdrs = ["public/examples/named_u32.h"],
strip_include_prefix = "public",
deps = [
"//pw_bytes",
"//pw_string",
Expand All @@ -37,7 +38,8 @@ cc_library(
name = "custom_allocator",
testonly = True,
srcs = ["custom_allocator.cc"],
hdrs = ["custom_allocator.h"],
hdrs = ["public/examples/custom_allocator.h"],
strip_include_prefix = "public",
deps = [
"//pw_allocator:allocator",
"//pw_log",
Expand All @@ -48,7 +50,8 @@ cc_library(
cc_library(
name = "custom_allocator_test_harness",
testonly = True,
hdrs = ["custom_allocator_test_harness.h"],
hdrs = ["public/examples/custom_allocator_test_harness.h"],
strip_include_prefix = "public",
deps = [
":custom_allocator",
"//pw_allocator:test_harness",
Expand Down Expand Up @@ -171,13 +174,13 @@ sphinx_docs_library(
"basic.cc",
"block_allocator.cc",
"custom_allocator.cc",
"custom_allocator.h",
"custom_allocator_perf_test.cc",
"custom_allocator_test.cc",
"custom_allocator_test_harness.h",
"linker_sections.cc",
"metrics.cc",
"pmr.cc",
"public/examples/custom_allocator.h",
"public/examples/custom_allocator_test_harness.h",
"size_report.cc",
"spin_lock.cc",
],
Expand Down
9 changes: 5 additions & 4 deletions pw_allocator/examples/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ import("$dir_pw_unit_test/test.gni")
# Libraries

config("default_config") {
include_dirs = [ dir_pigweed ]
include_dirs = [ "public" ]
visibility = [ ":*" ]
}

pw_source_set("named_u32") {
public_configs = [ ":default_config" ]
public = [ "named_u32.h" ]
public = [ "public/examples/named_u32.h" ]
public_deps = [
dir_pw_bytes,
dir_pw_string,
Expand All @@ -37,7 +38,7 @@ pw_source_set("named_u32") {

pw_source_set("custom_allocator") {
public_configs = [ ":default_config" ]
public = [ "custom_allocator.h" ]
public = [ "public/examples/custom_allocator.h" ]
public_deps = [ "$dir_pw_allocator:allocator" ]
sources = [ "custom_allocator.cc" ]
deps = [
Expand All @@ -48,7 +49,7 @@ pw_source_set("custom_allocator") {

pw_source_set("custom_allocator_test_harness") {
public_configs = [ ":default_config" ]
public = [ "custom_allocator_test_harness.h" ]
public = [ "public/examples/custom_allocator_test_harness.h" ]
public_deps = [
":custom_allocator",
"$dir_pw_allocator:test_harness",
Expand Down
12 changes: 9 additions & 3 deletions pw_allocator/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@ include("$ENV{PW_ROOT}/pw_thread/backend.cmake")

pw_add_library(pw_allocator.examples.named_u32 INTERFACE
HEADERS
named_u32.h
public/examples/named_u32.h
PUBLIC_INCLUDES
public
PUBLIC_DEPS
pw_bytes
pw_string
)

pw_add_library(pw_allocator.examples.custom_allocator STATIC
HEADERS
custom_allocator.h
public/examples/custom_allocator.h
PUBLIC_INCLUDES
public
PUBLIC_DEPS
pw_allocator.allocator
SOURCES
Expand All @@ -41,7 +45,9 @@ pw_add_library(pw_allocator.examples.custom_allocator STATIC

pw_add_library(pw_allocator.examples.custom_allocator_test_harness INTERFACE
HEADERS
custom_allocator_test_harness.h
public/examples/custom_allocator_test_harness.h
PUBLIC_INCLUDES
public
PUBLIC_DEPS
pw_allocator.examples.custom_allocator
pw_allocator.test_harness
Expand Down
2 changes: 1 addition & 1 deletion pw_allocator/examples/basic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// License for the specific language governing permissions and limitations under
// the License.

#include "examples/named_u32.h"
#include "pw_allocator/allocator.h"
#include "pw_allocator/examples/named_u32.h"
#include "pw_allocator/testing.h"
#include "pw_unit_test/framework.h"

Expand Down
2 changes: 1 addition & 1 deletion pw_allocator/examples/block_allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <array>
#include <cstdint>

#include "pw_allocator/examples/named_u32.h"
#include "examples/named_u32.h"
#include "pw_allocator/first_fit.h"
#include "pw_unit_test/framework.h"

Expand Down
2 changes: 1 addition & 1 deletion pw_allocator/examples/custom_allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// the License.

// DOCSTAG: [pw_allocator-examples-custom_allocator]
#include "pw_allocator/examples/custom_allocator.h"
#include "examples/custom_allocator.h"

#include <cstdint>

Expand Down
2 changes: 1 addition & 1 deletion pw_allocator/examples/custom_allocator_perf_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// DOCSTAG: [pw_allocator-examples-custom_allocator-perf_test]
#include <cstdint>

#include "pw_allocator/examples/custom_allocator_test_harness.h"
#include "examples/custom_allocator_test_harness.h"
#include "pw_perf_test/perf_test.h"
#include "pw_perf_test/state.h"

Expand Down
6 changes: 3 additions & 3 deletions pw_allocator/examples/custom_allocator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
// License for the specific language governing permissions and limitations under
// the License.

#include "pw_allocator/examples/custom_allocator.h"
#include "examples/custom_allocator.h"

#include <cstdint>

#include "pw_allocator/examples/custom_allocator_test_harness.h"
#include "pw_allocator/examples/named_u32.h"
#include "examples/custom_allocator_test_harness.h"
#include "examples/named_u32.h"
#include "pw_allocator/fuzzing.h"
#include "pw_allocator/testing.h"
#include "pw_containers/vector.h"
Expand Down
2 changes: 1 addition & 1 deletion pw_allocator/examples/linker_sections.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
#include <cstdint>
#include <string_view>

#include "examples/named_u32.h"
#include "pw_allocator/allocator.h"
#include "pw_allocator/block/detailed_block.h"
#include "pw_allocator/examples/named_u32.h"
#include "pw_allocator/first_fit.h"
#include "pw_allocator/worst_fit.h"
#include "pw_unit_test/framework.h"
Expand Down
2 changes: 1 addition & 1 deletion pw_allocator/examples/metrics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <cstdint>
#include <string_view>

#include "pw_allocator/examples/named_u32.h"
#include "examples/named_u32.h"
#include "pw_allocator/testing.h"
#include "pw_allocator/tracking_allocator.h"
#include "pw_tokenizer/tokenize.h"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// DOCSTAG: [pw_allocator-examples-custom_allocator-test_harness]
#include <cstddef>

#include "pw_allocator/examples/custom_allocator.h"
#include "examples/custom_allocator.h"
#include "pw_allocator/test_harness.h"
#include "pw_allocator/testing.h"

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion pw_allocator/examples/size_report.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// DOCSTAG: [pw_allocator-examples-size_report]
#include <cstdint>

#include "pw_allocator/examples/custom_allocator.h"
#include "examples/custom_allocator.h"
#include "pw_allocator/first_fit.h"
#include "pw_allocator/size_reporter.h"

Expand Down
2 changes: 1 addition & 1 deletion pw_allocator/examples/spin_lock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// License for the specific language governing permissions and limitations under
// the License.

#include "pw_allocator/examples/named_u32.h"
#include "examples/named_u32.h"
#include "pw_allocator/synchronized_allocator.h"
#include "pw_allocator/testing.h"
#include "pw_assert/check.h"
Expand Down
4 changes: 2 additions & 2 deletions pw_allocator/guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ and ``DoDeallocate`` methods.
For example, the following is a forwarding allocator that simply writes to the
log whenever a threshold is exceeded:

.. literalinclude:: examples/custom_allocator.h
.. literalinclude:: examples/public/examples/custom_allocator.h
:language: cpp
:linenos:
:start-after: [pw_allocator-examples-custom_allocator]
Expand Down Expand Up @@ -464,7 +464,7 @@ You can also extend the :ref:`module-pw_allocator-api-test_harness` to perform
pseudorandom sequences of allocations and deallocations, e.g. as part of a
performance test:

.. literalinclude:: examples/custom_allocator_test_harness.h
.. literalinclude:: examples/public/examples/custom_allocator_test_harness.h
:language: cpp
:linenos:
:start-after: [pw_allocator-examples-custom_allocator-test_harness]
Expand Down

0 comments on commit adf609f

Please sign in to comment.