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 = [ "bundled_update.options" ] 63 prefix = "pw_software_update" 64 python_package = "py" 65} 66 67pw_doc_group("docs") { 68 sources = [ 69 "cli.rst", 70 "design.rst", 71 "docs.rst", 72 "get_started.rst", 73 "guides.rst", 74 ] 75} 76 77if (pw_crypto_SHA256_BACKEND != "" && pw_crypto_ECDSA_BACKEND != "") { 78 pw_source_set("openable_reader") { 79 public_configs = [ ":public_include_path" ] 80 public_deps = [ dir_pw_stream ] 81 public = [ "public/pw_software_update/openable_reader.h" ] 82 } 83 84 pw_source_set("blob_store_openable_reader") { 85 public_configs = [ ":public_include_path" ] 86 public_deps = [ 87 ":openable_reader", 88 dir_pw_blob_store, 89 ] 90 public = [ "public/pw_software_update/blob_store_openable_reader.h" ] 91 } 92 93 pw_source_set("update_bundle") { 94 public_configs = [ ":public_include_path" ] 95 public_deps = [ 96 ":blob_store_openable_reader", 97 ":openable_reader", 98 "$dir_pw_stream:interval_reader", 99 dir_pw_protobuf, 100 dir_pw_result, 101 dir_pw_status, 102 dir_pw_stream, 103 ] 104 public = [ 105 "public/pw_software_update/bundled_update_backend.h", 106 "public/pw_software_update/manifest_accessor.h", 107 "public/pw_software_update/update_bundle_accessor.h", 108 ] 109 deps = [ 110 ":config", 111 ":protos.pwpb", 112 "$dir_pw_crypto:ecdsa", 113 "$dir_pw_crypto:sha256", 114 dir_pw_log, 115 dir_pw_string, 116 ] 117 sources = [ 118 "manifest_accessor.cc", 119 "update_bundle_accessor.cc", 120 ] 121 } 122} else { 123 group("openable_reader") { 124 } 125 group("blob_store_openable_reader") { 126 } 127 group("update_bundle") { 128 } 129} 130 131if (dir_pw_third_party_nanopb != "" && dir_pw_third_party_protobuf != "") { 132 pw_source_set("bundled_update_service") { 133 public_configs = [ ":public_include_path" ] 134 public_deps = [ 135 ":protos.nanopb_rpc", 136 ":update_bundle", 137 dir_pw_result, 138 dir_pw_status, 139 dir_pw_work_queue, 140 ] 141 deps = [ 142 ":config", 143 ":protos.pwpb", 144 "$dir_pw_sync:borrow", 145 "$dir_pw_sync:lock_annotations", 146 "$dir_pw_sync:mutex", 147 dir_pw_log, 148 dir_pw_string, 149 dir_pw_tokenizer, 150 ] 151 public = [ "public/pw_software_update/bundled_update_service.h" ] 152 sources = [ "bundled_update_service.cc" ] 153 } 154} else { 155 group("bundled_update_service") { 156 } 157} 158 159pw_source_set("bundled_update_service_pwpb") { 160 public_configs = [ ":public_include_path" ] 161 public_deps = [ 162 ":protos.pwpb_rpc", 163 ":update_bundle", 164 dir_pw_result, 165 dir_pw_status, 166 dir_pw_work_queue, 167 ] 168 deps = [ 169 ":config", 170 ":protos.pwpb", 171 "$dir_pw_sync:borrow", 172 "$dir_pw_sync:lock_annotations", 173 "$dir_pw_sync:mutex", 174 dir_pw_log, 175 dir_pw_string, 176 dir_pw_tokenizer, 177 ] 178 public = [ "public/pw_software_update/bundled_update_service_pwpb.h" ] 179 sources = [ "bundled_update_service_pwpb.cc" ] 180} 181 182pw_python_action("generate_test_bundle") { 183 header_output = "$target_gen_dir/$target_name/test_bundles.h" 184 script = "py/pw_software_update/generate_test_bundle.py" 185 python_deps = [ 186 ":protos.python", 187 "py", 188 ] 189 outputs = [ header_output ] 190 args = [ rebase_path(header_output) ] 191} 192 193config("generated_test_bundle_include") { 194 _generated_outputs = get_target_outputs(":generate_test_bundle") 195 include_dirs = [ get_path_info(_generated_outputs[0], "dir") ] 196} 197 198all_dependency_met = 199 dir_pw_third_party_nanopb != "" && dir_pw_third_party_protobuf != "" && 200 pw_thread_THREAD_BACKEND != "" && pw_crypto_SHA256_BACKEND != "" && 201 pw_crypto_ECDSA_BACKEND != "" 202 203pw_test("update_bundle_test") { 204 enable_if = all_dependency_met 205 sources = [ "update_bundle_test.cc" ] 206 public_deps = [ 207 ":blob_store_openable_reader", 208 ":bundled_update_service", 209 ":generate_test_bundle", 210 ":update_bundle", 211 "$dir_pw_kvs:fake_flash", 212 "$dir_pw_kvs:fake_flash_test_key_value_store", 213 dir_pw_blob_store, 214 ] 215 configs = [ ":generated_test_bundle_include" ] 216} 217 218pw_test_group("tests") { 219 tests = [ 220 ":bundled_update_service_pwpb_test", 221 ":bundled_update_service_test", 222 ":update_bundle_test", 223 ] 224} 225 226pw_test("bundled_update_service_test") { 227 enable_if = all_dependency_met 228 sources = [ "bundled_update_service_test.cc" ] 229 public_deps = [ ":bundled_update_service" ] 230} 231 232pw_test("bundled_update_service_pwpb_test") { 233 enable_if = pw_thread_THREAD_BACKEND != "" && 234 pw_crypto_SHA256_BACKEND != "" && pw_crypto_ECDSA_BACKEND != "" 235 sources = [ "bundled_update_service_pwpb_test.cc" ] 236 public_deps = [ ":bundled_update_service_pwpb" ] 237} 238