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