Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 3 | # Copyright (C) 2022 The Android Open Source Project |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 6 | # use this file except in compliance with the License. You may obtain a copy of |
| 7 | # the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | # License for the specific language governing permissions and limitations under |
| 15 | # the License. |
Daniel Norman | 4cc9df6 | 2019-07-18 10:11:07 -0700 | [diff] [blame] | 16 | # |
| 17 | """This script merges two partial target files packages. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 18 | |
Daniel Norman | dbbf5a3 | 2020-10-22 16:03:32 -0700 | [diff] [blame] | 19 | One input package contains framework files, and the other contains vendor files. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 20 | |
Daniel Norman | dbbf5a3 | 2020-10-22 16:03:32 -0700 | [diff] [blame] | 21 | This script produces a complete, merged target files package: |
| 22 | - This package can be used to generate a flashable IMG package. |
| 23 | See --output-img. |
| 24 | - This package can be used to generate an OTA package. See --output-ota. |
| 25 | - The merged package is checked for compatibility between the two inputs. |
| 26 | |
| 27 | Usage: merge_target_files [args] |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 28 | |
Dennis Song | 5bfa43e | 2023-03-30 18:28:00 +0800 | [diff] [blame] | 29 | --framework-target-files framework-target-files-package |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 30 | The input target files package containing framework bits. This is a zip |
Dennis Song | 5bfa43e | 2023-03-30 18:28:00 +0800 | [diff] [blame] | 31 | archive or a directory. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 32 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 33 | --framework-item-list framework-item-list-file |
Daniel Norman | 5f47677 | 2022-03-02 15:46:34 -0800 | [diff] [blame] | 34 | The optional path to a newline-separated config file of items that |
| 35 | are extracted as-is from the framework target files package. |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 36 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 37 | --framework-misc-info-keys framework-misc-info-keys-file |
Daniel Norman | 5f47677 | 2022-03-02 15:46:34 -0800 | [diff] [blame] | 38 | The optional path to a newline-separated config file of keys to |
| 39 | extract from the framework META/misc_info.txt file. |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 40 | |
Dennis Song | 5bfa43e | 2023-03-30 18:28:00 +0800 | [diff] [blame] | 41 | --vendor-target-files vendor-target-files-package |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 42 | The input target files package containing vendor bits. This is a zip |
Dennis Song | 5bfa43e | 2023-03-30 18:28:00 +0800 | [diff] [blame] | 43 | archive or a directory. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 44 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 45 | --vendor-item-list vendor-item-list-file |
Daniel Norman | 5f47677 | 2022-03-02 15:46:34 -0800 | [diff] [blame] | 46 | The optional path to a newline-separated config file of items that |
| 47 | are extracted as-is from the vendor target files package. |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 48 | |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 49 | --output-target-files output-target-files-package |
Daniel Norman | fdb3881 | 2019-04-15 09:47:24 -0700 | [diff] [blame] | 50 | If provided, the output merged target files package. Also a zip archive. |
| 51 | |
| 52 | --output-dir output-directory |
| 53 | If provided, the destination directory for saving merged files. Requires |
| 54 | the --output-item-list flag. |
| 55 | Can be provided alongside --output-target-files, or by itself. |
| 56 | |
| 57 | --output-item-list output-item-list-file. |
| 58 | The optional path to a newline-separated config file that specifies the |
| 59 | file patterns to copy into the --output-dir. Required if providing |
| 60 | the --output-dir flag. |
Daniel Norman | a4911da | 2019-03-15 14:36:21 -0700 | [diff] [blame] | 61 | |
Daniel Norman | 3b64ce1 | 2019-04-16 16:11:35 -0700 | [diff] [blame] | 62 | --output-ota output-ota-package |
| 63 | The output ota package. This is a zip archive. Use of this flag may |
| 64 | require passing the --path common flag; see common.py. |
| 65 | |
Daniel Norman | 1bd2a1d | 2019-04-18 12:32:18 -0700 | [diff] [blame] | 66 | --output-img output-img-package |
| 67 | The output img package, suitable for use with 'fastboot update'. Use of |
| 68 | this flag may require passing the --path common flag; see common.py. |
| 69 | |
Daniel Norman | f031825 | 2019-04-15 11:34:56 -0700 | [diff] [blame] | 70 | --output-super-empty output-super-empty-image |
| 71 | If provided, creates a super_empty.img file from the merged target |
| 72 | files package and saves it at this path. |
| 73 | |
Daniel Norman | a4911da | 2019-03-15 14:36:21 -0700 | [diff] [blame] | 74 | --rebuild_recovery |
Po Hu | a6c5912 | 2022-02-16 08:41:29 +0000 | [diff] [blame] | 75 | Copy the recovery image used by non-A/B devices, used when |
| 76 | regenerating vendor images with --rebuild-sepolicy. |
Bill Peckham | 364c1cc | 2019-03-29 18:27:23 -0700 | [diff] [blame] | 77 | |
Daniel Norman | b0c7591 | 2020-09-24 14:30:21 -0700 | [diff] [blame] | 78 | --allow-duplicate-apkapex-keys |
| 79 | If provided, duplicate APK/APEX keys are ignored and the value from the |
| 80 | framework is used. |
| 81 | |
Daniel Norman | 571e182 | 2021-06-25 17:18:25 -0700 | [diff] [blame] | 82 | --rebuild-sepolicy |
| 83 | If provided, rebuilds odm.img or vendor.img to include merged sepolicy |
| 84 | files. If odm is present then odm is preferred. |
| 85 | |
| 86 | --vendor-otatools otatools.zip |
| 87 | If provided, use this otatools.zip when recompiling the odm or vendor |
| 88 | image to include sepolicy. |
| 89 | |
Bill Peckham | 364c1cc | 2019-03-29 18:27:23 -0700 | [diff] [blame] | 90 | --keep-tmp |
| 91 | Keep tempoary files for debugging purposes. |
Jose Galmes | 9c8f6eb | 2021-07-21 09:34:08 -0700 | [diff] [blame] | 92 | |
Dennis Song | 4aae62e | 2023-10-02 04:31:34 +0000 | [diff] [blame^] | 93 | --avb-resolve-rollback-index-location-conflict |
| 94 | If provided, resolve the conflict AVB rollback index location when |
| 95 | necessary. |
| 96 | |
Jose Galmes | 9c8f6eb | 2021-07-21 09:34:08 -0700 | [diff] [blame] | 97 | The following only apply when using the VSDK to perform dexopt on vendor apps: |
| 98 | |
| 99 | --framework-dexpreopt-config |
| 100 | If provided, the location of framwework's dexpreopt_config.zip. |
| 101 | |
| 102 | --framework-dexpreopt-tools |
| 103 | if provided, the location of framework's dexpreopt_tools.zip. |
| 104 | |
| 105 | --vendor-dexpreopt-config |
| 106 | If provided, the location of vendor's dexpreopt_config.zip. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 107 | """ |
| 108 | |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 109 | import logging |
| 110 | import os |
Daniel Norman | fdb3881 | 2019-04-15 09:47:24 -0700 | [diff] [blame] | 111 | import shutil |
Bill Peckham | 540d91a | 2019-04-25 14:18:16 -0700 | [diff] [blame] | 112 | import subprocess |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 113 | import sys |
Daniel Norman | 5f47677 | 2022-03-02 15:46:34 -0800 | [diff] [blame] | 114 | import zipfile |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 115 | |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 116 | import add_img_to_target_files |
Daniel Norman | db8cacc | 2021-04-09 15:34:43 -0700 | [diff] [blame] | 117 | import build_image |
Daniel Norman | f031825 | 2019-04-15 11:34:56 -0700 | [diff] [blame] | 118 | import build_super_image |
| 119 | import common |
Daniel Norman | 1bd2a1d | 2019-04-18 12:32:18 -0700 | [diff] [blame] | 120 | import img_from_target_files |
Daniel Norman | 2465fc8 | 2022-03-02 12:01:20 -0800 | [diff] [blame] | 121 | import merge_compatibility_checks |
| 122 | import merge_dexopt |
| 123 | import merge_meta |
| 124 | import merge_utils |
Daniel Norman | 3b64ce1 | 2019-04-16 16:11:35 -0700 | [diff] [blame] | 125 | import ota_from_target_files |
Daniel Norman | db8cacc | 2021-04-09 15:34:43 -0700 | [diff] [blame] | 126 | |
Daniel Norman | a84d13b | 2022-02-17 14:16:40 -0800 | [diff] [blame] | 127 | from common import ExternalError |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 128 | |
| 129 | logger = logging.getLogger(__name__) |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 130 | |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 131 | OPTIONS = common.OPTIONS |
Bill Peckham | cb84817 | 2020-04-03 12:50:47 -0700 | [diff] [blame] | 132 | # Always turn on verbose logging. |
| 133 | OPTIONS.verbose = True |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 134 | OPTIONS.framework_target_files = None |
Daniel Norman | 5f47677 | 2022-03-02 15:46:34 -0800 | [diff] [blame] | 135 | OPTIONS.framework_item_list = [] |
| 136 | OPTIONS.framework_misc_info_keys = [] |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 137 | OPTIONS.vendor_target_files = None |
Daniel Norman | 5f47677 | 2022-03-02 15:46:34 -0800 | [diff] [blame] | 138 | OPTIONS.vendor_item_list = [] |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 139 | OPTIONS.output_target_files = None |
Daniel Norman | fdb3881 | 2019-04-15 09:47:24 -0700 | [diff] [blame] | 140 | OPTIONS.output_dir = None |
Daniel Norman | 5f47677 | 2022-03-02 15:46:34 -0800 | [diff] [blame] | 141 | OPTIONS.output_item_list = [] |
Daniel Norman | 3b64ce1 | 2019-04-16 16:11:35 -0700 | [diff] [blame] | 142 | OPTIONS.output_ota = None |
Daniel Norman | 1bd2a1d | 2019-04-18 12:32:18 -0700 | [diff] [blame] | 143 | OPTIONS.output_img = None |
Daniel Norman | f031825 | 2019-04-15 11:34:56 -0700 | [diff] [blame] | 144 | OPTIONS.output_super_empty = None |
Daniel Norman | a4911da | 2019-03-15 14:36:21 -0700 | [diff] [blame] | 145 | OPTIONS.rebuild_recovery = False |
Daniel Norman | b0c7591 | 2020-09-24 14:30:21 -0700 | [diff] [blame] | 146 | # TODO(b/150582573): Remove this option. |
| 147 | OPTIONS.allow_duplicate_apkapex_keys = False |
Daniel Norman | 571e182 | 2021-06-25 17:18:25 -0700 | [diff] [blame] | 148 | OPTIONS.vendor_otatools = None |
| 149 | OPTIONS.rebuild_sepolicy = False |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 150 | OPTIONS.keep_tmp = False |
Dennis Song | 4aae62e | 2023-10-02 04:31:34 +0000 | [diff] [blame^] | 151 | OPTIONS.avb_resolve_rollback_index_location_conflict = False |
Jose Galmes | 9c8f6eb | 2021-07-21 09:34:08 -0700 | [diff] [blame] | 152 | OPTIONS.framework_dexpreopt_config = None |
| 153 | OPTIONS.framework_dexpreopt_tools = None |
| 154 | OPTIONS.vendor_dexpreopt_config = None |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 155 | |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 156 | |
jiangxu5 | 2bd4273 | 2022-04-11 16:02:48 +0800 | [diff] [blame] | 157 | def move_only_exists(source, destination): |
| 158 | """Judge whether the file exists and then move the file.""" |
| 159 | |
| 160 | if os.path.exists(source): |
| 161 | shutil.move(source, destination) |
| 162 | |
| 163 | |
Dennis Song | 16d6fe0 | 2023-02-23 23:37:42 +0800 | [diff] [blame] | 164 | def remove_file_if_exists(file_name): |
| 165 | """Remove the file if it exists and skip otherwise.""" |
| 166 | |
| 167 | try: |
| 168 | os.remove(file_name) |
| 169 | except FileNotFoundError: |
| 170 | pass |
| 171 | |
| 172 | |
Po Hu | 09de314 | 2023-04-26 08:49:42 +0800 | [diff] [blame] | 173 | def include_extra_in_list(item_list): |
| 174 | """ |
| 175 | 1. Include all `META/*` files in the item list. |
Dennis Song | 09f5c5d | 2023-04-14 11:43:04 +0800 | [diff] [blame] | 176 | |
| 177 | To ensure that `AddImagesToTargetFiles` can still be used with vendor item |
| 178 | list that do not specify all of the required META/ files, those files should |
| 179 | be included by default. This preserves the backward compatibility of |
| 180 | `rebuild_image_with_sepolicy`. |
Po Hu | 09de314 | 2023-04-26 08:49:42 +0800 | [diff] [blame] | 181 | |
| 182 | 2. Include `SYSTEM/build.prop` file in the item list. |
| 183 | |
| 184 | To ensure that `AddImagesToTargetFiles` for GRF vendor images, can still |
| 185 | access SYSTEM/build.prop to pass GetPartitionFingerprint check in BuildInfo |
| 186 | constructor. |
Dennis Song | 09f5c5d | 2023-04-14 11:43:04 +0800 | [diff] [blame] | 187 | """ |
| 188 | if not item_list: |
| 189 | return None |
Po Hu | 09de314 | 2023-04-26 08:49:42 +0800 | [diff] [blame] | 190 | return list(item_list) + ['META/*'] + ['SYSTEM/build.prop'] |
Dennis Song | 09f5c5d | 2023-04-14 11:43:04 +0800 | [diff] [blame] | 191 | |
| 192 | |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 193 | def create_merged_package(temp_dir): |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 194 | """Merges two target files packages into one target files structure. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 195 | |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 196 | Returns: |
| 197 | Path to merged package under temp directory. |
| 198 | """ |
Daniel Norman | dbbf5a3 | 2020-10-22 16:03:32 -0700 | [diff] [blame] | 199 | # Extract "as is" items from the input framework and vendor partial target |
Dennis Song | 5bfa43e | 2023-03-30 18:28:00 +0800 | [diff] [blame] | 200 | # files packages directly into the output temporary directory, since these |
| 201 | # items do not need special case processing. |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 202 | |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 203 | output_target_files_temp_dir = os.path.join(temp_dir, 'output') |
Dennis Song | 5bfa43e | 2023-03-30 18:28:00 +0800 | [diff] [blame] | 204 | merge_utils.CollectTargetFiles( |
| 205 | input_zipfile_or_dir=OPTIONS.framework_target_files, |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 206 | output_dir=output_target_files_temp_dir, |
Dennis Song | 5bfa43e | 2023-03-30 18:28:00 +0800 | [diff] [blame] | 207 | item_list=OPTIONS.framework_item_list) |
| 208 | merge_utils.CollectTargetFiles( |
| 209 | input_zipfile_or_dir=OPTIONS.vendor_target_files, |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 210 | output_dir=output_target_files_temp_dir, |
Dennis Song | 5bfa43e | 2023-03-30 18:28:00 +0800 | [diff] [blame] | 211 | item_list=OPTIONS.vendor_item_list) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 212 | |
Daniel Norman | dbbf5a3 | 2020-10-22 16:03:32 -0700 | [diff] [blame] | 213 | # Perform special case processing on META/* items. |
| 214 | # After this function completes successfully, all the files we need to create |
| 215 | # the output target files package are in place. |
Daniel Norman | 2465fc8 | 2022-03-02 12:01:20 -0800 | [diff] [blame] | 216 | merge_meta.MergeMetaFiles( |
Dennis Song | 36ce326 | 2023-09-13 06:53:00 +0000 | [diff] [blame] | 217 | temp_dir=temp_dir, |
| 218 | merged_dir=output_target_files_temp_dir, |
| 219 | framework_partitions=OPTIONS.framework_partition_set) |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 220 | |
Daniel Norman | 2465fc8 | 2022-03-02 12:01:20 -0800 | [diff] [blame] | 221 | merge_dexopt.MergeDexopt( |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 222 | temp_dir=temp_dir, output_target_files_dir=output_target_files_temp_dir) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 223 | |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 224 | return output_target_files_temp_dir |
| 225 | |
| 226 | |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 227 | def generate_missing_images(target_files_dir): |
| 228 | """Generate any missing images from target files.""" |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 229 | |
| 230 | # Regenerate IMAGES in the target directory. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 231 | |
Daniel Norman | dbbf5a3 | 2020-10-22 16:03:32 -0700 | [diff] [blame] | 232 | add_img_args = [ |
| 233 | '--verbose', |
| 234 | '--add_missing', |
| 235 | ] |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 236 | if OPTIONS.rebuild_recovery: |
Daniel Norman | a4911da | 2019-03-15 14:36:21 -0700 | [diff] [blame] | 237 | add_img_args.append('--rebuild_recovery') |
Dennis Song | 4aae62e | 2023-10-02 04:31:34 +0000 | [diff] [blame^] | 238 | if OPTIONS.avb_resolve_rollback_index_location_conflict: |
| 239 | add_img_args.append('--avb_resolve_rollback_index_location_conflict') |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 240 | add_img_args.append(target_files_dir) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 241 | |
| 242 | add_img_to_target_files.main(add_img_args) |
| 243 | |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 244 | |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 245 | def rebuild_image_with_sepolicy(target_files_dir): |
Daniel Norman | 571e182 | 2021-06-25 17:18:25 -0700 | [diff] [blame] | 246 | """Rebuilds odm.img or vendor.img to include merged sepolicy files. |
| 247 | |
| 248 | If odm is present then odm is preferred -- otherwise vendor is used. |
Daniel Norman | 571e182 | 2021-06-25 17:18:25 -0700 | [diff] [blame] | 249 | """ |
| 250 | partition = 'vendor' |
Dennis Song | 16d6fe0 | 2023-02-23 23:37:42 +0800 | [diff] [blame] | 251 | if os.path.exists(os.path.join(target_files_dir, 'ODM')): |
Daniel Norman | 571e182 | 2021-06-25 17:18:25 -0700 | [diff] [blame] | 252 | partition = 'odm' |
| 253 | partition_img = '{}.img'.format(partition) |
Po Hu | a6c5912 | 2022-02-16 08:41:29 +0000 | [diff] [blame] | 254 | partition_map = '{}.map'.format(partition) |
Daniel Norman | 571e182 | 2021-06-25 17:18:25 -0700 | [diff] [blame] | 255 | |
| 256 | logger.info('Recompiling %s using the merged sepolicy files.', partition_img) |
| 257 | |
| 258 | # Copy the combined SEPolicy file and framework hashes to the image that is |
| 259 | # being rebuilt. |
| 260 | def copy_selinux_file(input_path, output_filename): |
Po Hu | 0e4403e | 2021-07-06 17:05:56 +0800 | [diff] [blame] | 261 | input_filename = os.path.join(target_files_dir, input_path) |
| 262 | if not os.path.exists(input_filename): |
Dennis Song | 5bfa43e | 2023-03-30 18:28:00 +0800 | [diff] [blame] | 263 | input_filename = input_filename.replace('SYSTEM_EXT/', |
| 264 | 'SYSTEM/system_ext/') \ |
Po Hu | 0e4403e | 2021-07-06 17:05:56 +0800 | [diff] [blame] | 265 | .replace('PRODUCT/', 'SYSTEM/product/') |
| 266 | if not os.path.exists(input_filename): |
| 267 | logger.info('Skipping copy_selinux_file for %s', input_filename) |
| 268 | return |
Daniel Norman | 571e182 | 2021-06-25 17:18:25 -0700 | [diff] [blame] | 269 | shutil.copy( |
Po Hu | 0e4403e | 2021-07-06 17:05:56 +0800 | [diff] [blame] | 270 | input_filename, |
Daniel Norman | 571e182 | 2021-06-25 17:18:25 -0700 | [diff] [blame] | 271 | os.path.join(target_files_dir, partition.upper(), 'etc/selinux', |
| 272 | output_filename)) |
| 273 | |
| 274 | copy_selinux_file('META/combined_sepolicy', 'precompiled_sepolicy') |
| 275 | copy_selinux_file('SYSTEM/etc/selinux/plat_sepolicy_and_mapping.sha256', |
| 276 | 'precompiled_sepolicy.plat_sepolicy_and_mapping.sha256') |
| 277 | copy_selinux_file( |
| 278 | 'SYSTEM_EXT/etc/selinux/system_ext_sepolicy_and_mapping.sha256', |
| 279 | 'precompiled_sepolicy.system_ext_sepolicy_and_mapping.sha256') |
| 280 | copy_selinux_file('PRODUCT/etc/selinux/product_sepolicy_and_mapping.sha256', |
| 281 | 'precompiled_sepolicy.product_sepolicy_and_mapping.sha256') |
| 282 | |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 283 | if not OPTIONS.vendor_otatools: |
Daniel Norman | 571e182 | 2021-06-25 17:18:25 -0700 | [diff] [blame] | 284 | # Remove the partition from the merged target-files archive. It will be |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 285 | # rebuilt later automatically by generate_missing_images(). |
Dennis Song | 16d6fe0 | 2023-02-23 23:37:42 +0800 | [diff] [blame] | 286 | remove_file_if_exists( |
| 287 | os.path.join(target_files_dir, 'IMAGES', partition_img)) |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 288 | return |
Daniel Norman | 571e182 | 2021-06-25 17:18:25 -0700 | [diff] [blame] | 289 | |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 290 | # TODO(b/192253131): Remove the need for vendor_otatools by fixing |
| 291 | # backwards-compatibility issues when compiling images across releases. |
| 292 | if not OPTIONS.vendor_target_files: |
| 293 | raise ValueError( |
| 294 | 'Expected vendor_target_files if vendor_otatools is not None.') |
| 295 | logger.info( |
| 296 | '%s recompilation will be performed using the vendor otatools.zip', |
| 297 | partition_img) |
Daniel Norman | 571e182 | 2021-06-25 17:18:25 -0700 | [diff] [blame] | 298 | |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 299 | # Unzip the vendor build's otatools.zip and target-files archive. |
| 300 | vendor_otatools_dir = common.MakeTempDir( |
| 301 | prefix='merge_target_files_vendor_otatools_') |
| 302 | vendor_target_files_dir = common.MakeTempDir( |
| 303 | prefix='merge_target_files_vendor_target_files_') |
| 304 | common.UnzipToDir(OPTIONS.vendor_otatools, vendor_otatools_dir) |
Dennis Song | 5bfa43e | 2023-03-30 18:28:00 +0800 | [diff] [blame] | 305 | merge_utils.CollectTargetFiles( |
| 306 | input_zipfile_or_dir=OPTIONS.vendor_target_files, |
| 307 | output_dir=vendor_target_files_dir, |
Po Hu | 09de314 | 2023-04-26 08:49:42 +0800 | [diff] [blame] | 308 | item_list=include_extra_in_list(OPTIONS.vendor_item_list)) |
Daniel Norman | 571e182 | 2021-06-25 17:18:25 -0700 | [diff] [blame] | 309 | |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 310 | # Copy the partition contents from the merged target-files archive to the |
| 311 | # vendor target-files archive. |
| 312 | shutil.rmtree(os.path.join(vendor_target_files_dir, partition.upper())) |
| 313 | shutil.copytree( |
| 314 | os.path.join(target_files_dir, partition.upper()), |
| 315 | os.path.join(vendor_target_files_dir, partition.upper()), |
| 316 | symlinks=True) |
Daniel Norman | 571e182 | 2021-06-25 17:18:25 -0700 | [diff] [blame] | 317 | |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 318 | # Delete then rebuild the partition. |
Dennis Song | 16d6fe0 | 2023-02-23 23:37:42 +0800 | [diff] [blame] | 319 | remove_file_if_exists( |
| 320 | os.path.join(vendor_target_files_dir, 'IMAGES', partition_img)) |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 321 | rebuild_partition_command = [ |
| 322 | os.path.join(vendor_otatools_dir, 'bin', 'add_img_to_target_files'), |
| 323 | '--verbose', |
| 324 | '--add_missing', |
| 325 | ] |
| 326 | if OPTIONS.rebuild_recovery: |
| 327 | rebuild_partition_command.append('--rebuild_recovery') |
| 328 | rebuild_partition_command.append(vendor_target_files_dir) |
| 329 | logger.info('Recompiling %s: %s', partition_img, |
| 330 | ' '.join(rebuild_partition_command)) |
| 331 | common.RunAndCheckOutput(rebuild_partition_command, verbose=True) |
Po Hu | a6c5912 | 2022-02-16 08:41:29 +0000 | [diff] [blame] | 332 | |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 333 | # Move the newly-created image to the merged target files dir. |
| 334 | if not os.path.exists(os.path.join(target_files_dir, 'IMAGES')): |
| 335 | os.makedirs(os.path.join(target_files_dir, 'IMAGES')) |
| 336 | shutil.move( |
| 337 | os.path.join(vendor_target_files_dir, 'IMAGES', partition_img), |
| 338 | os.path.join(target_files_dir, 'IMAGES', partition_img)) |
Dennis Song | 5bfa43e | 2023-03-30 18:28:00 +0800 | [diff] [blame] | 339 | move_only_exists( |
| 340 | os.path.join(vendor_target_files_dir, 'IMAGES', partition_map), |
| 341 | os.path.join(target_files_dir, 'IMAGES', partition_map)) |
Po Hu | a6c5912 | 2022-02-16 08:41:29 +0000 | [diff] [blame] | 342 | |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 343 | def copy_recovery_file(filename): |
| 344 | for subdir in ('VENDOR', 'SYSTEM/vendor'): |
| 345 | source = os.path.join(vendor_target_files_dir, subdir, filename) |
| 346 | if os.path.exists(source): |
| 347 | dest = os.path.join(target_files_dir, subdir, filename) |
| 348 | shutil.copy(source, dest) |
| 349 | return |
| 350 | logger.info('Skipping copy_recovery_file for %s, file not found', filename) |
| 351 | |
| 352 | if OPTIONS.rebuild_recovery: |
| 353 | copy_recovery_file('etc/recovery.img') |
| 354 | copy_recovery_file('bin/install-recovery.sh') |
| 355 | copy_recovery_file('recovery-from-boot.p') |
Daniel Norman | 571e182 | 2021-06-25 17:18:25 -0700 | [diff] [blame] | 356 | |
| 357 | |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 358 | def generate_super_empty_image(target_dir, output_super_empty): |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 359 | """Generates super_empty image from target package. |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 360 | |
| 361 | Args: |
| 362 | target_dir: Path to the target file package which contains misc_info.txt for |
| 363 | detailed information for super image. |
| 364 | output_super_empty: If provided, copies a super_empty.img file from the |
| 365 | target files package to this path. |
| 366 | """ |
Daniel Norman | 1bd2a1d | 2019-04-18 12:32:18 -0700 | [diff] [blame] | 367 | # Create super_empty.img using the merged misc_info.txt. |
| 368 | |
Daniel Norman | 4cc9df6 | 2019-07-18 10:11:07 -0700 | [diff] [blame] | 369 | misc_info_txt = os.path.join(target_dir, 'META', 'misc_info.txt') |
Daniel Norman | 1bd2a1d | 2019-04-18 12:32:18 -0700 | [diff] [blame] | 370 | |
Kiyoung Kim | ebe7c9c | 2019-06-25 17:09:55 +0900 | [diff] [blame] | 371 | use_dynamic_partitions = common.LoadDictionaryFromFile(misc_info_txt).get( |
| 372 | 'use_dynamic_partitions') |
Daniel Norman | 1bd2a1d | 2019-04-18 12:32:18 -0700 | [diff] [blame] | 373 | |
| 374 | if use_dynamic_partitions != 'true' and output_super_empty: |
| 375 | raise ValueError( |
| 376 | 'Building super_empty.img requires use_dynamic_partitions=true.') |
| 377 | elif use_dynamic_partitions == 'true': |
Daniel Norman | 4cc9df6 | 2019-07-18 10:11:07 -0700 | [diff] [blame] | 378 | super_empty_img = os.path.join(target_dir, 'IMAGES', 'super_empty.img') |
Daniel Norman | 1bd2a1d | 2019-04-18 12:32:18 -0700 | [diff] [blame] | 379 | build_super_image_args = [ |
| 380 | misc_info_txt, |
| 381 | super_empty_img, |
| 382 | ] |
| 383 | build_super_image.main(build_super_image_args) |
| 384 | |
| 385 | # Copy super_empty.img to the user-provided output_super_empty location. |
| 386 | if output_super_empty: |
| 387 | shutil.copyfile(super_empty_img, output_super_empty) |
| 388 | |
Daniel Norman | b8a2f9d | 2019-04-24 12:55:51 -0700 | [diff] [blame] | 389 | |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 390 | def create_target_files_archive(output_zip, source_dir, temp_dir): |
| 391 | """Creates a target_files zip archive from the input source dir. |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 392 | |
| 393 | Args: |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 394 | output_zip: The name of the zip archive target files package. |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 395 | source_dir: The target directory contains package to be archived. |
| 396 | temp_dir: Path to temporary directory for any intermediate files. |
| 397 | """ |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 398 | output_target_files_list = os.path.join(temp_dir, 'output.list') |
Daniel Norman | 4cc9df6 | 2019-07-18 10:11:07 -0700 | [diff] [blame] | 399 | output_target_files_meta_dir = os.path.join(source_dir, 'META') |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 400 | |
Daniel Norman | dbbf5a3 | 2020-10-22 16:03:32 -0700 | [diff] [blame] | 401 | def files_from_path(target_path, extra_args=None): |
| 402 | """Gets files under the given path and return a sorted list.""" |
| 403 | find_command = ['find', target_path] + (extra_args or []) |
| 404 | find_process = common.Run( |
| 405 | find_command, stdout=subprocess.PIPE, verbose=False) |
| 406 | return common.RunAndCheckOutput(['sort'], |
| 407 | stdin=find_process.stdout, |
| 408 | verbose=False) |
| 409 | |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 410 | # META content appears first in the zip. This is done by the |
| 411 | # standard build system for optimized extraction of those files, |
| 412 | # so we do the same step for merged target_files.zips here too. |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 413 | meta_content = files_from_path(output_target_files_meta_dir) |
Daniel Norman | 4cc9df6 | 2019-07-18 10:11:07 -0700 | [diff] [blame] | 414 | other_content = files_from_path( |
| 415 | source_dir, |
| 416 | ['-path', output_target_files_meta_dir, '-prune', '-o', '-print']) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 417 | |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 418 | with open(output_target_files_list, 'w') as f: |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 419 | f.write(meta_content) |
| 420 | f.write(other_content) |
| 421 | |
| 422 | command = [ |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 423 | 'soong_zip', |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 424 | '-d', |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 425 | '-o', |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 426 | os.path.abspath(output_zip), |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 427 | '-C', |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 428 | source_dir, |
Daniel Norman | eaf5c1d | 2021-02-09 11:01:42 -0800 | [diff] [blame] | 429 | '-r', |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 430 | output_target_files_list, |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 431 | ] |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 432 | |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 433 | logger.info('creating %s', output_zip) |
Daniel Norman | eaf5c1d | 2021-02-09 11:01:42 -0800 | [diff] [blame] | 434 | common.RunAndCheckOutput(command, verbose=True) |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 435 | logger.info('finished creating %s', output_zip) |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 436 | |
| 437 | |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 438 | def merge_target_files(temp_dir): |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 439 | """Merges two target files packages together. |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 440 | |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 441 | This function uses framework and vendor target files packages as input, |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 442 | performs various file extractions, special case processing, and finally |
| 443 | creates a merged zip archive as output. |
| 444 | |
| 445 | Args: |
| 446 | temp_dir: The name of a directory we use when we extract items from the |
| 447 | input target files packages, and also a scratch directory that we use for |
| 448 | temporary files. |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 449 | """ |
| 450 | |
| 451 | logger.info('starting: merge framework %s and vendor %s into output %s', |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 452 | OPTIONS.framework_target_files, OPTIONS.vendor_target_files, |
| 453 | OPTIONS.output_target_files) |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 454 | |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 455 | output_target_files_temp_dir = create_merged_package(temp_dir) |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 456 | |
Daniel Norman | 21c34f7 | 2020-11-11 17:25:50 -0800 | [diff] [blame] | 457 | partition_map = common.PartitionMapFromTargetFiles( |
| 458 | output_target_files_temp_dir) |
| 459 | |
Daniel Norman | 2465fc8 | 2022-03-02 12:01:20 -0800 | [diff] [blame] | 460 | compatibility_errors = merge_compatibility_checks.CheckCompatibility( |
| 461 | target_files_dir=output_target_files_temp_dir, |
| 462 | partition_map=partition_map) |
| 463 | if compatibility_errors: |
| 464 | for error in compatibility_errors: |
| 465 | logger.error(error) |
| 466 | raise ExternalError( |
| 467 | 'Found incompatibilities in the merged target files package.') |
Daniel Norman | d335156 | 2020-10-29 12:33:11 -0700 | [diff] [blame] | 468 | |
Daniel Norman | 571e182 | 2021-06-25 17:18:25 -0700 | [diff] [blame] | 469 | # Include the compiled policy in an image if requested. |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 470 | if OPTIONS.rebuild_sepolicy: |
| 471 | rebuild_image_with_sepolicy(output_target_files_temp_dir) |
Daniel Norman | 48603ff | 2021-02-22 15:15:24 -0800 | [diff] [blame] | 472 | |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 473 | generate_missing_images(output_target_files_temp_dir) |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 474 | |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 475 | generate_super_empty_image(output_target_files_temp_dir, |
| 476 | OPTIONS.output_super_empty) |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 477 | |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 478 | # Finally, create the output target files zip archive and/or copy the |
| 479 | # output items to the output target files directory. |
| 480 | |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 481 | if OPTIONS.output_dir: |
Daniel Norman | 2465fc8 | 2022-03-02 12:01:20 -0800 | [diff] [blame] | 482 | merge_utils.CopyItems(output_target_files_temp_dir, OPTIONS.output_dir, |
| 483 | OPTIONS.output_item_list) |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 484 | |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 485 | if not OPTIONS.output_target_files: |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 486 | return |
| 487 | |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 488 | create_target_files_archive(OPTIONS.output_target_files, |
| 489 | output_target_files_temp_dir, temp_dir) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 490 | |
Daniel Norman | 74eb74b | 2019-09-18 14:01:48 -0700 | [diff] [blame] | 491 | # Create the IMG package from the merged target files package. |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 492 | if OPTIONS.output_img: |
| 493 | img_from_target_files.main( |
| 494 | [OPTIONS.output_target_files, OPTIONS.output_img]) |
Daniel Norman | 74eb74b | 2019-09-18 14:01:48 -0700 | [diff] [blame] | 495 | |
Daniel Norman | 3b64ce1 | 2019-04-16 16:11:35 -0700 | [diff] [blame] | 496 | # Create the OTA package from the merged target files package. |
| 497 | |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 498 | if OPTIONS.output_ota: |
| 499 | ota_from_target_files.main( |
| 500 | [OPTIONS.output_target_files, OPTIONS.output_ota]) |
Daniel Norman | 3b64ce1 | 2019-04-16 16:11:35 -0700 | [diff] [blame] | 501 | |
Daniel Norman | 1bd2a1d | 2019-04-18 12:32:18 -0700 | [diff] [blame] | 502 | |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 503 | def main(): |
| 504 | """The main function. |
| 505 | |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 506 | Process command line arguments, then call merge_target_files to |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 507 | perform the heavy lifting. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 508 | """ |
| 509 | |
| 510 | common.InitLogging() |
| 511 | |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 512 | def option_handler(o, a): |
| 513 | if o == '--system-target-files': |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 514 | logger.warning( |
| 515 | '--system-target-files has been renamed to --framework-target-files') |
| 516 | OPTIONS.framework_target_files = a |
| 517 | elif o == '--framework-target-files': |
| 518 | OPTIONS.framework_target_files = a |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 519 | elif o == '--system-item-list': |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 520 | logger.warning( |
| 521 | '--system-item-list has been renamed to --framework-item-list') |
| 522 | OPTIONS.framework_item_list = a |
| 523 | elif o == '--framework-item-list': |
| 524 | OPTIONS.framework_item_list = a |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 525 | elif o == '--system-misc-info-keys': |
Daniel Norman | 4cc9df6 | 2019-07-18 10:11:07 -0700 | [diff] [blame] | 526 | logger.warning('--system-misc-info-keys has been renamed to ' |
| 527 | '--framework-misc-info-keys') |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 528 | OPTIONS.framework_misc_info_keys = a |
| 529 | elif o == '--framework-misc-info-keys': |
| 530 | OPTIONS.framework_misc_info_keys = a |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 531 | elif o == '--other-target-files': |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 532 | logger.warning( |
| 533 | '--other-target-files has been renamed to --vendor-target-files') |
| 534 | OPTIONS.vendor_target_files = a |
| 535 | elif o == '--vendor-target-files': |
| 536 | OPTIONS.vendor_target_files = a |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 537 | elif o == '--other-item-list': |
Daniel Norman | 2d7989a | 2021-04-05 17:40:47 +0000 | [diff] [blame] | 538 | logger.warning('--other-item-list has been renamed to --vendor-item-list') |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 539 | OPTIONS.vendor_item_list = a |
| 540 | elif o == '--vendor-item-list': |
| 541 | OPTIONS.vendor_item_list = a |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 542 | elif o == '--output-target-files': |
| 543 | OPTIONS.output_target_files = a |
Daniel Norman | fdb3881 | 2019-04-15 09:47:24 -0700 | [diff] [blame] | 544 | elif o == '--output-dir': |
| 545 | OPTIONS.output_dir = a |
| 546 | elif o == '--output-item-list': |
| 547 | OPTIONS.output_item_list = a |
Daniel Norman | 3b64ce1 | 2019-04-16 16:11:35 -0700 | [diff] [blame] | 548 | elif o == '--output-ota': |
| 549 | OPTIONS.output_ota = a |
Daniel Norman | 1bd2a1d | 2019-04-18 12:32:18 -0700 | [diff] [blame] | 550 | elif o == '--output-img': |
| 551 | OPTIONS.output_img = a |
Daniel Norman | f031825 | 2019-04-15 11:34:56 -0700 | [diff] [blame] | 552 | elif o == '--output-super-empty': |
| 553 | OPTIONS.output_super_empty = a |
Daniel Norman | 2465fc8 | 2022-03-02 12:01:20 -0800 | [diff] [blame] | 554 | elif o == '--rebuild_recovery' or o == '--rebuild-recovery': |
Daniel Norman | a4911da | 2019-03-15 14:36:21 -0700 | [diff] [blame] | 555 | OPTIONS.rebuild_recovery = True |
Daniel Norman | b0c7591 | 2020-09-24 14:30:21 -0700 | [diff] [blame] | 556 | elif o == '--allow-duplicate-apkapex-keys': |
| 557 | OPTIONS.allow_duplicate_apkapex_keys = True |
Daniel Norman | 571e182 | 2021-06-25 17:18:25 -0700 | [diff] [blame] | 558 | elif o == '--vendor-otatools': |
| 559 | OPTIONS.vendor_otatools = a |
| 560 | elif o == '--rebuild-sepolicy': |
| 561 | OPTIONS.rebuild_sepolicy = True |
Bill Peckham | 364c1cc | 2019-03-29 18:27:23 -0700 | [diff] [blame] | 562 | elif o == '--keep-tmp': |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 563 | OPTIONS.keep_tmp = True |
Dennis Song | 4aae62e | 2023-10-02 04:31:34 +0000 | [diff] [blame^] | 564 | elif o == '--avb-resolve-rollback-index-location-conflict': |
| 565 | OPTIONS.avb_resolve_rollback_index_location_conflict = True |
Jose Galmes | 9c8f6eb | 2021-07-21 09:34:08 -0700 | [diff] [blame] | 566 | elif o == '--framework-dexpreopt-config': |
| 567 | OPTIONS.framework_dexpreopt_config = a |
| 568 | elif o == '--framework-dexpreopt-tools': |
| 569 | OPTIONS.framework_dexpreopt_tools = a |
| 570 | elif o == '--vendor-dexpreopt-config': |
| 571 | OPTIONS.vendor_dexpreopt_config = a |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 572 | else: |
| 573 | return False |
| 574 | return True |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 575 | |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 576 | args = common.ParseOptions( |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 577 | sys.argv[1:], |
| 578 | __doc__, |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 579 | extra_long_opts=[ |
| 580 | 'system-target-files=', |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 581 | 'framework-target-files=', |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 582 | 'system-item-list=', |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 583 | 'framework-item-list=', |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 584 | 'system-misc-info-keys=', |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 585 | 'framework-misc-info-keys=', |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 586 | 'other-target-files=', |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 587 | 'vendor-target-files=', |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 588 | 'other-item-list=', |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 589 | 'vendor-item-list=', |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 590 | 'output-target-files=', |
Daniel Norman | fdb3881 | 2019-04-15 09:47:24 -0700 | [diff] [blame] | 591 | 'output-dir=', |
| 592 | 'output-item-list=', |
Daniel Norman | 3b64ce1 | 2019-04-16 16:11:35 -0700 | [diff] [blame] | 593 | 'output-ota=', |
Daniel Norman | 1bd2a1d | 2019-04-18 12:32:18 -0700 | [diff] [blame] | 594 | 'output-img=', |
Daniel Norman | f031825 | 2019-04-15 11:34:56 -0700 | [diff] [blame] | 595 | 'output-super-empty=', |
Jose Galmes | 9c8f6eb | 2021-07-21 09:34:08 -0700 | [diff] [blame] | 596 | 'framework-dexpreopt-config=', |
| 597 | 'framework-dexpreopt-tools=', |
| 598 | 'vendor-dexpreopt-config=', |
Daniel Norman | a4911da | 2019-03-15 14:36:21 -0700 | [diff] [blame] | 599 | 'rebuild_recovery', |
Daniel Norman | 2465fc8 | 2022-03-02 12:01:20 -0800 | [diff] [blame] | 600 | 'rebuild-recovery', |
Daniel Norman | b0c7591 | 2020-09-24 14:30:21 -0700 | [diff] [blame] | 601 | 'allow-duplicate-apkapex-keys', |
Daniel Norman | 571e182 | 2021-06-25 17:18:25 -0700 | [diff] [blame] | 602 | 'vendor-otatools=', |
| 603 | 'rebuild-sepolicy', |
Bill Peckham | 364c1cc | 2019-03-29 18:27:23 -0700 | [diff] [blame] | 604 | 'keep-tmp', |
Dennis Song | 4aae62e | 2023-10-02 04:31:34 +0000 | [diff] [blame^] | 605 | 'avb-resolve-rollback-index-location-conflict', |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 606 | ], |
| 607 | extra_option_handler=option_handler) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 608 | |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 609 | # pylint: disable=too-many-boolean-expressions |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 610 | if (args or OPTIONS.framework_target_files is None or |
| 611 | OPTIONS.vendor_target_files is None or |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 612 | (OPTIONS.output_target_files is None and OPTIONS.output_dir is None) or |
Daniel Norman | 5f47677 | 2022-03-02 15:46:34 -0800 | [diff] [blame] | 613 | (OPTIONS.output_dir is not None and not OPTIONS.output_item_list) or |
Po Hu | a6c5912 | 2022-02-16 08:41:29 +0000 | [diff] [blame] | 614 | (OPTIONS.rebuild_recovery and not OPTIONS.rebuild_sepolicy)): |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 615 | common.Usage(__doc__) |
Bill Peckham | 889b0c6 | 2019-02-21 18:53:37 -0800 | [diff] [blame] | 616 | sys.exit(1) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 617 | |
Dennis Song | 5bfa43e | 2023-03-30 18:28:00 +0800 | [diff] [blame] | 618 | framework_namelist = merge_utils.GetTargetFilesItems( |
| 619 | OPTIONS.framework_target_files) |
| 620 | vendor_namelist = merge_utils.GetTargetFilesItems( |
| 621 | OPTIONS.vendor_target_files) |
Daniel Norman | 5f47677 | 2022-03-02 15:46:34 -0800 | [diff] [blame] | 622 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 623 | if OPTIONS.framework_item_list: |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 624 | OPTIONS.framework_item_list = common.LoadListFromFile( |
| 625 | OPTIONS.framework_item_list) |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 626 | else: |
Daniel Norman | 5f47677 | 2022-03-02 15:46:34 -0800 | [diff] [blame] | 627 | OPTIONS.framework_item_list = merge_utils.InferItemList( |
| 628 | input_namelist=framework_namelist, framework=True) |
Daniel Norman | 2465fc8 | 2022-03-02 12:01:20 -0800 | [diff] [blame] | 629 | OPTIONS.framework_partition_set = merge_utils.ItemListToPartitionSet( |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 630 | OPTIONS.framework_item_list) |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 631 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 632 | if OPTIONS.framework_misc_info_keys: |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 633 | OPTIONS.framework_misc_info_keys = common.LoadListFromFile( |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 634 | OPTIONS.framework_misc_info_keys) |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 635 | else: |
Daniel Norman | 5f47677 | 2022-03-02 15:46:34 -0800 | [diff] [blame] | 636 | OPTIONS.framework_misc_info_keys = merge_utils.InferFrameworkMiscInfoKeys( |
| 637 | input_namelist=framework_namelist) |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 638 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 639 | if OPTIONS.vendor_item_list: |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 640 | OPTIONS.vendor_item_list = common.LoadListFromFile(OPTIONS.vendor_item_list) |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 641 | else: |
Daniel Norman | 5f47677 | 2022-03-02 15:46:34 -0800 | [diff] [blame] | 642 | OPTIONS.vendor_item_list = merge_utils.InferItemList( |
| 643 | input_namelist=vendor_namelist, framework=False) |
Daniel Norman | 2465fc8 | 2022-03-02 12:01:20 -0800 | [diff] [blame] | 644 | OPTIONS.vendor_partition_set = merge_utils.ItemListToPartitionSet( |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 645 | OPTIONS.vendor_item_list) |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 646 | |
Daniel Norman | fdb3881 | 2019-04-15 09:47:24 -0700 | [diff] [blame] | 647 | if OPTIONS.output_item_list: |
Daniel Norman | 0374741 | 2022-02-25 10:38:37 -0800 | [diff] [blame] | 648 | OPTIONS.output_item_list = common.LoadListFromFile(OPTIONS.output_item_list) |
Daniel Norman | fdb3881 | 2019-04-15 09:47:24 -0700 | [diff] [blame] | 649 | |
Daniel Norman | 2465fc8 | 2022-03-02 12:01:20 -0800 | [diff] [blame] | 650 | if not merge_utils.ValidateConfigLists(): |
Daniel Norman | e596452 | 2019-03-19 10:32:03 -0700 | [diff] [blame] | 651 | sys.exit(1) |
| 652 | |
Daniel Norman | 2465fc8 | 2022-03-02 12:01:20 -0800 | [diff] [blame] | 653 | temp_dir = common.MakeTempDir(prefix='merge_target_files_') |
| 654 | try: |
| 655 | merge_target_files(temp_dir) |
| 656 | finally: |
| 657 | if OPTIONS.keep_tmp: |
| 658 | logger.info('Keeping temp_dir %s', temp_dir) |
| 659 | else: |
| 660 | common.Cleanup() |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 661 | |
| 662 | |
| 663 | if __name__ == '__main__': |
Bill Peckham | 889b0c6 | 2019-02-21 18:53:37 -0800 | [diff] [blame] | 664 | main() |