blob: 01bf37f6067363a466bbc90a9a9a484e95690c79 [file] [log] [blame]
Wyatt Hepler48db4d62019-11-11 10:32:45 -08001# 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
Wyatt Hepler8a823ce2019-11-15 12:03:57 -080015import("$dir_pw_bloat/bloat.gni")
Wyatt Heplerfe85de22019-11-19 17:10:20 -080016import("$dir_pw_docgen/docs.gni")
Wyatt Hepler48db4d62019-11-11 10:32:45 -080017import("$dir_pw_unit_test/test.gni")
18
19config("default_config") {
20 include_dirs = [ "public" ]
21}
22
23source_set("pw_string") {
Wyatt Hepler21192402020-01-15 15:40:51 -080024 public_configs = [ ":default_config" ]
Wyatt Hepler48db4d62019-11-11 10:32:45 -080025 public = [
Wyatt Heplere2dc6d12019-11-15 09:05:07 -080026 "public/pw_string/format.h",
Wyatt Hepler99713932019-12-17 10:20:42 -080027 "public/pw_string/string_builder.h",
Wyatt Hepler58823c12019-11-13 14:27:31 -080028 "public/pw_string/to_string.h",
Wyatt Hepler48db4d62019-11-11 10:32:45 -080029 "public/pw_string/type_to_string.h",
Wyatt Heplerce9b9522019-11-11 10:45:48 -080030 "public/pw_string/util.h",
Wyatt Hepler48db4d62019-11-11 10:32:45 -080031 ]
32 sources = [
Wyatt Heplere2dc6d12019-11-15 09:05:07 -080033 "format.cc",
Wyatt Heplerce9b9522019-11-11 10:45:48 -080034 "string_builder.cc",
Wyatt Hepler48db4d62019-11-11 10:32:45 -080035 "type_to_string.cc",
36 ]
37 sources += public
38 public_deps = [
39 "$dir_pw_preprocessor",
40 "$dir_pw_span",
41 "$dir_pw_status",
42 ]
43}
44
Alexei Frolova454c682019-11-19 10:55:07 -080045pw_test_group("tests") {
46 tests = [
47 ":format_test",
Wyatt Hepler706a5ae2020-01-09 17:01:38 -080048 ":string_builder_test",
Alexei Frolova454c682019-11-19 10:55:07 -080049 ":to_string_test",
50 ":type_to_string_test",
Wyatt Hepler706a5ae2020-01-09 17:01:38 -080051 ":util_test",
Alexei Frolova454c682019-11-19 10:55:07 -080052 ]
53 group_deps = [
54 "$dir_pw_preprocessor:tests",
55 "$dir_pw_span:tests",
56 "$dir_pw_status:tests",
57 ]
58}
59
Wyatt Heplere2dc6d12019-11-15 09:05:07 -080060pw_test("format_test") {
61 deps = [
62 ":pw_string",
Wyatt Heplere2dc6d12019-11-15 09:05:07 -080063 ]
64 sources = [
65 "format_test.cc",
66 ]
67}
68
Wyatt Heplerce9b9522019-11-11 10:45:48 -080069pw_test("string_builder_test") {
70 deps = [
71 ":pw_string",
Wyatt Heplerce9b9522019-11-11 10:45:48 -080072 ]
73 sources = [
74 "string_builder_test.cc",
75 ]
76}
77
Wyatt Hepler58823c12019-11-13 14:27:31 -080078pw_test("to_string_test") {
79 deps = [
80 ":pw_string",
Wyatt Hepler58823c12019-11-13 14:27:31 -080081 ]
82 sources = [
83 "to_string_test.cc",
84 ]
85}
86
Wyatt Hepler48db4d62019-11-11 10:32:45 -080087pw_test("type_to_string_test") {
88 deps = [
89 ":pw_string",
Wyatt Hepler48db4d62019-11-11 10:32:45 -080090 ]
91 sources = [
92 "type_to_string_test.cc",
93 ]
94}
Wyatt Hepler8a823ce2019-11-15 12:03:57 -080095
Wyatt Heplerce9b9522019-11-11 10:45:48 -080096pw_test("util_test") {
97 deps = [
98 ":pw_string",
Wyatt Heplerce9b9522019-11-11 10:45:48 -080099 ]
100 sources = [
101 "util_test.cc",
102 ]
103}
104
Wyatt Heplerfe85de22019-11-19 17:10:20 -0800105pw_doc_group("docs") {
106 sources = [
107 "docs.rst",
108 ]
109 report_deps = [
110 ":format_size_report",
111 ":string_builder_size_report",
112 ]
113}
114
Wyatt Hepler8a823ce2019-11-15 12:03:57 -0800115pw_size_report("format_size_report") {
116 title = "Using pw::string::Format instead of snprintf"
117
118 binaries = [
119 {
120 target = "size_report:single_write_format"
121 base = "size_report:single_write_snprintf"
Wyatt Heplerfe85de22019-11-19 17:10:20 -0800122 label = "Format instead of snprintf once, return size"
Wyatt Hepler8a823ce2019-11-15 12:03:57 -0800123 },
124 {
125 target = "size_report:multiple_writes_format"
126 base = "size_report:multiple_writes_snprintf"
Wyatt Heplerfe85de22019-11-19 17:10:20 -0800127 label = "Format instead of snprintf 10 times, handle errors"
Wyatt Hepler8a823ce2019-11-15 12:03:57 -0800128 },
129 {
130 target = "size_report:many_writes_format"
131 base = "size_report:many_writes_snprintf"
Wyatt Heplerfe85de22019-11-19 17:10:20 -0800132 label = "Format instead of snprintf 50 times, no error handling"
133 },
134 ]
135}
136
137pw_size_report("string_builder_size_report") {
138 title = "Using pw::StringBuilder instead of snprintf"
139
140 binaries = [
141 {
142 target = "size_report:build_string_with_string_builder"
143 base = "size_report:build_string_with_snprintf"
144 label = "Total StringBuilder cost when used alongside snprintf"
145 },
146 {
147 target = "size_report:build_string_with_string_builder_no_base_snprintf"
148 base = "size_report:build_string_with_snprintf_no_base_snprintf"
149 label = "StringBuilder cost when completely replacing snprintf"
150 },
151 {
152 target = "size_report:build_string_incremental_with_string_builder"
153 base = "size_report:build_string_incremental_with_snprintf"
154 label = "Incremental cost relative to snprintf for 10 strings"
Wyatt Hepler8a823ce2019-11-15 12:03:57 -0800155 },
156 ]
157}