Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # |
| 3 | # Copyright (C) 2019 The Android Open Source Project |
| 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 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 29 | --framework-target-files framework-target-files-zip-archive |
| 30 | The input target files package containing framework bits. This is a zip |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 31 | archive. |
| 32 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 33 | --framework-item-list framework-item-list-file |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 34 | The optional path to a newline-separated config file that replaces the |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 35 | contents of DEFAULT_FRAMEWORK_ITEM_LIST if provided. |
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 | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 38 | The optional path to a newline-separated config file that replaces the |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 39 | contents of DEFAULT_FRAMEWORK_MISC_INFO_KEYS if provided. |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 40 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 41 | --vendor-target-files vendor-target-files-zip-archive |
| 42 | The input target files package containing vendor bits. This is a zip |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 43 | archive. |
| 44 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 45 | --vendor-item-list vendor-item-list-file |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 46 | The optional path to a newline-separated config file that replaces the |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 47 | contents of DEFAULT_VENDOR_ITEM_LIST if provided. |
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 |
Bill Peckham | e868aec | 2019-09-17 17:06:47 -0700 | [diff] [blame] | 75 | Deprecated; does nothing. |
Bill Peckham | 364c1cc | 2019-03-29 18:27:23 -0700 | [diff] [blame] | 76 | |
Daniel Norman | b0c7591 | 2020-09-24 14:30:21 -0700 | [diff] [blame] | 77 | --allow-duplicate-apkapex-keys |
| 78 | If provided, duplicate APK/APEX keys are ignored and the value from the |
| 79 | framework is used. |
| 80 | |
Bill Peckham | 364c1cc | 2019-03-29 18:27:23 -0700 | [diff] [blame] | 81 | --keep-tmp |
| 82 | Keep tempoary files for debugging purposes. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 83 | """ |
| 84 | |
| 85 | from __future__ import print_function |
| 86 | |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 87 | import fnmatch |
Daniel Norman | d335156 | 2020-10-29 12:33:11 -0700 | [diff] [blame^] | 88 | import json |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 89 | import logging |
| 90 | import os |
Bill Peckham | 19c3feb | 2020-03-20 18:31:43 -0700 | [diff] [blame] | 91 | import re |
Daniel Norman | fdb3881 | 2019-04-15 09:47:24 -0700 | [diff] [blame] | 92 | import shutil |
Bill Peckham | 540d91a | 2019-04-25 14:18:16 -0700 | [diff] [blame] | 93 | import subprocess |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 94 | import sys |
| 95 | import zipfile |
| 96 | |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 97 | import add_img_to_target_files |
Daniel Norman | f031825 | 2019-04-15 11:34:56 -0700 | [diff] [blame] | 98 | import build_super_image |
Yifan Hong | ade0d3f | 2019-08-21 16:37:11 -0700 | [diff] [blame] | 99 | import check_target_files_vintf |
Daniel Norman | f031825 | 2019-04-15 11:34:56 -0700 | [diff] [blame] | 100 | import common |
Daniel Norman | 1bd2a1d | 2019-04-18 12:32:18 -0700 | [diff] [blame] | 101 | import img_from_target_files |
Daniel Norman | b8d52a2 | 2020-10-26 17:55:00 -0700 | [diff] [blame] | 102 | import find_shareduid_violation |
Daniel Norman | 3b64ce1 | 2019-04-16 16:11:35 -0700 | [diff] [blame] | 103 | import ota_from_target_files |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 104 | |
| 105 | logger = logging.getLogger(__name__) |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 106 | |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 107 | OPTIONS = common.OPTIONS |
Bill Peckham | cb84817 | 2020-04-03 12:50:47 -0700 | [diff] [blame] | 108 | # Always turn on verbose logging. |
| 109 | OPTIONS.verbose = True |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 110 | OPTIONS.framework_target_files = None |
| 111 | OPTIONS.framework_item_list = None |
| 112 | OPTIONS.framework_misc_info_keys = None |
| 113 | OPTIONS.vendor_target_files = None |
| 114 | OPTIONS.vendor_item_list = None |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 115 | OPTIONS.output_target_files = None |
Daniel Norman | fdb3881 | 2019-04-15 09:47:24 -0700 | [diff] [blame] | 116 | OPTIONS.output_dir = None |
| 117 | OPTIONS.output_item_list = None |
Daniel Norman | 3b64ce1 | 2019-04-16 16:11:35 -0700 | [diff] [blame] | 118 | OPTIONS.output_ota = None |
Daniel Norman | 1bd2a1d | 2019-04-18 12:32:18 -0700 | [diff] [blame] | 119 | OPTIONS.output_img = None |
Daniel Norman | f031825 | 2019-04-15 11:34:56 -0700 | [diff] [blame] | 120 | OPTIONS.output_super_empty = None |
Bill Peckham | e868aec | 2019-09-17 17:06:47 -0700 | [diff] [blame] | 121 | # TODO(b/132730255): Remove this option. |
Daniel Norman | a4911da | 2019-03-15 14:36:21 -0700 | [diff] [blame] | 122 | OPTIONS.rebuild_recovery = False |
Daniel Norman | b0c7591 | 2020-09-24 14:30:21 -0700 | [diff] [blame] | 123 | # TODO(b/150582573): Remove this option. |
| 124 | OPTIONS.allow_duplicate_apkapex_keys = False |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 125 | OPTIONS.keep_tmp = False |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 126 | |
Bill Peckham | 19c3feb | 2020-03-20 18:31:43 -0700 | [diff] [blame] | 127 | # In an item list (framework or vendor), we may see entries that select whole |
| 128 | # partitions. Such an entry might look like this 'SYSTEM/*' (e.g., for the |
| 129 | # system partition). The following regex matches this and extracts the |
| 130 | # partition name. |
| 131 | |
| 132 | PARTITION_ITEM_PATTERN = re.compile(r'^([A-Z_]+)/\*$') |
| 133 | |
Bill Peckham | 5c7b034 | 2020-04-03 15:36:23 -0700 | [diff] [blame] | 134 | # In apexkeys.txt or apkcerts.txt, we will find partition tags on each entry in |
| 135 | # the file. We use these partition tags to filter the entries in those files |
| 136 | # from the two different target files packages to produce a merged apexkeys.txt |
| 137 | # or apkcerts.txt file. A partition tag (e.g., for the product partition) looks |
| 138 | # like this: 'partition="product"'. We use the group syntax grab the value of |
| 139 | # the tag. We use non-greedy matching in case there are other fields on the |
| 140 | # same line. |
Bill Peckham | 19c3feb | 2020-03-20 18:31:43 -0700 | [diff] [blame] | 141 | |
Bill Peckham | 5c7b034 | 2020-04-03 15:36:23 -0700 | [diff] [blame] | 142 | PARTITION_TAG_PATTERN = re.compile(r'partition="(.*?)"') |
Bill Peckham | 19c3feb | 2020-03-20 18:31:43 -0700 | [diff] [blame] | 143 | |
| 144 | # The sorting algorithm for apexkeys.txt and apkcerts.txt does not include the |
| 145 | # ".apex" or ".apk" suffix, so we use the following pattern to extract a key. |
| 146 | |
| 147 | MODULE_KEY_PATTERN = re.compile(r'name="(.+)\.(apex|apk)"') |
| 148 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 149 | # DEFAULT_FRAMEWORK_ITEM_LIST is a list of items to extract from the partial |
| 150 | # framework target files package as is, meaning these items will land in the |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 151 | # output target files package exactly as they appear in the input partial |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 152 | # framework target files package. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 153 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 154 | DEFAULT_FRAMEWORK_ITEM_LIST = ( |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 155 | 'META/apkcerts.txt', |
| 156 | 'META/filesystem_config.txt', |
| 157 | 'META/root_filesystem_config.txt', |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 158 | 'META/update_engine_config.txt', |
| 159 | 'PRODUCT/*', |
| 160 | 'ROOT/*', |
| 161 | 'SYSTEM/*', |
Daniel Norman | edf1247 | 2019-05-22 10:47:08 -0700 | [diff] [blame] | 162 | ) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 163 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 164 | # DEFAULT_FRAMEWORK_MISC_INFO_KEYS is a list of keys to obtain from the |
Daniel Norman | dbbf5a3 | 2020-10-22 16:03:32 -0700 | [diff] [blame] | 165 | # framework instance of META/misc_info.txt. The remaining keys should come |
| 166 | # from the vendor instance. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 167 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 168 | DEFAULT_FRAMEWORK_MISC_INFO_KEYS = ( |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 169 | 'avb_system_hashtree_enable', |
| 170 | 'avb_system_add_hashtree_footer_args', |
| 171 | 'avb_system_key_path', |
| 172 | 'avb_system_algorithm', |
| 173 | 'avb_system_rollback_index_location', |
| 174 | 'avb_product_hashtree_enable', |
| 175 | 'avb_product_add_hashtree_footer_args', |
Justin Yun | 6151e3f | 2019-06-25 15:58:13 +0900 | [diff] [blame] | 176 | 'avb_system_ext_hashtree_enable', |
| 177 | 'avb_system_ext_add_hashtree_footer_args', |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 178 | 'system_root_image', |
| 179 | 'root_dir', |
| 180 | 'ab_update', |
| 181 | 'default_system_dev_certificate', |
| 182 | 'system_size', |
Chris Gross | 203191b | 2020-05-30 02:39:12 +0000 | [diff] [blame] | 183 | 'building_system_image', |
| 184 | 'building_system_ext_image', |
| 185 | 'building_product_image', |
Daniel Norman | edf1247 | 2019-05-22 10:47:08 -0700 | [diff] [blame] | 186 | ) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 187 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 188 | # DEFAULT_VENDOR_ITEM_LIST is a list of items to extract from the partial |
| 189 | # vendor target files package as is, meaning these items will land in the output |
| 190 | # target files package exactly as they appear in the input partial vendor target |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 191 | # files package. |
| 192 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 193 | DEFAULT_VENDOR_ITEM_LIST = ( |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 194 | 'META/boot_filesystem_config.txt', |
| 195 | 'META/otakeys.txt', |
| 196 | 'META/releasetools.py', |
| 197 | 'META/vendor_filesystem_config.txt', |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 198 | 'BOOT/*', |
| 199 | 'DATA/*', |
| 200 | 'ODM/*', |
| 201 | 'OTA/android-info.txt', |
| 202 | 'PREBUILT_IMAGES/*', |
| 203 | 'RADIO/*', |
| 204 | 'VENDOR/*', |
Daniel Norman | edf1247 | 2019-05-22 10:47:08 -0700 | [diff] [blame] | 205 | ) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 206 | |
Daniel Norman | edf1247 | 2019-05-22 10:47:08 -0700 | [diff] [blame] | 207 | # The merge config lists should not attempt to extract items from both |
| 208 | # builds for any of the following partitions. The partitions in |
| 209 | # SINGLE_BUILD_PARTITIONS should come entirely from a single build (either |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 210 | # framework or vendor, but not both). |
Daniel Norman | edf1247 | 2019-05-22 10:47:08 -0700 | [diff] [blame] | 211 | |
| 212 | SINGLE_BUILD_PARTITIONS = ( |
| 213 | 'BOOT/', |
| 214 | 'DATA/', |
| 215 | 'ODM/', |
| 216 | 'PRODUCT/', |
Justin Yun | 6151e3f | 2019-06-25 15:58:13 +0900 | [diff] [blame] | 217 | 'SYSTEM_EXT/', |
Daniel Norman | edf1247 | 2019-05-22 10:47:08 -0700 | [diff] [blame] | 218 | 'RADIO/', |
| 219 | 'RECOVERY/', |
| 220 | 'ROOT/', |
| 221 | 'SYSTEM/', |
| 222 | 'SYSTEM_OTHER/', |
| 223 | 'VENDOR/', |
Yifan Hong | cfb917a | 2020-05-07 14:58:20 -0700 | [diff] [blame] | 224 | 'VENDOR_DLKM/', |
Yifan Hong | f496f1b | 2020-07-15 16:52:59 -0700 | [diff] [blame] | 225 | 'ODM_DLKM/', |
Daniel Norman | edf1247 | 2019-05-22 10:47:08 -0700 | [diff] [blame] | 226 | ) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 227 | |
| 228 | |
Chris Gross | fabf50a | 2019-05-02 12:42:09 -0700 | [diff] [blame] | 229 | def write_sorted_data(data, path): |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 230 | """Writes the sorted contents of either a list or dict to file. |
Chris Gross | fabf50a | 2019-05-02 12:42:09 -0700 | [diff] [blame] | 231 | |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 232 | This function sorts the contents of the list or dict and then writes the |
| 233 | resulting sorted contents to a file specified by path. |
Chris Gross | fabf50a | 2019-05-02 12:42:09 -0700 | [diff] [blame] | 234 | |
| 235 | Args: |
| 236 | data: The list or dict to sort and write. |
| 237 | path: Path to the file to write the sorted values to. The file at path will |
| 238 | be overridden if it exists. |
| 239 | """ |
| 240 | with open(path, 'w') as output: |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 241 | for entry in sorted(data): |
Chris Gross | fabf50a | 2019-05-02 12:42:09 -0700 | [diff] [blame] | 242 | out_str = '{}={}\n'.format(entry, data[entry]) if isinstance( |
| 243 | data, dict) else '{}\n'.format(entry) |
| 244 | output.write(out_str) |
| 245 | |
| 246 | |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 247 | def extract_items(target_files, target_files_temp_dir, extract_item_list): |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 248 | """Extracts items from target files to temporary directory. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 249 | |
| 250 | This function extracts from the specified target files zip archive into the |
| 251 | specified temporary directory, the items specified in the extract item list. |
| 252 | |
| 253 | Args: |
| 254 | target_files: The target files zip archive from which to extract items. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 255 | target_files_temp_dir: The temporary directory where the extracted items |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 256 | will land. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 257 | extract_item_list: A list of items to extract. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 258 | """ |
| 259 | |
| 260 | logger.info('extracting from %s', target_files) |
| 261 | |
| 262 | # Filter the extract_item_list to remove any items that do not exist in the |
| 263 | # zip file. Otherwise, the extraction step will fail. |
| 264 | |
Daniel Norman | 4cc9df6 | 2019-07-18 10:11:07 -0700 | [diff] [blame] | 265 | with zipfile.ZipFile(target_files, allowZip64=True) as target_files_zipfile: |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 266 | target_files_namelist = target_files_zipfile.namelist() |
| 267 | |
| 268 | filtered_extract_item_list = [] |
| 269 | for pattern in extract_item_list: |
| 270 | matching_namelist = fnmatch.filter(target_files_namelist, pattern) |
| 271 | if not matching_namelist: |
| 272 | logger.warning('no match for %s', pattern) |
| 273 | else: |
| 274 | filtered_extract_item_list.append(pattern) |
| 275 | |
Bill Peckham | 8ff3fbd | 2019-02-22 10:57:43 -0800 | [diff] [blame] | 276 | # Extract from target_files into target_files_temp_dir the |
| 277 | # filtered_extract_item_list. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 278 | |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 279 | common.UnzipToDir(target_files, target_files_temp_dir, |
| 280 | filtered_extract_item_list) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 281 | |
| 282 | |
Daniel Norman | fdb3881 | 2019-04-15 09:47:24 -0700 | [diff] [blame] | 283 | def copy_items(from_dir, to_dir, patterns): |
| 284 | """Similar to extract_items() except uses an input dir instead of zip.""" |
| 285 | file_paths = [] |
| 286 | for dirpath, _, filenames in os.walk(from_dir): |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 287 | file_paths.extend( |
| 288 | os.path.relpath(path=os.path.join(dirpath, filename), start=from_dir) |
| 289 | for filename in filenames) |
Daniel Norman | fdb3881 | 2019-04-15 09:47:24 -0700 | [diff] [blame] | 290 | |
| 291 | filtered_file_paths = set() |
| 292 | for pattern in patterns: |
| 293 | filtered_file_paths.update(fnmatch.filter(file_paths, pattern)) |
| 294 | |
| 295 | for file_path in filtered_file_paths: |
| 296 | original_file_path = os.path.join(from_dir, file_path) |
| 297 | copied_file_path = os.path.join(to_dir, file_path) |
| 298 | copied_file_dir = os.path.dirname(copied_file_path) |
| 299 | if not os.path.exists(copied_file_dir): |
| 300 | os.makedirs(copied_file_dir) |
| 301 | if os.path.islink(original_file_path): |
| 302 | os.symlink(os.readlink(original_file_path), copied_file_path) |
| 303 | else: |
| 304 | shutil.copyfile(original_file_path, copied_file_path) |
| 305 | |
| 306 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 307 | def validate_config_lists(framework_item_list, framework_misc_info_keys, |
| 308 | vendor_item_list): |
Daniel Norman | e596452 | 2019-03-19 10:32:03 -0700 | [diff] [blame] | 309 | """Performs validations on the merge config lists. |
| 310 | |
| 311 | Args: |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 312 | framework_item_list: The list of items to extract from the partial framework |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 313 | target files package as is. |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 314 | framework_misc_info_keys: A list of keys to obtain from the framework |
Daniel Norman | dbbf5a3 | 2020-10-22 16:03:32 -0700 | [diff] [blame] | 315 | instance of META/misc_info.txt. The remaining keys should come from the |
| 316 | vendor instance. |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 317 | vendor_item_list: The list of items to extract from the partial vendor |
| 318 | target files package as is. |
Daniel Norman | e596452 | 2019-03-19 10:32:03 -0700 | [diff] [blame] | 319 | |
| 320 | Returns: |
| 321 | False if a validation fails, otherwise true. |
| 322 | """ |
Daniel Norman | edf1247 | 2019-05-22 10:47:08 -0700 | [diff] [blame] | 323 | has_error = False |
| 324 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 325 | default_combined_item_set = set(DEFAULT_FRAMEWORK_ITEM_LIST) |
| 326 | default_combined_item_set.update(DEFAULT_VENDOR_ITEM_LIST) |
Daniel Norman | e596452 | 2019-03-19 10:32:03 -0700 | [diff] [blame] | 327 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 328 | combined_item_set = set(framework_item_list) |
| 329 | combined_item_set.update(vendor_item_list) |
Daniel Norman | e596452 | 2019-03-19 10:32:03 -0700 | [diff] [blame] | 330 | |
| 331 | # Check that the merge config lists are not missing any item specified |
| 332 | # by the default config lists. |
| 333 | difference = default_combined_item_set.difference(combined_item_set) |
| 334 | if difference: |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 335 | logger.error('Missing merge config items: %s', list(difference)) |
Daniel Norman | e596452 | 2019-03-19 10:32:03 -0700 | [diff] [blame] | 336 | logger.error('Please ensure missing items are in either the ' |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 337 | 'framework-item-list or vendor-item-list files provided to ' |
Daniel Norman | e596452 | 2019-03-19 10:32:03 -0700 | [diff] [blame] | 338 | 'this script.') |
Daniel Norman | edf1247 | 2019-05-22 10:47:08 -0700 | [diff] [blame] | 339 | has_error = True |
| 340 | |
Daniel Norman | dbbf5a3 | 2020-10-22 16:03:32 -0700 | [diff] [blame] | 341 | # Check that partitions only come from one input. |
Daniel Norman | edf1247 | 2019-05-22 10:47:08 -0700 | [diff] [blame] | 342 | for partition in SINGLE_BUILD_PARTITIONS: |
Daniel Norman | dbbf5a3 | 2020-10-22 16:03:32 -0700 | [diff] [blame] | 343 | image_path = 'IMAGES/{}.img'.format(partition.lower().replace('/', '')) |
| 344 | in_framework = ( |
| 345 | any(item.startswith(partition) for item in framework_item_list) or |
| 346 | image_path in framework_item_list) |
| 347 | in_vendor = ( |
| 348 | any(item.startswith(partition) for item in vendor_item_list) or |
| 349 | image_path in vendor_item_list) |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 350 | if in_framework and in_vendor: |
Daniel Norman | edf1247 | 2019-05-22 10:47:08 -0700 | [diff] [blame] | 351 | logger.error( |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 352 | 'Cannot extract items from %s for both the framework and vendor' |
Kiyoung Kim | ebe7c9c | 2019-06-25 17:09:55 +0900 | [diff] [blame] | 353 | ' builds. Please ensure only one merge config item list' |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 354 | ' includes %s.', partition, partition) |
Daniel Norman | edf1247 | 2019-05-22 10:47:08 -0700 | [diff] [blame] | 355 | has_error = True |
Daniel Norman | e596452 | 2019-03-19 10:32:03 -0700 | [diff] [blame] | 356 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 357 | if ('dynamic_partition_list' in framework_misc_info_keys) or ( |
| 358 | 'super_partition_groups' in framework_misc_info_keys): |
Daniel Norman | 19b9fe9 | 2019-03-19 14:48:02 -0700 | [diff] [blame] | 359 | logger.error('Dynamic partition misc info keys should come from ' |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 360 | 'the vendor instance of META/misc_info.txt.') |
Daniel Norman | edf1247 | 2019-05-22 10:47:08 -0700 | [diff] [blame] | 361 | has_error = True |
Daniel Norman | 19b9fe9 | 2019-03-19 14:48:02 -0700 | [diff] [blame] | 362 | |
Daniel Norman | edf1247 | 2019-05-22 10:47:08 -0700 | [diff] [blame] | 363 | return not has_error |
Daniel Norman | e596452 | 2019-03-19 10:32:03 -0700 | [diff] [blame] | 364 | |
| 365 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 366 | def process_ab_partitions_txt(framework_target_files_temp_dir, |
| 367 | vendor_target_files_temp_dir, |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 368 | output_target_files_temp_dir): |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 369 | """Performs special processing for META/ab_partitions.txt. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 370 | |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 371 | This function merges the contents of the META/ab_partitions.txt files from the |
| 372 | framework directory and the vendor directory, placing the merged result in the |
| 373 | output directory. The precondition in that the files are already extracted. |
| 374 | The post condition is that the output META/ab_partitions.txt contains the |
Daniel Norman | dbbf5a3 | 2020-10-22 16:03:32 -0700 | [diff] [blame] | 375 | merged content. The format for each ab_partitions.txt is one partition name |
| 376 | per line. The output file contains the union of the partition names. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 377 | |
| 378 | Args: |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 379 | framework_target_files_temp_dir: The name of a directory containing the |
| 380 | special items extracted from the framework target files package. |
| 381 | vendor_target_files_temp_dir: The name of a directory containing the special |
| 382 | items extracted from the vendor target files package. |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 383 | output_target_files_temp_dir: The name of a directory that will be used to |
| 384 | create the output target files package after all the special cases are |
| 385 | processed. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 386 | """ |
| 387 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 388 | framework_ab_partitions_txt = os.path.join(framework_target_files_temp_dir, |
| 389 | 'META', 'ab_partitions.txt') |
| 390 | |
| 391 | vendor_ab_partitions_txt = os.path.join(vendor_target_files_temp_dir, 'META', |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 392 | 'ab_partitions.txt') |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 393 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 394 | with open(framework_ab_partitions_txt) as f: |
| 395 | framework_ab_partitions = f.read().splitlines() |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 396 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 397 | with open(vendor_ab_partitions_txt) as f: |
| 398 | vendor_ab_partitions = f.read().splitlines() |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 399 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 400 | output_ab_partitions = set(framework_ab_partitions + vendor_ab_partitions) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 401 | |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 402 | output_ab_partitions_txt = os.path.join(output_target_files_temp_dir, 'META', |
| 403 | 'ab_partitions.txt') |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 404 | |
Chris Gross | fabf50a | 2019-05-02 12:42:09 -0700 | [diff] [blame] | 405 | write_sorted_data(data=output_ab_partitions, path=output_ab_partitions_txt) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 406 | |
| 407 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 408 | def process_misc_info_txt(framework_target_files_temp_dir, |
| 409 | vendor_target_files_temp_dir, |
| 410 | output_target_files_temp_dir, |
| 411 | framework_misc_info_keys): |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 412 | """Performs special processing for META/misc_info.txt. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 413 | |
| 414 | This function merges the contents of the META/misc_info.txt files from the |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 415 | framework directory and the vendor directory, placing the merged result in the |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 416 | output directory. The precondition in that the files are already extracted. |
| 417 | The post condition is that the output META/misc_info.txt contains the merged |
| 418 | content. |
| 419 | |
| 420 | Args: |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 421 | framework_target_files_temp_dir: The name of a directory containing the |
| 422 | special items extracted from the framework target files package. |
| 423 | vendor_target_files_temp_dir: The name of a directory containing the special |
| 424 | items extracted from the vendor target files package. |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 425 | output_target_files_temp_dir: The name of a directory that will be used to |
| 426 | create the output target files package after all the special cases are |
| 427 | processed. |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 428 | framework_misc_info_keys: A list of keys to obtain from the framework |
Daniel Norman | dbbf5a3 | 2020-10-22 16:03:32 -0700 | [diff] [blame] | 429 | instance of META/misc_info.txt. The remaining keys should come from the |
| 430 | vendor instance. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 431 | """ |
| 432 | |
Kiyoung Kim | ebe7c9c | 2019-06-25 17:09:55 +0900 | [diff] [blame] | 433 | misc_info_path = ['META', 'misc_info.txt'] |
| 434 | framework_dict = common.LoadDictionaryFromFile( |
| 435 | os.path.join(framework_target_files_temp_dir, *misc_info_path)) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 436 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 437 | # We take most of the misc info from the vendor target files. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 438 | |
Kiyoung Kim | ebe7c9c | 2019-06-25 17:09:55 +0900 | [diff] [blame] | 439 | merged_dict = common.LoadDictionaryFromFile( |
| 440 | os.path.join(vendor_target_files_temp_dir, *misc_info_path)) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 441 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 442 | # Replace certain values in merged_dict with values from |
| 443 | # framework_dict. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 444 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 445 | for key in framework_misc_info_keys: |
| 446 | merged_dict[key] = framework_dict[key] |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 447 | |
Daniel Norman | 19b9fe9 | 2019-03-19 14:48:02 -0700 | [diff] [blame] | 448 | # Merge misc info keys used for Dynamic Partitions. |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 449 | if (merged_dict.get('use_dynamic_partitions') == 'true') and ( |
| 450 | framework_dict.get('use_dynamic_partitions') == 'true'): |
Daniel Norman | bfc51ef | 2019-07-24 14:34:54 -0700 | [diff] [blame] | 451 | merged_dynamic_partitions_dict = common.MergeDynamicPartitionInfoDicts( |
Daniel Norman | 5541714 | 2019-11-25 16:04:36 -0800 | [diff] [blame] | 452 | framework_dict=framework_dict, vendor_dict=merged_dict) |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 453 | merged_dict.update(merged_dynamic_partitions_dict) |
Tao Bao | 48a2feb | 2019-06-28 11:00:05 -0700 | [diff] [blame] | 454 | # Ensure that add_img_to_target_files rebuilds super split images for |
| 455 | # devices that retrofit dynamic partitions. This flag may have been set to |
| 456 | # false in the partial builds to prevent duplicate building of super.img. |
Daniel Norman | 0bf940c | 2019-06-10 12:50:19 -0700 | [diff] [blame] | 457 | merged_dict['build_super_partition'] = 'true' |
Daniel Norman | 19b9fe9 | 2019-03-19 14:48:02 -0700 | [diff] [blame] | 458 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 459 | # Replace <image>_selinux_fc values with framework or vendor file_contexts.bin |
Daniel Norman | 72c626f | 2019-05-13 15:58:14 -0700 | [diff] [blame] | 460 | # depending on which dictionary the key came from. |
| 461 | # Only the file basename is required because all selinux_fc properties are |
| 462 | # replaced with the full path to the file under META/ when misc_info.txt is |
| 463 | # loaded from target files for repacking. See common.py LoadInfoDict(). |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 464 | for key in merged_dict: |
Daniel Norman | 72c626f | 2019-05-13 15:58:14 -0700 | [diff] [blame] | 465 | if key.endswith('_selinux_fc'): |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 466 | merged_dict[key] = 'vendor_file_contexts.bin' |
| 467 | for key in framework_dict: |
Daniel Norman | 72c626f | 2019-05-13 15:58:14 -0700 | [diff] [blame] | 468 | if key.endswith('_selinux_fc'): |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 469 | merged_dict[key] = 'framework_file_contexts.bin' |
Daniel Norman | 72c626f | 2019-05-13 15:58:14 -0700 | [diff] [blame] | 470 | |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 471 | output_misc_info_txt = os.path.join(output_target_files_temp_dir, 'META', |
| 472 | 'misc_info.txt') |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 473 | write_sorted_data(data=merged_dict, path=output_misc_info_txt) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 474 | |
| 475 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 476 | def process_dynamic_partitions_info_txt(framework_target_files_dir, |
| 477 | vendor_target_files_dir, |
Daniel Norman | a61cde0 | 2019-05-03 14:19:13 -0700 | [diff] [blame] | 478 | output_target_files_dir): |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 479 | """Performs special processing for META/dynamic_partitions_info.txt. |
Daniel Norman | a61cde0 | 2019-05-03 14:19:13 -0700 | [diff] [blame] | 480 | |
| 481 | This function merges the contents of the META/dynamic_partitions_info.txt |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 482 | files from the framework directory and the vendor directory, placing the |
| 483 | merged result in the output directory. |
Daniel Norman | a61cde0 | 2019-05-03 14:19:13 -0700 | [diff] [blame] | 484 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 485 | This function does nothing if META/dynamic_partitions_info.txt from the vendor |
Daniel Norman | a61cde0 | 2019-05-03 14:19:13 -0700 | [diff] [blame] | 486 | directory does not exist. |
| 487 | |
| 488 | Args: |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 489 | framework_target_files_dir: The name of a directory containing the special |
| 490 | items extracted from the framework target files package. |
| 491 | vendor_target_files_dir: The name of a directory containing the special |
| 492 | items extracted from the vendor target files package. |
Daniel Norman | a61cde0 | 2019-05-03 14:19:13 -0700 | [diff] [blame] | 493 | output_target_files_dir: The name of a directory that will be used to create |
| 494 | the output target files package after all the special cases are processed. |
| 495 | """ |
| 496 | |
| 497 | if not os.path.exists( |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 498 | os.path.join(vendor_target_files_dir, 'META', |
Daniel Norman | a61cde0 | 2019-05-03 14:19:13 -0700 | [diff] [blame] | 499 | 'dynamic_partitions_info.txt')): |
| 500 | return |
| 501 | |
Kiyoung Kim | ebe7c9c | 2019-06-25 17:09:55 +0900 | [diff] [blame] | 502 | dynamic_partitions_info_path = ['META', 'dynamic_partitions_info.txt'] |
Daniel Norman | a61cde0 | 2019-05-03 14:19:13 -0700 | [diff] [blame] | 503 | |
Kiyoung Kim | ebe7c9c | 2019-06-25 17:09:55 +0900 | [diff] [blame] | 504 | framework_dynamic_partitions_dict = common.LoadDictionaryFromFile( |
| 505 | os.path.join(framework_target_files_dir, *dynamic_partitions_info_path)) |
| 506 | vendor_dynamic_partitions_dict = common.LoadDictionaryFromFile( |
| 507 | os.path.join(vendor_target_files_dir, *dynamic_partitions_info_path)) |
Daniel Norman | a61cde0 | 2019-05-03 14:19:13 -0700 | [diff] [blame] | 508 | |
Daniel Norman | bfc51ef | 2019-07-24 14:34:54 -0700 | [diff] [blame] | 509 | merged_dynamic_partitions_dict = common.MergeDynamicPartitionInfoDicts( |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 510 | framework_dict=framework_dynamic_partitions_dict, |
Daniel Norman | 5541714 | 2019-11-25 16:04:36 -0800 | [diff] [blame] | 511 | vendor_dict=vendor_dynamic_partitions_dict) |
Daniel Norman | a61cde0 | 2019-05-03 14:19:13 -0700 | [diff] [blame] | 512 | |
| 513 | output_dynamic_partitions_info_txt = os.path.join( |
| 514 | output_target_files_dir, 'META', 'dynamic_partitions_info.txt') |
Chris Gross | fabf50a | 2019-05-02 12:42:09 -0700 | [diff] [blame] | 515 | write_sorted_data( |
| 516 | data=merged_dynamic_partitions_dict, |
| 517 | path=output_dynamic_partitions_info_txt) |
| 518 | |
| 519 | |
Bill Peckham | 19c3feb | 2020-03-20 18:31:43 -0700 | [diff] [blame] | 520 | def item_list_to_partition_set(item_list): |
| 521 | """Converts a target files item list to a partition set. |
| 522 | |
| 523 | The item list contains items that might look like 'SYSTEM/*' or 'VENDOR/*' or |
| 524 | 'OTA/android-info.txt'. Items that end in '/*' are assumed to match entire |
| 525 | directories where 'SYSTEM' or 'VENDOR' is a directory name that identifies the |
| 526 | contents of a partition of the same name. Other items in the list, such as the |
| 527 | 'OTA' example contain metadata. This function iterates such a list, returning |
| 528 | a set that contains the partition entries. |
| 529 | |
| 530 | Args: |
| 531 | item_list: A list of items in a target files package. |
Daniel Norman | b0c7591 | 2020-09-24 14:30:21 -0700 | [diff] [blame] | 532 | |
Bill Peckham | 19c3feb | 2020-03-20 18:31:43 -0700 | [diff] [blame] | 533 | Returns: |
| 534 | A set of partitions extracted from the list of items. |
| 535 | """ |
| 536 | |
| 537 | partition_set = set() |
| 538 | |
| 539 | for item in item_list: |
| 540 | match = PARTITION_ITEM_PATTERN.search(item.strip()) |
| 541 | partition_tag = match.group(1).lower() if match else None |
| 542 | |
| 543 | if partition_tag: |
| 544 | partition_set.add(partition_tag) |
| 545 | |
| 546 | return partition_set |
| 547 | |
| 548 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 549 | def process_apex_keys_apk_certs_common(framework_target_files_dir, |
| 550 | vendor_target_files_dir, |
Bill Peckham | 19c3feb | 2020-03-20 18:31:43 -0700 | [diff] [blame] | 551 | output_target_files_dir, |
| 552 | framework_partition_set, |
| 553 | vendor_partition_set, file_name): |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 554 | """Performs special processing for META/apexkeys.txt or META/apkcerts.txt. |
Chris Gross | fabf50a | 2019-05-02 12:42:09 -0700 | [diff] [blame] | 555 | |
| 556 | This function merges the contents of the META/apexkeys.txt or |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 557 | META/apkcerts.txt files from the framework directory and the vendor directory, |
| 558 | placing the merged result in the output directory. The precondition in that |
| 559 | the files are already extracted. The post condition is that the output |
| 560 | META/apexkeys.txt or META/apkcerts.txt contains the merged content. |
Chris Gross | fabf50a | 2019-05-02 12:42:09 -0700 | [diff] [blame] | 561 | |
| 562 | Args: |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 563 | framework_target_files_dir: The name of a directory containing the special |
| 564 | items extracted from the framework target files package. |
| 565 | vendor_target_files_dir: The name of a directory containing the special |
| 566 | items extracted from the vendor target files package. |
Chris Gross | fabf50a | 2019-05-02 12:42:09 -0700 | [diff] [blame] | 567 | output_target_files_dir: The name of a directory that will be used to create |
| 568 | the output target files package after all the special cases are processed. |
Bill Peckham | 19c3feb | 2020-03-20 18:31:43 -0700 | [diff] [blame] | 569 | framework_partition_set: Partitions that are considered framework |
| 570 | partitions. Used to filter apexkeys.txt and apkcerts.txt. |
| 571 | vendor_partition_set: Partitions that are considered vendor partitions. Used |
| 572 | to filter apexkeys.txt and apkcerts.txt. |
Chris Gross | fabf50a | 2019-05-02 12:42:09 -0700 | [diff] [blame] | 573 | file_name: The name of the file to merge. One of apkcerts.txt or |
| 574 | apexkeys.txt. |
| 575 | """ |
| 576 | |
| 577 | def read_helper(d): |
| 578 | temp = {} |
| 579 | file_path = os.path.join(d, 'META', file_name) |
| 580 | with open(file_path) as f: |
| 581 | for line in f: |
| 582 | if line.strip(): |
Bill Peckham | 19c3feb | 2020-03-20 18:31:43 -0700 | [diff] [blame] | 583 | name = line.split()[0] |
| 584 | match = MODULE_KEY_PATTERN.search(name) |
| 585 | temp[match.group(1)] = line.strip() |
Chris Gross | fabf50a | 2019-05-02 12:42:09 -0700 | [diff] [blame] | 586 | return temp |
| 587 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 588 | framework_dict = read_helper(framework_target_files_dir) |
| 589 | vendor_dict = read_helper(vendor_target_files_dir) |
Bill Peckham | 19c3feb | 2020-03-20 18:31:43 -0700 | [diff] [blame] | 590 | merged_dict = {} |
Chris Gross | fabf50a | 2019-05-02 12:42:09 -0700 | [diff] [blame] | 591 | |
Bill Peckham | 19c3feb | 2020-03-20 18:31:43 -0700 | [diff] [blame] | 592 | def filter_into_merged_dict(item_dict, partition_set): |
| 593 | for key, value in item_dict.items(): |
| 594 | match = PARTITION_TAG_PATTERN.search(value) |
| 595 | |
| 596 | if match is None: |
| 597 | raise ValueError('Entry missing partition tag: %s' % value) |
| 598 | |
| 599 | partition_tag = match.group(1) |
| 600 | |
| 601 | if partition_tag in partition_set: |
| 602 | if key in merged_dict: |
Daniel Norman | b0c7591 | 2020-09-24 14:30:21 -0700 | [diff] [blame] | 603 | if OPTIONS.allow_duplicate_apkapex_keys: |
| 604 | # TODO(b/150582573) Always raise on duplicates. |
| 605 | logger.warning('Duplicate key %s' % key) |
| 606 | continue |
| 607 | else: |
| 608 | raise ValueError('Duplicate key %s' % key) |
Bill Peckham | 19c3feb | 2020-03-20 18:31:43 -0700 | [diff] [blame] | 609 | |
| 610 | merged_dict[key] = value |
| 611 | |
| 612 | filter_into_merged_dict(framework_dict, framework_partition_set) |
| 613 | filter_into_merged_dict(vendor_dict, vendor_partition_set) |
Chris Gross | fabf50a | 2019-05-02 12:42:09 -0700 | [diff] [blame] | 614 | |
| 615 | output_file = os.path.join(output_target_files_dir, 'META', file_name) |
| 616 | |
Bill Peckham | 19c3feb | 2020-03-20 18:31:43 -0700 | [diff] [blame] | 617 | # The following code is similar to write_sorted_data, but different enough |
| 618 | # that we couldn't use that function. We need the output to be sorted by the |
| 619 | # basename of the apex/apk (without the ".apex" or ".apk" suffix). This |
| 620 | # allows the sort to be consistent with the framework/vendor input data and |
| 621 | # eases comparison of input data with merged data. |
| 622 | with open(output_file, 'w') as output: |
| 623 | for key in sorted(merged_dict.keys()): |
| 624 | out_str = merged_dict[key] + '\n' |
| 625 | output.write(out_str) |
Daniel Norman | a61cde0 | 2019-05-03 14:19:13 -0700 | [diff] [blame] | 626 | |
| 627 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 628 | def copy_file_contexts(framework_target_files_dir, vendor_target_files_dir, |
Daniel Norman | 72c626f | 2019-05-13 15:58:14 -0700 | [diff] [blame] | 629 | output_target_files_dir): |
| 630 | """Creates named copies of each build's file_contexts.bin in output META/.""" |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 631 | framework_fc_path = os.path.join(framework_target_files_dir, 'META', |
| 632 | 'framework_file_contexts.bin') |
| 633 | if not os.path.exists(framework_fc_path): |
| 634 | framework_fc_path = os.path.join(framework_target_files_dir, 'META', |
| 635 | 'file_contexts.bin') |
| 636 | if not os.path.exists(framework_fc_path): |
| 637 | raise ValueError('Missing framework file_contexts.bin.') |
| 638 | shutil.copyfile( |
| 639 | framework_fc_path, |
| 640 | os.path.join(output_target_files_dir, 'META', |
| 641 | 'framework_file_contexts.bin')) |
| 642 | |
| 643 | vendor_fc_path = os.path.join(vendor_target_files_dir, 'META', |
| 644 | 'vendor_file_contexts.bin') |
| 645 | if not os.path.exists(vendor_fc_path): |
| 646 | vendor_fc_path = os.path.join(vendor_target_files_dir, 'META', |
Daniel Norman | edf1247 | 2019-05-22 10:47:08 -0700 | [diff] [blame] | 647 | 'file_contexts.bin') |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 648 | if not os.path.exists(vendor_fc_path): |
| 649 | raise ValueError('Missing vendor file_contexts.bin.') |
Daniel Norman | 72c626f | 2019-05-13 15:58:14 -0700 | [diff] [blame] | 650 | shutil.copyfile( |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 651 | vendor_fc_path, |
| 652 | os.path.join(output_target_files_dir, 'META', 'vendor_file_contexts.bin')) |
Daniel Norman | 72c626f | 2019-05-13 15:58:14 -0700 | [diff] [blame] | 653 | |
| 654 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 655 | def process_special_cases(framework_target_files_temp_dir, |
| 656 | vendor_target_files_temp_dir, |
| 657 | output_target_files_temp_dir, |
Daniel Norman | b0c7591 | 2020-09-24 14:30:21 -0700 | [diff] [blame] | 658 | framework_misc_info_keys, framework_partition_set, |
Bill Peckham | 19c3feb | 2020-03-20 18:31:43 -0700 | [diff] [blame] | 659 | vendor_partition_set): |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 660 | """Performs special-case processing for certain target files items. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 661 | |
| 662 | Certain files in the output target files package require special-case |
| 663 | processing. This function performs all that special-case processing. |
| 664 | |
| 665 | Args: |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 666 | framework_target_files_temp_dir: The name of a directory containing the |
| 667 | special items extracted from the framework target files package. |
| 668 | vendor_target_files_temp_dir: The name of a directory containing the special |
| 669 | items extracted from the vendor target files package. |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 670 | output_target_files_temp_dir: The name of a directory that will be used to |
| 671 | create the output target files package after all the special cases are |
| 672 | processed. |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 673 | framework_misc_info_keys: A list of keys to obtain from the framework |
Daniel Norman | dbbf5a3 | 2020-10-22 16:03:32 -0700 | [diff] [blame] | 674 | instance of META/misc_info.txt. The remaining keys should come from the |
| 675 | vendor instance. |
Bill Peckham | 19c3feb | 2020-03-20 18:31:43 -0700 | [diff] [blame] | 676 | framework_partition_set: Partitions that are considered framework |
| 677 | partitions. Used to filter apexkeys.txt and apkcerts.txt. |
| 678 | vendor_partition_set: Partitions that are considered vendor partitions. Used |
| 679 | to filter apexkeys.txt and apkcerts.txt. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 680 | """ |
| 681 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 682 | if 'ab_update' in framework_misc_info_keys: |
Bill Peckham | 364c1cc | 2019-03-29 18:27:23 -0700 | [diff] [blame] | 683 | process_ab_partitions_txt( |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 684 | framework_target_files_temp_dir=framework_target_files_temp_dir, |
| 685 | vendor_target_files_temp_dir=vendor_target_files_temp_dir, |
Bill Peckham | 364c1cc | 2019-03-29 18:27:23 -0700 | [diff] [blame] | 686 | output_target_files_temp_dir=output_target_files_temp_dir) |
| 687 | |
Daniel Norman | 72c626f | 2019-05-13 15:58:14 -0700 | [diff] [blame] | 688 | copy_file_contexts( |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 689 | framework_target_files_dir=framework_target_files_temp_dir, |
| 690 | vendor_target_files_dir=vendor_target_files_temp_dir, |
Daniel Norman | 72c626f | 2019-05-13 15:58:14 -0700 | [diff] [blame] | 691 | output_target_files_dir=output_target_files_temp_dir) |
| 692 | |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 693 | process_misc_info_txt( |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 694 | framework_target_files_temp_dir=framework_target_files_temp_dir, |
| 695 | vendor_target_files_temp_dir=vendor_target_files_temp_dir, |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 696 | output_target_files_temp_dir=output_target_files_temp_dir, |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 697 | framework_misc_info_keys=framework_misc_info_keys) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 698 | |
Daniel Norman | a61cde0 | 2019-05-03 14:19:13 -0700 | [diff] [blame] | 699 | process_dynamic_partitions_info_txt( |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 700 | framework_target_files_dir=framework_target_files_temp_dir, |
| 701 | vendor_target_files_dir=vendor_target_files_temp_dir, |
Daniel Norman | 714bd12 | 2019-05-08 16:20:02 -0700 | [diff] [blame] | 702 | output_target_files_dir=output_target_files_temp_dir) |
Daniel Norman | a61cde0 | 2019-05-03 14:19:13 -0700 | [diff] [blame] | 703 | |
Chris Gross | fabf50a | 2019-05-02 12:42:09 -0700 | [diff] [blame] | 704 | process_apex_keys_apk_certs_common( |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 705 | framework_target_files_dir=framework_target_files_temp_dir, |
| 706 | vendor_target_files_dir=vendor_target_files_temp_dir, |
Chris Gross | fabf50a | 2019-05-02 12:42:09 -0700 | [diff] [blame] | 707 | output_target_files_dir=output_target_files_temp_dir, |
Bill Peckham | 19c3feb | 2020-03-20 18:31:43 -0700 | [diff] [blame] | 708 | framework_partition_set=framework_partition_set, |
| 709 | vendor_partition_set=vendor_partition_set, |
Chris Gross | fabf50a | 2019-05-02 12:42:09 -0700 | [diff] [blame] | 710 | file_name='apkcerts.txt') |
| 711 | |
| 712 | process_apex_keys_apk_certs_common( |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 713 | framework_target_files_dir=framework_target_files_temp_dir, |
| 714 | vendor_target_files_dir=vendor_target_files_temp_dir, |
Chris Gross | fabf50a | 2019-05-02 12:42:09 -0700 | [diff] [blame] | 715 | output_target_files_dir=output_target_files_temp_dir, |
Bill Peckham | 19c3feb | 2020-03-20 18:31:43 -0700 | [diff] [blame] | 716 | framework_partition_set=framework_partition_set, |
| 717 | vendor_partition_set=vendor_partition_set, |
Chris Gross | fabf50a | 2019-05-02 12:42:09 -0700 | [diff] [blame] | 718 | file_name='apexkeys.txt') |
| 719 | |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 720 | |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 721 | def create_merged_package(temp_dir, framework_target_files, framework_item_list, |
| 722 | vendor_target_files, vendor_item_list, |
Daniel Norman | 4cc9df6 | 2019-07-18 10:11:07 -0700 | [diff] [blame] | 723 | framework_misc_info_keys, rebuild_recovery): |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 724 | """Merges two target files packages into one target files structure. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 725 | |
| 726 | Args: |
| 727 | temp_dir: The name of a directory we use when we extract items from the |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 728 | input target files packages, and also a scratch directory that we use for |
| 729 | temporary files. |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 730 | framework_target_files: The name of the zip archive containing the framework |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 731 | partial target files package. |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 732 | framework_item_list: The list of items to extract from the partial framework |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 733 | target files package as is, meaning these items will land in the output |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 734 | target files package exactly as they appear in the input partial framework |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 735 | target files package. |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 736 | vendor_target_files: The name of the zip archive containing the vendor |
| 737 | partial target files package. |
| 738 | vendor_item_list: The list of items to extract from the partial vendor |
| 739 | target files package as is, meaning these items will land in the output |
| 740 | target files package exactly as they appear in the input partial vendor |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 741 | target files package. |
Daniel Norman | dbbf5a3 | 2020-10-22 16:03:32 -0700 | [diff] [blame] | 742 | framework_misc_info_keys: A list of keys to obtain from the framework |
| 743 | instance of META/misc_info.txt. The remaining keys should come from the |
| 744 | vendor instance. |
Daniel Norman | a4911da | 2019-03-15 14:36:21 -0700 | [diff] [blame] | 745 | rebuild_recovery: If true, rebuild the recovery patch used by non-A/B |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 746 | devices and write it to the system image. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 747 | |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 748 | Returns: |
| 749 | Path to merged package under temp directory. |
| 750 | """ |
Daniel Norman | dbbf5a3 | 2020-10-22 16:03:32 -0700 | [diff] [blame] | 751 | # Extract "as is" items from the input framework and vendor partial target |
| 752 | # files packages directly into the output temporary directory, since these items |
| 753 | # do not need special case processing. |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 754 | |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 755 | output_target_files_temp_dir = os.path.join(temp_dir, 'output') |
Bill Peckham | 889b0c6 | 2019-02-21 18:53:37 -0800 | [diff] [blame] | 756 | extract_items( |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 757 | target_files=framework_target_files, |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 758 | target_files_temp_dir=output_target_files_temp_dir, |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 759 | extract_item_list=framework_item_list) |
Bill Peckham | 889b0c6 | 2019-02-21 18:53:37 -0800 | [diff] [blame] | 760 | extract_items( |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 761 | target_files=vendor_target_files, |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 762 | target_files_temp_dir=output_target_files_temp_dir, |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 763 | extract_item_list=vendor_item_list) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 764 | |
Daniel Norman | dbbf5a3 | 2020-10-22 16:03:32 -0700 | [diff] [blame] | 765 | # Perform special case processing on META/* items. |
| 766 | # After this function completes successfully, all the files we need to create |
| 767 | # the output target files package are in place. |
| 768 | framework_target_files_temp_dir = os.path.join(temp_dir, 'framework') |
| 769 | vendor_target_files_temp_dir = os.path.join(temp_dir, 'vendor') |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 770 | extract_items( |
| 771 | target_files=framework_target_files, |
| 772 | target_files_temp_dir=framework_target_files_temp_dir, |
Daniel Norman | dbbf5a3 | 2020-10-22 16:03:32 -0700 | [diff] [blame] | 773 | extract_item_list=('META/*',)) |
Bill Peckham | 889b0c6 | 2019-02-21 18:53:37 -0800 | [diff] [blame] | 774 | extract_items( |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 775 | target_files=vendor_target_files, |
| 776 | target_files_temp_dir=vendor_target_files_temp_dir, |
Daniel Norman | dbbf5a3 | 2020-10-22 16:03:32 -0700 | [diff] [blame] | 777 | extract_item_list=('META/*',)) |
Bill Peckham | 889b0c6 | 2019-02-21 18:53:37 -0800 | [diff] [blame] | 778 | process_special_cases( |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 779 | framework_target_files_temp_dir=framework_target_files_temp_dir, |
| 780 | vendor_target_files_temp_dir=vendor_target_files_temp_dir, |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 781 | output_target_files_temp_dir=output_target_files_temp_dir, |
Bill Peckham | 19c3feb | 2020-03-20 18:31:43 -0700 | [diff] [blame] | 782 | framework_misc_info_keys=framework_misc_info_keys, |
| 783 | framework_partition_set=item_list_to_partition_set(framework_item_list), |
| 784 | vendor_partition_set=item_list_to_partition_set(vendor_item_list)) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 785 | |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 786 | return output_target_files_temp_dir |
| 787 | |
| 788 | |
| 789 | def generate_images(target_files_dir, rebuild_recovery): |
| 790 | """Generate images from target files. |
| 791 | |
| 792 | This function takes merged output temporary directory and create images |
| 793 | from it. |
| 794 | |
| 795 | Args: |
| 796 | target_files_dir: Path to merged temp directory. |
| 797 | rebuild_recovery: If true, rebuild the recovery patch used by non-A/B |
| 798 | devices and write it to the system image. |
| 799 | """ |
| 800 | |
| 801 | # Regenerate IMAGES in the target directory. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 802 | |
Daniel Norman | dbbf5a3 | 2020-10-22 16:03:32 -0700 | [diff] [blame] | 803 | add_img_args = [ |
| 804 | '--verbose', |
| 805 | '--add_missing', |
| 806 | ] |
Bill Peckham | e868aec | 2019-09-17 17:06:47 -0700 | [diff] [blame] | 807 | # TODO(b/132730255): Remove this if statement. |
Daniel Norman | a4911da | 2019-03-15 14:36:21 -0700 | [diff] [blame] | 808 | if rebuild_recovery: |
| 809 | add_img_args.append('--rebuild_recovery') |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 810 | add_img_args.append(target_files_dir) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 811 | |
| 812 | add_img_to_target_files.main(add_img_args) |
| 813 | |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 814 | |
| 815 | def generate_super_empty_image(target_dir, output_super_empty): |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 816 | """Generates super_empty image from target package. |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 817 | |
| 818 | Args: |
| 819 | target_dir: Path to the target file package which contains misc_info.txt for |
| 820 | detailed information for super image. |
| 821 | output_super_empty: If provided, copies a super_empty.img file from the |
| 822 | target files package to this path. |
| 823 | """ |
Daniel Norman | 1bd2a1d | 2019-04-18 12:32:18 -0700 | [diff] [blame] | 824 | # Create super_empty.img using the merged misc_info.txt. |
| 825 | |
Daniel Norman | 4cc9df6 | 2019-07-18 10:11:07 -0700 | [diff] [blame] | 826 | misc_info_txt = os.path.join(target_dir, 'META', 'misc_info.txt') |
Daniel Norman | 1bd2a1d | 2019-04-18 12:32:18 -0700 | [diff] [blame] | 827 | |
Kiyoung Kim | ebe7c9c | 2019-06-25 17:09:55 +0900 | [diff] [blame] | 828 | use_dynamic_partitions = common.LoadDictionaryFromFile(misc_info_txt).get( |
| 829 | 'use_dynamic_partitions') |
Daniel Norman | 1bd2a1d | 2019-04-18 12:32:18 -0700 | [diff] [blame] | 830 | |
| 831 | if use_dynamic_partitions != 'true' and output_super_empty: |
| 832 | raise ValueError( |
| 833 | 'Building super_empty.img requires use_dynamic_partitions=true.') |
| 834 | elif use_dynamic_partitions == 'true': |
Daniel Norman | 4cc9df6 | 2019-07-18 10:11:07 -0700 | [diff] [blame] | 835 | super_empty_img = os.path.join(target_dir, 'IMAGES', 'super_empty.img') |
Daniel Norman | 1bd2a1d | 2019-04-18 12:32:18 -0700 | [diff] [blame] | 836 | build_super_image_args = [ |
| 837 | misc_info_txt, |
| 838 | super_empty_img, |
| 839 | ] |
| 840 | build_super_image.main(build_super_image_args) |
| 841 | |
| 842 | # Copy super_empty.img to the user-provided output_super_empty location. |
| 843 | if output_super_empty: |
| 844 | shutil.copyfile(super_empty_img, output_super_empty) |
| 845 | |
Daniel Norman | b8a2f9d | 2019-04-24 12:55:51 -0700 | [diff] [blame] | 846 | |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 847 | def create_target_files_archive(output_file, source_dir, temp_dir): |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 848 | """Creates archive from target package. |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 849 | |
| 850 | Args: |
| 851 | output_file: The name of the zip archive target files package. |
| 852 | source_dir: The target directory contains package to be archived. |
| 853 | temp_dir: Path to temporary directory for any intermediate files. |
| 854 | """ |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 855 | output_target_files_list = os.path.join(temp_dir, 'output.list') |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 856 | output_zip = os.path.abspath(output_file) |
Daniel Norman | 4cc9df6 | 2019-07-18 10:11:07 -0700 | [diff] [blame] | 857 | output_target_files_meta_dir = os.path.join(source_dir, 'META') |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 858 | |
Daniel Norman | dbbf5a3 | 2020-10-22 16:03:32 -0700 | [diff] [blame] | 859 | def files_from_path(target_path, extra_args=None): |
| 860 | """Gets files under the given path and return a sorted list.""" |
| 861 | find_command = ['find', target_path] + (extra_args or []) |
| 862 | find_process = common.Run( |
| 863 | find_command, stdout=subprocess.PIPE, verbose=False) |
| 864 | return common.RunAndCheckOutput(['sort'], |
| 865 | stdin=find_process.stdout, |
| 866 | verbose=False) |
| 867 | |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 868 | meta_content = files_from_path(output_target_files_meta_dir) |
Daniel Norman | 4cc9df6 | 2019-07-18 10:11:07 -0700 | [diff] [blame] | 869 | other_content = files_from_path( |
| 870 | source_dir, |
| 871 | ['-path', output_target_files_meta_dir, '-prune', '-o', '-print']) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 872 | |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 873 | with open(output_target_files_list, 'w') as f: |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 874 | f.write(meta_content) |
| 875 | f.write(other_content) |
| 876 | |
| 877 | command = [ |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 878 | 'soong_zip', |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 879 | '-d', |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 880 | '-o', |
| 881 | output_zip, |
| 882 | '-C', |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 883 | source_dir, |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 884 | '-l', |
| 885 | output_target_files_list, |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 886 | ] |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 887 | |
| 888 | logger.info('creating %s', output_file) |
Bill Peckham | 889b0c6 | 2019-02-21 18:53:37 -0800 | [diff] [blame] | 889 | common.RunAndWait(command, verbose=True) |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 890 | logger.info('finished creating %s', output_file) |
| 891 | |
| 892 | return output_zip |
| 893 | |
| 894 | |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 895 | def merge_target_files(temp_dir, framework_target_files, framework_item_list, |
| 896 | framework_misc_info_keys, vendor_target_files, |
| 897 | vendor_item_list, output_target_files, output_dir, |
| 898 | output_item_list, output_ota, output_img, |
| 899 | output_super_empty, rebuild_recovery): |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 900 | """Merges two target files packages together. |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 901 | |
| 902 | This function takes framework and vendor target files packages as input, |
| 903 | performs various file extractions, special case processing, and finally |
| 904 | creates a merged zip archive as output. |
| 905 | |
| 906 | Args: |
| 907 | temp_dir: The name of a directory we use when we extract items from the |
| 908 | input target files packages, and also a scratch directory that we use for |
| 909 | temporary files. |
| 910 | framework_target_files: The name of the zip archive containing the framework |
| 911 | partial target files package. |
| 912 | framework_item_list: The list of items to extract from the partial framework |
| 913 | target files package as is, meaning these items will land in the output |
| 914 | target files package exactly as they appear in the input partial framework |
| 915 | target files package. |
Daniel Norman | dbbf5a3 | 2020-10-22 16:03:32 -0700 | [diff] [blame] | 916 | framework_misc_info_keys: A list of keys to obtain from the framework |
| 917 | instance of META/misc_info.txt. The remaining keys should come from the |
| 918 | vendor instance. |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 919 | vendor_target_files: The name of the zip archive containing the vendor |
| 920 | partial target files package. |
| 921 | vendor_item_list: The list of items to extract from the partial vendor |
| 922 | target files package as is, meaning these items will land in the output |
| 923 | target files package exactly as they appear in the input partial vendor |
| 924 | target files package. |
| 925 | output_target_files: The name of the output zip archive target files package |
| 926 | created by merging framework and vendor. |
| 927 | output_dir: The destination directory for saving merged files. |
| 928 | output_item_list: The list of items to copy into the output_dir. |
| 929 | output_ota: The name of the output zip archive ota package. |
| 930 | output_img: The name of the output zip archive img package. |
| 931 | output_super_empty: If provided, creates a super_empty.img file from the |
| 932 | merged target files package and saves it at this path. |
| 933 | rebuild_recovery: If true, rebuild the recovery patch used by non-A/B |
| 934 | devices and write it to the system image. |
| 935 | """ |
| 936 | |
| 937 | logger.info('starting: merge framework %s and vendor %s into output %s', |
| 938 | framework_target_files, vendor_target_files, output_target_files) |
| 939 | |
| 940 | output_target_files_temp_dir = create_merged_package( |
| 941 | temp_dir, framework_target_files, framework_item_list, |
| 942 | vendor_target_files, vendor_item_list, framework_misc_info_keys, |
| 943 | rebuild_recovery) |
| 944 | |
Yifan Hong | ade0d3f | 2019-08-21 16:37:11 -0700 | [diff] [blame] | 945 | if not check_target_files_vintf.CheckVintf(output_target_files_temp_dir): |
Daniel Norman | b0c7591 | 2020-09-24 14:30:21 -0700 | [diff] [blame] | 946 | raise RuntimeError('Incompatible VINTF metadata') |
Yifan Hong | ade0d3f | 2019-08-21 16:37:11 -0700 | [diff] [blame] | 947 | |
Daniel Norman | d335156 | 2020-10-29 12:33:11 -0700 | [diff] [blame^] | 948 | # Generate and check for cross-partition violations of sharedUserId |
| 949 | # values in APKs. This requires the input target-files packages to contain |
| 950 | # *.apk files. |
Daniel Norman | b8d52a2 | 2020-10-26 17:55:00 -0700 | [diff] [blame] | 951 | shareduid_violation_modules = os.path.join( |
| 952 | output_target_files_temp_dir, 'META', 'shareduid_violation_modules.json') |
| 953 | with open(shareduid_violation_modules, 'w') as f: |
Daniel Norman | d335156 | 2020-10-29 12:33:11 -0700 | [diff] [blame^] | 954 | framework_partitions = item_list_to_partition_set(framework_item_list) |
| 955 | vendor_partitions = item_list_to_partition_set(vendor_item_list) |
| 956 | |
| 957 | partition_map = {} |
| 958 | for partition in (framework_partitions.union(vendor_partitions)): |
| 959 | partition_map[partition.lower()] = partition.upper() |
Daniel Norman | b8d52a2 | 2020-10-26 17:55:00 -0700 | [diff] [blame] | 960 | violation = find_shareduid_violation.FindShareduidViolation( |
| 961 | output_target_files_temp_dir, partition_map) |
Daniel Norman | d335156 | 2020-10-29 12:33:11 -0700 | [diff] [blame^] | 962 | |
| 963 | # Write the output to a file to enable debugging. |
Daniel Norman | b8d52a2 | 2020-10-26 17:55:00 -0700 | [diff] [blame] | 964 | f.write(violation) |
Daniel Norman | d335156 | 2020-10-29 12:33:11 -0700 | [diff] [blame^] | 965 | |
| 966 | # Check for violations across the input builds' partition groups. |
| 967 | shareduid_errors = common.SharedUidPartitionViolations( |
| 968 | json.loads(violation), [framework_partitions, vendor_partitions]) |
| 969 | if shareduid_errors: |
| 970 | for error in shareduid_errors: |
| 971 | logger.error(error) |
| 972 | raise ValueError('sharedUserId APK error. See %s' % |
| 973 | shareduid_violation_modules) |
Daniel Norman | b8d52a2 | 2020-10-26 17:55:00 -0700 | [diff] [blame] | 974 | |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 975 | generate_images(output_target_files_temp_dir, rebuild_recovery) |
| 976 | |
| 977 | generate_super_empty_image(output_target_files_temp_dir, output_super_empty) |
| 978 | |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 979 | # Finally, create the output target files zip archive and/or copy the |
| 980 | # output items to the output target files directory. |
| 981 | |
| 982 | if output_dir: |
| 983 | copy_items(output_target_files_temp_dir, output_dir, output_item_list) |
| 984 | |
| 985 | if not output_target_files: |
| 986 | return |
| 987 | |
| 988 | output_zip = create_target_files_archive(output_target_files, |
| 989 | output_target_files_temp_dir, |
| 990 | temp_dir) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 991 | |
Daniel Norman | 74eb74b | 2019-09-18 14:01:48 -0700 | [diff] [blame] | 992 | # Create the IMG package from the merged target files package. |
| 993 | |
| 994 | if output_img: |
| 995 | img_from_target_files.main([output_zip, output_img]) |
| 996 | |
Daniel Norman | 3b64ce1 | 2019-04-16 16:11:35 -0700 | [diff] [blame] | 997 | # Create the OTA package from the merged target files package. |
| 998 | |
| 999 | if output_ota: |
Daniel Norman | 4cc9df6 | 2019-07-18 10:11:07 -0700 | [diff] [blame] | 1000 | ota_from_target_files.main([output_zip, output_ota]) |
Daniel Norman | 3b64ce1 | 2019-04-16 16:11:35 -0700 | [diff] [blame] | 1001 | |
Daniel Norman | 1bd2a1d | 2019-04-18 12:32:18 -0700 | [diff] [blame] | 1002 | |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 1003 | def call_func_with_temp_dir(func, keep_tmp): |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 1004 | """Manages the creation and cleanup of the temporary directory. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1005 | |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 1006 | This function calls the given function after first creating a temporary |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1007 | directory. It also cleans up the temporary directory. |
| 1008 | |
| 1009 | Args: |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 1010 | func: The function to call. Should accept one parameter, the path to the |
| 1011 | temporary directory. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1012 | keep_tmp: Keep the temporary directory after processing is complete. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1013 | """ |
| 1014 | |
| 1015 | # Create a temporary directory. This will serve as the parent of directories |
| 1016 | # we use when we extract items from the input target files packages, and also |
| 1017 | # a scratch directory that we use for temporary files. |
| 1018 | |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1019 | temp_dir = common.MakeTempDir(prefix='merge_target_files_') |
| 1020 | |
| 1021 | try: |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 1022 | func(temp_dir) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1023 | finally: |
| 1024 | if keep_tmp: |
| 1025 | logger.info('keeping %s', temp_dir) |
| 1026 | else: |
| 1027 | common.Cleanup() |
| 1028 | |
| 1029 | |
| 1030 | def main(): |
| 1031 | """The main function. |
| 1032 | |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 1033 | Process command line arguments, then call merge_target_files to |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1034 | perform the heavy lifting. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1035 | """ |
| 1036 | |
| 1037 | common.InitLogging() |
| 1038 | |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 1039 | def option_handler(o, a): |
| 1040 | if o == '--system-target-files': |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1041 | logger.warning( |
| 1042 | '--system-target-files has been renamed to --framework-target-files') |
| 1043 | OPTIONS.framework_target_files = a |
| 1044 | elif o == '--framework-target-files': |
| 1045 | OPTIONS.framework_target_files = a |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 1046 | elif o == '--system-item-list': |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1047 | logger.warning( |
| 1048 | '--system-item-list has been renamed to --framework-item-list') |
| 1049 | OPTIONS.framework_item_list = a |
| 1050 | elif o == '--framework-item-list': |
| 1051 | OPTIONS.framework_item_list = a |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 1052 | elif o == '--system-misc-info-keys': |
Daniel Norman | 4cc9df6 | 2019-07-18 10:11:07 -0700 | [diff] [blame] | 1053 | logger.warning('--system-misc-info-keys has been renamed to ' |
| 1054 | '--framework-misc-info-keys') |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1055 | OPTIONS.framework_misc_info_keys = a |
| 1056 | elif o == '--framework-misc-info-keys': |
| 1057 | OPTIONS.framework_misc_info_keys = a |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 1058 | elif o == '--other-target-files': |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1059 | logger.warning( |
| 1060 | '--other-target-files has been renamed to --vendor-target-files') |
| 1061 | OPTIONS.vendor_target_files = a |
| 1062 | elif o == '--vendor-target-files': |
| 1063 | OPTIONS.vendor_target_files = a |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 1064 | elif o == '--other-item-list': |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1065 | logger.warning('--other-item-list has been renamed to --vendor-item-list') |
| 1066 | OPTIONS.vendor_item_list = a |
| 1067 | elif o == '--vendor-item-list': |
| 1068 | OPTIONS.vendor_item_list = a |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 1069 | elif o == '--output-target-files': |
| 1070 | OPTIONS.output_target_files = a |
Daniel Norman | fdb3881 | 2019-04-15 09:47:24 -0700 | [diff] [blame] | 1071 | elif o == '--output-dir': |
| 1072 | OPTIONS.output_dir = a |
| 1073 | elif o == '--output-item-list': |
| 1074 | OPTIONS.output_item_list = a |
Daniel Norman | 3b64ce1 | 2019-04-16 16:11:35 -0700 | [diff] [blame] | 1075 | elif o == '--output-ota': |
| 1076 | OPTIONS.output_ota = a |
Daniel Norman | 1bd2a1d | 2019-04-18 12:32:18 -0700 | [diff] [blame] | 1077 | elif o == '--output-img': |
| 1078 | OPTIONS.output_img = a |
Daniel Norman | f031825 | 2019-04-15 11:34:56 -0700 | [diff] [blame] | 1079 | elif o == '--output-super-empty': |
| 1080 | OPTIONS.output_super_empty = a |
Daniel Norman | b0c7591 | 2020-09-24 14:30:21 -0700 | [diff] [blame] | 1081 | elif o == '--rebuild_recovery': # TODO(b/132730255): Warn |
Daniel Norman | a4911da | 2019-03-15 14:36:21 -0700 | [diff] [blame] | 1082 | OPTIONS.rebuild_recovery = True |
Daniel Norman | b0c7591 | 2020-09-24 14:30:21 -0700 | [diff] [blame] | 1083 | elif o == '--allow-duplicate-apkapex-keys': |
| 1084 | OPTIONS.allow_duplicate_apkapex_keys = True |
Bill Peckham | 364c1cc | 2019-03-29 18:27:23 -0700 | [diff] [blame] | 1085 | elif o == '--keep-tmp': |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 1086 | OPTIONS.keep_tmp = True |
| 1087 | else: |
| 1088 | return False |
| 1089 | return True |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1090 | |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 1091 | args = common.ParseOptions( |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 1092 | sys.argv[1:], |
| 1093 | __doc__, |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 1094 | extra_long_opts=[ |
| 1095 | 'system-target-files=', |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1096 | 'framework-target-files=', |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 1097 | 'system-item-list=', |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1098 | 'framework-item-list=', |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 1099 | 'system-misc-info-keys=', |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1100 | 'framework-misc-info-keys=', |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 1101 | 'other-target-files=', |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1102 | 'vendor-target-files=', |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 1103 | 'other-item-list=', |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1104 | 'vendor-item-list=', |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 1105 | 'output-target-files=', |
Daniel Norman | fdb3881 | 2019-04-15 09:47:24 -0700 | [diff] [blame] | 1106 | 'output-dir=', |
| 1107 | 'output-item-list=', |
Daniel Norman | 3b64ce1 | 2019-04-16 16:11:35 -0700 | [diff] [blame] | 1108 | 'output-ota=', |
Daniel Norman | 1bd2a1d | 2019-04-18 12:32:18 -0700 | [diff] [blame] | 1109 | 'output-img=', |
Daniel Norman | f031825 | 2019-04-15 11:34:56 -0700 | [diff] [blame] | 1110 | 'output-super-empty=', |
Daniel Norman | a4911da | 2019-03-15 14:36:21 -0700 | [diff] [blame] | 1111 | 'rebuild_recovery', |
Daniel Norman | b0c7591 | 2020-09-24 14:30:21 -0700 | [diff] [blame] | 1112 | 'allow-duplicate-apkapex-keys', |
Bill Peckham | 364c1cc | 2019-03-29 18:27:23 -0700 | [diff] [blame] | 1113 | 'keep-tmp', |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 1114 | ], |
| 1115 | extra_option_handler=option_handler) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1116 | |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 1117 | # pylint: disable=too-many-boolean-expressions |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1118 | if (args or OPTIONS.framework_target_files is None or |
| 1119 | OPTIONS.vendor_target_files is None or |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 1120 | (OPTIONS.output_target_files is None and OPTIONS.output_dir is None) or |
| 1121 | (OPTIONS.output_dir is not None and OPTIONS.output_item_list is None)): |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 1122 | common.Usage(__doc__) |
Bill Peckham | 889b0c6 | 2019-02-21 18:53:37 -0800 | [diff] [blame] | 1123 | sys.exit(1) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1124 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1125 | if OPTIONS.framework_item_list: |
Daniel Norman | 4cc9df6 | 2019-07-18 10:11:07 -0700 | [diff] [blame] | 1126 | framework_item_list = common.LoadListFromFile(OPTIONS.framework_item_list) |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 1127 | else: |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1128 | framework_item_list = DEFAULT_FRAMEWORK_ITEM_LIST |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 1129 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1130 | if OPTIONS.framework_misc_info_keys: |
Daniel Norman | 4cc9df6 | 2019-07-18 10:11:07 -0700 | [diff] [blame] | 1131 | framework_misc_info_keys = common.LoadListFromFile( |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1132 | OPTIONS.framework_misc_info_keys) |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 1133 | else: |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1134 | framework_misc_info_keys = DEFAULT_FRAMEWORK_MISC_INFO_KEYS |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 1135 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1136 | if OPTIONS.vendor_item_list: |
Daniel Norman | 4cc9df6 | 2019-07-18 10:11:07 -0700 | [diff] [blame] | 1137 | vendor_item_list = common.LoadListFromFile(OPTIONS.vendor_item_list) |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 1138 | else: |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1139 | vendor_item_list = DEFAULT_VENDOR_ITEM_LIST |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 1140 | |
Daniel Norman | fdb3881 | 2019-04-15 09:47:24 -0700 | [diff] [blame] | 1141 | if OPTIONS.output_item_list: |
Daniel Norman | 4cc9df6 | 2019-07-18 10:11:07 -0700 | [diff] [blame] | 1142 | output_item_list = common.LoadListFromFile(OPTIONS.output_item_list) |
Daniel Norman | fdb3881 | 2019-04-15 09:47:24 -0700 | [diff] [blame] | 1143 | else: |
| 1144 | output_item_list = None |
| 1145 | |
Daniel Norman | e596452 | 2019-03-19 10:32:03 -0700 | [diff] [blame] | 1146 | if not validate_config_lists( |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1147 | framework_item_list=framework_item_list, |
| 1148 | framework_misc_info_keys=framework_misc_info_keys, |
| 1149 | vendor_item_list=vendor_item_list): |
Daniel Norman | e596452 | 2019-03-19 10:32:03 -0700 | [diff] [blame] | 1150 | sys.exit(1) |
| 1151 | |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 1152 | call_func_with_temp_dir( |
| 1153 | lambda temp_dir: merge_target_files( |
| 1154 | temp_dir=temp_dir, |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1155 | framework_target_files=OPTIONS.framework_target_files, |
| 1156 | framework_item_list=framework_item_list, |
| 1157 | framework_misc_info_keys=framework_misc_info_keys, |
| 1158 | vendor_target_files=OPTIONS.vendor_target_files, |
| 1159 | vendor_item_list=vendor_item_list, |
Daniel Norman | a4911da | 2019-03-15 14:36:21 -0700 | [diff] [blame] | 1160 | output_target_files=OPTIONS.output_target_files, |
Daniel Norman | fdb3881 | 2019-04-15 09:47:24 -0700 | [diff] [blame] | 1161 | output_dir=OPTIONS.output_dir, |
| 1162 | output_item_list=output_item_list, |
Daniel Norman | 3b64ce1 | 2019-04-16 16:11:35 -0700 | [diff] [blame] | 1163 | output_ota=OPTIONS.output_ota, |
Daniel Norman | 1bd2a1d | 2019-04-18 12:32:18 -0700 | [diff] [blame] | 1164 | output_img=OPTIONS.output_img, |
Daniel Norman | f031825 | 2019-04-15 11:34:56 -0700 | [diff] [blame] | 1165 | output_super_empty=OPTIONS.output_super_empty, |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 1166 | rebuild_recovery=OPTIONS.rebuild_recovery), OPTIONS.keep_tmp) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1167 | |
| 1168 | |
| 1169 | if __name__ == '__main__': |
Bill Peckham | 889b0c6 | 2019-02-21 18:53:37 -0800 | [diff] [blame] | 1170 | main() |