xref: /aosp_15_r20/external/pigweed/pw_result/BUILD.gn (revision 61c4878ac05f98d0ceed94b57d316916de578985)
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("public_include_path") {
23  include_dirs = [ "public" ]
24}
25
26pw_source_set("pw_result") {
27  public_configs = [ ":public_include_path" ]
28  public_deps = [
29    "$dir_pw_assert",
30    "$dir_pw_preprocessor",
31    "$dir_pw_status",
32  ]
33  public = [ "public/pw_result/result.h" ]
34  sources = [ "public/pw_result/internal/result_internal.h" ]
35}
36
37pw_test_group("tests") {
38  tests = [
39    ":result_test",
40    ":expected_test",
41  ]
42}
43
44pw_test("result_test") {
45  deps = [
46    ":pw_result",
47    dir_pw_status,
48  ]
49  sources = [
50    "result_test.cc",
51    "statusor_test.cc",
52  ]
53}
54
55pw_source_set("expected") {
56  public_configs = [ ":public_include_path" ]
57  public = [ "public/pw_result/expected.h" ]
58  sources = [ "public/pw_result/internal/expected_impl.h" ]
59}
60
61pw_test("expected_test") {
62  deps = [ ":expected" ]
63  sources = [ "expected_test.cc" ]
64}
65
66pw_doc_group("docs") {
67  inputs = [ "Kconfig" ]
68  sources = [ "docs.rst" ]
69  report_deps = [ ":result_size" ]
70}
71
72pw_size_diff("result_size") {
73  title = "pw::Result vs. pw::Status and out pointer"
74
75  binaries = [
76    {
77      target = "size_report:result_simple"
78      base = "size_report:pointer_simple"
79      label = "Simple function"
80    },
81    {
82      target = "size_report:result_noinline"
83      base = "size_report:pointer_noinline"
84      label = "Simple function without inlining"
85    },
86    {
87      target = "size_report:result_read"
88      base = "size_report:pointer_read"
89      label = "Returning a larger object (std::span)"
90    },
91    {
92      target = "size_report:monadic_and_then"
93      base = "size_report:ladder_and_then"
94      label = "Using and_then instead of if ladder"
95    },
96    {
97      target = "size_report:monadic_or_else"
98      base = "size_report:ladder_or_else"
99      label = "Using or_else instead of if ladder"
100    },
101    {
102      target = "size_report:monadic_transform"
103      base = "size_report:ladder_transform"
104      label = "Using transform instead of if ladder"
105    },
106  ]
107}
108