blob: 0742938c909f68ac29b223c8eef5dc72affc2bc6 [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
Armando Montanezfb3d3fb2020-06-09 18:12:12 -070015import("//build_overrides/pigweed.gni")
16
Wyatt Hepler8a823ce2019-11-15 12:03:57 -080017import("$dir_pw_bloat/bloat.gni")
Alexei Frolovedd2f142020-06-09 19:11:27 -070018import("$dir_pw_build/target_types.gni")
Wyatt Heplerfe85de22019-11-19 17:10:20 -080019import("$dir_pw_docgen/docs.gni")
Wyatt Hepler48db4d62019-11-11 10:32:45 -080020import("$dir_pw_unit_test/test.gni")
Wyatt Heplerd49f8fe2020-10-15 10:13:47 -070021
Wyatt Hepler8bd4fb02021-05-03 15:30:58 -070022config("public_include_path") {
Wyatt Hepler48db4d62019-11-11 10:32:45 -080023 include_dirs = [ "public" ]
24}
25
Alexei Frolovedd2f142020-06-09 19:11:27 -070026pw_source_set("pw_string") {
Wyatt Hepler8bd4fb02021-05-03 15:30:58 -070027 public_configs = [ ":public_include_path" ]
Wyatt Hepler48db4d62019-11-11 10:32:45 -080028 public = [
Wyatt Heplere2dc6d12019-11-15 09:05:07 -080029 "public/pw_string/format.h",
Ewout van Bekkumf89f1372021-05-03 11:15:54 -070030 "public/pw_string/internal/length.h",
Wyatt Hepler99713932019-12-17 10:20:42 -080031 "public/pw_string/string_builder.h",
Wyatt Hepler58823c12019-11-13 14:27:31 -080032 "public/pw_string/to_string.h",
Wyatt Hepler48db4d62019-11-11 10:32:45 -080033 "public/pw_string/type_to_string.h",
Wyatt Heplerce9b9522019-11-11 10:45:48 -080034 "public/pw_string/util.h",
Wyatt Hepler48db4d62019-11-11 10:32:45 -080035 ]
36 sources = [
Wyatt Heplere2dc6d12019-11-15 09:05:07 -080037 "format.cc",
Wyatt Heplerce9b9522019-11-11 10:45:48 -080038 "string_builder.cc",
Wyatt Hepler48db4d62019-11-11 10:32:45 -080039 "type_to_string.cc",
40 ]
Wyatt Hepler48db4d62019-11-11 10:32:45 -080041 public_deps = [
Ewout van Bekkumc2e9d882021-04-29 16:01:27 -070042 "$dir_pw_assert",
Wyatt Hepler48db4d62019-11-11 10:32:45 -080043 "$dir_pw_preprocessor",
Ewout van Bekkumf89f1372021-05-03 11:15:54 -070044 "$dir_pw_result",
Wyatt Hepler48db4d62019-11-11 10:32:45 -080045 "$dir_pw_status",
46 ]
47}
48
Alexei Frolova454c682019-11-19 10:55:07 -080049pw_test_group("tests") {
50 tests = [
51 ":format_test",
Wyatt Hepler706a5ae2020-01-09 17:01:38 -080052 ":string_builder_test",
Alexei Frolova454c682019-11-19 10:55:07 -080053 ":to_string_test",
54 ":type_to_string_test",
Wyatt Hepler706a5ae2020-01-09 17:01:38 -080055 ":util_test",
Alexei Frolova454c682019-11-19 10:55:07 -080056 ]
57 group_deps = [
58 "$dir_pw_preprocessor:tests",
Alexei Frolova454c682019-11-19 10:55:07 -080059 "$dir_pw_status:tests",
60 ]
61}
62
Wyatt Heplere2dc6d12019-11-15 09:05:07 -080063pw_test("format_test") {
Rob Mohra0ba54f2020-02-27 11:43:49 -080064 deps = [ ":pw_string" ]
65 sources = [ "format_test.cc" ]
Wyatt Heplere2dc6d12019-11-15 09:05:07 -080066}
67
Wyatt Heplerce9b9522019-11-11 10:45:48 -080068pw_test("string_builder_test") {
Rob Mohra0ba54f2020-02-27 11:43:49 -080069 deps = [ ":pw_string" ]
70 sources = [ "string_builder_test.cc" ]
Wyatt Heplerce9b9522019-11-11 10:45:48 -080071}
72
Wyatt Hepler58823c12019-11-13 14:27:31 -080073pw_test("to_string_test") {
Rob Mohra0ba54f2020-02-27 11:43:49 -080074 deps = [ ":pw_string" ]
75 sources = [ "to_string_test.cc" ]
Wyatt Hepler58823c12019-11-13 14:27:31 -080076}
77
Wyatt Hepler48db4d62019-11-11 10:32:45 -080078pw_test("type_to_string_test") {
Rob Mohra0ba54f2020-02-27 11:43:49 -080079 deps = [ ":pw_string" ]
80 sources = [ "type_to_string_test.cc" ]
Wyatt Hepler48db4d62019-11-11 10:32:45 -080081}
Wyatt Hepler8a823ce2019-11-15 12:03:57 -080082
Wyatt Heplerce9b9522019-11-11 10:45:48 -080083pw_test("util_test") {
Rob Mohra0ba54f2020-02-27 11:43:49 -080084 deps = [ ":pw_string" ]
85 sources = [ "util_test.cc" ]
Wyatt Heplerce9b9522019-11-11 10:45:48 -080086}
87
Wyatt Heplerfe85de22019-11-19 17:10:20 -080088pw_doc_group("docs") {
Rob Mohra0ba54f2020-02-27 11:43:49 -080089 sources = [ "docs.rst" ]
Wyatt Heplerfe85de22019-11-19 17:10:20 -080090 report_deps = [
91 ":format_size_report",
92 ":string_builder_size_report",
93 ]
94}
95
Wyatt Hepler8a823ce2019-11-15 12:03:57 -080096pw_size_report("format_size_report") {
97 title = "Using pw::string::Format instead of snprintf"
98
99 binaries = [
100 {
101 target = "size_report:single_write_format"
102 base = "size_report:single_write_snprintf"
Wyatt Heplerfe85de22019-11-19 17:10:20 -0800103 label = "Format instead of snprintf once, return size"
Wyatt Hepler8a823ce2019-11-15 12:03:57 -0800104 },
105 {
106 target = "size_report:multiple_writes_format"
107 base = "size_report:multiple_writes_snprintf"
Wyatt Heplerfe85de22019-11-19 17:10:20 -0800108 label = "Format instead of snprintf 10 times, handle errors"
Wyatt Hepler8a823ce2019-11-15 12:03:57 -0800109 },
110 {
111 target = "size_report:many_writes_format"
112 base = "size_report:many_writes_snprintf"
Wyatt Heplerfe85de22019-11-19 17:10:20 -0800113 label = "Format instead of snprintf 50 times, no error handling"
114 },
115 ]
116}
117
118pw_size_report("string_builder_size_report") {
119 title = "Using pw::StringBuilder instead of snprintf"
120
121 binaries = [
122 {
123 target = "size_report:build_string_with_string_builder"
124 base = "size_report:build_string_with_snprintf"
125 label = "Total StringBuilder cost when used alongside snprintf"
126 },
127 {
128 target = "size_report:build_string_with_string_builder_no_base_snprintf"
129 base = "size_report:build_string_with_snprintf_no_base_snprintf"
130 label = "StringBuilder cost when completely replacing snprintf"
131 },
132 {
133 target = "size_report:build_string_incremental_with_string_builder"
134 base = "size_report:build_string_incremental_with_snprintf"
135 label = "Incremental cost relative to snprintf for 10 strings"
Wyatt Hepler8a823ce2019-11-15 12:03:57 -0800136 },
137 ]
138}