• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  ]
136}
137
138pw_test("basic_log_test") {
139  enable_if = pw_log_BACKEND != ""
140  deps = [
141    ":pw_log",
142    dir_pw_preprocessor,
143    pw_log_BACKEND,
144  ]
145
146  sources = [
147    "basic_log_test.cc",
148    "basic_log_test_plain_c.c",
149  ]
150}
151
152pw_test("glog_adapter_test") {
153  enable_if = pw_log_BACKEND != ""
154  deps = [
155    ":glog_adapter",
156    pw_log_BACKEND,
157  ]
158  sources = [ "glog_adapter_test.cc" ]
159}
160
161pw_test("proto_utils_test") {
162  enable_if = pw_log_BACKEND != ""
163  deps = [
164    ":proto_utils",
165    ":pw_log.facade",
166    "$dir_pw_containers",
167    "$dir_pw_log:protos.pwpb",
168    "$dir_pw_preprocessor",
169    "$dir_pw_protobuf",
170    "$dir_pw_protobuf:bytes_utils",
171  ]
172  sources = [ "proto_utils_test.cc" ]
173}
174
175pw_proto_library("protos") {
176  sources = [ "log.proto" ]
177  prefix = "pw_log/proto"
178  deps = [
179    "$dir_pw_protobuf:common_protos",
180    "$dir_pw_tokenizer:proto",
181  ]
182  python_package = "py"
183}
184
185pw_doc_group("docs") {
186  sources = [
187    "backends.rst",
188    "docs.rst",
189    "protobuf.rst",
190    "tokenized_args.rst",
191  ]
192  inputs = [
193    "example_layer_diagram.svg",
194    "log.proto",
195  ]
196}
197