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