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/target_types.gni")
19import("$dir_pw_docgen/docs.gni")
20import("$dir_pw_unit_test/test.gni")
21
22config("default_config") {
23  include_dirs = [ "public" ]
24}
25
26pw_source_set("pw_string") {
27  public_configs = [ ":default_config" ]
28  public = [
29    "public/pw_string/format.h",
30    "public/pw_string/string_builder.h",
31    "public/pw_string/to_string.h",
32    "public/pw_string/type_to_string.h",
33    "public/pw_string/util.h",
34  ]
35  sources = [
36    "format.cc",
37    "string_builder.cc",
38    "type_to_string.cc",
39  ]
40  public_deps = [
41    "$dir_pw_preprocessor",
42    "$dir_pw_status",
43  ]
44}
45
46pw_test_group("tests") {
47  tests = [
48    ":format_test",
49    ":string_builder_test",
50    ":to_string_test",
51    ":type_to_string_test",
52    ":util_test",
53  ]
54  group_deps = [
55    "$dir_pw_preprocessor:tests",
56    "$dir_pw_status:tests",
57  ]
58}
59
60pw_test("format_test") {
61  deps = [ ":pw_string" ]
62  sources = [ "format_test.cc" ]
63}
64
65pw_test("string_builder_test") {
66  deps = [ ":pw_string" ]
67  sources = [ "string_builder_test.cc" ]
68}
69
70pw_test("to_string_test") {
71  deps = [ ":pw_string" ]
72  sources = [ "to_string_test.cc" ]
73}
74
75pw_test("type_to_string_test") {
76  deps = [ ":pw_string" ]
77  sources = [ "type_to_string_test.cc" ]
78}
79
80pw_test("util_test") {
81  deps = [ ":pw_string" ]
82  sources = [ "util_test.cc" ]
83}
84
85pw_doc_group("docs") {
86  sources = [ "docs.rst" ]
87  report_deps = [
88    ":format_size_report",
89    ":string_builder_size_report",
90  ]
91}
92
93pw_size_report("format_size_report") {
94  title = "Using pw::string::Format instead of snprintf"
95
96  binaries = [
97    {
98      target = "size_report:single_write_format"
99      base = "size_report:single_write_snprintf"
100      label = "Format instead of snprintf once, return size"
101    },
102    {
103      target = "size_report:multiple_writes_format"
104      base = "size_report:multiple_writes_snprintf"
105      label = "Format instead of snprintf 10 times, handle errors"
106    },
107    {
108      target = "size_report:many_writes_format"
109      base = "size_report:many_writes_snprintf"
110      label = "Format instead of snprintf 50 times, no error handling"
111    },
112  ]
113}
114
115pw_size_report("string_builder_size_report") {
116  title = "Using pw::StringBuilder instead of snprintf"
117
118  binaries = [
119    {
120      target = "size_report:build_string_with_string_builder"
121      base = "size_report:build_string_with_snprintf"
122      label = "Total StringBuilder cost when used alongside snprintf"
123    },
124    {
125      target = "size_report:build_string_with_string_builder_no_base_snprintf"
126      base = "size_report:build_string_with_snprintf_no_base_snprintf"
127      label = "StringBuilder cost when completely replacing snprintf"
128    },
129    {
130      target = "size_report:build_string_incremental_with_string_builder"
131      base = "size_report:build_string_incremental_with_snprintf"
132      label = "Incremental cost relative to snprintf for 10 strings"
133    },
134  ]
135}
136