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 | |
Alexei Frolov | edd2f14 | 2020-06-09 19:11:27 -0700 | [diff] [blame^] | 15 | import("$dir_pw_build/target_types.gni") |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 16 | import("$dir_pw_docgen/docs.gni") |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 17 | import("$dir_pw_protobuf_compiler/proto.gni") |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 18 | import("$dir_pw_unit_test/test.gni") |
| 19 | |
| 20 | config("default_config") { |
| 21 | include_dirs = [ "public" ] |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 22 | visibility = [ ":*" ] |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 23 | } |
| 24 | |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 25 | # pw_rpc servers depend on the protobuf library used to encode and decode |
| 26 | # requests and responses when invoking methods. This template is used to create |
| 27 | # instances of the pw_rpc server library with different implementations. |
| 28 | # |
| 29 | # The implementation parameter must refer to a library that provides the |
| 30 | # definition of the Method class in pw_rpc/internal/method.h. The Method class |
| 31 | # provides the Invoke function, which handles the server use to call into the |
| 32 | # RPC functions themselves. |
| 33 | template("_pw_rpc_server_library") { |
| 34 | assert(defined(invoker.implementation), |
| 35 | "_pw_rpc_server_library requires an implementation to be set") |
Wyatt Hepler | 7da973a | 2020-06-09 10:04:48 -0700 | [diff] [blame] | 36 | _target_name = target_name |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 37 | |
Alexei Frolov | edd2f14 | 2020-06-09 19:11:27 -0700 | [diff] [blame^] | 38 | pw_source_set(_target_name) { |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 39 | forward_variables_from(invoker, "*") |
| 40 | |
| 41 | public_configs = [ ":default_config" ] |
| 42 | public_deps = [ |
| 43 | ":common", |
| 44 | dir_pw_span, |
| 45 | dir_pw_status, |
| 46 | implementation, |
| 47 | ] |
| 48 | deps = [ |
| 49 | dir_pw_assert, |
| 50 | dir_pw_log, |
| 51 | ] |
| 52 | public = [ |
| 53 | "public/pw_rpc/server.h", |
| 54 | "public/pw_rpc/server_context.h", |
| 55 | ] |
| 56 | sources = [ |
Wyatt Hepler | cb9d957 | 2020-06-01 11:25:58 -0700 | [diff] [blame] | 57 | "base_server_writer.cc", |
| 58 | "public/pw_rpc/internal/base_server_writer.h", |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 59 | "public/pw_rpc/internal/service.h", |
| 60 | "public/pw_rpc/internal/service_registry.h", |
| 61 | "server.cc", |
| 62 | "service.cc", |
| 63 | "service_registry.cc", |
| 64 | ] |
| 65 | allow_circular_includes_from = [ implementation ] |
Wyatt Hepler | 948f547 | 2020-06-02 16:52:28 -0700 | [diff] [blame] | 66 | friend = [ "./*" ] |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 67 | } |
Wyatt Hepler | 7da973a | 2020-06-09 10:04:48 -0700 | [diff] [blame] | 68 | |
| 69 | source_set("test_utils_$_target_name") { |
| 70 | public = [ "pw_rpc_private/test_utils.h" ] |
| 71 | public_configs = [ ":private_includes" ] |
| 72 | public_deps = [ |
| 73 | ":$_target_name", |
| 74 | ":common", |
| 75 | dir_pw_span, |
| 76 | ] |
| 77 | visibility = [ "./*" ] |
| 78 | } |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | # Classes with no dependencies on the protobuf library for method invocations. |
Alexei Frolov | edd2f14 | 2020-06-09 19:11:27 -0700 | [diff] [blame^] | 82 | pw_source_set("common") { |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 83 | public_configs = [ ":default_config" ] |
| 84 | public_deps = [ |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 85 | ":protos_pwpb", |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 86 | dir_pw_assert, |
| 87 | dir_pw_span, |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 88 | dir_pw_status, |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 89 | ] |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 90 | public = [ "public/pw_rpc/channel.h" ] |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 91 | sources = [ |
| 92 | "channel.cc", |
| 93 | "packet.cc", |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 94 | "public/pw_rpc/internal/base_method.h", |
Wyatt Hepler | 7da973a | 2020-06-09 10:04:48 -0700 | [diff] [blame] | 95 | "public/pw_rpc/internal/call.h", |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 96 | "public/pw_rpc/internal/packet.h", |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 97 | ] |
Wyatt Hepler | 948f547 | 2020-06-02 16:52:28 -0700 | [diff] [blame] | 98 | friend = [ "./*" ] |
| 99 | visibility = [ "./*" ] |
| 100 | } |
| 101 | |
| 102 | # RPC server that uses Nanopb to encode and decode protobufs. RPCs use Nanopb |
| 103 | # structs as their requests and responses. |
| 104 | _pw_rpc_server_library("nanopb_server") { |
| 105 | implementation = "nanopb" |
| 106 | } |
| 107 | |
| 108 | config("private_includes") { |
| 109 | include_dirs = [ "." ] |
Wyatt Hepler | 7da973a | 2020-06-09 10:04:48 -0700 | [diff] [blame] | 110 | visibility = [ ":*" ] |
Wyatt Hepler | cb9d957 | 2020-06-01 11:25:58 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 113 | pw_proto_library("protos") { |
| 114 | sources = [ "pw_rpc_protos/packet.proto" ] |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | pw_doc_group("docs") { |
| 118 | sources = [ "docs.rst" ] |
| 119 | } |
| 120 | |
| 121 | pw_test_group("tests") { |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 122 | tests = [ |
Wyatt Hepler | cb9d957 | 2020-06-01 11:25:58 -0700 | [diff] [blame] | 123 | ":base_server_writer_test", |
Wyatt Hepler | 948f547 | 2020-06-02 16:52:28 -0700 | [diff] [blame] | 124 | "nanopb:method_test", |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 125 | ":packet_test", |
| 126 | ":server_test", |
| 127 | ] |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 130 | # RPC server for tests only. A mock method implementation is used. |
| 131 | _pw_rpc_server_library("test_server") { |
Wyatt Hepler | 948f547 | 2020-06-02 16:52:28 -0700 | [diff] [blame] | 132 | implementation = "test_impl" |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 133 | visibility = [ ":*" ] |
| 134 | } |
| 135 | |
Wyatt Hepler | 948f547 | 2020-06-02 16:52:28 -0700 | [diff] [blame] | 136 | pw_proto_library("test_protos") { |
| 137 | sources = [ "pw_rpc_test_protos/test.proto" ] |
| 138 | visibility = [ "./*" ] |
Alexei Frolov | 26e3ae6 | 2020-05-04 17:06:17 -0700 | [diff] [blame] | 139 | } |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 140 | |
Wyatt Hepler | cb9d957 | 2020-06-01 11:25:58 -0700 | [diff] [blame] | 141 | pw_test("base_server_writer_test") { |
| 142 | deps = [ |
| 143 | ":test_server", |
Wyatt Hepler | 7da973a | 2020-06-09 10:04:48 -0700 | [diff] [blame] | 144 | ":test_utils_test_server", |
Wyatt Hepler | cb9d957 | 2020-06-01 11:25:58 -0700 | [diff] [blame] | 145 | ] |
| 146 | sources = [ "base_server_writer_test.cc" ] |
| 147 | } |
| 148 | |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 149 | pw_test("packet_test") { |
| 150 | deps = [ |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 151 | ":common", |
Alexei Frolov | 5d6d392 | 2020-05-08 13:57:02 -0700 | [diff] [blame] | 152 | dir_pw_protobuf, |
| 153 | ] |
| 154 | sources = [ "packet_test.cc" ] |
| 155 | } |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 156 | |
| 157 | pw_test("server_test") { |
| 158 | deps = [ |
| 159 | ":protos_pwpb", |
| 160 | ":test_server", |
Wyatt Hepler | 7da973a | 2020-06-09 10:04:48 -0700 | [diff] [blame] | 161 | ":test_utils_test_server", |
Wyatt Hepler | 80f26ff | 2020-06-01 09:30:17 -0700 | [diff] [blame] | 162 | dir_pw_assert, |
| 163 | ] |
| 164 | sources = [ "server_test.cc" ] |
| 165 | } |