1# Copyright 2021 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_crypto/backend.gni") 19import("$dir_pw_docgen/docs.gni") 20import("$dir_pw_protobuf_compiler/proto.gni") 21import("$dir_pw_third_party/nanopb/nanopb.gni") 22import("$dir_pw_third_party/protobuf/protobuf.gni") 23import("$dir_pw_thread/backend.gni") 24import("$dir_pw_unit_test/test.gni") 25 26declare_args() { 27 # The build target that overrides the default configuration options for this 28 # module. This should point to a source set that provides defines through a 29 # public config (which may -include a file or add defines directly). 30 pw_software_update_CONFIG = pw_build_DEFAULT_MODULE_CONFIG 31} 32 33config("public_include_path") { 34 include_dirs = [ "public" ] 35 visibility = [ ":*" ] 36} 37 38pw_source_set("config") { 39 public = [ "public/pw_software_update/config.h" ] 40 public_configs = [ ":public_include_path" ] 41 public_deps = [ pw_software_update_CONFIG ] 42} 43 44pw_proto_library("protos") { 45 deps = [ 46 "$dir_pw_protobuf:common_protos", 47 "$dir_pw_tokenizer:proto", 48 ] 49 50 if (dir_pw_third_party_protobuf != "") { 51 # nanopb does not automatically generate the well-known types. If we have 52 # a checkout of the protobuf repo, add it here so we can enable the nanopb 53 # targets. 54 deps += [ "$dir_pw_third_party/protobuf:wellknown_types" ] 55 } 56 57 sources = [ 58 "bundled_update.proto", 59 "tuf.proto", 60 "update_bundle.proto", 61 ] 62 inputs = [ 63 "bundled_update.pwpb_options", 64 "bundled_update.options", 65 ] 66 prefix = "pw_software_update" 67 python_package = "py" 68} 69 70pw_doc_group("docs") { 71 sources = [ 72 "cli.rst", 73 "design.rst", 74 "docs.rst", 75 "get_started.rst", 76 "guides.rst", 77 ] 78} 79 80if (pw_crypto_SHA256_BACKEND != "" && pw_crypto_ECDSA_BACKEND != "") { 81 pw_source_set("openable_reader") { 82 public_configs = [ ":public_include_path" ] 83 public_deps = [ dir_pw_stream ] 84 public = [ "public/pw_software_update/openable_reader.h" ] 85 } 86 87 pw_source_set("blob_store_openable_reader") { 88 public_configs = [ ":public_include_path" ] 89 public_deps = [ 90 ":openable_reader", 91 dir_pw_blob_store, 92 ] 93 public = [ "public/pw_software_update/blob_store_openable_reader.h" ] 94 } 95 96 pw_source_set("update_bundle") { 97 public_configs = [ ":public_include_path" ] 98 public_deps = [ 99 ":blob_store_openable_reader", 100 ":openable_reader", 101 "$dir_pw_stream:interval_reader", 102 dir_pw_protobuf, 103 dir_pw_result, 104 dir_pw_status, 105 dir_pw_stream, 106 ] 107 public = [ 108 "public/pw_software_update/bundled_update_backend.h", 109 "public/pw_software_update/manifest_accessor.h", 110 "public/pw_software_update/update_bundle_accessor.h", 111 ] 112 deps = [ 113 ":config", 114 ":protos.pwpb", 115 "$dir_pw_crypto:ecdsa", 116 "$dir_pw_crypto:sha256", 117 dir_pw_log, 118 dir_pw_string, 119 ] 120 sources = [ 121 "manifest_accessor.cc", 122 "update_bundle_accessor.cc", 123 ] 124 } 125} else { 126 group("openable_reader") { 127 } 128 group("blob_store_openable_reader") { 129 } 130 group("update_bundle") { 131 } 132} 133 134if (dir_pw_third_party_nanopb != "" && dir_pw_third_party_protobuf != "") { 135 pw_source_set("bundled_update_service") { 136 public_configs = [ ":public_include_path" ] 137 public_deps = [ 138 ":protos.nanopb_rpc", 139 ":update_bundle", 140 dir_pw_result, 141 dir_pw_status, 142 dir_pw_work_queue, 143 ] 144 deps = [ 145 ":config", 146 ":protos.pwpb", 147 "$dir_pw_sync:borrow", 148 "$dir_pw_sync:lock_annotations", 149 "$dir_pw_sync:mutex", 150 dir_pw_log, 151 dir_pw_string, 152 dir_pw_tokenizer, 153 ] 154 public = [ "public/pw_software_update/bundled_update_service.h" ] 155 sources = [ "bundled_update_service.cc" ] 156 } 157} else { 158 group("bundled_update_service") { 159 } 160} 161 162pw_source_set("bundled_update_service_pwpb") { 163 public_configs = [ ":public_include_path" ] 164 public_deps = [ 165 ":protos.pwpb_rpc", 166 ":update_bundle", 167 dir_pw_result, 168 dir_pw_status, 169 dir_pw_work_queue, 170 ] 171 deps = [ 172 ":config", 173 ":protos.pwpb", 174 "$dir_pw_sync:borrow", 175 "$dir_pw_sync:lock_annotations", 176 "$dir_pw_sync:mutex", 177 dir_pw_log, 178 dir_pw_string, 179 dir_pw_tokenizer, 180 ] 181 public = [ "public/pw_software_update/bundled_update_service_pwpb.h" ] 182 sources = [ "bundled_update_service_pwpb.cc" ] 183} 184 185pw_python_action("generate_test_bundle") { 186 header_output = "$target_gen_dir/$target_name/test_bundles.h" 187 script = "py/pw_software_update/generate_test_bundle.py" 188 python_deps = [ 189 ":protos.python", 190 "py", 191 ] 192 outputs = [ header_output ] 193 args = [ rebase_path(header_output) ] 194} 195 196config("generated_test_bundle_include") { 197 _generated_outputs = get_target_outputs(":generate_test_bundle") 198 include_dirs = [ get_path_info(_generated_outputs[0], "dir") ] 199} 200 201all_dependency_met = 202 dir_pw_third_party_nanopb != "" && dir_pw_third_party_protobuf != "" && 203 pw_thread_THREAD_BACKEND != "" && pw_crypto_SHA256_BACKEND != "" && 204 pw_crypto_ECDSA_BACKEND != "" 205 206pw_test("update_bundle_test") { 207 enable_if = all_dependency_met 208 sources = [ "update_bundle_test.cc" ] 209 public_deps = [ 210 ":blob_store_openable_reader", 211 ":bundled_update_service", 212 ":generate_test_bundle", 213 ":update_bundle", 214 "$dir_pw_kvs:fake_flash", 215 "$dir_pw_kvs:fake_flash_test_key_value_store", 216 dir_pw_blob_store, 217 ] 218 configs = [ ":generated_test_bundle_include" ] 219} 220 221pw_test_group("tests") { 222 tests = [ 223 ":bundled_update_service_pwpb_test", 224 ":bundled_update_service_test", 225 ":update_bundle_test", 226 ] 227} 228 229pw_test("bundled_update_service_test") { 230 enable_if = all_dependency_met 231 sources = [ "bundled_update_service_test.cc" ] 232 public_deps = [ ":bundled_update_service" ] 233} 234 235pw_test("bundled_update_service_pwpb_test") { 236 enable_if = pw_thread_THREAD_BACKEND != "" && 237 pw_crypto_SHA256_BACKEND != "" && pw_crypto_ECDSA_BACKEND != "" 238 sources = [ "bundled_update_service_pwpb_test.cc" ] 239 public_deps = [ ":bundled_update_service_pwpb" ] 240} 241