1# Copyright 2022 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/error.gni") 18import("$dir_pw_build/facade.gni") 19import("$dir_pw_build/module_config.gni") 20import("$dir_pw_build/target_types.gni") 21import("$dir_pw_docgen/docs.gni") 22import("$dir_pw_unit_test/test.gni") 23import("backend.gni") 24 25declare_args() { 26 pw_log_string_CONFIG = pw_build_DEFAULT_MODULE_CONFIG 27} 28 29config("public_include_path") { 30 include_dirs = [ "public" ] 31} 32 33config("backend_config") { 34 include_dirs = [ "public_overrides" ] 35} 36 37pw_source_set("config") { 38 public = [ "public/pw_log_string/config.h" ] 39 public_configs = [ ":public_include_path" ] 40 public_deps = [ 41 "$dir_pw_preprocessor", 42 pw_log_string_CONFIG, 43 ] 44} 45 46# This source set only provides pw_log's backend interface by invoking the 47# :handler facade. 48pw_source_set("pw_log_string") { 49 public_configs = [ ":backend_config" ] 50 public = [ "public_overrides/pw_log_backend/log_backend.h" ] 51 public_deps = [ ":handler" ] 52} 53 54pw_source_set("pw_log_string.impl") { 55 deps = [ ":handler.impl" ] 56} 57 58# This facade is a C API for string based logging which may be used to back 59# pw_log or for example to mix tokenized and string based logging. 60pw_facade("handler") { 61 backend = pw_log_string_HANDLER_BACKEND 62 public_configs = [ ":public_include_path" ] 63 public = [ "public/pw_log_string/handler.h" ] 64 public_deps = [ 65 ":config", 66 "$dir_pw_preprocessor", 67 ] 68 sources = [ "handler.cc" ] 69 70 require_link_deps = [ ":handler.impl" ] 71} 72 73# Logging is low-level and ubiquitous. Because of this, it can often cause 74# circular dependencies. This target collects dependencies from the backend that 75# cannot be used because they would cause circular deps. 76# 77# This group ("$dir_pw_log_string:handler_impl") must be listed in 78# pw_build_LINK_DEPS if pw_log_string_HANDLER_BACKEND is set. 79# 80# pw_log_string:handler backends must provide their own "impl" target that 81# collects their actual dependencies. The backend "impl" group may be empty 82# if everything can go directly in the backend target without causing circular 83# dependencies. 84if (pw_log_string_HANDLER_BACKEND != "") { 85 pw_source_set("handler.impl") { 86 deps = [ get_label_info(pw_log_string_HANDLER_BACKEND, 87 "label_no_toolchain") + ".impl" ] 88 } 89} else { 90 pw_error("handler.impl") { 91 message = 92 string_join(" ", 93 [ 94 "To use pw_log_string:handler, please direct", 95 "pw_log_string_HANDLER_BACKEND to the source set that", 96 "implements the C API.", 97 ]) 98 } 99} 100 101config("wrap_newlib_assert_config") { 102 ldflags = [ "-Wl,--wrap=__assert_func" ] 103 visibility = [ ":*" ] 104} 105 106pw_source_set("wrap_newlib_assert") { 107 all_dependent_configs = [ ":wrap_newlib_assert_config" ] 108 sources = [ "wrap_newlib_assert.cc" ] 109 deps = [ 110 ":handler", 111 dir_pw_log, 112 ] 113} 114 115pw_doc_group("docs") { 116 sources = [ "docs.rst" ] 117} 118 119pw_test_group("tests") { 120} 121