system_image.gni (12399B)
1 # Copyright 2022 The Chromium Authors 2 # Use of this source code is governed by a BSD-style license that can be 3 # found in the LICENSE file. 4 5 import("//chromium/build/config/android/rules.gni") 6 7 # Creates a stub .apk suitable for use with compressed system APKs. 8 # 9 # Variables: 10 # package_name: Package name to use for the stub. 11 # version_code: Version code for the stub. 12 # version_name: Version name for the stub. 13 # package_info_from_target: Use the package name, version_code, and <permission>s 14 # from this apk/bundle target. 15 # static_library_name: For static library apks, name for the <static-library>. 16 # static_library_version: For static library apks, version for the 17 # <static-library> tag (for TrichromeLibrary, we set this to be the same 18 # as the package's version_code) 19 # stub_output: Path to output stub apk (default: do not create a stub). 20 # 21 # package_name and package_info_from_target are mutually exclusive. 22 template("system_image_stub_apk") { 23 # Android requires stubs end with -Stub.apk. 24 assert(filter_exclude([ invoker.stub_output ], [ "*-Stub.apk" ]) == [], 25 "stub_output \"${invoker.stub_output}\" must end with \"-Stub.apk\"") 26 27 _resource_apk_path = "${target_out_dir}/$target_name.ap_" 28 _resource_apk_target_name = "${target_name}__compile_resources" 29 30 _manifest_target_name = "${target_name}__manifest" 31 _manifest_path = "$target_gen_dir/$_manifest_target_name.xml" 32 33 if (defined(invoker.package_info_from_target)) { 34 _apk_or_bundle_target = invoker.package_info_from_target 35 _build_config = 36 get_label_info(_apk_or_bundle_target, "target_gen_dir") + "/" + 37 get_label_info(_apk_or_bundle_target, "name") + ".build_config.json" 38 _rebased_build_config = rebase_path(_build_config, root_build_dir) 39 } 40 action_with_pydeps("$_manifest_target_name") { 41 outputs = [ _manifest_path ] 42 script = "//chromium/build/android/gyp/create_stub_manifest.py" 43 args = [ 44 "--output", 45 rebase_path(_manifest_path, root_build_dir), 46 ] 47 if (defined(invoker.static_library_name)) { 48 args += [ 49 "--static-library-name", 50 invoker.static_library_name, 51 ] 52 53 # TODO(crbug.com/40253411): Make static_library_version mandatory. 54 if (defined(invoker.static_library_version)) { 55 args += [ 56 "--static-library-version", 57 invoker.static_library_version, 58 ] 59 } else { 60 args += [ "--static-library-version=1" ] 61 } 62 } 63 if (defined(_apk_or_bundle_target)) { 64 deps = [ "$_apk_or_bundle_target$build_config_target_suffix" ] 65 inputs = [ _build_config ] 66 args += [ "--use-permissions-from=@FileArg($_rebased_build_config:deps_info:lint_android_manifest)" ] 67 } 68 } 69 70 _target_sdk_version = default_target_sdk_version 71 if (defined(invoker.override_target_sdk)) { 72 _target_sdk_version = invoker.override_target_sdk 73 } 74 75 action_with_pydeps(_resource_apk_target_name) { 76 script = "//chromium/build/android/gyp/compile_resources.py" 77 inputs = [ 78 _manifest_path, 79 android_sdk_tools_bundle_aapt2, 80 android_sdk_jar, 81 82 # TODO(b/315080809#comment4): remove these files after fixing 83 # build/print_python_deps.py. 84 "//third_party/protobuf/python/google/__init__.py", 85 "//third_party/protobuf/python/google/protobuf/__init__.py", 86 "//third_party/protobuf/python/google/protobuf/compiler/__init__.py", 87 "//third_party/protobuf/python/google/protobuf/compiler/plugin_pb2.py", 88 "//third_party/protobuf/python/google/protobuf/descriptor.py", 89 "//third_party/protobuf/python/google/protobuf/descriptor_database.py", 90 "//third_party/protobuf/python/google/protobuf/descriptor_pb2.py", 91 "//third_party/protobuf/python/google/protobuf/descriptor_pool.py", 92 "//third_party/protobuf/python/google/protobuf/internal/__init__.py", 93 "//third_party/protobuf/python/google/protobuf/internal/api_implementation.py", 94 "//third_party/protobuf/python/google/protobuf/internal/builder.py", 95 "//third_party/protobuf/python/google/protobuf/internal/containers.py", 96 "//third_party/protobuf/python/google/protobuf/internal/decoder.py", 97 "//third_party/protobuf/python/google/protobuf/internal/descriptor_database_test.py", 98 "//third_party/protobuf/python/google/protobuf/internal/descriptor_pool_test.py", 99 "//third_party/protobuf/python/google/protobuf/internal/descriptor_test.py", 100 "//third_party/protobuf/python/google/protobuf/internal/encoder.py", 101 "//third_party/protobuf/python/google/protobuf/internal/enum_type_wrapper.py", 102 "//third_party/protobuf/python/google/protobuf/internal/extension_dict.py", 103 "//third_party/protobuf/python/google/protobuf/internal/field_mask.py", 104 "//third_party/protobuf/python/google/protobuf/internal/generator_test.py", 105 "//third_party/protobuf/python/google/protobuf/internal/import_test.py", 106 "//third_party/protobuf/python/google/protobuf/internal/import_test_package/__init__.py", 107 "//third_party/protobuf/python/google/protobuf/internal/json_format_test.py", 108 "//third_party/protobuf/python/google/protobuf/internal/keywords_test.py", 109 "//third_party/protobuf/python/google/protobuf/internal/message_factory_test.py", 110 "//third_party/protobuf/python/google/protobuf/internal/message_listener.py", 111 "//third_party/protobuf/python/google/protobuf/internal/message_test.py", 112 "//third_party/protobuf/python/google/protobuf/internal/proto_builder_test.py", 113 "//third_party/protobuf/python/google/protobuf/internal/python_edition_defaults.py", 114 "//third_party/protobuf/python/google/protobuf/internal/python_message.py", 115 "//third_party/protobuf/python/google/protobuf/internal/reflection_test.py", 116 "//third_party/protobuf/python/google/protobuf/internal/service_reflection_test.py", 117 "//third_party/protobuf/python/google/protobuf/internal/symbol_database_test.py", 118 "//third_party/protobuf/python/google/protobuf/internal/test_util.py", 119 "//third_party/protobuf/python/google/protobuf/internal/testing_refleaks.py", 120 "//third_party/protobuf/python/google/protobuf/internal/text_encoding_test.py", 121 "//third_party/protobuf/python/google/protobuf/internal/text_format_test.py", 122 "//third_party/protobuf/python/google/protobuf/internal/type_checkers.py", 123 "//third_party/protobuf/python/google/protobuf/internal/unknown_fields_test.py", 124 "//third_party/protobuf/python/google/protobuf/internal/well_known_types.py", 125 "//third_party/protobuf/python/google/protobuf/internal/well_known_types_test.py", 126 "//third_party/protobuf/python/google/protobuf/internal/wire_format.py", 127 "//third_party/protobuf/python/google/protobuf/internal/wire_format_test.py", 128 "//third_party/protobuf/python/google/protobuf/json_format.py", 129 "//third_party/protobuf/python/google/protobuf/message.py", 130 "//third_party/protobuf/python/google/protobuf/message_factory.py", 131 "//third_party/protobuf/python/google/protobuf/proto_builder.py", 132 "//third_party/protobuf/python/google/protobuf/pyext/__init__.py", 133 "//third_party/protobuf/python/google/protobuf/pyext/cpp_message.py", 134 "//third_party/protobuf/python/google/protobuf/reflection.py", 135 "//third_party/protobuf/python/google/protobuf/runtime_version.py", 136 "//third_party/protobuf/python/google/protobuf/service_reflection.py", 137 "//third_party/protobuf/python/google/protobuf/symbol_database.py", 138 "//third_party/protobuf/python/google/protobuf/text_encoding.py", 139 "//third_party/protobuf/python/google/protobuf/text_format.py", 140 "//third_party/protobuf/python/google/protobuf/unknown_fields.py", 141 "//third_party/protobuf/python/google/protobuf/util/__init__.py", 142 ] 143 outputs = [ _resource_apk_path ] 144 args = [ 145 "--aapt2-path", 146 rebase_path(android_sdk_tools_bundle_aapt2, root_build_dir), 147 "--min-sdk-version=$default_min_sdk_version", 148 "--target-sdk-version=$_target_sdk_version", 149 "--android-manifest", 150 rebase_path(_manifest_path, root_build_dir), 151 "--arsc-path", 152 rebase_path(_resource_apk_path, root_build_dir), 153 ] 154 deps = [ ":$_manifest_target_name" ] 155 if (defined(invoker.package_name)) { 156 _package_name = invoker.package_name 157 _version_code = invoker.version_code 158 _version_name = invoker.version_name 159 160 # TODO(crbug.com/40253411): Make static_library_version mandatory. 161 if (defined(invoker.static_library_version)) { 162 assert(invoker.static_library_version == _version_code, 163 "$invoker.static_library_version must equal $_version_code.") 164 } 165 } else { 166 deps += [ "${_apk_or_bundle_target}$build_config_target_suffix" ] 167 inputs += [ _build_config ] 168 _package_name = "@FileArg($_rebased_build_config:deps_info:package_name)" 169 _version_code = "@FileArg($_rebased_build_config:deps_info:version_code)" 170 _version_name = "@FileArg($_rebased_build_config:deps_info:version_name)" 171 172 # TODO(crbug.com/40253411): Make static_library_version mandatory. 173 # Pass this through to ensure that the version code in the build config is 174 # the same as the static library version. 175 if (defined(invoker.static_library_version)) { 176 args += [ 177 "--static-library-version", 178 invoker.static_library_version, 179 ] 180 } 181 } 182 183 args += [ 184 "--rename-manifest-package=$_package_name", 185 "--arsc-package-name=$_package_name", 186 "--version-code=$_version_code", 187 "--version-name=$_version_name", 188 "--include-resources", 189 rebase_path(android_sdk_jar, root_build_dir), 190 ] 191 } 192 193 package_apk(target_name) { 194 forward_variables_from(invoker, 195 [ 196 "keystore_name", 197 "keystore_path", 198 "keystore_password", 199 ]) 200 min_sdk_version = default_min_sdk_version 201 deps = [ ":$_resource_apk_target_name" ] 202 203 packaged_resources_path = _resource_apk_path 204 output_apk_path = invoker.stub_output 205 } 206 } 207 208 # Generates artifacts for system APKs. 209 # 210 # Variables: 211 # apk_or_bundle_target: Target that creates input bundle or apk. 212 # input_apk_or_bundle: Path to input .apk or .aab. 213 # static_library_name: For static library apks, name for the <static-library>. 214 # static_library_version: For static library apks, version for the 215 # <static-library> tag (for TrichromeLibrary, we set this to be the same 216 # as the package's version_code) 217 # output: Path to the output system .apk or .zip. 218 # fuse_apk: Fuse all apk splits into a single .apk (default: false). 219 # stub_output: Path to output stub apk (default: do not create a stub). 220 # 221 template("system_image_apks") { 222 if (defined(invoker.stub_output)) { 223 _stub_apk_target_name = "${target_name}__stub" 224 system_image_stub_apk(_stub_apk_target_name) { 225 forward_variables_from(invoker, 226 [ 227 "static_library_name", 228 "static_library_version", 229 "override_target_sdk", 230 ]) 231 package_info_from_target = invoker.apk_or_bundle_target 232 stub_output = invoker.stub_output 233 } 234 } 235 236 action_with_pydeps(target_name) { 237 script = "//chromium/build/android/gyp/system_image_apks.py" 238 deps = [ invoker.apk_or_bundle_target ] 239 inputs = [ invoker.input_apk_or_bundle ] 240 if (defined(invoker.stub_output)) { 241 public_deps = [ ":$_stub_apk_target_name" ] 242 } 243 outputs = [ invoker.output ] 244 args = [ 245 "--input", 246 rebase_path(invoker.input_apk_or_bundle, root_out_dir), 247 "--output", 248 rebase_path(invoker.output, root_out_dir), 249 ] 250 251 _is_bundle = 252 filter_exclude([ invoker.input_apk_or_bundle ], [ "*.aab" ]) == [] 253 254 if (_is_bundle) { 255 _wrapper_path = "$root_out_dir/bin/" + 256 get_label_info(invoker.apk_or_bundle_target, "name") 257 args += [ 258 "--bundle-wrapper", 259 rebase_path(_wrapper_path, root_out_dir), 260 ] 261 inputs += [ _wrapper_path ] 262 deps += [ "//chromium/build/android:apk_operations_py" ] 263 if (defined(invoker.fuse_apk) && invoker.fuse_apk) { 264 args += [ "--fuse-apk" ] 265 } 266 } 267 } 268 }