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