• 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("glog_adapter") {
63  public_configs = [ ":public_include_path" ]
64  public = [
65    "public/pw_log/glog_adapter.h",
66    "public/pw_log/glog_adapter_config.h",
67  ]
68  public_deps = [
69    ":config",
70    "$dir_pw_assert",
71    "$dir_pw_log",
72    "$dir_pw_preprocessor",
73    "$dir_pw_string",
74    pw_log_GLOG_ADAPTER_CONFIG,
75  ]
76  sources = [ "public/pw_log/internal/glog_adapter.h" ]
77}
78
79pw_source_set("proto_utils") {
80  public_configs = [ ":public_include_path" ]
81  public = [ "public/pw_log/proto_utils.h" ]
82  public_deps = [
83    ":pw_log.facade",
84    "$dir_pw_bytes",
85    "$dir_pw_log:protos.pwpb",
86    "$dir_pw_log_tokenized:metadata",
87    "$dir_pw_result",
88    dir_pw_span,
89  ]
90  deps = [ "$dir_pw_protobuf" ]
91  sources = [ "proto_utils.cc" ]
92}
93
94# pw_log is low-level and ubiquitous. Because of this, it can often cause
95# circular dependencies. This target collects dependencies from the backend that
96# cannot be used because they would cause circular deps.
97#
98# This group ("$dir_pw_log:impl") must listed in pw_build_LINK_DEPS if
99# pw_log_BACKEND is set.
100#
101# pw_log backends must provide their own "impl" target that collects their
102# actual dependencies. The backend "impl" group may be empty if everything can
103# go directly in the backend target without causing circular dependencies.
104group("impl") {
105  public_deps = []
106
107  if (pw_log_BACKEND != "") {
108    public_deps +=
109        [ get_label_info(pw_log_BACKEND, "label_no_toolchain") + ".impl" ]
110  }
111}
112
113pw_test_group("tests") {
114  tests = [
115    ":basic_log_test",
116    ":glog_adapter_test",
117    ":proto_utils_test",
118  ]
119}
120
121pw_test("basic_log_test") {
122  enable_if = pw_log_BACKEND != ""
123  deps = [
124    ":pw_log",
125    dir_pw_preprocessor,
126    pw_log_BACKEND,
127  ]
128
129  sources = [
130    "basic_log_test.cc",
131    "basic_log_test_plain_c.c",
132  ]
133}
134
135pw_test("glog_adapter_test") {
136  enable_if = pw_log_BACKEND != ""
137  deps = [
138    ":glog_adapter",
139    pw_log_BACKEND,
140  ]
141  sources = [ "glog_adapter_test.cc" ]
142}
143
144pw_test("proto_utils_test") {
145  enable_if = pw_log_BACKEND != ""
146  deps = [
147    ":proto_utils",
148    ":pw_log.facade",
149    "$dir_pw_containers",
150    "$dir_pw_log:protos.pwpb",
151    "$dir_pw_preprocessor",
152    "$dir_pw_protobuf",
153    "$dir_pw_protobuf:bytes_utils",
154  ]
155  sources = [ "proto_utils_test.cc" ]
156}
157
158pw_proto_library("protos") {
159  sources = [ "log.proto" ]
160  prefix = "pw_log/proto"
161  deps = [
162    "$dir_pw_protobuf:common_protos",
163    "$dir_pw_tokenizer:proto",
164  ]
165}
166
167pw_doc_group("docs") {
168  sources = [
169    "docs.rst",
170    "protobuf.rst",
171  ]
172  inputs = [
173    "example_layer_diagram.svg",
174    "log.proto",
175  ]
176}
177