xref: /aosp_15_r20/external/pigweed/pw_log/BUILD.gn (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1# Copyright 2021 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_chrono/backend.gni")
20import("$dir_pw_docgen/docs.gni")
21import("$dir_pw_log/backend.gni")
22import("$dir_pw_protobuf_compiler/proto.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_CONFIG = pw_build_DEFAULT_MODULE_CONFIG
30
31  # The build target that overrides the default configuration options for the
32  # glog adapter portion of this module.
33  pw_log_GLOG_ADAPTER_CONFIG = pw_build_DEFAULT_MODULE_CONFIG
34}
35
36config("public_include_path") {
37  include_dirs = [ "public" ]
38  visibility = [ ":*" ]
39}
40
41pw_source_set("config") {
42  public = [ "public/pw_log/config.h" ]
43  public_configs = [ ":public_include_path" ]
44  public_deps = [ pw_log_CONFIG ]
45}
46
47pw_facade("pw_log") {
48  backend = pw_log_BACKEND
49  public_configs = [ ":public_include_path" ]
50  public = [
51    "public/pw_log/levels.h",
52    "public/pw_log/log.h",
53    "public/pw_log/options.h",
54    "public/pw_log/short.h",
55    "public/pw_log/shorter.h",
56  ]
57  public_deps = [ ":config" ]
58
59  require_link_deps = [ ":impl" ]
60}
61
62pw_source_set("rate_limited") {
63  public_configs = [ ":public_include_path" ]
64  public = [ "public/pw_log/rate_limited.h" ]
65  public_deps = [
66    ":config",
67    ":pw_log",
68    "$dir_pw_chrono:system_clock",
69  ]
70  sources = [ "rate_limited.cc" ]
71}
72
73pw_source_set("args") {
74  public_configs = [ ":public_include_path" ]
75  public_deps = [ dir_pw_tokenizer ]
76  public = [ "public/pw_log/tokenized_args.h" ]
77}
78
79pw_source_set("glog_adapter") {
80  public_configs = [ ":public_include_path" ]
81  public = [
82    "public/pw_log/glog_adapter.h",
83    "public/pw_log/glog_adapter_config.h",
84  ]
85  public_deps = [
86    ":config",
87    "$dir_pw_assert",
88    "$dir_pw_log",
89    "$dir_pw_preprocessor",
90    "$dir_pw_string",
91    pw_log_GLOG_ADAPTER_CONFIG,
92  ]
93  sources = [ "public/pw_log/internal/glog_adapter.h" ]
94}
95
96pw_source_set("proto_utils") {
97  public_configs = [ ":public_include_path" ]
98  public = [ "public/pw_log/proto_utils.h" ]
99  public_deps = [
100    ":pw_log.facade",
101    "$dir_pw_bytes",
102    "$dir_pw_log:protos.pwpb",
103    "$dir_pw_log_tokenized:metadata",
104    "$dir_pw_result",
105    dir_pw_span,
106  ]
107  deps = [ "$dir_pw_protobuf" ]
108  sources = [ "proto_utils.cc" ]
109}
110
111# pw_log is low-level and ubiquitous. Because of this, it can often cause
112# circular dependencies. This target collects dependencies from the backend that
113# cannot be used because they would cause circular deps.
114#
115# This group ("$dir_pw_log:impl") must listed in pw_build_LINK_DEPS if
116# pw_log_BACKEND is set.
117#
118# pw_log backends must provide their own "impl" target that collects their
119# actual dependencies. The backend "impl" group may be empty if everything can
120# go directly in the backend target without causing circular dependencies.
121group("impl") {
122  public_deps = []
123
124  if (pw_log_BACKEND != "") {
125    public_deps +=
126        [ get_label_info(pw_log_BACKEND, "label_no_toolchain") + ".impl" ]
127  }
128}
129
130pw_test_group("tests") {
131  tests = [
132    ":basic_log_test",
133    ":glog_adapter_test",
134    ":proto_utils_test",
135    ":log_enum_test",
136  ]
137}
138
139pw_test("basic_log_test") {
140  enable_if = pw_log_BACKEND != ""
141  deps = [
142    ":pw_log",
143    dir_pw_preprocessor,
144    pw_log_BACKEND,
145  ]
146
147  sources = [
148    "basic_log_test.cc",
149    "basic_log_test_plain_c.c",
150  ]
151}
152
153pw_test("glog_adapter_test") {
154  enable_if = pw_log_BACKEND != ""
155  deps = [
156    ":glog_adapter",
157    pw_log_BACKEND,
158  ]
159  sources = [ "glog_adapter_test.cc" ]
160}
161
162pw_test("proto_utils_test") {
163  enable_if = pw_log_BACKEND != ""
164  deps = [
165    ":proto_utils",
166    ":pw_log.facade",
167    "$dir_pw_containers",
168    "$dir_pw_log:protos.pwpb",
169    "$dir_pw_preprocessor",
170    "$dir_pw_protobuf",
171    "$dir_pw_protobuf:bytes_utils",
172  ]
173  sources = [ "proto_utils_test.cc" ]
174}
175
176pw_test("log_enum_test") {
177  enable_if = pw_log_BACKEND != ""
178  deps = [
179    ":args",
180    ":pw_log",
181    dir_pw_tokenizer,
182  ]
183
184  sources = [ "log_enum_test.cc" ]
185}
186
187pw_proto_library("protos") {
188  sources = [ "log.proto" ]
189  prefix = "pw_log/proto"
190  deps = [
191    "$dir_pw_protobuf:common_protos",
192    "$dir_pw_tokenizer:proto",
193  ]
194  python_package = "py"
195}
196
197pw_doc_group("docs") {
198  sources = [
199    "backends.rst",
200    "docs.rst",
201    "protobuf.rst",
202    "tokenized_args.rst",
203  ]
204  inputs = [
205    "example_layer_diagram.svg",
206    "log.proto",
207  ]
208}
209