xref: /aosp_15_r20/external/pigweed/pw_transfer/BUILD.gn (revision 61c4878ac05f98d0ceed94b57d316916de578985)
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
15import("//build_overrides/pigweed.gni")
16
17import("$dir_pw_build/module_config.gni")
18import("$dir_pw_docgen/docs.gni")
19import("$dir_pw_protobuf_compiler/proto.gni")
20import("$dir_pw_rpc/internal/integration_test_ports.gni")
21import("$dir_pw_thread/backend.gni")
22import("$dir_pw_toolchain/generate_toolchain.gni")
23import("$dir_pw_unit_test/test.gni")
24
25declare_args() {
26  # The build target that overrides the default configuration options for this
27  # module. This should point to a source set that provides defines through a
28  # public config (which may -include a file or add defines directly).
29  pw_transfer_CONFIG = pw_build_DEFAULT_MODULE_CONFIG
30}
31
32config("public_include_path") {
33  include_dirs = [ "public" ]
34  visibility = [ ":*" ]
35}
36
37pw_source_set("config") {
38  public = [ "public/pw_transfer/internal/config.h" ]
39  public_configs = [ ":public_include_path" ]
40  public_deps = [
41    "$dir_pw_chrono:system_timer",
42    pw_transfer_CONFIG,
43  ]
44  visibility = [ ":*" ]
45}
46
47pw_source_set("pw_transfer") {
48  public_configs = [ ":public_include_path" ]
49  public_deps = [
50    ":core",
51    ":proto.raw_rpc",
52    "$dir_pw_sync:mutex",
53    dir_pw_assert,
54    dir_pw_bytes,
55    dir_pw_result,
56    dir_pw_status,
57    dir_pw_stream,
58  ]
59  deps = [ dir_pw_log ]
60  public = [ "public/pw_transfer/transfer.h" ]
61  sources = [ "transfer.cc" ]
62}
63
64pw_source_set("client") {
65  public_configs = [ ":public_include_path" ]
66  public_deps = [
67    ":core",
68    ":proto.raw_rpc",
69    dir_pw_assert,
70    dir_pw_function,
71    dir_pw_stream,
72  ]
73  deps = [ dir_pw_log ]
74  public = [ "public/pw_transfer/client.h" ]
75  sources = [ "client.cc" ]
76}
77
78pw_source_set("core") {
79  public_configs = [ ":public_include_path" ]
80  public_deps = [
81    ":config",
82    ":proto.pwpb",
83    "$dir_pw_chrono:system_clock",
84    "$dir_pw_preprocessor",
85    "$dir_pw_rpc:client",
86    "$dir_pw_rpc/raw:client_api",
87    "$dir_pw_rpc/raw:server_api",
88    "$dir_pw_sync:binary_semaphore",
89    "$dir_pw_sync:timed_thread_notification",
90    "$dir_pw_thread:thread_core",
91    dir_pw_assert,
92    dir_pw_bytes,
93    dir_pw_result,
94    dir_pw_span,
95    dir_pw_status,
96    dir_pw_stream,
97  ]
98  deps = [
99    "$dir_pw_log:rate_limited",
100    dir_pw_log,
101    dir_pw_protobuf,
102    dir_pw_varint,
103  ]
104  public = [
105    "public/pw_transfer/handler.h",
106    "public/pw_transfer/rate_estimate.h",
107    "public/pw_transfer/transfer_thread.h",
108  ]
109  sources = [
110    "chunk.cc",
111    "client_context.cc",
112    "context.cc",
113    "public/pw_transfer/internal/chunk.h",
114    "public/pw_transfer/internal/client_context.h",
115    "public/pw_transfer/internal/context.h",
116    "public/pw_transfer/internal/event.h",
117    "public/pw_transfer/internal/protocol.h",
118    "public/pw_transfer/internal/server_context.h",
119    "rate_estimate.cc",
120    "server_context.cc",
121    "transfer_thread.cc",
122  ]
123  friend = [ ":*" ]
124  visibility = [ ":*" ]
125}
126
127pw_source_set("atomic_file_transfer_handler") {
128  public_configs = [ ":public_include_path" ]
129  public = [ "public/pw_transfer/atomic_file_transfer_handler.h" ]
130  sources = [ "atomic_file_transfer_handler.cc" ]
131  public_deps = [
132    ":core",
133    "$dir_pw_stream:std_file_stream",
134  ]
135  deps = [
136    ":atomic_file_transfer_handler_internal",
137    dir_pw_log,
138  ]
139}
140
141pw_source_set("atomic_file_transfer_handler_internal") {
142  sources = [ "pw_transfer_private/filename_generator.h" ]
143  friend = [ ":*" ]
144  visibility = [ ":*" ]
145}
146
147pw_source_set("test_helpers") {
148  public_deps = [
149    ":core",
150    dir_pw_containers,
151  ]
152  sources = [ "pw_transfer_private/chunk_testing.h" ]
153  friend = [ ":*" ]
154  visibility = [ ":*" ]
155}
156
157pw_proto_library("proto") {
158  sources = [ "transfer.proto" ]
159  python_package = "py"
160  prefix = "pw_transfer"
161}
162
163pw_test_group("tests") {
164  tests = [
165    ":chunk_test",
166    ":client_test",
167    ":transfer_thread_test",
168    ":handler_test",
169    ":atomic_file_transfer_handler_test",
170    ":transfer_test",
171  ]
172}
173
174# TODO: b/235345886 - Fix transfer tests on Windows and non-host builds.
175_is_host_toolchain = defined(pw_toolchain_SCOPE.is_host_toolchain) &&
176                     pw_toolchain_SCOPE.is_host_toolchain
177not_needed([ "_is_host_toolchain" ])
178
179pw_test("chunk_test") {
180  enable_if = pw_thread_THREAD_BACKEND != ""
181  sources = [ "chunk_test.cc" ]
182  deps = [ ":core" ]
183}
184
185pw_test("handler_test") {
186  enable_if =
187      pw_thread_THREAD_BACKEND != "" && _is_host_toolchain && host_os != "win"
188  sources = [ "handler_test.cc" ]
189  deps = [ ":pw_transfer" ]
190}
191
192pw_test("atomic_file_transfer_handler_test") {
193  enable_if =
194      pw_thread_THREAD_BACKEND != "" && _is_host_toolchain && host_os != "win"
195  sources = [ "atomic_file_transfer_handler_test.cc" ]
196  deps = [
197    ":atomic_file_transfer_handler",
198    ":atomic_file_transfer_handler_internal",
199    ":pw_transfer",
200    "$dir_pw_random",
201    "$dir_pw_string",
202  ]
203}
204
205pw_test("transfer_test") {
206  enable_if = pw_thread_THREAD_BACKEND == "$dir_pw_thread_stl:thread" &&
207              _is_host_toolchain && host_os != "win"
208  sources = [ "transfer_test.cc" ]
209  deps = [
210    ":proto.pwpb",
211    ":pw_transfer",
212    ":test_helpers",
213    "$dir_pw_assert",
214    "$dir_pw_containers",
215    "$dir_pw_rpc:test_helpers",
216    "$dir_pw_rpc/raw:test_method_context",
217    "$dir_pw_thread:thread",
218  ]
219}
220
221pw_test("transfer_thread_test") {
222  enable_if = pw_thread_THREAD_BACKEND == "$dir_pw_thread_stl:thread" &&
223              pw_unit_test_BACKEND == "$dir_pw_unit_test:light"
224  sources = [ "transfer_thread_test.cc" ]
225  deps = [
226    ":core",
227    ":proto.raw_rpc",
228    ":pw_transfer",
229    ":test_helpers",
230    "$dir_pw_rpc:test_helpers",
231    "$dir_pw_rpc/raw:client_testing",
232    "$dir_pw_rpc/raw:test_method_context",
233    "$dir_pw_thread:thread",
234  ]
235}
236
237pw_test("client_test") {
238  enable_if = pw_thread_THREAD_BACKEND == "$dir_pw_thread_stl:thread"
239  sources = [ "client_test.cc" ]
240  deps = [
241    ":client",
242    ":test_helpers",
243    "$dir_pw_rpc:test_helpers",
244    "$dir_pw_rpc/raw:client_testing",
245    "$dir_pw_thread:sleep",
246    "$dir_pw_thread:thread",
247  ]
248}
249
250pw_doc_group("docs") {
251  sources = [
252    "api.rst",
253    "docs.rst",
254  ]
255  inputs = [
256    "transfer.proto",
257    "read.svg",
258    "write.svg",
259  ]
260}
261
262pw_executable("integration_test_server") {
263  sources = [ "integration_test/server.cc" ]
264  deps = [
265    ":pw_transfer",
266    "$dir_pw_assert",
267    "$dir_pw_rpc/system_server",
268    "$dir_pw_rpc/system_server:socket",
269    "$dir_pw_stream",
270    "$dir_pw_stream:std_file_stream",
271    "$dir_pw_thread:thread",
272    "$dir_pw_thread_stl:thread",
273    dir_pw_log,
274  ]
275}
276
277pw_executable("integration_test_client") {
278  testonly = pw_unit_test_TESTONLY
279  sources = [ "integration_test/client.cc" ]
280  deps = [
281    ":client",
282    "$dir_pw_rpc:integration_testing",
283    "$dir_pw_stream:std_file_stream",
284    "$dir_pw_sync:binary_semaphore",
285    "$dir_pw_thread:thread",
286    dir_pw_assert,
287    dir_pw_log,
288    dir_pw_status,
289  ]
290}
291
292# TODO: b/228516801 - Make this actually work; this is just a placeholder.
293pw_python_script("integration_test_python_client") {
294  sources = [ "integration_test/python_client.py" ]
295}
296
297# TODO: b/228516801 - Make this actually work; this is just a placeholder.
298pw_python_script("integration_test_proxy") {
299  sources = [ "integration_test/proxy.py" ]
300}
301
302# TODO: b/228516801 - Make this actually work; this is just a placeholder.
303pw_python_script("integration_test_proxy_test") {
304  sources = [ "integration_test/proxy_test.py" ]
305}
306
307# TODO: b/228516801 - Make this actually work; this is just a placeholder.
308pw_python_script("integration_test_fixture") {
309  sources = [ "integration_test/test_fixture.py" ]
310}
311
312# TODO: b/228516801 - Make this actually work; this is just a placeholder.
313pw_python_script("cross_language_small_test") {
314  sources = [ "integration_test/cross_language_small_test.py" ]
315}
316
317# TODO: b/228516801 - Make this actually work; this is just a placeholder.
318pw_python_script("cross_language_medium_read_test") {
319  sources = [ "integration_test/cross_language_medium_read_test.py" ]
320}
321
322# TODO: b/228516801 - Make this actually work; this is just a placeholder.
323pw_python_script("cross_language_medium_write_test") {
324  sources = [ "integration_test/cross_language_medium_write_test.py" ]
325}
326
327# TODO: b/228516801 - Make this actually work; this is just a placeholder.
328pw_python_script("cross_language_large_read_test") {
329  sources = [ "integration_test/cross_language_large_read_test.py" ]
330}
331
332# TODO: b/228516801 - Make this actually work; this is just a placeholder.
333pw_python_script("cross_language_large_write_test") {
334  sources = [ "integration_test/cross_language_large_write_test.py" ]
335}
336
337# TODO: b/228516801 - Make this actually work; this is just a placeholder.
338pw_python_script("multi_transfer_test") {
339  sources = [ "integration_test/multi_transfer_test.py" ]
340}
341
342# TODO: b/228516801 - Make this actually work; this is just a placeholder.
343pw_python_script("expected_errors_test") {
344  sources = [ "integration_test/expected_errors_test.py" ]
345}
346
347# TODO: b/228516801 - Make this actually work; this is just a placeholder.
348pw_python_script("legacy_binaries_test") {
349  sources = [ "integration_test/legacy_binaries_test.py" ]
350}
351