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