xref: /aosp_15_r20/external/pigweed/pw_log_tokenized/BUILD.gn (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1# Copyright 2020 The Pigweed Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4# use this file except in compliance with the License. You may obtain a copy of
5# the License at
6#
7#     https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations under
13# the License.
14
15import("//build_overrides/pigweed.gni")
16
17import("$dir_pw_build/facade.gni")
18import("$dir_pw_build/module_config.gni")
19import("$dir_pw_build/target_types.gni")
20import("$dir_pw_docgen/docs.gni")
21import("$dir_pw_log/backend.gni")
22import("$dir_pw_log_tokenized/backend.gni")
23import("$dir_pw_unit_test/test.gni")
24
25declare_args() {
26  # The build target that overrides the default configuration options for this
27  # module. This should point to a source set that provides defines through a
28  # public config (which may -include a file or add defines directly).
29  pw_log_tokenized_CONFIG = pw_build_DEFAULT_MODULE_CONFIG
30}
31
32config("public_include_path") {
33  include_dirs = [ "public" ]
34  visibility = [ ":*" ]
35}
36
37config("backend_config") {
38  include_dirs = [ "public_overrides" ]
39  visibility = [ ":*" ]
40}
41
42config("gcc_partially_tokenized_backend_config") {
43  include_dirs = [ "public_overrides" ]
44  visibility = [ ":*" ]
45}
46
47# This target provides the backend for pw_log.
48pw_source_set("pw_log_tokenized") {
49  public_configs = [ ":backend_config" ]
50  public_deps = [
51    ":handler.facade",  # Depend on the facade to avoid circular dependencies.
52    ":headers",
53  ]
54  public = [
55    "public_overrides/pw_log_backend/log_backend.h",
56    "public_overrides/pw_log_backend/log_backend_uses_pw_tokenizer.h",
57  ]
58
59  sources = [ "log_tokenized.cc" ]
60}
61
62pw_source_set("headers") {
63  visibility = [ ":*" ]
64  public_configs = [ ":public_include_path" ]
65  public_deps = [
66    ":config",
67    ":metadata",
68    dir_pw_preprocessor,
69    dir_pw_tokenizer,
70  ]
71  public = [ "public/pw_log_tokenized/log_tokenized.h" ]
72}
73
74# This target provides the backend for pw_log for GCC which tokenizes as much as
75# it can and uses pw_log_string:handler for the rest.
76pw_source_set("gcc_partially_tokenized") {
77  public_configs = [
78    ":gcc_partially_tokenized_backend_config",
79    ":public_include_path",
80  ]
81  public_deps = [
82    ":handler.facade",  # Depend on the facade to avoid circular dependencies.
83    ":headers",
84    "$dir_pw_log_string:handler",
85  ]
86  public = [
87    "gcc_partially_tokenized_public_overrides/pw_log_backend/log_backend.h",
88    "public/pw_log_tokenized/gcc_partially_tokenized.h",
89  ]
90  sources = [ "log_tokenized.cc" ]
91}
92
93pw_facade("handler") {
94  public_configs = [ ":public_include_path" ]
95  public_deps = [ dir_pw_preprocessor ]
96
97  public = [ "public/pw_log_tokenized/handler.h" ]
98
99  backend = pw_log_tokenized_HANDLER_BACKEND
100}
101
102pw_source_set("metadata") {
103  public_configs = [ ":public_include_path" ]
104  public_deps = [ ":config" ]
105  public = [ "public/pw_log_tokenized/metadata.h" ]
106}
107
108pw_source_set("config") {
109  public_configs = [ ":public_include_path" ]
110  public_deps = [
111    "$dir_pw_log:facade",
112    "$dir_pw_tokenizer:config",
113    dir_pw_polyfill,
114    pw_log_tokenized_CONFIG,
115  ]
116  public = [ "public/pw_log_tokenized/config.h" ]
117}
118
119# The log backend deps that might cause circular dependencies, since
120# pw_log is so ubiquitous. These deps are kept separate so they can be
121# depended on from elsewhere.
122pw_source_set("pw_log_tokenized.impl") {
123  deps = [ ":pw_log_tokenized" ]
124
125  if (pw_log_tokenized_HANDLER_BACKEND != "") {
126    deps += [ ":handler" ]
127  }
128}
129
130pw_source_set("base64") {
131  public_configs = [ ":public_include_path" ]
132  public = [ "public/pw_log_tokenized/base64.h" ]
133  public_deps = [
134    ":config",
135    "$dir_pw_tokenizer:base64",
136  ]
137}
138
139# This target provides a backend for pw_tokenizer that encodes tokenized logs as
140# Base64, encodes them into HDLC frames, and writes them over sys_io.
141pw_source_set("base64_over_hdlc") {
142  sources = [ "base64_over_hdlc.cc" ]
143  deps = [
144    ":base64",
145    ":handler.facade",
146    "$dir_pw_hdlc:encoder",
147    "$dir_pw_stream:sys_io_stream",
148    "$dir_pw_tokenizer:base64",
149    dir_pw_span,
150  ]
151}
152
153pw_test_group("tests") {
154  tests = [
155    ":log_tokenized_test",
156    ":metadata_test",
157    ":tokenized_args_test",
158  ]
159}
160
161pw_test("log_tokenized_test") {
162  sources = [
163    "log_tokenized_test.cc",
164    "log_tokenized_test_c.c",
165    "pw_log_tokenized_private/test_utils.h",
166  ]
167  deps = [
168    ":base64",
169    ":headers",
170    dir_pw_preprocessor,
171  ]
172}
173
174pw_test("metadata_test") {
175  sources = [ "metadata_test.cc" ]
176  deps = [ ":metadata" ]
177}
178
179pw_test("tokenized_args_test") {
180  enable_if = pw_log_BACKEND != "" &&
181              (host_os != "win" || pw_log_tokenized_HANDLER_BACKEND != "")
182  deps = [
183    "$dir_pw_log:args",
184    dir_pw_log_tokenized,
185    dir_pw_tokenizer,
186  ]
187
188  sources = [ "tokenized_args_test.cc" ]
189}
190
191pw_doc_group("docs") {
192  sources = [ "docs.rst" ]
193  other_deps = [ "py" ]
194}
195