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