1# Copyright 2019 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_bloat/bloat.gni") 18import("$dir_pw_build/module_config.gni") 19import("$dir_pw_build/target_types.gni") 20import("$dir_pw_docgen/docs.gni") 21import("$dir_pw_unit_test/test.gni") 22 23declare_args() { 24 # The build target that overrides the default configuration options for this 25 # module. This should point to a source set that provides defines through a 26 # public config (which may -include a file or add defines directly). 27 pw_string_CONFIG = pw_build_DEFAULT_MODULE_CONFIG 28} 29 30config("public_include_path") { 31 include_dirs = [ "public" ] 32} 33 34config("enable_decimal_float_expansion_config") { 35 defines = [ "PW_STRING_ENABLE_DECIMAL_FLOAT_EXPANSION=1" ] 36} 37 38pw_source_set("enable_decimal_float_expansion") { 39 public_configs = [ ":enable_decimal_float_expansion_config" ] 40} 41 42pw_source_set("config") { 43 public = [ "public/pw_string/internal/config.h" ] 44 public_configs = [ ":public_include_path" ] 45 public_deps = [ pw_string_CONFIG ] 46} 47 48group("pw_string") { 49 public_deps = [ 50 ":builder", 51 ":format", 52 ":to_string", 53 ] 54} 55 56pw_source_set("builder") { 57 public_configs = [ ":public_include_path" ] 58 public = [ "public/pw_string/string_builder.h" ] 59 sources = [ "string_builder.cc" ] 60 public_deps = [ 61 ":format", 62 ":string", 63 ":to_string", 64 ":util", 65 dir_pw_preprocessor, 66 dir_pw_span, 67 dir_pw_status, 68 ] 69 70 # TODO: b/259746255 - Remove this when everything compiles with -Wconversion. 71 configs = [ "$dir_pw_build:conversion_warnings" ] 72} 73 74pw_source_set("format") { 75 public_configs = [ ":public_include_path" ] 76 public = [ "public/pw_string/format.h" ] 77 sources = [ "format.cc" ] 78 public_deps = [ 79 ":string", 80 dir_pw_preprocessor, 81 dir_pw_span, 82 dir_pw_status, 83 ] 84 85 # TODO: b/259746255 - Remove this when everything compiles with -Wconversion. 86 configs = [ "$dir_pw_build:conversion_warnings" ] 87} 88 89pw_source_set("string") { 90 public_configs = [ ":public_include_path" ] 91 public = [ "public/pw_string/string.h" ] 92 sources = [ 93 "public/pw_string/internal/string_common_functions.inc", 94 "public/pw_string/internal/string_impl.h", 95 ] 96 public_deps = [ dir_pw_assert ] 97 98 # TODO: b/259746255 - Remove this when everything compiles with -Wconversion. 99 configs = [ "$dir_pw_build:conversion_warnings" ] 100} 101 102pw_source_set("to_string") { 103 public_configs = [ ":public_include_path" ] 104 public = [ 105 "public/pw_string/to_string.h", 106 "public/pw_string/type_to_string.h", 107 ] 108 sources = [ "type_to_string.cc" ] 109 public_deps = [ 110 ":config", 111 ":format", 112 ":util", 113 "$dir_pw_third_party/fuchsia:stdcompat", 114 dir_pw_result, 115 dir_pw_span, 116 dir_pw_status, 117 ] 118 119 # TODO: b/259746255 - Remove this when everything compiles with -Wconversion. 120 configs = [ "$dir_pw_build:conversion_warnings" ] 121} 122 123pw_source_set("util") { 124 public_configs = [ ":public_include_path" ] 125 public = [ "public/pw_string/util.h" ] 126 sources = [ "public/pw_string/internal/length.h" ] 127 public_deps = [ 128 ":string", 129 dir_pw_assert, 130 dir_pw_result, 131 dir_pw_span, 132 dir_pw_status, 133 ] 134} 135 136pw_test_group("tests") { 137 tests = [ 138 ":string_test", 139 ":format_test", 140 ":string_builder_test", 141 ":to_string_test", 142 ":type_to_string_test", 143 ":util_test", 144 ] 145 group_deps = [ 146 "$dir_pw_preprocessor:tests", 147 "$dir_pw_status:tests", 148 ] 149} 150 151pw_test("format_test") { 152 deps = [ ":format" ] 153 sources = [ "format_test.cc" ] 154 155 # TODO: b/259746255 - Remove this when everything compiles with -Wconversion. 156 configs = [ "$dir_pw_build:conversion_warnings" ] 157} 158 159pw_test("string_test") { 160 deps = [ ":string" ] 161 sources = [ "string_test.cc" ] 162 negative_compilation_tests = true 163 164 # TODO: b/259746255 - Remove this when everything compiles with -Wconversion. 165 configs = [ "$dir_pw_build:conversion_warnings" ] 166} 167 168pw_test("string_builder_test") { 169 deps = [ ":builder" ] 170 sources = [ "string_builder_test.cc" ] 171 172 # TODO: b/259746255 - Remove this when everything compiles with -Wconversion. 173 configs = [ "$dir_pw_build:conversion_warnings" ] 174} 175 176pw_test("to_string_test") { 177 deps = [ 178 ":config", 179 ":pw_string", 180 ] 181 sources = [ "to_string_test.cc" ] 182 183 # TODO: b/259746255 - Remove this when everything compiles with -Wconversion. 184 configs = [ "$dir_pw_build:conversion_warnings" ] 185} 186 187pw_test("type_to_string_test") { 188 deps = [ ":to_string" ] 189 sources = [ "type_to_string_test.cc" ] 190 191 # TODO: b/259746255 - Remove this when everything compiles with -Wconversion. 192 configs = [ "$dir_pw_build:conversion_warnings" ] 193} 194 195pw_test("util_test") { 196 deps = [ ":util" ] 197 sources = [ "util_test.cc" ] 198 199 # TODO: b/259746255 - Remove this when everything compiles with -Wconversion. 200 configs = [ "$dir_pw_build:conversion_warnings" ] 201} 202 203pw_doc_group("docs") { 204 sources = [ 205 "api.rst", 206 "code_size.rst", 207 "design.rst", 208 "docs.rst", 209 "guide.rst", 210 ] 211 report_deps = [ 212 ":format_size_report", 213 ":string_builder_size_report", 214 ] 215} 216 217pw_size_diff("format_size_report") { 218 title = "Using pw::string::Format instead of snprintf" 219 220 binaries = [ 221 { 222 target = "size_report:single_write_format" 223 base = "size_report:single_write_snprintf" 224 label = "Format instead of snprintf once, return size" 225 }, 226 { 227 target = "size_report:multiple_writes_format" 228 base = "size_report:multiple_writes_snprintf" 229 label = "Format instead of snprintf 10 times, handle errors" 230 }, 231 { 232 target = "size_report:many_writes_format" 233 base = "size_report:many_writes_snprintf" 234 label = "Format instead of snprintf 50 times, no error handling" 235 }, 236 ] 237} 238 239pw_size_diff("string_builder_size_report") { 240 title = "Using pw::StringBuilder instead of snprintf" 241 242 binaries = [ 243 { 244 target = "size_report:build_string_with_string_builder" 245 base = "size_report:build_string_with_snprintf" 246 label = "Total StringBuilder cost when used alongside snprintf" 247 }, 248 { 249 target = "size_report:build_string_with_string_builder_no_base_snprintf" 250 base = "size_report:build_string_with_snprintf_no_base_snprintf" 251 label = "StringBuilder cost when completely replacing snprintf" 252 }, 253 { 254 target = "size_report:build_string_incremental_with_string_builder" 255 base = "size_report:build_string_incremental_with_snprintf" 256 label = "Incremental cost relative to snprintf for 10 strings" 257 }, 258 ] 259} 260