Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 1 | # Copyright 2020 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 Montanez | fb3d3fb | 2020-06-09 18:12:12 -0700 | [diff] [blame] | 15 | # gn-format disable |
| 16 | import("//build_overrides/pigweed.gni") |
| 17 | |
Alexei Frolov | edd2f14 | 2020-06-09 19:11:27 -0700 | [diff] [blame] | 18 | import("$dir_pw_build/target_types.gni") |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 19 | import("$dir_pw_docgen/docs.gni") |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 20 | import("$dir_pw_protobuf_compiler/proto.gni") |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 21 | import("$dir_pw_unit_test/test.gni") |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 22 | config("default_config") { |
| 23 | include_dirs = [ "public" ] |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 24 | visibility = [ ":*" ] |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 25 | } |
| 26 | |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 27 | # pw_rpc servers depend on the protobuf library used to encode and decode |
| 28 | # requests and responses when invoking methods. This template is used to create |
| 29 | # instances of the pw_rpc server library with different implementations. |
| 30 | # |
| 31 | # The implementation parameter must refer to a library that provides the |
| 32 | # definition of the Method class in pw_rpc/internal/method.h. The Method class |
| 33 | # provides the Invoke function, which handles the server use to call into the |
| 34 | # RPC functions themselves. |
| 35 | template("_pw_rpc_server_library") { |
| 36 | assert(defined(invoker.implementation), |
| 37 | "_pw_rpc_server_library requires an implementation to be set") |
Wyatt Hepler | 7da973a | 2020-06-09 10:04:48 -0700 | [diff] [blame] | 38 | _target_name = target_name |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 39 | |
Alexei Frolov | edd2f14 | 2020-06-09 19:11:27 -0700 | [diff] [blame] | 40 | pw_source_set(_target_name) { |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 41 | forward_variables_from(invoker, "*") |
| 42 | |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 43 | public_deps = [ |
Wyatt Hepler | 3e2d719 | 2020-06-11 08:28:21 -0700 | [diff] [blame] | 44 | ":server_library_deps", |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 45 | implementation, |
| 46 | ] |
| 47 | deps = [ |
| 48 | dir_pw_assert, |
| 49 | dir_pw_log, |
| 50 | ] |
| 51 | public = [ |
| 52 | "public/pw_rpc/server.h", |
| 53 | "public/pw_rpc/server_context.h", |
| 54 | ] |
| 55 | sources = [ |
Wyatt Hepler | cb9d957 | 2020-06-01 11:25:58 -0700 | [diff] [blame] | 56 | "base_server_writer.cc", |
| 57 | "public/pw_rpc/internal/base_server_writer.h", |
Wyatt Hepler | 671946e | 2020-06-09 14:39:33 -0700 | [diff] [blame] | 58 | "public/pw_rpc/internal/server.h", |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 59 | "public/pw_rpc/internal/service.h", |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 60 | "server.cc", |
| 61 | "service.cc", |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 62 | ] |
| 63 | allow_circular_includes_from = [ implementation ] |
Wyatt Hepler | 948f547 | 2020-06-02 16:52:28 -0700 | [diff] [blame] | 64 | friend = [ "./*" ] |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 65 | } |
Wyatt Hepler | 7da973a | 2020-06-09 10:04:48 -0700 | [diff] [blame] | 66 | |
Wyatt Hepler | 8aa0292 | 2020-07-17 08:54:37 -0700 | [diff] [blame] | 67 | pw_source_set("internal_test_utils_$_target_name") { |
| 68 | public = [ "pw_rpc_private/internal_test_utils.h" ] |
Wyatt Hepler | 7da973a | 2020-06-09 10:04:48 -0700 | [diff] [blame] | 69 | public_configs = [ ":private_includes" ] |
| 70 | public_deps = [ |
| 71 | ":$_target_name", |
| 72 | ":common", |
| 73 | dir_pw_span, |
Wyatt Hepler | 712d367 | 2020-07-13 15:52:11 -0700 | [diff] [blame] | 74 | dir_pw_unit_test, |
Wyatt Hepler | 7da973a | 2020-06-09 10:04:48 -0700 | [diff] [blame] | 75 | ] |
| 76 | visibility = [ "./*" ] |
| 77 | } |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Wyatt Hepler | 3e2d719 | 2020-06-11 08:28:21 -0700 | [diff] [blame] | 80 | # Put these dependencies into a group since they need to be shared by the server |
| 81 | # library and its implementation library. |
| 82 | group("server_library_deps") { |
| 83 | public_configs = [ ":default_config" ] |
| 84 | public_deps = [ |
| 85 | ":common", |
| 86 | "$dir_pw_containers:intrusive_list", |
| 87 | dir_pw_span, |
| 88 | dir_pw_status, |
| 89 | ] |
| 90 | visibility = [ "./*" ] |
| 91 | } |
| 92 | |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 93 | # Classes with no dependencies on the protobuf library for method invocations. |
Alexei Frolov | edd2f14 | 2020-06-09 19:11:27 -0700 | [diff] [blame] | 94 | pw_source_set("common") { |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 95 | public_configs = [ ":default_config" ] |
| 96 | public_deps = [ |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 97 | ":protos_pwpb", |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 98 | dir_pw_assert, |
Wyatt Hepler | 671946e | 2020-06-09 14:39:33 -0700 | [diff] [blame] | 99 | dir_pw_log, |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 100 | dir_pw_span, |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 101 | dir_pw_status, |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 102 | ] |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 103 | public = [ "public/pw_rpc/channel.h" ] |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 104 | sources = [ |
| 105 | "channel.cc", |
| 106 | "packet.cc", |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 107 | "public/pw_rpc/internal/base_method.h", |
Wyatt Hepler | 7da973a | 2020-06-09 10:04:48 -0700 | [diff] [blame] | 108 | "public/pw_rpc/internal/call.h", |
Wyatt Hepler | 671946e | 2020-06-09 14:39:33 -0700 | [diff] [blame] | 109 | "public/pw_rpc/internal/channel.h", |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 110 | "public/pw_rpc/internal/packet.h", |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 111 | ] |
Wyatt Hepler | 948f547 | 2020-06-02 16:52:28 -0700 | [diff] [blame] | 112 | friend = [ "./*" ] |
| 113 | visibility = [ "./*" ] |
| 114 | } |
| 115 | |
| 116 | # RPC server that uses Nanopb to encode and decode protobufs. RPCs use Nanopb |
| 117 | # structs as their requests and responses. |
| 118 | _pw_rpc_server_library("nanopb_server") { |
| 119 | implementation = "nanopb" |
| 120 | } |
| 121 | |
Wyatt Hepler | 8aa0292 | 2020-07-17 08:54:37 -0700 | [diff] [blame] | 122 | pw_source_set("nanopb_test_method_context") { |
| 123 | public_configs = [ ":default_config" ] |
| 124 | public = [ "public/pw_rpc/test_method_context.h" ] |
| 125 | sources = [ "public/pw_rpc/internal/hash.h" ] |
| 126 | public_deps = [ |
| 127 | ":nanopb_server", |
| 128 | dir_pw_containers, |
| 129 | dir_pw_unit_test, |
| 130 | ] |
Alexei Frolov | 15255c5 | 2020-07-17 08:25:49 -0700 | [diff] [blame] | 131 | friend = [ "nanopb:*" ] |
Wyatt Hepler | 8aa0292 | 2020-07-17 08:54:37 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Wyatt Hepler | 948f547 | 2020-06-02 16:52:28 -0700 | [diff] [blame] | 134 | config("private_includes") { |
| 135 | include_dirs = [ "." ] |
Wyatt Hepler | 7da973a | 2020-06-09 10:04:48 -0700 | [diff] [blame] | 136 | visibility = [ ":*" ] |
Wyatt Hepler | cb9d957 | 2020-06-01 11:25:58 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 139 | pw_proto_library("protos") { |
| 140 | sources = [ "pw_rpc_protos/packet.proto" ] |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Alexei Frolov | 7c7a386 | 2020-07-16 15:36:02 -0700 | [diff] [blame^] | 143 | pw_proto_library("echo_service_proto") { |
| 144 | sources = [ "pw_rpc_protos/echo.proto" ] |
| 145 | inputs = [ "pw_rpc_protos/echo.options" ] |
| 146 | } |
| 147 | |
Alexei Frolov | 79b7cb0 | 2020-07-06 13:51:43 -0700 | [diff] [blame] | 148 | # Source files for pw_protobuf's protoc plugin. |
| 149 | pw_input_group("nanopb_protoc_plugin") { |
| 150 | inputs = [ |
| 151 | "py/pw_rpc/codegen_nanopb.py", |
| 152 | "py/pw_rpc/plugin.py", |
| 153 | "py/pw_rpc/ids.py", |
| 154 | ] |
Alexei Frolov | 15255c5 | 2020-07-17 08:25:49 -0700 | [diff] [blame] | 155 | deps = [ "$dir_pw_protobuf:codegen_protoc_lib" ] |
Alexei Frolov | 79b7cb0 | 2020-07-06 13:51:43 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 158 | pw_doc_group("docs") { |
| 159 | sources = [ "docs.rst" ] |
Alexei Frolov | 7c7a386 | 2020-07-16 15:36:02 -0700 | [diff] [blame^] | 160 | inputs = [ |
| 161 | "pw_rpc_protos/echo.proto", |
| 162 | "pw_rpc_protos/packet.proto", |
| 163 | ] |
| 164 | group_deps = [ "nanopb:docs" ] |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | pw_test_group("tests") { |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 168 | tests = [ |
Wyatt Hepler | cb9d957 | 2020-06-01 11:25:58 -0700 | [diff] [blame] | 169 | ":base_server_writer_test", |
Wyatt Hepler | 671946e | 2020-06-09 14:39:33 -0700 | [diff] [blame] | 170 | ":channel_test", |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 171 | ":packet_test", |
| 172 | ":server_test", |
| 173 | ] |
Wyatt Hepler | af83568 | 2020-06-17 11:42:53 -0700 | [diff] [blame] | 174 | group_deps = [ "nanopb:tests" ] |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 175 | } |
| 176 | |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 177 | # RPC server for tests only. A mock method implementation is used. |
| 178 | _pw_rpc_server_library("test_server") { |
Wyatt Hepler | 948f547 | 2020-06-02 16:52:28 -0700 | [diff] [blame] | 179 | implementation = "test_impl" |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 180 | visibility = [ ":*" ] |
| 181 | } |
| 182 | |
Wyatt Hepler | 948f547 | 2020-06-02 16:52:28 -0700 | [diff] [blame] | 183 | pw_proto_library("test_protos") { |
| 184 | sources = [ "pw_rpc_test_protos/test.proto" ] |
| 185 | visibility = [ "./*" ] |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 186 | } |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 187 | |
Wyatt Hepler | cb9d957 | 2020-06-01 11:25:58 -0700 | [diff] [blame] | 188 | pw_test("base_server_writer_test") { |
| 189 | deps = [ |
Wyatt Hepler | 8aa0292 | 2020-07-17 08:54:37 -0700 | [diff] [blame] | 190 | ":internal_test_utils_test_server", |
Wyatt Hepler | cb9d957 | 2020-06-01 11:25:58 -0700 | [diff] [blame] | 191 | ":test_server", |
Wyatt Hepler | cb9d957 | 2020-06-01 11:25:58 -0700 | [diff] [blame] | 192 | ] |
| 193 | sources = [ "base_server_writer_test.cc" ] |
| 194 | } |
| 195 | |
Wyatt Hepler | 671946e | 2020-06-09 14:39:33 -0700 | [diff] [blame] | 196 | pw_test("channel_test") { |
| 197 | deps = [ |
| 198 | ":common", |
Wyatt Hepler | 8aa0292 | 2020-07-17 08:54:37 -0700 | [diff] [blame] | 199 | ":internal_test_utils_test_server", |
Wyatt Hepler | 671946e | 2020-06-09 14:39:33 -0700 | [diff] [blame] | 200 | ] |
| 201 | sources = [ "channel_test.cc" ] |
| 202 | } |
| 203 | |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 204 | pw_test("packet_test") { |
| 205 | deps = [ |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 206 | ":common", |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 207 | dir_pw_protobuf, |
| 208 | ] |
| 209 | sources = [ "packet_test.cc" ] |
| 210 | } |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 211 | |
| 212 | pw_test("server_test") { |
| 213 | deps = [ |
Wyatt Hepler | 8aa0292 | 2020-07-17 08:54:37 -0700 | [diff] [blame] | 214 | ":internal_test_utils_test_server", |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 215 | ":protos_pwpb", |
| 216 | ":test_server", |
| 217 | dir_pw_assert, |
| 218 | ] |
| 219 | sources = [ "server_test.cc" ] |
| 220 | } |