blob: 2a6b6375c8dcd3a59b7f247f3dd20203599de9fa [file] [log] [blame]
Alexei Frolov26e3ae62020-05-04 17:06:17 -07001# 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
15import("$dir_pw_docgen/docs.gni")
Alexei Frolov5d6d3922020-05-08 13:57:02 -070016import("$dir_pw_protobuf_compiler/proto.gni")
Alexei Frolov26e3ae62020-05-04 17:06:17 -070017import("$dir_pw_unit_test/test.gni")
18
19config("default_config") {
20 include_dirs = [ "public" ]
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070021 visibility = [ ":*" ]
Alexei Frolov26e3ae62020-05-04 17:06:17 -070022}
23
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070024# 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.
32template("_pw_rpc_server_library") {
33 assert(defined(invoker.implementation),
34 "_pw_rpc_server_library requires an implementation to be set")
Wyatt Hepler7da973a2020-06-09 10:04:48 -070035 _target_name = target_name
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070036
Wyatt Hepler7da973a2020-06-09 10:04:48 -070037 source_set(_target_name) {
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070038 forward_variables_from(invoker, "*")
39
40 public_configs = [ ":default_config" ]
41 public_deps = [
42 ":common",
43 dir_pw_span,
44 dir_pw_status,
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 Heplercb9d9572020-06-01 11:25:58 -070056 "base_server_writer.cc",
57 "public/pw_rpc/internal/base_server_writer.h",
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070058 "public/pw_rpc/internal/service.h",
59 "public/pw_rpc/internal/service_registry.h",
60 "server.cc",
61 "service.cc",
62 "service_registry.cc",
63 ]
64 allow_circular_includes_from = [ implementation ]
Wyatt Hepler948f5472020-06-02 16:52:28 -070065 friend = [ "./*" ]
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070066 }
Wyatt Hepler7da973a2020-06-09 10:04:48 -070067
68 source_set("test_utils_$_target_name") {
69 public = [ "pw_rpc_private/test_utils.h" ]
70 public_configs = [ ":private_includes" ]
71 public_deps = [
72 ":$_target_name",
73 ":common",
74 dir_pw_span,
75 ]
76 visibility = [ "./*" ]
77 }
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070078}
79
80# Classes with no dependencies on the protobuf library for method invocations.
81source_set("common") {
Alexei Frolov26e3ae62020-05-04 17:06:17 -070082 public_configs = [ ":default_config" ]
83 public_deps = [
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070084 ":protos_pwpb",
Alexei Frolov26e3ae62020-05-04 17:06:17 -070085 dir_pw_assert,
86 dir_pw_span,
Alexei Frolov5d6d3922020-05-08 13:57:02 -070087 dir_pw_status,
Alexei Frolov26e3ae62020-05-04 17:06:17 -070088 ]
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070089 public = [ "public/pw_rpc/channel.h" ]
Alexei Frolov5d6d3922020-05-08 13:57:02 -070090 sources = [
91 "channel.cc",
92 "packet.cc",
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070093 "public/pw_rpc/internal/base_method.h",
Wyatt Hepler7da973a2020-06-09 10:04:48 -070094 "public/pw_rpc/internal/call.h",
Alexei Frolov5d6d3922020-05-08 13:57:02 -070095 "public/pw_rpc/internal/packet.h",
Alexei Frolov5d6d3922020-05-08 13:57:02 -070096 ]
Wyatt Hepler948f5472020-06-02 16:52:28 -070097 friend = [ "./*" ]
98 visibility = [ "./*" ]
99}
100
101# RPC server that uses Nanopb to encode and decode protobufs. RPCs use Nanopb
102# structs as their requests and responses.
103_pw_rpc_server_library("nanopb_server") {
104 implementation = "nanopb"
105}
106
107config("private_includes") {
108 include_dirs = [ "." ]
Wyatt Hepler7da973a2020-06-09 10:04:48 -0700109 visibility = [ ":*" ]
Wyatt Heplercb9d9572020-06-01 11:25:58 -0700110}
111
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700112pw_proto_library("protos") {
113 sources = [ "pw_rpc_protos/packet.proto" ]
Alexei Frolov26e3ae62020-05-04 17:06:17 -0700114}
115
116pw_doc_group("docs") {
117 sources = [ "docs.rst" ]
118}
119
120pw_test_group("tests") {
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700121 tests = [
Wyatt Heplercb9d9572020-06-01 11:25:58 -0700122 ":base_server_writer_test",
Wyatt Hepler948f5472020-06-02 16:52:28 -0700123 "nanopb:method_test",
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700124 ":packet_test",
125 ":server_test",
126 ]
Alexei Frolov26e3ae62020-05-04 17:06:17 -0700127}
128
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700129# RPC server for tests only. A mock method implementation is used.
130_pw_rpc_server_library("test_server") {
Wyatt Hepler948f5472020-06-02 16:52:28 -0700131 implementation = "test_impl"
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700132 visibility = [ ":*" ]
133}
134
Wyatt Hepler948f5472020-06-02 16:52:28 -0700135pw_proto_library("test_protos") {
136 sources = [ "pw_rpc_test_protos/test.proto" ]
137 visibility = [ "./*" ]
Alexei Frolov26e3ae62020-05-04 17:06:17 -0700138}
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700139
Wyatt Heplercb9d9572020-06-01 11:25:58 -0700140pw_test("base_server_writer_test") {
141 deps = [
142 ":test_server",
Wyatt Hepler7da973a2020-06-09 10:04:48 -0700143 ":test_utils_test_server",
Wyatt Heplercb9d9572020-06-01 11:25:58 -0700144 ]
145 sources = [ "base_server_writer_test.cc" ]
146}
147
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700148pw_test("packet_test") {
149 deps = [
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700150 ":common",
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700151 dir_pw_protobuf,
152 ]
153 sources = [ "packet_test.cc" ]
154}
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700155
156pw_test("server_test") {
157 deps = [
158 ":protos_pwpb",
159 ":test_server",
Wyatt Hepler7da973a2020-06-09 10:04:48 -0700160 ":test_utils_test_server",
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700161 dir_pw_assert,
162 ]
163 sources = [ "server_test.cc" ]
164}