blob: 99ef6783225b3ec1552efac69105528336d36d47 [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")
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 Heplercb9d9572020-06-01 11:25:58 -070055 "base_server_writer.cc",
56 "public/pw_rpc/internal/base_server_writer.h",
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070057 "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.
69source_set("common") {
Alexei Frolov26e3ae62020-05-04 17:06:17 -070070 public_configs = [ ":default_config" ]
71 public_deps = [
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070072 ":protos_pwpb",
Alexei Frolov26e3ae62020-05-04 17:06:17 -070073 dir_pw_assert,
74 dir_pw_span,
Alexei Frolov5d6d3922020-05-08 13:57:02 -070075 dir_pw_status,
Alexei Frolov26e3ae62020-05-04 17:06:17 -070076 ]
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070077 public = [ "public/pw_rpc/channel.h" ]
Alexei Frolov5d6d3922020-05-08 13:57:02 -070078 sources = [
79 "channel.cc",
80 "packet.cc",
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070081 "public/pw_rpc/internal/base_method.h",
Alexei Frolov5d6d3922020-05-08 13:57:02 -070082 "public/pw_rpc/internal/packet.h",
Alexei Frolov5d6d3922020-05-08 13:57:02 -070083 ]
84 friend = [ ":*" ]
Wyatt Hepler80f26ff2020-06-01 09:30:17 -070085 visibility = [ ":*" ]
Alexei Frolov5d6d3922020-05-08 13:57:02 -070086}
87
Wyatt Heplercb9d9572020-06-01 11:25:58 -070088source_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 Frolov5d6d3922020-05-08 13:57:02 -070097pw_proto_library("protos") {
98 sources = [ "pw_rpc_protos/packet.proto" ]
Alexei Frolov26e3ae62020-05-04 17:06:17 -070099}
100
101pw_doc_group("docs") {
102 sources = [ "docs.rst" ]
103}
104
105pw_test_group("tests") {
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700106 tests = [
Wyatt Heplercb9d9572020-06-01 11:25:58 -0700107 ":base_server_writer_test",
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700108 ":packet_test",
109 ":server_test",
110 ]
Alexei Frolov26e3ae62020-05-04 17:06:17 -0700111}
112
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700113# 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
119config("test_config") {
120 include_dirs = [ "test_public" ]
121 visibility = [ ":test_method" ]
122}
123
124source_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 Frolov26e3ae62020-05-04 17:06:17 -0700129}
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700130
Wyatt Heplercb9d9572020-06-01 11:25:58 -0700131pw_test("base_server_writer_test") {
132 deps = [
133 ":test_server",
134 ":test_utils",
135 ]
136 sources = [ "base_server_writer_test.cc" ]
137}
138
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700139pw_test("packet_test") {
140 deps = [
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700141 ":common",
Alexei Frolov5d6d3922020-05-08 13:57:02 -0700142 dir_pw_protobuf,
143 ]
144 sources = [ "packet_test.cc" ]
145}
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700146
147pw_test("server_test") {
148 deps = [
149 ":protos_pwpb",
150 ":test_server",
Wyatt Heplercb9d9572020-06-01 11:25:58 -0700151 ":test_utils",
Wyatt Hepler80f26ff2020-06-01 09:30:17 -0700152 dir_pw_assert,
153 ]
154 sources = [ "server_test.cc" ]
155}