blob: 69513da762de410744f0b5663e78d62255b1a6ef [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") {
Rob Mohra0ba54f2020-02-27 11:43:49 -080061 deps = [ ":pw_string" ]
62 sources = [ "format_test.cc" ]
Wyatt Heplere2dc6d12019-11-15 09:05:07 -080063}
64
Wyatt Heplerce9b9522019-11-11 10:45:48 -080065pw_test("string_builder_test") {
Rob Mohra0ba54f2020-02-27 11:43:49 -080066 deps = [ ":pw_string" ]
67 sources = [ "string_builder_test.cc" ]
Wyatt Heplerce9b9522019-11-11 10:45:48 -080068}
69
Wyatt Hepler58823c12019-11-13 14:27:31 -080070pw_test("to_string_test") {
Rob Mohra0ba54f2020-02-27 11:43:49 -080071 deps = [ ":pw_string" ]
72 sources = [ "to_string_test.cc" ]
Wyatt Hepler58823c12019-11-13 14:27:31 -080073}
74
Wyatt Hepler48db4d62019-11-11 10:32:45 -080075pw_test("type_to_string_test") {
Rob Mohra0ba54f2020-02-27 11:43:49 -080076 deps = [ ":pw_string" ]
77 sources = [ "type_to_string_test.cc" ]
Wyatt Hepler48db4d62019-11-11 10:32:45 -080078}
Wyatt Hepler8a823ce2019-11-15 12:03:57 -080079
Wyatt Heplerce9b9522019-11-11 10:45:48 -080080pw_test("util_test") {
Rob Mohra0ba54f2020-02-27 11:43:49 -080081 deps = [ ":pw_string" ]
82 sources = [ "util_test.cc" ]
Wyatt Heplerce9b9522019-11-11 10:45:48 -080083}
84
Wyatt Heplerfe85de22019-11-19 17:10:20 -080085pw_doc_group("docs") {
Rob Mohra0ba54f2020-02-27 11:43:49 -080086 sources = [ "docs.rst" ]
Wyatt Heplerfe85de22019-11-19 17:10:20 -080087 report_deps = [
88 ":format_size_report",
89 ":string_builder_size_report",
90 ]
91}
92
Wyatt Hepler8a823ce2019-11-15 12:03:57 -080093pw_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"
Wyatt Heplerfe85de22019-11-19 17:10:20 -0800100 label = "Format instead of snprintf once, return size"
Wyatt Hepler8a823ce2019-11-15 12:03:57 -0800101 },
102 {
103 target = "size_report:multiple_writes_format"
104 base = "size_report:multiple_writes_snprintf"
Wyatt Heplerfe85de22019-11-19 17:10:20 -0800105 label = "Format instead of snprintf 10 times, handle errors"
Wyatt Hepler8a823ce2019-11-15 12:03:57 -0800106 },
107 {
108 target = "size_report:many_writes_format"
109 base = "size_report:many_writes_snprintf"
Wyatt Heplerfe85de22019-11-19 17:10:20 -0800110 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"
Wyatt Hepler8a823ce2019-11-15 12:03:57 -0800133 },
134 ]
135}