• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2022 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
15load("@com_google_protobuf//bazel:java_lite_proto_library.bzl", "java_lite_proto_library")
16load("@com_google_protobuf//bazel:java_proto_library.bzl", "java_proto_library")
17load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
18load("@rules_cc//cc:cc_library.bzl", "cc_library")
19load("@rules_python//python:proto.bzl", "py_proto_library")
20load("@rules_python//sphinxdocs:sphinx_docs_library.bzl", "sphinx_docs_library")
21load("//pw_build:compatibility.bzl", "incompatible_with_mcu")
22load("//pw_build:copy_to_bin.bzl", "copy_to_bin")
23load(
24    "//pw_protobuf_compiler:pw_proto_library.bzl",
25    "pwpb_proto_library",
26    "raw_rpc_proto_library",
27)
28load("//pw_unit_test:pw_cc_test.bzl", "pw_cc_test")
29
30package(
31    default_visibility = ["//visibility:public"],
32    features = ["-layering_check"],
33)
34
35licenses(["notice"])
36
37hosts_lin_mac = {
38    "@platforms//os:linux": [],
39    "@platforms//os:macos": [],
40    "//conditions:default": ["@platforms//:incompatible"],
41}
42
43cc_library(
44    name = "config",
45    hdrs = ["public/pw_transfer/internal/config.h"],
46    strip_include_prefix = "public",
47    deps = [
48        ":config_override",
49        "//pw_chrono:system_clock",
50        "//pw_preprocessor",
51    ],
52)
53
54label_flag(
55    name = "config_override",
56    build_setting_default = "//pw_build:default_module_config",
57)
58
59cc_library(
60    name = "core",
61    srcs = [
62        "chunk.cc",
63        "client_context.cc",
64        "context.cc",
65        "rate_estimate.cc",
66        "server_context.cc",
67        "transfer_thread.cc",
68    ],
69    hdrs = [
70        "public/pw_transfer/handler.h",
71        "public/pw_transfer/internal/chunk.h",
72        "public/pw_transfer/internal/client_context.h",
73        "public/pw_transfer/internal/context.h",
74        "public/pw_transfer/internal/event.h",
75        "public/pw_transfer/internal/protocol.h",
76        "public/pw_transfer/internal/server_context.h",
77        "public/pw_transfer/rate_estimate.h",
78        "public/pw_transfer/transfer_thread.h",
79    ],
80    implementation_deps = ["//pw_assert:check"],
81    strip_include_prefix = "public",
82    deps = [
83        ":config",
84        ":transfer_pwpb",
85        ":transfer_raw_rpc",
86        "//pw_assert:assert",
87        "//pw_bytes",
88        "//pw_chrono:system_clock",
89        "//pw_containers:intrusive_list",
90        "//pw_log",
91        "//pw_log:rate_limited",
92        "//pw_preprocessor",
93        "//pw_protobuf",
94        "//pw_result",
95        "//pw_rpc:client_server",
96        "//pw_rpc:internal_packet_pwpb",
97        "//pw_rpc/raw:client_api",
98        "//pw_rpc/raw:server_api",
99        "//pw_status",
100        "//pw_stream",
101        "//pw_sync:binary_semaphore",
102        "//pw_sync:timed_thread_notification",
103        "//pw_thread:thread_core",
104        "//pw_varint",
105    ],
106)
107
108cc_library(
109    name = "pw_transfer",
110    srcs = [
111        "transfer.cc",
112    ],
113    hdrs = [
114        "public/pw_transfer/transfer.h",
115    ],
116    implementation_deps = ["//pw_assert:check"],
117    strip_include_prefix = "public",
118    deps = [
119        ":core",
120        "//pw_bytes",
121        "//pw_log",
122        "//pw_result",
123        "//pw_rpc:internal_packet_pwpb",
124        "//pw_rpc/raw:server_api",
125        "//pw_status",
126        "//pw_stream",
127    ],
128)
129
130cc_library(
131    name = "client",
132    srcs = [
133        "client.cc",
134    ],
135    hdrs = [
136        "public/pw_transfer/client.h",
137    ],
138    strip_include_prefix = "public",
139    deps = [
140        ":core",
141        "//pw_function",
142        "//pw_log",
143        "//pw_stream",
144    ],
145)
146
147cc_library(
148    name = "atomic_file_transfer_handler",
149    srcs = ["atomic_file_transfer_handler.cc"],
150    hdrs = [
151        "public/pw_transfer/atomic_file_transfer_handler.h",
152    ],
153    strip_include_prefix = "public",
154    deps = [
155        ":atomic_file_transfer_handler_internal",
156        ":core",
157        "//pw_log",
158        "//pw_stream:std_file_stream",
159    ],
160)
161
162cc_library(
163    name = "atomic_file_transfer_handler_internal",
164    srcs = [
165        "pw_transfer_private/filename_generator.h",
166    ],
167)
168
169cc_library(
170    name = "test_helpers",
171    testonly = True,
172    srcs = [
173        "pw_transfer_private/chunk_testing.h",
174    ],
175    implementation_deps = ["//pw_containers:vector"],
176    deps = [
177        ":core",
178        "//pw_unit_test",
179    ],
180)
181
182pw_cc_test(
183    name = "chunk_test",
184    srcs = ["chunk_test.cc"],
185    deps = [":core"],
186)
187
188pw_cc_test(
189    name = "handler_test",
190    srcs = ["handler_test.cc"],
191    # TODO: b/235345886 - Fix transfer tests on Windows and non-host builds.
192    target_compatible_with = select(hosts_lin_mac),
193    deps = [":pw_transfer"],
194)
195
196pw_cc_test(
197    name = "atomic_file_transfer_handler_test",
198    srcs = ["atomic_file_transfer_handler_test.cc"],
199    # TODO: b/235345886 - Fix transfer tests on Windows and non-host builds.
200    target_compatible_with = select(hosts_lin_mac),
201    deps = [
202        ":atomic_file_transfer_handler",
203        ":atomic_file_transfer_handler_internal",
204        ":pw_transfer",
205        "//pw_random",
206        "//pw_string",
207    ],
208)
209
210pw_cc_test(
211    name = "transfer_thread_test",
212    srcs = ["transfer_thread_test.cc"],
213    # TODO: b/235345886 - Fix transfer tests on Windows and non-host builds.
214    target_compatible_with = select(hosts_lin_mac),
215    deps = [
216        ":pw_transfer",
217        ":test_helpers",
218        "//pw_assert:check",
219        "//pw_rpc:test_helpers",
220        "//pw_rpc/raw:client_testing",
221        "//pw_rpc/raw:test_method_context",
222        "//pw_thread:thread",
223    ],
224)
225
226pw_cc_test(
227    name = "transfer_test",
228    srcs = ["transfer_test.cc"],
229    # TODO: b/235345886 - Fix transfer tests on Windows and non-host builds.
230    target_compatible_with = select(hosts_lin_mac),
231    deps = [
232        ":pw_transfer",
233        ":test_helpers",
234        "//pw_assert:check",
235        "//pw_containers:algorithm",
236        "//pw_rpc:test_helpers",
237        "//pw_rpc/raw:test_method_context",
238        "//pw_thread:thread",
239    ],
240)
241
242pw_cc_test(
243    name = "client_test",
244    srcs = ["client_test.cc"],
245    # TODO: b/235345886 - Fix transfer tests on Windows and non-host builds.
246    target_compatible_with = select(hosts_lin_mac),
247    deps = [
248        ":client",
249        ":test_helpers",
250        "//pw_assert:check",
251        "//pw_rpc:test_helpers",
252        "//pw_rpc/raw:client_testing",
253        "//pw_thread:sleep",
254        "//pw_thread:thread",
255    ],
256)
257
258proto_library(
259    name = "transfer_proto",
260    srcs = [
261        "transfer.proto",
262    ],
263)
264
265pwpb_proto_library(
266    name = "transfer_pwpb",
267    deps = [":transfer_proto"],
268)
269
270raw_rpc_proto_library(
271    name = "transfer_raw_rpc",
272    deps = [":transfer_proto"],
273)
274
275py_proto_library(
276    name = "transfer_proto_pb2",
277    deps = [":transfer_proto"],
278)
279
280java_proto_library(
281    name = "transfer_proto_java",
282    deps = [":transfer_proto"],
283)
284
285java_lite_proto_library(
286    name = "transfer_proto_java_lite",
287    deps = [":transfer_proto"],
288)
289
290filegroup(
291    name = "doxygen",
292    srcs = [
293        "public/pw_transfer/atomic_file_transfer_handler.h",
294    ],
295)
296
297sphinx_docs_library(
298    name = "docs",
299    srcs = [
300        "api.rst",
301        "docs.rst",
302        "transfer.proto",
303    ],
304    prefix = "pw_transfer/",
305    target_compatible_with = incompatible_with_mcu(),
306)
307
308copy_to_bin(
309    name = "js_protos",
310    srcs = ["transfer.proto"],
311)
312