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 | |
Daniel Norman | 571e182 | 2021-06-25 17:18:25 -0700 | [diff] [blame] | 81 | --rebuild-sepolicy |
| 82 | If provided, rebuilds odm.img or vendor.img to include merged sepolicy |
| 83 | files. If odm is present then odm is preferred. |
| 84 | |
| 85 | --vendor-otatools otatools.zip |
| 86 | If provided, use this otatools.zip when recompiling the odm or vendor |
| 87 | image to include sepolicy. |
| 88 | |
Bill Peckham | 364c1cc | 2019-03-29 18:27:23 -0700 | [diff] [blame] | 89 | --keep-tmp |
| 90 | Keep tempoary files for debugging purposes. |
Jose Galmes | 9c8f6eb | 2021-07-21 09:34:08 -0700 | [diff] [blame] | 91 | |
| 92 | The following only apply when using the VSDK to perform dexopt on vendor apps: |
| 93 | |
| 94 | --framework-dexpreopt-config |
| 95 | If provided, the location of framwework's dexpreopt_config.zip. |
| 96 | |
| 97 | --framework-dexpreopt-tools |
| 98 | if provided, the location of framework's dexpreopt_tools.zip. |
| 99 | |
| 100 | --vendor-dexpreopt-config |
| 101 | If provided, the location of vendor's dexpreopt_config.zip. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 102 | """ |
| 103 | |
| 104 | from __future__ import print_function |
| 105 | |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 106 | import fnmatch |
Jose Galmes | 9c8f6eb | 2021-07-21 09:34:08 -0700 | [diff] [blame] | 107 | import glob |
Daniel Norman | d335156 | 2020-10-29 12:33:11 -0700 | [diff] [blame] | 108 | import json |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 109 | import logging |
| 110 | import os |
Bill Peckham | 19c3feb | 2020-03-20 18:31:43 -0700 | [diff] [blame] | 111 | import re |
Daniel Norman | fdb3881 | 2019-04-15 09:47:24 -0700 | [diff] [blame] | 112 | import shutil |
Bill Peckham | 540d91a | 2019-04-25 14:18:16 -0700 | [diff] [blame] | 113 | import subprocess |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 114 | import sys |
| 115 | import zipfile |
Daniel Norman | 48603ff | 2021-02-22 15:15:24 -0800 | [diff] [blame] | 116 | from xml.etree import ElementTree |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 117 | |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 118 | import add_img_to_target_files |
Daniel Norman | e9af70a | 2021-04-15 16:39:22 -0700 | [diff] [blame] | 119 | import apex_utils |
Daniel Norman | db8cacc | 2021-04-09 15:34:43 -0700 | [diff] [blame] | 120 | import build_image |
Daniel Norman | f031825 | 2019-04-15 11:34:56 -0700 | [diff] [blame] | 121 | import build_super_image |
Yifan Hong | ade0d3f | 2019-08-21 16:37:11 -0700 | [diff] [blame] | 122 | import check_target_files_vintf |
Daniel Norman | f031825 | 2019-04-15 11:34:56 -0700 | [diff] [blame] | 123 | import common |
Daniel Norman | 1bd2a1d | 2019-04-18 12:32:18 -0700 | [diff] [blame] | 124 | import img_from_target_files |
Daniel Norman | b8d52a2 | 2020-10-26 17:55:00 -0700 | [diff] [blame] | 125 | import find_shareduid_violation |
Daniel Norman | 3b64ce1 | 2019-04-16 16:11:35 -0700 | [diff] [blame] | 126 | import ota_from_target_files |
Daniel Norman | db8cacc | 2021-04-09 15:34:43 -0700 | [diff] [blame] | 127 | import sparse_img |
| 128 | import verity_utils |
| 129 | |
| 130 | from common import AddCareMapForAbOta, ExternalError, PARTITIONS_WITH_CARE_MAP |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 131 | |
| 132 | logger = logging.getLogger(__name__) |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 133 | |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 134 | OPTIONS = common.OPTIONS |
Bill Peckham | cb84817 | 2020-04-03 12:50:47 -0700 | [diff] [blame] | 135 | # Always turn on verbose logging. |
| 136 | OPTIONS.verbose = True |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 137 | OPTIONS.framework_target_files = None |
| 138 | OPTIONS.framework_item_list = None |
| 139 | OPTIONS.framework_misc_info_keys = None |
| 140 | OPTIONS.vendor_target_files = None |
| 141 | OPTIONS.vendor_item_list = None |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 142 | OPTIONS.output_target_files = None |
Daniel Norman | fdb3881 | 2019-04-15 09:47:24 -0700 | [diff] [blame] | 143 | OPTIONS.output_dir = None |
| 144 | OPTIONS.output_item_list = None |
Daniel Norman | 3b64ce1 | 2019-04-16 16:11:35 -0700 | [diff] [blame] | 145 | OPTIONS.output_ota = None |
Daniel Norman | 1bd2a1d | 2019-04-18 12:32:18 -0700 | [diff] [blame] | 146 | OPTIONS.output_img = None |
Daniel Norman | f031825 | 2019-04-15 11:34:56 -0700 | [diff] [blame] | 147 | OPTIONS.output_super_empty = None |
Bill Peckham | e868aec | 2019-09-17 17:06:47 -0700 | [diff] [blame] | 148 | # TODO(b/132730255): Remove this option. |
Daniel Norman | a4911da | 2019-03-15 14:36:21 -0700 | [diff] [blame] | 149 | OPTIONS.rebuild_recovery = False |
Daniel Norman | b0c7591 | 2020-09-24 14:30:21 -0700 | [diff] [blame] | 150 | # TODO(b/150582573): Remove this option. |
| 151 | OPTIONS.allow_duplicate_apkapex_keys = False |
Daniel Norman | 571e182 | 2021-06-25 17:18:25 -0700 | [diff] [blame] | 152 | OPTIONS.vendor_otatools = None |
| 153 | OPTIONS.rebuild_sepolicy = False |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 154 | OPTIONS.keep_tmp = False |
Jose Galmes | 9c8f6eb | 2021-07-21 09:34:08 -0700 | [diff] [blame] | 155 | OPTIONS.framework_dexpreopt_config = None |
| 156 | OPTIONS.framework_dexpreopt_tools = None |
| 157 | OPTIONS.vendor_dexpreopt_config = None |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 158 | |
Bill Peckham | 19c3feb | 2020-03-20 18:31:43 -0700 | [diff] [blame] | 159 | # In an item list (framework or vendor), we may see entries that select whole |
| 160 | # partitions. Such an entry might look like this 'SYSTEM/*' (e.g., for the |
| 161 | # system partition). The following regex matches this and extracts the |
| 162 | # partition name. |
| 163 | |
| 164 | PARTITION_ITEM_PATTERN = re.compile(r'^([A-Z_]+)/\*$') |
| 165 | |
Bill Peckham | 5c7b034 | 2020-04-03 15:36:23 -0700 | [diff] [blame] | 166 | # In apexkeys.txt or apkcerts.txt, we will find partition tags on each entry in |
| 167 | # the file. We use these partition tags to filter the entries in those files |
| 168 | # from the two different target files packages to produce a merged apexkeys.txt |
| 169 | # or apkcerts.txt file. A partition tag (e.g., for the product partition) looks |
| 170 | # like this: 'partition="product"'. We use the group syntax grab the value of |
| 171 | # the tag. We use non-greedy matching in case there are other fields on the |
| 172 | # same line. |
Bill Peckham | 19c3feb | 2020-03-20 18:31:43 -0700 | [diff] [blame] | 173 | |
Bill Peckham | 5c7b034 | 2020-04-03 15:36:23 -0700 | [diff] [blame] | 174 | PARTITION_TAG_PATTERN = re.compile(r'partition="(.*?)"') |
Bill Peckham | 19c3feb | 2020-03-20 18:31:43 -0700 | [diff] [blame] | 175 | |
| 176 | # The sorting algorithm for apexkeys.txt and apkcerts.txt does not include the |
| 177 | # ".apex" or ".apk" suffix, so we use the following pattern to extract a key. |
| 178 | |
| 179 | MODULE_KEY_PATTERN = re.compile(r'name="(.+)\.(apex|apk)"') |
| 180 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 181 | # DEFAULT_FRAMEWORK_ITEM_LIST is a list of items to extract from the partial |
| 182 | # 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] | 183 | # output target files package exactly as they appear in the input partial |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 184 | # framework target files package. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 185 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 186 | DEFAULT_FRAMEWORK_ITEM_LIST = ( |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 187 | 'META/apkcerts.txt', |
| 188 | 'META/filesystem_config.txt', |
| 189 | 'META/root_filesystem_config.txt', |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 190 | 'META/update_engine_config.txt', |
| 191 | 'PRODUCT/*', |
| 192 | 'ROOT/*', |
| 193 | 'SYSTEM/*', |
Daniel Norman | edf1247 | 2019-05-22 10:47:08 -0700 | [diff] [blame] | 194 | ) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 195 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 196 | # 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] | 197 | # framework instance of META/misc_info.txt. The remaining keys should come |
| 198 | # from the vendor instance. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 199 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 200 | DEFAULT_FRAMEWORK_MISC_INFO_KEYS = ( |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 201 | 'avb_system_hashtree_enable', |
| 202 | 'avb_system_add_hashtree_footer_args', |
| 203 | 'avb_system_key_path', |
| 204 | 'avb_system_algorithm', |
| 205 | 'avb_system_rollback_index_location', |
| 206 | 'avb_product_hashtree_enable', |
| 207 | 'avb_product_add_hashtree_footer_args', |
Justin Yun | 6151e3f | 2019-06-25 15:58:13 +0900 | [diff] [blame] | 208 | 'avb_system_ext_hashtree_enable', |
| 209 | 'avb_system_ext_add_hashtree_footer_args', |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 210 | 'system_root_image', |
| 211 | 'root_dir', |
| 212 | 'ab_update', |
| 213 | 'default_system_dev_certificate', |
| 214 | 'system_size', |
Chris Gross | 203191b | 2020-05-30 02:39:12 +0000 | [diff] [blame] | 215 | 'building_system_image', |
| 216 | 'building_system_ext_image', |
| 217 | 'building_product_image', |
Daniel Norman | edf1247 | 2019-05-22 10:47:08 -0700 | [diff] [blame] | 218 | ) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 219 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 220 | # DEFAULT_VENDOR_ITEM_LIST is a list of items to extract from the partial |
| 221 | # vendor target files package as is, meaning these items will land in the output |
| 222 | # 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] | 223 | # files package. |
| 224 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 225 | DEFAULT_VENDOR_ITEM_LIST = ( |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 226 | 'META/boot_filesystem_config.txt', |
| 227 | 'META/otakeys.txt', |
| 228 | 'META/releasetools.py', |
| 229 | 'META/vendor_filesystem_config.txt', |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 230 | 'BOOT/*', |
| 231 | 'DATA/*', |
| 232 | 'ODM/*', |
| 233 | 'OTA/android-info.txt', |
| 234 | 'PREBUILT_IMAGES/*', |
| 235 | 'RADIO/*', |
| 236 | 'VENDOR/*', |
Daniel Norman | edf1247 | 2019-05-22 10:47:08 -0700 | [diff] [blame] | 237 | ) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 238 | |
Daniel Norman | edf1247 | 2019-05-22 10:47:08 -0700 | [diff] [blame] | 239 | # The merge config lists should not attempt to extract items from both |
| 240 | # builds for any of the following partitions. The partitions in |
| 241 | # SINGLE_BUILD_PARTITIONS should come entirely from a single build (either |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 242 | # framework or vendor, but not both). |
Daniel Norman | edf1247 | 2019-05-22 10:47:08 -0700 | [diff] [blame] | 243 | |
| 244 | SINGLE_BUILD_PARTITIONS = ( |
| 245 | 'BOOT/', |
| 246 | 'DATA/', |
| 247 | 'ODM/', |
| 248 | 'PRODUCT/', |
Justin Yun | 6151e3f | 2019-06-25 15:58:13 +0900 | [diff] [blame] | 249 | 'SYSTEM_EXT/', |
Daniel Norman | edf1247 | 2019-05-22 10:47:08 -0700 | [diff] [blame] | 250 | 'RADIO/', |
| 251 | 'RECOVERY/', |
| 252 | 'ROOT/', |
| 253 | 'SYSTEM/', |
| 254 | 'SYSTEM_OTHER/', |
| 255 | 'VENDOR/', |
Yifan Hong | cfb917a | 2020-05-07 14:58:20 -0700 | [diff] [blame] | 256 | 'VENDOR_DLKM/', |
Yifan Hong | f496f1b | 2020-07-15 16:52:59 -0700 | [diff] [blame] | 257 | 'ODM_DLKM/', |
Daniel Norman | edf1247 | 2019-05-22 10:47:08 -0700 | [diff] [blame] | 258 | ) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 259 | |
| 260 | |
Chris Gross | fabf50a | 2019-05-02 12:42:09 -0700 | [diff] [blame] | 261 | def write_sorted_data(data, path): |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 262 | """Writes the sorted contents of either a list or dict to file. |
Chris Gross | fabf50a | 2019-05-02 12:42:09 -0700 | [diff] [blame] | 263 | |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 264 | This function sorts the contents of the list or dict and then writes the |
| 265 | resulting sorted contents to a file specified by path. |
Chris Gross | fabf50a | 2019-05-02 12:42:09 -0700 | [diff] [blame] | 266 | |
| 267 | Args: |
| 268 | data: The list or dict to sort and write. |
| 269 | path: Path to the file to write the sorted values to. The file at path will |
| 270 | be overridden if it exists. |
| 271 | """ |
| 272 | with open(path, 'w') as output: |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 273 | for entry in sorted(data): |
Chris Gross | fabf50a | 2019-05-02 12:42:09 -0700 | [diff] [blame] | 274 | out_str = '{}={}\n'.format(entry, data[entry]) if isinstance( |
| 275 | data, dict) else '{}\n'.format(entry) |
| 276 | output.write(out_str) |
| 277 | |
| 278 | |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 279 | def extract_items(target_files, target_files_temp_dir, extract_item_list): |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 280 | """Extracts items from target files to temporary directory. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 281 | |
| 282 | This function extracts from the specified target files zip archive into the |
| 283 | specified temporary directory, the items specified in the extract item list. |
| 284 | |
| 285 | Args: |
| 286 | target_files: The target files zip archive from which to extract items. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 287 | target_files_temp_dir: The temporary directory where the extracted items |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 288 | will land. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 289 | extract_item_list: A list of items to extract. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 290 | """ |
| 291 | |
| 292 | logger.info('extracting from %s', target_files) |
| 293 | |
| 294 | # Filter the extract_item_list to remove any items that do not exist in the |
| 295 | # zip file. Otherwise, the extraction step will fail. |
| 296 | |
Daniel Norman | 4cc9df6 | 2019-07-18 10:11:07 -0700 | [diff] [blame] | 297 | with zipfile.ZipFile(target_files, allowZip64=True) as target_files_zipfile: |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 298 | target_files_namelist = target_files_zipfile.namelist() |
| 299 | |
| 300 | filtered_extract_item_list = [] |
| 301 | for pattern in extract_item_list: |
| 302 | matching_namelist = fnmatch.filter(target_files_namelist, pattern) |
| 303 | if not matching_namelist: |
| 304 | logger.warning('no match for %s', pattern) |
| 305 | else: |
| 306 | filtered_extract_item_list.append(pattern) |
| 307 | |
Bill Peckham | 8ff3fbd | 2019-02-22 10:57:43 -0800 | [diff] [blame] | 308 | # Extract from target_files into target_files_temp_dir the |
| 309 | # filtered_extract_item_list. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 310 | |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 311 | common.UnzipToDir(target_files, target_files_temp_dir, |
| 312 | filtered_extract_item_list) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 313 | |
| 314 | |
Daniel Norman | fdb3881 | 2019-04-15 09:47:24 -0700 | [diff] [blame] | 315 | def copy_items(from_dir, to_dir, patterns): |
| 316 | """Similar to extract_items() except uses an input dir instead of zip.""" |
| 317 | file_paths = [] |
| 318 | for dirpath, _, filenames in os.walk(from_dir): |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 319 | file_paths.extend( |
| 320 | os.path.relpath(path=os.path.join(dirpath, filename), start=from_dir) |
| 321 | for filename in filenames) |
Daniel Norman | fdb3881 | 2019-04-15 09:47:24 -0700 | [diff] [blame] | 322 | |
| 323 | filtered_file_paths = set() |
| 324 | for pattern in patterns: |
| 325 | filtered_file_paths.update(fnmatch.filter(file_paths, pattern)) |
| 326 | |
| 327 | for file_path in filtered_file_paths: |
| 328 | original_file_path = os.path.join(from_dir, file_path) |
| 329 | copied_file_path = os.path.join(to_dir, file_path) |
| 330 | copied_file_dir = os.path.dirname(copied_file_path) |
| 331 | if not os.path.exists(copied_file_dir): |
| 332 | os.makedirs(copied_file_dir) |
| 333 | if os.path.islink(original_file_path): |
| 334 | os.symlink(os.readlink(original_file_path), copied_file_path) |
| 335 | else: |
| 336 | shutil.copyfile(original_file_path, copied_file_path) |
| 337 | |
| 338 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 339 | def validate_config_lists(framework_item_list, framework_misc_info_keys, |
| 340 | vendor_item_list): |
Daniel Norman | e596452 | 2019-03-19 10:32:03 -0700 | [diff] [blame] | 341 | """Performs validations on the merge config lists. |
| 342 | |
| 343 | Args: |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 344 | 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] | 345 | target files package as is. |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 346 | 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] | 347 | instance of META/misc_info.txt. The remaining keys should come from the |
| 348 | vendor instance. |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 349 | vendor_item_list: The list of items to extract from the partial vendor |
| 350 | target files package as is. |
Daniel Norman | e596452 | 2019-03-19 10:32:03 -0700 | [diff] [blame] | 351 | |
| 352 | Returns: |
| 353 | False if a validation fails, otherwise true. |
| 354 | """ |
Daniel Norman | edf1247 | 2019-05-22 10:47:08 -0700 | [diff] [blame] | 355 | has_error = False |
| 356 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 357 | default_combined_item_set = set(DEFAULT_FRAMEWORK_ITEM_LIST) |
| 358 | default_combined_item_set.update(DEFAULT_VENDOR_ITEM_LIST) |
Daniel Norman | e596452 | 2019-03-19 10:32:03 -0700 | [diff] [blame] | 359 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 360 | combined_item_set = set(framework_item_list) |
| 361 | combined_item_set.update(vendor_item_list) |
Daniel Norman | e596452 | 2019-03-19 10:32:03 -0700 | [diff] [blame] | 362 | |
| 363 | # Check that the merge config lists are not missing any item specified |
| 364 | # by the default config lists. |
| 365 | difference = default_combined_item_set.difference(combined_item_set) |
| 366 | if difference: |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 367 | logger.error('Missing merge config items: %s', list(difference)) |
Daniel Norman | e596452 | 2019-03-19 10:32:03 -0700 | [diff] [blame] | 368 | logger.error('Please ensure missing items are in either the ' |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 369 | 'framework-item-list or vendor-item-list files provided to ' |
Daniel Norman | e596452 | 2019-03-19 10:32:03 -0700 | [diff] [blame] | 370 | 'this script.') |
Daniel Norman | edf1247 | 2019-05-22 10:47:08 -0700 | [diff] [blame] | 371 | has_error = True |
| 372 | |
Daniel Norman | dbbf5a3 | 2020-10-22 16:03:32 -0700 | [diff] [blame] | 373 | # Check that partitions only come from one input. |
Daniel Norman | edf1247 | 2019-05-22 10:47:08 -0700 | [diff] [blame] | 374 | for partition in SINGLE_BUILD_PARTITIONS: |
Daniel Norman | dbbf5a3 | 2020-10-22 16:03:32 -0700 | [diff] [blame] | 375 | image_path = 'IMAGES/{}.img'.format(partition.lower().replace('/', '')) |
| 376 | in_framework = ( |
| 377 | any(item.startswith(partition) for item in framework_item_list) or |
| 378 | image_path in framework_item_list) |
| 379 | in_vendor = ( |
| 380 | any(item.startswith(partition) for item in vendor_item_list) or |
| 381 | image_path in vendor_item_list) |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 382 | if in_framework and in_vendor: |
Daniel Norman | edf1247 | 2019-05-22 10:47:08 -0700 | [diff] [blame] | 383 | logger.error( |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 384 | 'Cannot extract items from %s for both the framework and vendor' |
Kiyoung Kim | ebe7c9c | 2019-06-25 17:09:55 +0900 | [diff] [blame] | 385 | ' builds. Please ensure only one merge config item list' |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 386 | ' includes %s.', partition, partition) |
Daniel Norman | edf1247 | 2019-05-22 10:47:08 -0700 | [diff] [blame] | 387 | has_error = True |
Daniel Norman | e596452 | 2019-03-19 10:32:03 -0700 | [diff] [blame] | 388 | |
Daniel Norman | db8cacc | 2021-04-09 15:34:43 -0700 | [diff] [blame] | 389 | if ('dynamic_partition_list' |
| 390 | in framework_misc_info_keys) or ('super_partition_groups' |
| 391 | in framework_misc_info_keys): |
Daniel Norman | 19b9fe9 | 2019-03-19 14:48:02 -0700 | [diff] [blame] | 392 | logger.error('Dynamic partition misc info keys should come from ' |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 393 | 'the vendor instance of META/misc_info.txt.') |
Daniel Norman | edf1247 | 2019-05-22 10:47:08 -0700 | [diff] [blame] | 394 | has_error = True |
Daniel Norman | 19b9fe9 | 2019-03-19 14:48:02 -0700 | [diff] [blame] | 395 | |
Daniel Norman | edf1247 | 2019-05-22 10:47:08 -0700 | [diff] [blame] | 396 | return not has_error |
Daniel Norman | e596452 | 2019-03-19 10:32:03 -0700 | [diff] [blame] | 397 | |
| 398 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 399 | def process_ab_partitions_txt(framework_target_files_temp_dir, |
| 400 | vendor_target_files_temp_dir, |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 401 | output_target_files_temp_dir): |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 402 | """Performs special processing for META/ab_partitions.txt. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 403 | |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 404 | This function merges the contents of the META/ab_partitions.txt files from the |
| 405 | framework directory and the vendor directory, placing the merged result in the |
| 406 | output directory. The precondition in that the files are already extracted. |
| 407 | 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] | 408 | merged content. The format for each ab_partitions.txt is one partition name |
| 409 | per line. The output file contains the union of the partition names. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 410 | |
| 411 | Args: |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 412 | framework_target_files_temp_dir: The name of a directory containing the |
| 413 | special items extracted from the framework target files package. |
| 414 | vendor_target_files_temp_dir: The name of a directory containing the special |
| 415 | items extracted from the vendor target files package. |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 416 | output_target_files_temp_dir: The name of a directory that will be used to |
| 417 | create the output target files package after all the special cases are |
| 418 | processed. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 419 | """ |
| 420 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 421 | framework_ab_partitions_txt = os.path.join(framework_target_files_temp_dir, |
| 422 | 'META', 'ab_partitions.txt') |
| 423 | |
| 424 | 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] | 425 | 'ab_partitions.txt') |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 426 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 427 | with open(framework_ab_partitions_txt) as f: |
| 428 | framework_ab_partitions = f.read().splitlines() |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 429 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 430 | with open(vendor_ab_partitions_txt) as f: |
| 431 | vendor_ab_partitions = f.read().splitlines() |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 432 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 433 | output_ab_partitions = set(framework_ab_partitions + vendor_ab_partitions) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 434 | |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 435 | output_ab_partitions_txt = os.path.join(output_target_files_temp_dir, 'META', |
| 436 | 'ab_partitions.txt') |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 437 | |
Chris Gross | fabf50a | 2019-05-02 12:42:09 -0700 | [diff] [blame] | 438 | write_sorted_data(data=output_ab_partitions, path=output_ab_partitions_txt) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 439 | |
| 440 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 441 | def process_misc_info_txt(framework_target_files_temp_dir, |
| 442 | vendor_target_files_temp_dir, |
| 443 | output_target_files_temp_dir, |
| 444 | framework_misc_info_keys): |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 445 | """Performs special processing for META/misc_info.txt. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 446 | |
| 447 | 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] | 448 | framework directory and the vendor directory, placing the merged result in the |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 449 | output directory. The precondition in that the files are already extracted. |
| 450 | The post condition is that the output META/misc_info.txt contains the merged |
| 451 | content. |
| 452 | |
| 453 | Args: |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 454 | framework_target_files_temp_dir: The name of a directory containing the |
| 455 | special items extracted from the framework target files package. |
| 456 | vendor_target_files_temp_dir: The name of a directory containing the special |
| 457 | items extracted from the vendor target files package. |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 458 | output_target_files_temp_dir: The name of a directory that will be used to |
| 459 | create the output target files package after all the special cases are |
| 460 | processed. |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 461 | 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] | 462 | instance of META/misc_info.txt. The remaining keys should come from the |
| 463 | vendor instance. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 464 | """ |
| 465 | |
Kiyoung Kim | ebe7c9c | 2019-06-25 17:09:55 +0900 | [diff] [blame] | 466 | misc_info_path = ['META', 'misc_info.txt'] |
| 467 | framework_dict = common.LoadDictionaryFromFile( |
| 468 | os.path.join(framework_target_files_temp_dir, *misc_info_path)) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 469 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 470 | # We take most of the misc info from the vendor target files. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 471 | |
Kiyoung Kim | ebe7c9c | 2019-06-25 17:09:55 +0900 | [diff] [blame] | 472 | merged_dict = common.LoadDictionaryFromFile( |
| 473 | os.path.join(vendor_target_files_temp_dir, *misc_info_path)) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 474 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 475 | # Replace certain values in merged_dict with values from |
| 476 | # framework_dict. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 477 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 478 | for key in framework_misc_info_keys: |
| 479 | merged_dict[key] = framework_dict[key] |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 480 | |
Daniel Norman | 19b9fe9 | 2019-03-19 14:48:02 -0700 | [diff] [blame] | 481 | # Merge misc info keys used for Dynamic Partitions. |
Daniel Norman | db8cacc | 2021-04-09 15:34:43 -0700 | [diff] [blame] | 482 | if (merged_dict.get('use_dynamic_partitions') |
| 483 | == 'true') and (framework_dict.get('use_dynamic_partitions') == 'true'): |
Daniel Norman | bfc51ef | 2019-07-24 14:34:54 -0700 | [diff] [blame] | 484 | merged_dynamic_partitions_dict = common.MergeDynamicPartitionInfoDicts( |
Daniel Norman | 5541714 | 2019-11-25 16:04:36 -0800 | [diff] [blame] | 485 | framework_dict=framework_dict, vendor_dict=merged_dict) |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 486 | merged_dict.update(merged_dynamic_partitions_dict) |
Tao Bao | 48a2feb | 2019-06-28 11:00:05 -0700 | [diff] [blame] | 487 | # Ensure that add_img_to_target_files rebuilds super split images for |
| 488 | # devices that retrofit dynamic partitions. This flag may have been set to |
| 489 | # false in the partial builds to prevent duplicate building of super.img. |
Daniel Norman | 0bf940c | 2019-06-10 12:50:19 -0700 | [diff] [blame] | 490 | merged_dict['build_super_partition'] = 'true' |
Daniel Norman | 19b9fe9 | 2019-03-19 14:48:02 -0700 | [diff] [blame] | 491 | |
Daniel Norman | 38888d3 | 2020-11-19 14:51:15 -0800 | [diff] [blame] | 492 | # If AVB is enabled then ensure that we build vbmeta.img. |
| 493 | # Partial builds with AVB enabled may set PRODUCT_BUILD_VBMETA_IMAGE=false to |
| 494 | # skip building an incomplete vbmeta.img. |
| 495 | if merged_dict.get('avb_enable') == 'true': |
| 496 | merged_dict['avb_building_vbmeta_image'] = 'true' |
| 497 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 498 | # Replace <image>_selinux_fc values with framework or vendor file_contexts.bin |
Daniel Norman | 72c626f | 2019-05-13 15:58:14 -0700 | [diff] [blame] | 499 | # depending on which dictionary the key came from. |
| 500 | # Only the file basename is required because all selinux_fc properties are |
| 501 | # replaced with the full path to the file under META/ when misc_info.txt is |
| 502 | # loaded from target files for repacking. See common.py LoadInfoDict(). |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 503 | for key in merged_dict: |
Daniel Norman | 72c626f | 2019-05-13 15:58:14 -0700 | [diff] [blame] | 504 | if key.endswith('_selinux_fc'): |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 505 | merged_dict[key] = 'vendor_file_contexts.bin' |
| 506 | for key in framework_dict: |
Daniel Norman | 72c626f | 2019-05-13 15:58:14 -0700 | [diff] [blame] | 507 | if key.endswith('_selinux_fc'): |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 508 | merged_dict[key] = 'framework_file_contexts.bin' |
Daniel Norman | 72c626f | 2019-05-13 15:58:14 -0700 | [diff] [blame] | 509 | |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 510 | output_misc_info_txt = os.path.join(output_target_files_temp_dir, 'META', |
| 511 | 'misc_info.txt') |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 512 | write_sorted_data(data=merged_dict, path=output_misc_info_txt) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 513 | |
| 514 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 515 | def process_dynamic_partitions_info_txt(framework_target_files_dir, |
| 516 | vendor_target_files_dir, |
Daniel Norman | a61cde0 | 2019-05-03 14:19:13 -0700 | [diff] [blame] | 517 | output_target_files_dir): |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 518 | """Performs special processing for META/dynamic_partitions_info.txt. |
Daniel Norman | a61cde0 | 2019-05-03 14:19:13 -0700 | [diff] [blame] | 519 | |
| 520 | This function merges the contents of the META/dynamic_partitions_info.txt |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 521 | files from the framework directory and the vendor directory, placing the |
| 522 | merged result in the output directory. |
Daniel Norman | a61cde0 | 2019-05-03 14:19:13 -0700 | [diff] [blame] | 523 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 524 | 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] | 525 | directory does not exist. |
| 526 | |
| 527 | Args: |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 528 | framework_target_files_dir: The name of a directory containing the special |
| 529 | items extracted from the framework target files package. |
| 530 | vendor_target_files_dir: The name of a directory containing the special |
| 531 | items extracted from the vendor target files package. |
Daniel Norman | a61cde0 | 2019-05-03 14:19:13 -0700 | [diff] [blame] | 532 | output_target_files_dir: The name of a directory that will be used to create |
| 533 | the output target files package after all the special cases are processed. |
| 534 | """ |
| 535 | |
| 536 | if not os.path.exists( |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 537 | os.path.join(vendor_target_files_dir, 'META', |
Daniel Norman | a61cde0 | 2019-05-03 14:19:13 -0700 | [diff] [blame] | 538 | 'dynamic_partitions_info.txt')): |
| 539 | return |
| 540 | |
Kiyoung Kim | ebe7c9c | 2019-06-25 17:09:55 +0900 | [diff] [blame] | 541 | dynamic_partitions_info_path = ['META', 'dynamic_partitions_info.txt'] |
Daniel Norman | a61cde0 | 2019-05-03 14:19:13 -0700 | [diff] [blame] | 542 | |
Kiyoung Kim | ebe7c9c | 2019-06-25 17:09:55 +0900 | [diff] [blame] | 543 | framework_dynamic_partitions_dict = common.LoadDictionaryFromFile( |
| 544 | os.path.join(framework_target_files_dir, *dynamic_partitions_info_path)) |
| 545 | vendor_dynamic_partitions_dict = common.LoadDictionaryFromFile( |
| 546 | os.path.join(vendor_target_files_dir, *dynamic_partitions_info_path)) |
Daniel Norman | a61cde0 | 2019-05-03 14:19:13 -0700 | [diff] [blame] | 547 | |
Daniel Norman | bfc51ef | 2019-07-24 14:34:54 -0700 | [diff] [blame] | 548 | merged_dynamic_partitions_dict = common.MergeDynamicPartitionInfoDicts( |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 549 | framework_dict=framework_dynamic_partitions_dict, |
Daniel Norman | 5541714 | 2019-11-25 16:04:36 -0800 | [diff] [blame] | 550 | vendor_dict=vendor_dynamic_partitions_dict) |
Daniel Norman | a61cde0 | 2019-05-03 14:19:13 -0700 | [diff] [blame] | 551 | |
| 552 | output_dynamic_partitions_info_txt = os.path.join( |
| 553 | output_target_files_dir, 'META', 'dynamic_partitions_info.txt') |
Chris Gross | fabf50a | 2019-05-02 12:42:09 -0700 | [diff] [blame] | 554 | write_sorted_data( |
| 555 | data=merged_dynamic_partitions_dict, |
| 556 | path=output_dynamic_partitions_info_txt) |
| 557 | |
| 558 | |
Bill Peckham | 19c3feb | 2020-03-20 18:31:43 -0700 | [diff] [blame] | 559 | def item_list_to_partition_set(item_list): |
| 560 | """Converts a target files item list to a partition set. |
| 561 | |
| 562 | The item list contains items that might look like 'SYSTEM/*' or 'VENDOR/*' or |
| 563 | 'OTA/android-info.txt'. Items that end in '/*' are assumed to match entire |
| 564 | directories where 'SYSTEM' or 'VENDOR' is a directory name that identifies the |
| 565 | contents of a partition of the same name. Other items in the list, such as the |
| 566 | 'OTA' example contain metadata. This function iterates such a list, returning |
| 567 | a set that contains the partition entries. |
| 568 | |
| 569 | Args: |
| 570 | item_list: A list of items in a target files package. |
Daniel Norman | b0c7591 | 2020-09-24 14:30:21 -0700 | [diff] [blame] | 571 | |
Bill Peckham | 19c3feb | 2020-03-20 18:31:43 -0700 | [diff] [blame] | 572 | Returns: |
| 573 | A set of partitions extracted from the list of items. |
| 574 | """ |
| 575 | |
| 576 | partition_set = set() |
| 577 | |
| 578 | for item in item_list: |
| 579 | match = PARTITION_ITEM_PATTERN.search(item.strip()) |
| 580 | partition_tag = match.group(1).lower() if match else None |
| 581 | |
| 582 | if partition_tag: |
| 583 | partition_set.add(partition_tag) |
| 584 | |
| 585 | return partition_set |
| 586 | |
| 587 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 588 | def process_apex_keys_apk_certs_common(framework_target_files_dir, |
| 589 | vendor_target_files_dir, |
Bill Peckham | 19c3feb | 2020-03-20 18:31:43 -0700 | [diff] [blame] | 590 | output_target_files_dir, |
| 591 | framework_partition_set, |
| 592 | vendor_partition_set, file_name): |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 593 | """Performs special processing for META/apexkeys.txt or META/apkcerts.txt. |
Chris Gross | fabf50a | 2019-05-02 12:42:09 -0700 | [diff] [blame] | 594 | |
| 595 | This function merges the contents of the META/apexkeys.txt or |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 596 | META/apkcerts.txt files from the framework directory and the vendor directory, |
| 597 | placing the merged result in the output directory. The precondition in that |
| 598 | the files are already extracted. The post condition is that the output |
| 599 | META/apexkeys.txt or META/apkcerts.txt contains the merged content. |
Chris Gross | fabf50a | 2019-05-02 12:42:09 -0700 | [diff] [blame] | 600 | |
| 601 | Args: |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 602 | framework_target_files_dir: The name of a directory containing the special |
| 603 | items extracted from the framework target files package. |
| 604 | vendor_target_files_dir: The name of a directory containing the special |
| 605 | items extracted from the vendor target files package. |
Chris Gross | fabf50a | 2019-05-02 12:42:09 -0700 | [diff] [blame] | 606 | output_target_files_dir: The name of a directory that will be used to create |
| 607 | the output target files package after all the special cases are processed. |
Bill Peckham | 19c3feb | 2020-03-20 18:31:43 -0700 | [diff] [blame] | 608 | framework_partition_set: Partitions that are considered framework |
| 609 | partitions. Used to filter apexkeys.txt and apkcerts.txt. |
| 610 | vendor_partition_set: Partitions that are considered vendor partitions. Used |
| 611 | to filter apexkeys.txt and apkcerts.txt. |
Chris Gross | fabf50a | 2019-05-02 12:42:09 -0700 | [diff] [blame] | 612 | file_name: The name of the file to merge. One of apkcerts.txt or |
| 613 | apexkeys.txt. |
| 614 | """ |
| 615 | |
| 616 | def read_helper(d): |
| 617 | temp = {} |
| 618 | file_path = os.path.join(d, 'META', file_name) |
| 619 | with open(file_path) as f: |
| 620 | for line in f: |
| 621 | if line.strip(): |
Bill Peckham | 19c3feb | 2020-03-20 18:31:43 -0700 | [diff] [blame] | 622 | name = line.split()[0] |
| 623 | match = MODULE_KEY_PATTERN.search(name) |
| 624 | temp[match.group(1)] = line.strip() |
Chris Gross | fabf50a | 2019-05-02 12:42:09 -0700 | [diff] [blame] | 625 | return temp |
| 626 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 627 | framework_dict = read_helper(framework_target_files_dir) |
| 628 | vendor_dict = read_helper(vendor_target_files_dir) |
Bill Peckham | 19c3feb | 2020-03-20 18:31:43 -0700 | [diff] [blame] | 629 | merged_dict = {} |
Chris Gross | fabf50a | 2019-05-02 12:42:09 -0700 | [diff] [blame] | 630 | |
Bill Peckham | 19c3feb | 2020-03-20 18:31:43 -0700 | [diff] [blame] | 631 | def filter_into_merged_dict(item_dict, partition_set): |
| 632 | for key, value in item_dict.items(): |
| 633 | match = PARTITION_TAG_PATTERN.search(value) |
| 634 | |
| 635 | if match is None: |
| 636 | raise ValueError('Entry missing partition tag: %s' % value) |
| 637 | |
| 638 | partition_tag = match.group(1) |
| 639 | |
| 640 | if partition_tag in partition_set: |
| 641 | if key in merged_dict: |
Daniel Norman | b0c7591 | 2020-09-24 14:30:21 -0700 | [diff] [blame] | 642 | if OPTIONS.allow_duplicate_apkapex_keys: |
| 643 | # TODO(b/150582573) Always raise on duplicates. |
| 644 | logger.warning('Duplicate key %s' % key) |
| 645 | continue |
| 646 | else: |
| 647 | raise ValueError('Duplicate key %s' % key) |
Bill Peckham | 19c3feb | 2020-03-20 18:31:43 -0700 | [diff] [blame] | 648 | |
| 649 | merged_dict[key] = value |
| 650 | |
| 651 | filter_into_merged_dict(framework_dict, framework_partition_set) |
| 652 | filter_into_merged_dict(vendor_dict, vendor_partition_set) |
Chris Gross | fabf50a | 2019-05-02 12:42:09 -0700 | [diff] [blame] | 653 | |
| 654 | output_file = os.path.join(output_target_files_dir, 'META', file_name) |
| 655 | |
Bill Peckham | 19c3feb | 2020-03-20 18:31:43 -0700 | [diff] [blame] | 656 | # The following code is similar to write_sorted_data, but different enough |
| 657 | # that we couldn't use that function. We need the output to be sorted by the |
| 658 | # basename of the apex/apk (without the ".apex" or ".apk" suffix). This |
| 659 | # allows the sort to be consistent with the framework/vendor input data and |
| 660 | # eases comparison of input data with merged data. |
| 661 | with open(output_file, 'w') as output: |
| 662 | for key in sorted(merged_dict.keys()): |
| 663 | out_str = merged_dict[key] + '\n' |
| 664 | output.write(out_str) |
Daniel Norman | a61cde0 | 2019-05-03 14:19:13 -0700 | [diff] [blame] | 665 | |
| 666 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 667 | def copy_file_contexts(framework_target_files_dir, vendor_target_files_dir, |
Daniel Norman | 72c626f | 2019-05-13 15:58:14 -0700 | [diff] [blame] | 668 | output_target_files_dir): |
| 669 | """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] | 670 | framework_fc_path = os.path.join(framework_target_files_dir, 'META', |
| 671 | 'framework_file_contexts.bin') |
| 672 | if not os.path.exists(framework_fc_path): |
| 673 | framework_fc_path = os.path.join(framework_target_files_dir, 'META', |
| 674 | 'file_contexts.bin') |
| 675 | if not os.path.exists(framework_fc_path): |
| 676 | raise ValueError('Missing framework file_contexts.bin.') |
| 677 | shutil.copyfile( |
| 678 | framework_fc_path, |
| 679 | os.path.join(output_target_files_dir, 'META', |
| 680 | 'framework_file_contexts.bin')) |
| 681 | |
| 682 | vendor_fc_path = os.path.join(vendor_target_files_dir, 'META', |
| 683 | 'vendor_file_contexts.bin') |
| 684 | if not os.path.exists(vendor_fc_path): |
| 685 | vendor_fc_path = os.path.join(vendor_target_files_dir, 'META', |
Daniel Norman | edf1247 | 2019-05-22 10:47:08 -0700 | [diff] [blame] | 686 | 'file_contexts.bin') |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 687 | if not os.path.exists(vendor_fc_path): |
| 688 | raise ValueError('Missing vendor file_contexts.bin.') |
Daniel Norman | 72c626f | 2019-05-13 15:58:14 -0700 | [diff] [blame] | 689 | shutil.copyfile( |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 690 | vendor_fc_path, |
| 691 | os.path.join(output_target_files_dir, 'META', 'vendor_file_contexts.bin')) |
Daniel Norman | 72c626f | 2019-05-13 15:58:14 -0700 | [diff] [blame] | 692 | |
| 693 | |
Daniel Norman | 571e182 | 2021-06-25 17:18:25 -0700 | [diff] [blame] | 694 | def compile_split_sepolicy(product_out, partition_map): |
Daniel Norman | 48603ff | 2021-02-22 15:15:24 -0800 | [diff] [blame] | 695 | """Uses secilc to compile a split sepolicy file. |
| 696 | |
| 697 | Depends on various */etc/selinux/* and */etc/vintf/* files within partitions. |
| 698 | |
| 699 | Args: |
| 700 | product_out: PRODUCT_OUT directory, containing partition directories. |
| 701 | partition_map: A map of partition name -> relative path within product_out. |
Daniel Norman | 48603ff | 2021-02-22 15:15:24 -0800 | [diff] [blame] | 702 | |
| 703 | Returns: |
| 704 | A command list that can be executed to create the compiled sepolicy. |
| 705 | """ |
| 706 | |
| 707 | def get_file(partition, path): |
| 708 | if partition not in partition_map: |
| 709 | logger.warning('Cannot load SEPolicy files for missing partition %s', |
| 710 | partition) |
| 711 | return None |
| 712 | return os.path.join(product_out, partition_map[partition], path) |
| 713 | |
| 714 | # Load the kernel sepolicy version from the FCM. This is normally provided |
| 715 | # directly to selinux.cpp as a build flag, but is also available in this file. |
| 716 | fcm_file = get_file('system', 'etc/vintf/compatibility_matrix.device.xml') |
| 717 | if not fcm_file or not os.path.exists(fcm_file): |
| 718 | raise ExternalError('Missing required file for loading sepolicy: %s', fcm) |
| 719 | kernel_sepolicy_version = ElementTree.parse(fcm_file).getroot().find( |
| 720 | 'sepolicy/kernel-sepolicy-version').text |
| 721 | |
| 722 | # Load the vendor's plat sepolicy version. This is the version used for |
| 723 | # locating sepolicy mapping files. |
| 724 | vendor_plat_version_file = get_file('vendor', |
| 725 | 'etc/selinux/plat_sepolicy_vers.txt') |
| 726 | if not vendor_plat_version_file or not os.path.exists( |
Daniel Norman | 2d7989a | 2021-04-05 17:40:47 +0000 | [diff] [blame] | 727 | vendor_plat_version_file): |
Daniel Norman | 48603ff | 2021-02-22 15:15:24 -0800 | [diff] [blame] | 728 | raise ExternalError('Missing required sepolicy file %s', |
| 729 | vendor_plat_version_file) |
| 730 | with open(vendor_plat_version_file) as f: |
| 731 | vendor_plat_version = f.read().strip() |
| 732 | |
| 733 | # Use the same flags and arguments as selinux.cpp OpenSplitPolicy(). |
| 734 | cmd = ['secilc', '-m', '-M', 'true', '-G', '-N'] |
| 735 | cmd.extend(['-c', kernel_sepolicy_version]) |
Daniel Norman | 571e182 | 2021-06-25 17:18:25 -0700 | [diff] [blame] | 736 | cmd.extend(['-o', os.path.join(product_out, 'META/combined_sepolicy')]) |
Daniel Norman | 48603ff | 2021-02-22 15:15:24 -0800 | [diff] [blame] | 737 | cmd.extend(['-f', '/dev/null']) |
| 738 | |
| 739 | required_policy_files = ( |
| 740 | ('system', 'etc/selinux/plat_sepolicy.cil'), |
| 741 | ('system', 'etc/selinux/mapping/%s.cil' % vendor_plat_version), |
| 742 | ('vendor', 'etc/selinux/vendor_sepolicy.cil'), |
| 743 | ('vendor', 'etc/selinux/plat_pub_versioned.cil'), |
| 744 | ) |
| 745 | for policy in (map(lambda partition_and_path: get_file(*partition_and_path), |
| 746 | required_policy_files)): |
| 747 | if not policy or not os.path.exists(policy): |
| 748 | raise ExternalError('Missing required sepolicy file %s', policy) |
| 749 | cmd.append(policy) |
| 750 | |
| 751 | optional_policy_files = ( |
| 752 | ('system', 'etc/selinux/mapping/%s.compat.cil' % vendor_plat_version), |
| 753 | ('system_ext', 'etc/selinux/system_ext_sepolicy.cil'), |
| 754 | ('system_ext', 'etc/selinux/mapping/%s.cil' % vendor_plat_version), |
| 755 | ('product', 'etc/selinux/product_sepolicy.cil'), |
| 756 | ('product', 'etc/selinux/mapping/%s.cil' % vendor_plat_version), |
| 757 | ('odm', 'etc/selinux/odm_sepolicy.cil'), |
| 758 | ) |
| 759 | for policy in (map(lambda partition_and_path: get_file(*partition_and_path), |
| 760 | optional_policy_files)): |
| 761 | if policy and os.path.exists(policy): |
| 762 | cmd.append(policy) |
| 763 | |
| 764 | return cmd |
| 765 | |
| 766 | |
Daniel Norman | e9af70a | 2021-04-15 16:39:22 -0700 | [diff] [blame] | 767 | def validate_merged_apex_info(output_target_files_dir, partitions): |
| 768 | """Validates the APEX files in the merged target files directory. |
| 769 | |
| 770 | Checks the APEX files in all possible preinstalled APEX directories. |
| 771 | Depends on the <partition>/apex/* APEX files within partitions. |
| 772 | |
| 773 | Args: |
Daniel Norman | 571e182 | 2021-06-25 17:18:25 -0700 | [diff] [blame] | 774 | output_target_files_dir: Output directory containing merged partition |
| 775 | directories. |
Daniel Norman | e9af70a | 2021-04-15 16:39:22 -0700 | [diff] [blame] | 776 | partitions: A list of all the partitions in the output directory. |
| 777 | |
| 778 | Raises: |
| 779 | RuntimeError: if apex_utils fails to parse any APEX file. |
| 780 | ExternalError: if the same APEX package is provided by multiple partitions. |
| 781 | """ |
| 782 | apex_packages = set() |
| 783 | |
| 784 | apex_partitions = ('system', 'system_ext', 'product', 'vendor') |
| 785 | for partition in filter(lambda p: p in apex_partitions, partitions): |
| 786 | apex_info = apex_utils.GetApexInfoFromTargetFiles( |
| 787 | output_target_files_dir, partition, compressed_only=False) |
| 788 | partition_apex_packages = set([info.package_name for info in apex_info]) |
| 789 | duplicates = apex_packages.intersection(partition_apex_packages) |
| 790 | if duplicates: |
| 791 | raise ExternalError( |
| 792 | 'Duplicate APEX packages found in multiple partitions: %s' % |
| 793 | ' '.join(duplicates)) |
| 794 | apex_packages.update(partition_apex_packages) |
| 795 | |
| 796 | |
Daniel Norman | db8cacc | 2021-04-09 15:34:43 -0700 | [diff] [blame] | 797 | def generate_care_map(partitions, output_target_files_dir): |
| 798 | """Generates a merged META/care_map.pb file in the output target files dir. |
| 799 | |
| 800 | Depends on the info dict from META/misc_info.txt, as well as built images |
| 801 | within IMAGES/. |
| 802 | |
| 803 | Args: |
| 804 | partitions: A list of partitions to potentially include in the care map. |
| 805 | output_target_files_dir: The name of a directory that will be used to create |
| 806 | the output target files package after all the special cases are processed. |
| 807 | """ |
| 808 | OPTIONS.info_dict = common.LoadInfoDict(output_target_files_dir) |
| 809 | partition_image_map = {} |
| 810 | for partition in partitions: |
| 811 | image_path = os.path.join(output_target_files_dir, 'IMAGES', |
| 812 | '{}.img'.format(partition)) |
| 813 | if os.path.exists(image_path): |
| 814 | partition_image_map[partition] = image_path |
| 815 | # Regenerated images should have their image_size property already set. |
| 816 | image_size_prop = '{}_image_size'.format(partition) |
| 817 | if image_size_prop not in OPTIONS.info_dict: |
| 818 | # Images copied directly from input target files packages will need |
| 819 | # their image sizes calculated. |
| 820 | partition_size = sparse_img.GetImagePartitionSize(image_path) |
| 821 | image_props = build_image.ImagePropFromGlobalDict( |
| 822 | OPTIONS.info_dict, partition) |
| 823 | verity_image_builder = verity_utils.CreateVerityImageBuilder( |
| 824 | image_props) |
| 825 | image_size = verity_image_builder.CalculateMaxImageSize(partition_size) |
| 826 | OPTIONS.info_dict[image_size_prop] = image_size |
| 827 | |
| 828 | AddCareMapForAbOta( |
| 829 | os.path.join(output_target_files_dir, 'META', 'care_map.pb'), |
| 830 | PARTITIONS_WITH_CARE_MAP, partition_image_map) |
| 831 | |
| 832 | |
Jose Galmes | 9c8f6eb | 2021-07-21 09:34:08 -0700 | [diff] [blame] | 833 | def process_special_cases(temp_dir, framework_meta, vendor_meta, |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 834 | output_target_files_temp_dir, |
Daniel Norman | b0c7591 | 2020-09-24 14:30:21 -0700 | [diff] [blame] | 835 | framework_misc_info_keys, framework_partition_set, |
Jose Galmes | 9c8f6eb | 2021-07-21 09:34:08 -0700 | [diff] [blame] | 836 | vendor_partition_set, framework_dexpreopt_tools, |
| 837 | framework_dexpreopt_config, vendor_dexpreopt_config): |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 838 | """Performs special-case processing for certain target files items. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 839 | |
| 840 | Certain files in the output target files package require special-case |
| 841 | processing. This function performs all that special-case processing. |
| 842 | |
| 843 | Args: |
Jose Galmes | 9c8f6eb | 2021-07-21 09:34:08 -0700 | [diff] [blame] | 844 | temp_dir: Location containing an 'output' directory where target files have |
| 845 | been extracted, e.g. <temp_dir>/output/SYSTEM, <temp_dir>/output/IMAGES, etc. |
| 846 | framework_meta: The name of a directory containing the special items |
| 847 | extracted from the framework target files package. |
| 848 | vendor_meta: The name of a directory containing the special items |
| 849 | extracted from the vendor target files package. |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 850 | output_target_files_temp_dir: The name of a directory that will be used to |
| 851 | create the output target files package after all the special cases are |
| 852 | processed. |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 853 | 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] | 854 | instance of META/misc_info.txt. The remaining keys should come from the |
| 855 | vendor instance. |
Bill Peckham | 19c3feb | 2020-03-20 18:31:43 -0700 | [diff] [blame] | 856 | framework_partition_set: Partitions that are considered framework |
| 857 | partitions. Used to filter apexkeys.txt and apkcerts.txt. |
| 858 | vendor_partition_set: Partitions that are considered vendor partitions. Used |
| 859 | to filter apexkeys.txt and apkcerts.txt. |
Jose Galmes | 9c8f6eb | 2021-07-21 09:34:08 -0700 | [diff] [blame] | 860 | |
| 861 | The following are only used if dexpreopt is applied: |
| 862 | |
| 863 | framework_dexpreopt_tools: Location of dexpreopt_tools.zip. |
| 864 | framework_dexpreopt_config: Location of framework's dexpreopt_config.zip. |
| 865 | vendor_dexpreopt_config: Location of vendor's dexpreopt_config.zip. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 866 | """ |
| 867 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 868 | if 'ab_update' in framework_misc_info_keys: |
Bill Peckham | 364c1cc | 2019-03-29 18:27:23 -0700 | [diff] [blame] | 869 | process_ab_partitions_txt( |
Jose Galmes | 9c8f6eb | 2021-07-21 09:34:08 -0700 | [diff] [blame] | 870 | framework_target_files_temp_dir=framework_meta, |
| 871 | vendor_target_files_temp_dir=vendor_meta, |
Bill Peckham | 364c1cc | 2019-03-29 18:27:23 -0700 | [diff] [blame] | 872 | output_target_files_temp_dir=output_target_files_temp_dir) |
| 873 | |
Daniel Norman | 72c626f | 2019-05-13 15:58:14 -0700 | [diff] [blame] | 874 | copy_file_contexts( |
Jose Galmes | 9c8f6eb | 2021-07-21 09:34:08 -0700 | [diff] [blame] | 875 | framework_target_files_dir=framework_meta, |
| 876 | vendor_target_files_dir=vendor_meta, |
Daniel Norman | 72c626f | 2019-05-13 15:58:14 -0700 | [diff] [blame] | 877 | output_target_files_dir=output_target_files_temp_dir) |
| 878 | |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 879 | process_misc_info_txt( |
Jose Galmes | 9c8f6eb | 2021-07-21 09:34:08 -0700 | [diff] [blame] | 880 | framework_target_files_temp_dir=framework_meta, |
| 881 | vendor_target_files_temp_dir=vendor_meta, |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 882 | output_target_files_temp_dir=output_target_files_temp_dir, |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 883 | framework_misc_info_keys=framework_misc_info_keys) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 884 | |
Daniel Norman | a61cde0 | 2019-05-03 14:19:13 -0700 | [diff] [blame] | 885 | process_dynamic_partitions_info_txt( |
Jose Galmes | 9c8f6eb | 2021-07-21 09:34:08 -0700 | [diff] [blame] | 886 | framework_target_files_dir=framework_meta, |
| 887 | vendor_target_files_dir=vendor_meta, |
Daniel Norman | 714bd12 | 2019-05-08 16:20:02 -0700 | [diff] [blame] | 888 | output_target_files_dir=output_target_files_temp_dir) |
Daniel Norman | a61cde0 | 2019-05-03 14:19:13 -0700 | [diff] [blame] | 889 | |
Chris Gross | fabf50a | 2019-05-02 12:42:09 -0700 | [diff] [blame] | 890 | process_apex_keys_apk_certs_common( |
Jose Galmes | 9c8f6eb | 2021-07-21 09:34:08 -0700 | [diff] [blame] | 891 | framework_target_files_dir=framework_meta, |
| 892 | vendor_target_files_dir=vendor_meta, |
Chris Gross | fabf50a | 2019-05-02 12:42:09 -0700 | [diff] [blame] | 893 | output_target_files_dir=output_target_files_temp_dir, |
Bill Peckham | 19c3feb | 2020-03-20 18:31:43 -0700 | [diff] [blame] | 894 | framework_partition_set=framework_partition_set, |
| 895 | vendor_partition_set=vendor_partition_set, |
Chris Gross | fabf50a | 2019-05-02 12:42:09 -0700 | [diff] [blame] | 896 | file_name='apkcerts.txt') |
| 897 | |
| 898 | process_apex_keys_apk_certs_common( |
Jose Galmes | 9c8f6eb | 2021-07-21 09:34:08 -0700 | [diff] [blame] | 899 | framework_target_files_dir=framework_meta, |
| 900 | vendor_target_files_dir=vendor_meta, |
Chris Gross | fabf50a | 2019-05-02 12:42:09 -0700 | [diff] [blame] | 901 | output_target_files_dir=output_target_files_temp_dir, |
Bill Peckham | 19c3feb | 2020-03-20 18:31:43 -0700 | [diff] [blame] | 902 | framework_partition_set=framework_partition_set, |
| 903 | vendor_partition_set=vendor_partition_set, |
Chris Gross | fabf50a | 2019-05-02 12:42:09 -0700 | [diff] [blame] | 904 | file_name='apexkeys.txt') |
| 905 | |
Jose Galmes | 9c8f6eb | 2021-07-21 09:34:08 -0700 | [diff] [blame] | 906 | process_dexopt( |
| 907 | temp_dir=temp_dir, |
| 908 | framework_meta=framework_meta, |
| 909 | vendor_meta=vendor_meta, |
| 910 | output_target_files_temp_dir=output_target_files_temp_dir, |
| 911 | framework_dexpreopt_tools=framework_dexpreopt_tools, |
| 912 | framework_dexpreopt_config=framework_dexpreopt_config, |
| 913 | vendor_dexpreopt_config=vendor_dexpreopt_config) |
| 914 | |
| 915 | |
| 916 | def process_dexopt(temp_dir, framework_meta, vendor_meta, |
| 917 | output_target_files_temp_dir, |
| 918 | framework_dexpreopt_tools, framework_dexpreopt_config, |
| 919 | vendor_dexpreopt_config): |
| 920 | """If needed, generates dexopt files for vendor apps. |
| 921 | |
| 922 | Args: |
| 923 | temp_dir: Location containing an 'output' directory where target files have |
| 924 | been extracted, e.g. <temp_dir>/output/SYSTEM, <temp_dir>/output/IMAGES, etc. |
| 925 | framework_meta: The name of a directory containing the special items |
| 926 | extracted from the framework target files package. |
| 927 | vendor_meta: The name of a directory containing the special items extracted |
| 928 | from the vendor target files package. |
| 929 | output_target_files_temp_dir: The name of a directory that will be used to |
| 930 | create the output target files package after all the special cases are |
| 931 | processed. |
| 932 | framework_dexpreopt_tools: Location of dexpreopt_tools.zip. |
| 933 | framework_dexpreopt_config: Location of framework's dexpreopt_config.zip. |
| 934 | vendor_dexpreopt_config: Location of vendor's dexpreopt_config.zip. |
| 935 | """ |
| 936 | # Load vendor and framework META/misc_info.txt. |
| 937 | misc_info_path = ['META', 'misc_info.txt'] |
| 938 | vendor_misc_info_dict = common.LoadDictionaryFromFile( |
| 939 | os.path.join(vendor_meta, *misc_info_path)) |
| 940 | |
| 941 | if (vendor_misc_info_dict.get('building_with_vsdk') != 'true' or |
| 942 | framework_dexpreopt_tools is None or |
| 943 | framework_dexpreopt_config is None or |
| 944 | vendor_dexpreopt_config is None): |
| 945 | return |
| 946 | |
| 947 | logger.info('applying dexpreopt') |
| 948 | |
| 949 | # The directory structure to apply dexpreopt is: |
| 950 | # |
| 951 | # <temp_dir>/ |
| 952 | # framework_meta/ |
| 953 | # META/ |
| 954 | # vendor_meta/ |
| 955 | # META/ |
| 956 | # output/ |
| 957 | # SYSTEM/ |
| 958 | # VENDOR/ |
| 959 | # IMAGES/ |
| 960 | # <other items extracted from system and vendor target files> |
| 961 | # tools/ |
| 962 | # <contents of dexpreopt_tools.zip> |
| 963 | # system_config/ |
| 964 | # <contents of system dexpreopt_config.zip> |
| 965 | # vendor_config/ |
| 966 | # <contents of vendor dexpreopt_config.zip> |
| 967 | # system -> output/SYSTEM |
| 968 | # vendor -> output/VENDOR |
| 969 | # apex -> output/SYSTEM/apex (only for flattened APEX builds) |
| 970 | # apex/ (extracted updatable APEX) |
| 971 | # <apex 1>/ |
| 972 | # ... |
| 973 | # <apex 2>/ |
| 974 | # ... |
| 975 | # ... |
| 976 | # out/dex2oat_result/vendor/ |
| 977 | # <app> |
| 978 | # oat/arm64/ |
| 979 | # package.vdex |
| 980 | # package.odex |
| 981 | # <priv-app> |
| 982 | # oat/arm64/ |
| 983 | # package.vdex |
| 984 | # package.odex |
| 985 | dexpreopt_tools_files_temp_dir = os.path.join(temp_dir, 'tools') |
| 986 | dexpreopt_framework_config_files_temp_dir = os.path.join(temp_dir, 'system_config') |
| 987 | dexpreopt_vendor_config_files_temp_dir = os.path.join(temp_dir, 'vendor_config') |
| 988 | |
| 989 | extract_items( |
| 990 | target_files=OPTIONS.framework_dexpreopt_tools, |
| 991 | target_files_temp_dir=dexpreopt_tools_files_temp_dir, |
| 992 | extract_item_list=('*',)) |
| 993 | extract_items( |
| 994 | target_files=OPTIONS.framework_dexpreopt_config, |
| 995 | target_files_temp_dir=dexpreopt_framework_config_files_temp_dir, |
| 996 | extract_item_list=('*',)) |
| 997 | extract_items( |
| 998 | target_files=OPTIONS.vendor_dexpreopt_config, |
| 999 | target_files_temp_dir=dexpreopt_vendor_config_files_temp_dir, |
| 1000 | extract_item_list=('*',)) |
| 1001 | |
| 1002 | os.symlink(os.path.join(output_target_files_temp_dir, "SYSTEM"), |
| 1003 | os.path.join(temp_dir, "system")) |
| 1004 | os.symlink(os.path.join(output_target_files_temp_dir, "VENDOR"), |
| 1005 | os.path.join(temp_dir, "vendor")) |
| 1006 | |
| 1007 | # The directory structure for flatteded APEXes is: |
| 1008 | # |
| 1009 | # SYSTEM |
| 1010 | # apex |
| 1011 | # <APEX name, e.g., com.android.wifi> |
| 1012 | # apex_manifest.pb |
| 1013 | # apex_pubkey |
| 1014 | # etc/ |
| 1015 | # javalib/ |
| 1016 | # lib/ |
| 1017 | # lib64/ |
| 1018 | # priv-app/ |
| 1019 | # |
| 1020 | # The directory structure for updatable APEXes is: |
| 1021 | # |
| 1022 | # SYSTEM |
| 1023 | # apex |
| 1024 | # com.android.adbd.apex |
| 1025 | # com.android.appsearch.apex |
| 1026 | # com.android.art.apex |
| 1027 | # ... |
| 1028 | apex_root = os.path.join(output_target_files_temp_dir, "SYSTEM", "apex") |
| 1029 | framework_misc_info_dict = common.LoadDictionaryFromFile( |
| 1030 | os.path.join(framework_meta, *misc_info_path)) |
| 1031 | |
| 1032 | # Check for flattended versus updatable APEX. |
| 1033 | if framework_misc_info_dict.get('target_flatten_apex') == 'false': |
| 1034 | # Extract APEX. |
| 1035 | logging.info('extracting APEX') |
| 1036 | |
| 1037 | apex_extract_root_dir = os.path.join(temp_dir, 'apex') |
| 1038 | os.makedirs(apex_extract_root_dir) |
| 1039 | |
| 1040 | for apex in (glob.glob(os.path.join(apex_root, '*.apex')) + |
| 1041 | glob.glob(os.path.join(apex_root, '*.capex'))): |
| 1042 | logging.info(' apex: %s', apex) |
| 1043 | # deapexer is in the same directory as the merge_target_files binary extracted |
| 1044 | # from otatools.zip. |
| 1045 | apex_json_info = subprocess.check_output(['deapexer', 'info', apex]) |
| 1046 | logging.info(' info: %s', apex_json_info) |
| 1047 | apex_info = json.loads(apex_json_info) |
| 1048 | apex_name = apex_info['name'] |
| 1049 | logging.info(' name: %s', apex_name) |
| 1050 | |
| 1051 | apex_extract_dir = os.path.join(apex_extract_root_dir, apex_name) |
| 1052 | os.makedirs(apex_extract_dir) |
| 1053 | |
| 1054 | # deapexer uses debugfs_static, which is part of otatools.zip. |
| 1055 | command = [ |
| 1056 | 'deapexer', |
| 1057 | '--debugfs_path', |
| 1058 | 'debugfs_static', |
| 1059 | 'extract', |
| 1060 | apex, |
| 1061 | apex_extract_dir, |
| 1062 | ] |
| 1063 | logging.info(' running %s', command) |
| 1064 | subprocess.check_call(command) |
| 1065 | else: |
| 1066 | # Flattened APEXes don't need to be extracted since they have the necessary |
| 1067 | # directory structure. |
| 1068 | os.symlink(os.path.join(apex_root), os.path.join(temp_dir, 'apex')) |
| 1069 | |
| 1070 | # Modify system config to point to the tools that have been extracted. |
| 1071 | # Absolute or .. paths are not allowed by the dexpreopt_gen tool in |
| 1072 | # dexpreopt_soong.config. |
| 1073 | dexpreopt_framework_soon_config = os.path.join( |
| 1074 | dexpreopt_framework_config_files_temp_dir, 'dexpreopt_soong.config') |
| 1075 | with open(dexpreopt_framework_soon_config, 'w') as f: |
| 1076 | dexpreopt_soong_config = { |
| 1077 | 'Profman': 'tools/profman', |
| 1078 | 'Dex2oat': 'tools/dex2oatd', |
| 1079 | 'Aapt': 'tools/aapt2', |
| 1080 | 'SoongZip': 'tools/soong_zip', |
| 1081 | 'Zip2zip': 'tools/zip2zip', |
| 1082 | 'ManifestCheck': 'tools/manifest_check', |
| 1083 | 'ConstructContext': 'tools/construct_context', |
| 1084 | } |
| 1085 | json.dump(dexpreopt_soong_config, f) |
| 1086 | |
| 1087 | # TODO(b/188179859): Make *dex location configurable to vendor or system_other. |
| 1088 | use_system_other_odex = False |
| 1089 | |
| 1090 | if use_system_other_odex: |
| 1091 | dex_img = 'SYSTEM_OTHER' |
| 1092 | else: |
| 1093 | dex_img = 'VENDOR' |
| 1094 | # Open vendor_filesystem_config to append the items generated by dexopt. |
| 1095 | vendor_file_system_config = open( |
| 1096 | os.path.join(temp_dir, 'output', 'META', 'vendor_filesystem_config.txt'), |
| 1097 | 'a') |
| 1098 | |
| 1099 | # Dexpreopt vendor apps. |
| 1100 | dexpreopt_config_suffix = '_dexpreopt.config' |
| 1101 | for config in glob.glob(os.path.join( |
| 1102 | dexpreopt_vendor_config_files_temp_dir, '*' + dexpreopt_config_suffix)): |
| 1103 | app = os.path.basename(config)[:-len(dexpreopt_config_suffix)] |
| 1104 | logging.info('dexpreopt config: %s %s', config, app) |
| 1105 | |
| 1106 | apk_dir = 'app' |
| 1107 | apk_path = os.path.join(temp_dir, 'vendor', apk_dir, app, app + '.apk') |
| 1108 | if not os.path.exists(apk_path): |
| 1109 | apk_dir = 'priv-app' |
| 1110 | apk_path = os.path.join(temp_dir, 'vendor', apk_dir, app, app + '.apk') |
| 1111 | if not os.path.exists(apk_path): |
| 1112 | logging.warning('skipping dexpreopt for %s, no apk found in vendor/app ' |
| 1113 | 'or vendor/priv-app', app) |
| 1114 | continue |
| 1115 | |
| 1116 | # Generate dexpreopting script. Note 'out_dir' is not the output directory |
| 1117 | # where the script is generated, but the OUT_DIR at build time referenced |
| 1118 | # in the dexpreot config files, e.g., "out/.../core-oj.jar", so the tool knows |
| 1119 | # how to adjust the path. |
| 1120 | command = [ |
| 1121 | os.path.join(dexpreopt_tools_files_temp_dir, 'dexpreopt_gen'), |
| 1122 | '-global', |
| 1123 | os.path.join(dexpreopt_framework_config_files_temp_dir, 'dexpreopt.config'), |
| 1124 | '-global_soong', |
| 1125 | os.path.join( |
| 1126 | dexpreopt_framework_config_files_temp_dir, 'dexpreopt_soong.config'), |
| 1127 | '-module', |
| 1128 | config, |
| 1129 | '-dexpreopt_script', |
| 1130 | 'dexpreopt_app.sh', |
| 1131 | '-out_dir', |
| 1132 | 'out', |
| 1133 | '-base_path', |
| 1134 | '.', |
| 1135 | '--uses_target_files', |
| 1136 | ] |
| 1137 | |
| 1138 | # Run the command from temp_dir so all tool paths are its descendants. |
| 1139 | logging.info("running %s", command) |
| 1140 | subprocess.check_call(command, cwd = temp_dir) |
| 1141 | |
| 1142 | # Call the generated script. |
| 1143 | command = ['sh', 'dexpreopt_app.sh', apk_path] |
| 1144 | logging.info("running %s", command) |
| 1145 | subprocess.check_call(command, cwd = temp_dir) |
| 1146 | |
| 1147 | # Output files are in: |
| 1148 | # |
| 1149 | # <temp_dir>/out/dex2oat_result/vendor/priv-app/<app>/oat/arm64/package.vdex |
| 1150 | # <temp_dir>/out/dex2oat_result/vendor/priv-app/<app>/oat/arm64/package.odex |
| 1151 | # <temp_dir>/out/dex2oat_result/vendor/app/<app>/oat/arm64/package.vdex |
| 1152 | # <temp_dir>/out/dex2oat_result/vendor/app/<app>/oat/arm64/package.odex |
| 1153 | # |
| 1154 | # Copy the files to their destination. The structure of system_other is: |
| 1155 | # |
| 1156 | # system_other/ |
| 1157 | # system-other-odex-marker |
| 1158 | # system/ |
| 1159 | # app/ |
| 1160 | # <app>/oat/arm64/ |
| 1161 | # <app>.odex |
| 1162 | # <app>.vdex |
| 1163 | # ... |
| 1164 | # priv-app/ |
| 1165 | # <app>/oat/arm64/ |
| 1166 | # <app>.odex |
| 1167 | # <app>.vdex |
| 1168 | # ... |
| 1169 | |
| 1170 | # TODO(b/188179859): Support for other architectures. |
| 1171 | arch = 'arm64' |
| 1172 | |
| 1173 | dex_destination = os.path.join(temp_dir, 'output', dex_img, apk_dir, app, 'oat', arch) |
| 1174 | os.makedirs(dex_destination) |
| 1175 | dex2oat_path = os.path.join( |
| 1176 | temp_dir, 'out', 'dex2oat_result', 'vendor', apk_dir, app, 'oat', arch) |
| 1177 | shutil.copy(os.path.join(dex2oat_path, 'package.vdex'), |
| 1178 | os.path.join(dex_destination, app + '.vdex')) |
| 1179 | shutil.copy(os.path.join(dex2oat_path, 'package.odex'), |
| 1180 | os.path.join(dex_destination, app + '.odex')) |
| 1181 | |
| 1182 | # Append entries to vendor_file_system_config.txt, such as: |
| 1183 | # |
| 1184 | # vendor/app/<app>/oat 0 2000 755 selabel=u:object_r:vendor_app_file:s0 capabilities=0x0 |
| 1185 | # vendor/app/<app>/oat/arm64 0 2000 755 selabel=u:object_r:vendor_app_file:s0 capabilities=0x0 |
| 1186 | # vendor/app/<app>/oat/arm64/<app>.odex 0 0 644 selabel=u:object_r:vendor_app_file:s0 capabilities=0x0 |
| 1187 | # vendor/app/<app>/oat/arm64/<app>.vdex 0 0 644 selabel=u:object_r:vendor_app_file:s0 capabilities=0x0 |
| 1188 | if not use_system_other_odex: |
| 1189 | vendor_app_prefix = 'vendor/' + apk_dir + '/' + app + '/oat' |
| 1190 | selabel = 'selabel=u:object_r:vendor_app_file:s0 capabilities=0x0' |
| 1191 | vendor_file_system_config.writelines([ |
| 1192 | vendor_app_prefix + ' 0 2000 755 ' + selabel + '\n', |
| 1193 | vendor_app_prefix + '/' + arch + ' 0 2000 755 ' + selabel + '\n', |
| 1194 | vendor_app_prefix + '/' + arch + '/' + app + '.odex 0 0 644 ' + selabel + '\n', |
| 1195 | vendor_app_prefix + '/' + arch + '/' + app + '.vdex 0 0 644 ' + selabel + '\n', |
| 1196 | ]) |
| 1197 | |
| 1198 | if not use_system_other_odex: |
| 1199 | vendor_file_system_config.close() |
| 1200 | # Delete vendor.img so that it will be regenerated. |
| 1201 | # TODO(b/188179859): Rebuilding a vendor image in GRF mode (e.g., T(framework) |
| 1202 | # and S(vendor) may require logic similar to that in |
| 1203 | # rebuild_image_with_sepolicy. |
| 1204 | vendor_img = os.path.join(output_target_files_temp_dir, 'IMAGES', 'vendor.img') |
| 1205 | if os.path.exists(vendor_img): |
| 1206 | logging.info('Deleting %s', vendor_img) |
| 1207 | os.remove(vendor_img) |
| 1208 | |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1209 | |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 1210 | def create_merged_package(temp_dir, framework_target_files, framework_item_list, |
| 1211 | vendor_target_files, vendor_item_list, |
Jose Galmes | 9c8f6eb | 2021-07-21 09:34:08 -0700 | [diff] [blame] | 1212 | framework_misc_info_keys, rebuild_recovery, |
| 1213 | framework_dexpreopt_tools, framework_dexpreopt_config, |
| 1214 | vendor_dexpreopt_config): |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 1215 | """Merges two target files packages into one target files structure. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1216 | |
| 1217 | Args: |
| 1218 | 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] | 1219 | input target files packages, and also a scratch directory that we use for |
| 1220 | temporary files. |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1221 | framework_target_files: The name of the zip archive containing the framework |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 1222 | partial target files package. |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1223 | 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] | 1224 | 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] | 1225 | target files package exactly as they appear in the input partial framework |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 1226 | target files package. |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1227 | vendor_target_files: The name of the zip archive containing the vendor |
| 1228 | partial target files package. |
| 1229 | vendor_item_list: The list of items to extract from the partial vendor |
| 1230 | target files package as is, meaning these items will land in the output |
| 1231 | target files package exactly as they appear in the input partial vendor |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 1232 | target files package. |
Daniel Norman | dbbf5a3 | 2020-10-22 16:03:32 -0700 | [diff] [blame] | 1233 | framework_misc_info_keys: A list of keys to obtain from the framework |
| 1234 | instance of META/misc_info.txt. The remaining keys should come from the |
| 1235 | vendor instance. |
Daniel Norman | a4911da | 2019-03-15 14:36:21 -0700 | [diff] [blame] | 1236 | 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] | 1237 | devices and write it to the system image. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1238 | |
Jose Galmes | 9c8f6eb | 2021-07-21 09:34:08 -0700 | [diff] [blame] | 1239 | The following are only used if dexpreopt is applied: |
| 1240 | |
| 1241 | framework_dexpreopt_tools: Location of dexpreopt_tools.zip. |
| 1242 | framework_dexpreopt_config: Location of framework's dexpreopt_config.zip. |
| 1243 | vendor_dexpreopt_config: Location of vendor's dexpreopt_config.zip. |
| 1244 | |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 1245 | Returns: |
| 1246 | Path to merged package under temp directory. |
| 1247 | """ |
Daniel Norman | dbbf5a3 | 2020-10-22 16:03:32 -0700 | [diff] [blame] | 1248 | # Extract "as is" items from the input framework and vendor partial target |
| 1249 | # files packages directly into the output temporary directory, since these items |
| 1250 | # do not need special case processing. |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 1251 | |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1252 | output_target_files_temp_dir = os.path.join(temp_dir, 'output') |
Bill Peckham | 889b0c6 | 2019-02-21 18:53:37 -0800 | [diff] [blame] | 1253 | extract_items( |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1254 | target_files=framework_target_files, |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1255 | target_files_temp_dir=output_target_files_temp_dir, |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1256 | extract_item_list=framework_item_list) |
Bill Peckham | 889b0c6 | 2019-02-21 18:53:37 -0800 | [diff] [blame] | 1257 | extract_items( |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1258 | target_files=vendor_target_files, |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1259 | target_files_temp_dir=output_target_files_temp_dir, |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1260 | extract_item_list=vendor_item_list) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1261 | |
Daniel Norman | dbbf5a3 | 2020-10-22 16:03:32 -0700 | [diff] [blame] | 1262 | # Perform special case processing on META/* items. |
| 1263 | # After this function completes successfully, all the files we need to create |
| 1264 | # the output target files package are in place. |
Jose Galmes | 9c8f6eb | 2021-07-21 09:34:08 -0700 | [diff] [blame] | 1265 | framework_meta = os.path.join(temp_dir, 'framework_meta') |
| 1266 | vendor_meta = os.path.join(temp_dir, 'vendor_meta') |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1267 | extract_items( |
| 1268 | target_files=framework_target_files, |
Jose Galmes | 9c8f6eb | 2021-07-21 09:34:08 -0700 | [diff] [blame] | 1269 | target_files_temp_dir=framework_meta, |
Daniel Norman | dbbf5a3 | 2020-10-22 16:03:32 -0700 | [diff] [blame] | 1270 | extract_item_list=('META/*',)) |
Bill Peckham | 889b0c6 | 2019-02-21 18:53:37 -0800 | [diff] [blame] | 1271 | extract_items( |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1272 | target_files=vendor_target_files, |
Jose Galmes | 9c8f6eb | 2021-07-21 09:34:08 -0700 | [diff] [blame] | 1273 | target_files_temp_dir=vendor_meta, |
Daniel Norman | dbbf5a3 | 2020-10-22 16:03:32 -0700 | [diff] [blame] | 1274 | extract_item_list=('META/*',)) |
Bill Peckham | 889b0c6 | 2019-02-21 18:53:37 -0800 | [diff] [blame] | 1275 | process_special_cases( |
Jose Galmes | 9c8f6eb | 2021-07-21 09:34:08 -0700 | [diff] [blame] | 1276 | temp_dir=temp_dir, |
| 1277 | framework_meta=framework_meta, |
| 1278 | vendor_meta=vendor_meta, |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 1279 | output_target_files_temp_dir=output_target_files_temp_dir, |
Bill Peckham | 19c3feb | 2020-03-20 18:31:43 -0700 | [diff] [blame] | 1280 | framework_misc_info_keys=framework_misc_info_keys, |
| 1281 | framework_partition_set=item_list_to_partition_set(framework_item_list), |
Jose Galmes | 9c8f6eb | 2021-07-21 09:34:08 -0700 | [diff] [blame] | 1282 | vendor_partition_set=item_list_to_partition_set(vendor_item_list), |
| 1283 | framework_dexpreopt_tools=framework_dexpreopt_tools, |
| 1284 | framework_dexpreopt_config=framework_dexpreopt_config, |
| 1285 | vendor_dexpreopt_config=vendor_dexpreopt_config) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1286 | |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 1287 | return output_target_files_temp_dir |
| 1288 | |
| 1289 | |
| 1290 | def generate_images(target_files_dir, rebuild_recovery): |
| 1291 | """Generate images from target files. |
| 1292 | |
| 1293 | This function takes merged output temporary directory and create images |
| 1294 | from it. |
| 1295 | |
| 1296 | Args: |
| 1297 | target_files_dir: Path to merged temp directory. |
| 1298 | rebuild_recovery: If true, rebuild the recovery patch used by non-A/B |
| 1299 | devices and write it to the system image. |
| 1300 | """ |
| 1301 | |
| 1302 | # Regenerate IMAGES in the target directory. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1303 | |
Daniel Norman | dbbf5a3 | 2020-10-22 16:03:32 -0700 | [diff] [blame] | 1304 | add_img_args = [ |
| 1305 | '--verbose', |
| 1306 | '--add_missing', |
| 1307 | ] |
Bill Peckham | e868aec | 2019-09-17 17:06:47 -0700 | [diff] [blame] | 1308 | # TODO(b/132730255): Remove this if statement. |
Daniel Norman | a4911da | 2019-03-15 14:36:21 -0700 | [diff] [blame] | 1309 | if rebuild_recovery: |
| 1310 | add_img_args.append('--rebuild_recovery') |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 1311 | add_img_args.append(target_files_dir) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1312 | |
| 1313 | add_img_to_target_files.main(add_img_args) |
| 1314 | |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 1315 | |
Daniel Norman | 571e182 | 2021-06-25 17:18:25 -0700 | [diff] [blame] | 1316 | def rebuild_image_with_sepolicy(target_files_dir, |
| 1317 | vendor_otatools=None, |
| 1318 | vendor_target_files=None): |
| 1319 | """Rebuilds odm.img or vendor.img to include merged sepolicy files. |
| 1320 | |
| 1321 | If odm is present then odm is preferred -- otherwise vendor is used. |
| 1322 | |
| 1323 | Args: |
| 1324 | target_files_dir: Path to the extracted merged target-files package. |
| 1325 | vendor_otatools: If not None, path to an otatools.zip from the vendor build |
| 1326 | that is used when recompiling the image. |
| 1327 | vendor_target_files: Expected if vendor_otatools is not None. Path to the |
| 1328 | vendor target-files zip. |
| 1329 | """ |
| 1330 | partition = 'vendor' |
| 1331 | if os.path.exists(os.path.join(target_files_dir, 'ODM')) or os.path.exists( |
| 1332 | os.path.join(target_files_dir, 'IMAGES/odm.img')): |
| 1333 | partition = 'odm' |
| 1334 | partition_img = '{}.img'.format(partition) |
| 1335 | |
| 1336 | logger.info('Recompiling %s using the merged sepolicy files.', partition_img) |
| 1337 | |
| 1338 | # Copy the combined SEPolicy file and framework hashes to the image that is |
| 1339 | # being rebuilt. |
| 1340 | def copy_selinux_file(input_path, output_filename): |
Po Hu | 0e4403e | 2021-07-06 17:05:56 +0800 | [diff] [blame] | 1341 | input_filename = os.path.join(target_files_dir, input_path) |
| 1342 | if not os.path.exists(input_filename): |
| 1343 | input_filename = input_filename.replace('SYSTEM_EXT/', 'SYSTEM/system_ext/') \ |
| 1344 | .replace('PRODUCT/', 'SYSTEM/product/') |
| 1345 | if not os.path.exists(input_filename): |
| 1346 | logger.info('Skipping copy_selinux_file for %s', input_filename) |
| 1347 | return |
Daniel Norman | 571e182 | 2021-06-25 17:18:25 -0700 | [diff] [blame] | 1348 | shutil.copy( |
Po Hu | 0e4403e | 2021-07-06 17:05:56 +0800 | [diff] [blame] | 1349 | input_filename, |
Daniel Norman | 571e182 | 2021-06-25 17:18:25 -0700 | [diff] [blame] | 1350 | os.path.join(target_files_dir, partition.upper(), 'etc/selinux', |
| 1351 | output_filename)) |
| 1352 | |
| 1353 | copy_selinux_file('META/combined_sepolicy', 'precompiled_sepolicy') |
| 1354 | copy_selinux_file('SYSTEM/etc/selinux/plat_sepolicy_and_mapping.sha256', |
| 1355 | 'precompiled_sepolicy.plat_sepolicy_and_mapping.sha256') |
| 1356 | copy_selinux_file( |
| 1357 | 'SYSTEM_EXT/etc/selinux/system_ext_sepolicy_and_mapping.sha256', |
| 1358 | 'precompiled_sepolicy.system_ext_sepolicy_and_mapping.sha256') |
| 1359 | copy_selinux_file('PRODUCT/etc/selinux/product_sepolicy_and_mapping.sha256', |
| 1360 | 'precompiled_sepolicy.product_sepolicy_and_mapping.sha256') |
| 1361 | |
| 1362 | if not vendor_otatools: |
| 1363 | # Remove the partition from the merged target-files archive. It will be |
| 1364 | # rebuilt later automatically by generate_images(). |
| 1365 | os.remove(os.path.join(target_files_dir, 'IMAGES', partition_img)) |
| 1366 | else: |
| 1367 | # TODO(b/192253131): Remove the need for vendor_otatools by fixing |
| 1368 | # backwards-compatibility issues when compiling images on R from S+. |
| 1369 | if not vendor_target_files: |
| 1370 | raise ValueError( |
| 1371 | 'Expected vendor_target_files if vendor_otatools is not None.') |
| 1372 | logger.info( |
| 1373 | '%s recompilation will be performed using the vendor otatools.zip', |
| 1374 | partition_img) |
| 1375 | |
| 1376 | # Unzip the vendor build's otatools.zip and target-files archive. |
| 1377 | vendor_otatools_dir = common.MakeTempDir( |
| 1378 | prefix='merge_target_files_vendor_otatools_') |
| 1379 | vendor_target_files_dir = common.MakeTempDir( |
| 1380 | prefix='merge_target_files_vendor_target_files_') |
| 1381 | common.UnzipToDir(vendor_otatools, vendor_otatools_dir) |
| 1382 | common.UnzipToDir(vendor_target_files, vendor_target_files_dir) |
| 1383 | |
| 1384 | # Copy the partition contents from the merged target-files archive to the |
| 1385 | # vendor target-files archive. |
| 1386 | shutil.rmtree(os.path.join(vendor_target_files_dir, partition.upper())) |
| 1387 | shutil.copytree( |
| 1388 | os.path.join(target_files_dir, partition.upper()), |
Po Hu | 0e4403e | 2021-07-06 17:05:56 +0800 | [diff] [blame] | 1389 | os.path.join(vendor_target_files_dir, partition.upper()), |
| 1390 | symlinks=True) |
Daniel Norman | 571e182 | 2021-06-25 17:18:25 -0700 | [diff] [blame] | 1391 | |
| 1392 | # Delete then rebuild the partition. |
| 1393 | os.remove(os.path.join(vendor_target_files_dir, 'IMAGES', partition_img)) |
| 1394 | rebuild_partition_command = [ |
| 1395 | os.path.join(vendor_otatools_dir, 'bin', 'add_img_to_target_files'), |
| 1396 | '--verbose', |
| 1397 | '--add_missing', |
| 1398 | vendor_target_files_dir, |
| 1399 | ] |
| 1400 | logger.info('Recompiling %s: %s', partition_img, |
| 1401 | ' '.join(rebuild_partition_command)) |
| 1402 | common.RunAndCheckOutput(rebuild_partition_command, verbose=True) |
| 1403 | |
| 1404 | # Move the newly-created image to the merged target files dir. |
Po Hu | 0e4403e | 2021-07-06 17:05:56 +0800 | [diff] [blame] | 1405 | if not os.path.exists(os.path.join(target_files_dir, 'IMAGES')): |
| 1406 | os.makedirs(os.path.join(target_files_dir, 'IMAGES')) |
Daniel Norman | 571e182 | 2021-06-25 17:18:25 -0700 | [diff] [blame] | 1407 | shutil.move( |
| 1408 | os.path.join(vendor_target_files_dir, 'IMAGES', partition_img), |
| 1409 | os.path.join(target_files_dir, 'IMAGES', partition_img)) |
| 1410 | |
| 1411 | |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 1412 | def generate_super_empty_image(target_dir, output_super_empty): |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 1413 | """Generates super_empty image from target package. |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 1414 | |
| 1415 | Args: |
| 1416 | target_dir: Path to the target file package which contains misc_info.txt for |
| 1417 | detailed information for super image. |
| 1418 | output_super_empty: If provided, copies a super_empty.img file from the |
| 1419 | target files package to this path. |
| 1420 | """ |
Daniel Norman | 1bd2a1d | 2019-04-18 12:32:18 -0700 | [diff] [blame] | 1421 | # Create super_empty.img using the merged misc_info.txt. |
| 1422 | |
Daniel Norman | 4cc9df6 | 2019-07-18 10:11:07 -0700 | [diff] [blame] | 1423 | misc_info_txt = os.path.join(target_dir, 'META', 'misc_info.txt') |
Daniel Norman | 1bd2a1d | 2019-04-18 12:32:18 -0700 | [diff] [blame] | 1424 | |
Kiyoung Kim | ebe7c9c | 2019-06-25 17:09:55 +0900 | [diff] [blame] | 1425 | use_dynamic_partitions = common.LoadDictionaryFromFile(misc_info_txt).get( |
| 1426 | 'use_dynamic_partitions') |
Daniel Norman | 1bd2a1d | 2019-04-18 12:32:18 -0700 | [diff] [blame] | 1427 | |
| 1428 | if use_dynamic_partitions != 'true' and output_super_empty: |
| 1429 | raise ValueError( |
| 1430 | 'Building super_empty.img requires use_dynamic_partitions=true.') |
| 1431 | elif use_dynamic_partitions == 'true': |
Daniel Norman | 4cc9df6 | 2019-07-18 10:11:07 -0700 | [diff] [blame] | 1432 | super_empty_img = os.path.join(target_dir, 'IMAGES', 'super_empty.img') |
Daniel Norman | 1bd2a1d | 2019-04-18 12:32:18 -0700 | [diff] [blame] | 1433 | build_super_image_args = [ |
| 1434 | misc_info_txt, |
| 1435 | super_empty_img, |
| 1436 | ] |
| 1437 | build_super_image.main(build_super_image_args) |
| 1438 | |
| 1439 | # Copy super_empty.img to the user-provided output_super_empty location. |
| 1440 | if output_super_empty: |
| 1441 | shutil.copyfile(super_empty_img, output_super_empty) |
| 1442 | |
Daniel Norman | b8a2f9d | 2019-04-24 12:55:51 -0700 | [diff] [blame] | 1443 | |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 1444 | def create_target_files_archive(output_file, source_dir, temp_dir): |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 1445 | """Creates archive from target package. |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 1446 | |
| 1447 | Args: |
| 1448 | output_file: The name of the zip archive target files package. |
| 1449 | source_dir: The target directory contains package to be archived. |
| 1450 | temp_dir: Path to temporary directory for any intermediate files. |
| 1451 | """ |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1452 | output_target_files_list = os.path.join(temp_dir, 'output.list') |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 1453 | output_zip = os.path.abspath(output_file) |
Daniel Norman | 4cc9df6 | 2019-07-18 10:11:07 -0700 | [diff] [blame] | 1454 | output_target_files_meta_dir = os.path.join(source_dir, 'META') |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1455 | |
Daniel Norman | dbbf5a3 | 2020-10-22 16:03:32 -0700 | [diff] [blame] | 1456 | def files_from_path(target_path, extra_args=None): |
| 1457 | """Gets files under the given path and return a sorted list.""" |
| 1458 | find_command = ['find', target_path] + (extra_args or []) |
| 1459 | find_process = common.Run( |
| 1460 | find_command, stdout=subprocess.PIPE, verbose=False) |
| 1461 | return common.RunAndCheckOutput(['sort'], |
| 1462 | stdin=find_process.stdout, |
| 1463 | verbose=False) |
| 1464 | |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 1465 | meta_content = files_from_path(output_target_files_meta_dir) |
Daniel Norman | 4cc9df6 | 2019-07-18 10:11:07 -0700 | [diff] [blame] | 1466 | other_content = files_from_path( |
| 1467 | source_dir, |
| 1468 | ['-path', output_target_files_meta_dir, '-prune', '-o', '-print']) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1469 | |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 1470 | with open(output_target_files_list, 'w') as f: |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1471 | f.write(meta_content) |
| 1472 | f.write(other_content) |
| 1473 | |
| 1474 | command = [ |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 1475 | 'soong_zip', |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1476 | '-d', |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 1477 | '-o', |
| 1478 | output_zip, |
| 1479 | '-C', |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 1480 | source_dir, |
Daniel Norman | eaf5c1d | 2021-02-09 11:01:42 -0800 | [diff] [blame] | 1481 | '-r', |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 1482 | output_target_files_list, |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1483 | ] |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 1484 | |
| 1485 | logger.info('creating %s', output_file) |
Daniel Norman | eaf5c1d | 2021-02-09 11:01:42 -0800 | [diff] [blame] | 1486 | common.RunAndCheckOutput(command, verbose=True) |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 1487 | logger.info('finished creating %s', output_file) |
| 1488 | |
| 1489 | return output_zip |
| 1490 | |
| 1491 | |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 1492 | def merge_target_files(temp_dir, framework_target_files, framework_item_list, |
| 1493 | framework_misc_info_keys, vendor_target_files, |
| 1494 | vendor_item_list, output_target_files, output_dir, |
| 1495 | output_item_list, output_ota, output_img, |
Daniel Norman | 571e182 | 2021-06-25 17:18:25 -0700 | [diff] [blame] | 1496 | output_super_empty, rebuild_recovery, vendor_otatools, |
Jose Galmes | 9c8f6eb | 2021-07-21 09:34:08 -0700 | [diff] [blame] | 1497 | rebuild_sepolicy, framework_dexpreopt_tools, |
| 1498 | framework_dexpreopt_config, vendor_dexpreopt_config): |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 1499 | """Merges two target files packages together. |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 1500 | |
| 1501 | This function takes framework and vendor target files packages as input, |
| 1502 | performs various file extractions, special case processing, and finally |
| 1503 | creates a merged zip archive as output. |
| 1504 | |
| 1505 | Args: |
| 1506 | temp_dir: The name of a directory we use when we extract items from the |
| 1507 | input target files packages, and also a scratch directory that we use for |
| 1508 | temporary files. |
| 1509 | framework_target_files: The name of the zip archive containing the framework |
| 1510 | partial target files package. |
| 1511 | framework_item_list: The list of items to extract from the partial framework |
| 1512 | target files package as is, meaning these items will land in the output |
| 1513 | target files package exactly as they appear in the input partial framework |
| 1514 | target files package. |
Daniel Norman | dbbf5a3 | 2020-10-22 16:03:32 -0700 | [diff] [blame] | 1515 | framework_misc_info_keys: A list of keys to obtain from the framework |
| 1516 | instance of META/misc_info.txt. The remaining keys should come from the |
| 1517 | vendor instance. |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 1518 | vendor_target_files: The name of the zip archive containing the vendor |
| 1519 | partial target files package. |
| 1520 | vendor_item_list: The list of items to extract from the partial vendor |
| 1521 | target files package as is, meaning these items will land in the output |
| 1522 | target files package exactly as they appear in the input partial vendor |
| 1523 | target files package. |
| 1524 | output_target_files: The name of the output zip archive target files package |
| 1525 | created by merging framework and vendor. |
| 1526 | output_dir: The destination directory for saving merged files. |
| 1527 | output_item_list: The list of items to copy into the output_dir. |
| 1528 | output_ota: The name of the output zip archive ota package. |
| 1529 | output_img: The name of the output zip archive img package. |
| 1530 | output_super_empty: If provided, creates a super_empty.img file from the |
| 1531 | merged target files package and saves it at this path. |
| 1532 | rebuild_recovery: If true, rebuild the recovery patch used by non-A/B |
| 1533 | devices and write it to the system image. |
Daniel Norman | 571e182 | 2021-06-25 17:18:25 -0700 | [diff] [blame] | 1534 | vendor_otatools: Path to an otatools zip used for recompiling vendor images. |
| 1535 | rebuild_sepolicy: If true, rebuild odm.img (if target uses ODM) or |
| 1536 | vendor.img using a merged precompiled_sepolicy file. |
Jose Galmes | 9c8f6eb | 2021-07-21 09:34:08 -0700 | [diff] [blame] | 1537 | |
| 1538 | The following are only used if dexpreopt is applied: |
| 1539 | |
| 1540 | framework_dexpreopt_tools: Location of dexpreopt_tools.zip. |
| 1541 | framework_dexpreopt_config: Location of framework's dexpreopt_config.zip. |
| 1542 | vendor_dexpreopt_config: Location of vendor's dexpreopt_config.zip. |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 1543 | """ |
| 1544 | |
| 1545 | logger.info('starting: merge framework %s and vendor %s into output %s', |
| 1546 | framework_target_files, vendor_target_files, output_target_files) |
| 1547 | |
| 1548 | output_target_files_temp_dir = create_merged_package( |
| 1549 | temp_dir, framework_target_files, framework_item_list, |
| 1550 | vendor_target_files, vendor_item_list, framework_misc_info_keys, |
Jose Galmes | 9c8f6eb | 2021-07-21 09:34:08 -0700 | [diff] [blame] | 1551 | rebuild_recovery, framework_dexpreopt_tools, framework_dexpreopt_config, |
| 1552 | vendor_dexpreopt_config) |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 1553 | |
Yifan Hong | ade0d3f | 2019-08-21 16:37:11 -0700 | [diff] [blame] | 1554 | if not check_target_files_vintf.CheckVintf(output_target_files_temp_dir): |
Daniel Norman | b0c7591 | 2020-09-24 14:30:21 -0700 | [diff] [blame] | 1555 | raise RuntimeError('Incompatible VINTF metadata') |
Yifan Hong | ade0d3f | 2019-08-21 16:37:11 -0700 | [diff] [blame] | 1556 | |
Daniel Norman | 21c34f7 | 2020-11-11 17:25:50 -0800 | [diff] [blame] | 1557 | partition_map = common.PartitionMapFromTargetFiles( |
| 1558 | output_target_files_temp_dir) |
| 1559 | |
Daniel Norman | d335156 | 2020-10-29 12:33:11 -0700 | [diff] [blame] | 1560 | # Generate and check for cross-partition violations of sharedUserId |
| 1561 | # values in APKs. This requires the input target-files packages to contain |
| 1562 | # *.apk files. |
Daniel Norman | b8d52a2 | 2020-10-26 17:55:00 -0700 | [diff] [blame] | 1563 | shareduid_violation_modules = os.path.join( |
| 1564 | output_target_files_temp_dir, 'META', 'shareduid_violation_modules.json') |
| 1565 | with open(shareduid_violation_modules, 'w') as f: |
Daniel Norman | b8d52a2 | 2020-10-26 17:55:00 -0700 | [diff] [blame] | 1566 | violation = find_shareduid_violation.FindShareduidViolation( |
| 1567 | output_target_files_temp_dir, partition_map) |
Daniel Norman | d335156 | 2020-10-29 12:33:11 -0700 | [diff] [blame] | 1568 | |
| 1569 | # Write the output to a file to enable debugging. |
Daniel Norman | b8d52a2 | 2020-10-26 17:55:00 -0700 | [diff] [blame] | 1570 | f.write(violation) |
Daniel Norman | d335156 | 2020-10-29 12:33:11 -0700 | [diff] [blame] | 1571 | |
| 1572 | # Check for violations across the input builds' partition groups. |
Daniel Norman | 21c34f7 | 2020-11-11 17:25:50 -0800 | [diff] [blame] | 1573 | framework_partitions = item_list_to_partition_set(framework_item_list) |
| 1574 | vendor_partitions = item_list_to_partition_set(vendor_item_list) |
Daniel Norman | d335156 | 2020-10-29 12:33:11 -0700 | [diff] [blame] | 1575 | shareduid_errors = common.SharedUidPartitionViolations( |
| 1576 | json.loads(violation), [framework_partitions, vendor_partitions]) |
| 1577 | if shareduid_errors: |
| 1578 | for error in shareduid_errors: |
| 1579 | logger.error(error) |
| 1580 | raise ValueError('sharedUserId APK error. See %s' % |
| 1581 | shareduid_violation_modules) |
Daniel Norman | b8d52a2 | 2020-10-26 17:55:00 -0700 | [diff] [blame] | 1582 | |
Daniel Norman | 48603ff | 2021-02-22 15:15:24 -0800 | [diff] [blame] | 1583 | # host_init_verifier and secilc check only the following partitions: |
Daniel Norman | 21c34f7 | 2020-11-11 17:25:50 -0800 | [diff] [blame] | 1584 | filtered_partitions = { |
| 1585 | partition: path |
| 1586 | for partition, path in partition_map.items() |
Daniel Norman | 21c34f7 | 2020-11-11 17:25:50 -0800 | [diff] [blame] | 1587 | if partition in ['system', 'system_ext', 'product', 'vendor', 'odm'] |
| 1588 | } |
Daniel Norman | 48603ff | 2021-02-22 15:15:24 -0800 | [diff] [blame] | 1589 | |
| 1590 | # Run host_init_verifier on the combined init rc files. |
Daniel Norman | 21c34f7 | 2020-11-11 17:25:50 -0800 | [diff] [blame] | 1591 | common.RunHostInitVerifier( |
| 1592 | product_out=output_target_files_temp_dir, |
| 1593 | partition_map=filtered_partitions) |
| 1594 | |
Daniel Norman | 48603ff | 2021-02-22 15:15:24 -0800 | [diff] [blame] | 1595 | # Check that the split sepolicy from the multiple builds can compile. |
Daniel Norman | 571e182 | 2021-06-25 17:18:25 -0700 | [diff] [blame] | 1596 | split_sepolicy_cmd = compile_split_sepolicy(output_target_files_temp_dir, |
| 1597 | filtered_partitions) |
Daniel Norman | 48603ff | 2021-02-22 15:15:24 -0800 | [diff] [blame] | 1598 | logger.info('Compiling split sepolicy: %s', ' '.join(split_sepolicy_cmd)) |
| 1599 | common.RunAndCheckOutput(split_sepolicy_cmd) |
Daniel Norman | 571e182 | 2021-06-25 17:18:25 -0700 | [diff] [blame] | 1600 | # Include the compiled policy in an image if requested. |
| 1601 | if rebuild_sepolicy: |
| 1602 | rebuild_image_with_sepolicy(output_target_files_temp_dir, vendor_otatools, |
| 1603 | vendor_target_files) |
Daniel Norman | 48603ff | 2021-02-22 15:15:24 -0800 | [diff] [blame] | 1604 | |
Daniel Norman | e9af70a | 2021-04-15 16:39:22 -0700 | [diff] [blame] | 1605 | # Run validation checks on the pre-installed APEX files. |
| 1606 | validate_merged_apex_info(output_target_files_temp_dir, partition_map.keys()) |
| 1607 | |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 1608 | generate_images(output_target_files_temp_dir, rebuild_recovery) |
| 1609 | |
| 1610 | generate_super_empty_image(output_target_files_temp_dir, output_super_empty) |
| 1611 | |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 1612 | # Finally, create the output target files zip archive and/or copy the |
| 1613 | # output items to the output target files directory. |
| 1614 | |
| 1615 | if output_dir: |
| 1616 | copy_items(output_target_files_temp_dir, output_dir, output_item_list) |
| 1617 | |
| 1618 | if not output_target_files: |
| 1619 | return |
| 1620 | |
Iavor-Valentin Iftime | b837b71 | 2022-01-27 16:29:37 +0000 | [diff] [blame] | 1621 | # Create the merged META/care_map.pb if A/B update |
| 1622 | if 'ab_update' in framework_misc_info_keys: |
| 1623 | generate_care_map(partition_map.keys(), output_target_files_temp_dir) |
Daniel Norman | db8cacc | 2021-04-09 15:34:43 -0700 | [diff] [blame] | 1624 | |
Kiyoung Kim | 7cbeda7 | 2019-06-28 13:26:04 +0900 | [diff] [blame] | 1625 | output_zip = create_target_files_archive(output_target_files, |
| 1626 | output_target_files_temp_dir, |
| 1627 | temp_dir) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1628 | |
Daniel Norman | 74eb74b | 2019-09-18 14:01:48 -0700 | [diff] [blame] | 1629 | # Create the IMG package from the merged target files package. |
Daniel Norman | 74eb74b | 2019-09-18 14:01:48 -0700 | [diff] [blame] | 1630 | if output_img: |
| 1631 | img_from_target_files.main([output_zip, output_img]) |
| 1632 | |
Daniel Norman | 3b64ce1 | 2019-04-16 16:11:35 -0700 | [diff] [blame] | 1633 | # Create the OTA package from the merged target files package. |
| 1634 | |
| 1635 | if output_ota: |
Daniel Norman | 4cc9df6 | 2019-07-18 10:11:07 -0700 | [diff] [blame] | 1636 | ota_from_target_files.main([output_zip, output_ota]) |
Daniel Norman | 3b64ce1 | 2019-04-16 16:11:35 -0700 | [diff] [blame] | 1637 | |
Daniel Norman | 1bd2a1d | 2019-04-18 12:32:18 -0700 | [diff] [blame] | 1638 | |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 1639 | def call_func_with_temp_dir(func, keep_tmp): |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 1640 | """Manages the creation and cleanup of the temporary directory. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1641 | |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 1642 | This function calls the given function after first creating a temporary |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1643 | directory. It also cleans up the temporary directory. |
| 1644 | |
| 1645 | Args: |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 1646 | func: The function to call. Should accept one parameter, the path to the |
| 1647 | temporary directory. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1648 | keep_tmp: Keep the temporary directory after processing is complete. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1649 | """ |
| 1650 | |
| 1651 | # Create a temporary directory. This will serve as the parent of directories |
| 1652 | # we use when we extract items from the input target files packages, and also |
| 1653 | # a scratch directory that we use for temporary files. |
| 1654 | |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1655 | temp_dir = common.MakeTempDir(prefix='merge_target_files_') |
| 1656 | |
| 1657 | try: |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 1658 | func(temp_dir) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1659 | finally: |
| 1660 | if keep_tmp: |
| 1661 | logger.info('keeping %s', temp_dir) |
| 1662 | else: |
| 1663 | common.Cleanup() |
| 1664 | |
| 1665 | |
| 1666 | def main(): |
| 1667 | """The main function. |
| 1668 | |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 1669 | Process command line arguments, then call merge_target_files to |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1670 | perform the heavy lifting. |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1671 | """ |
| 1672 | |
| 1673 | common.InitLogging() |
| 1674 | |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 1675 | def option_handler(o, a): |
| 1676 | if o == '--system-target-files': |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1677 | logger.warning( |
| 1678 | '--system-target-files has been renamed to --framework-target-files') |
| 1679 | OPTIONS.framework_target_files = a |
| 1680 | elif o == '--framework-target-files': |
| 1681 | OPTIONS.framework_target_files = a |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 1682 | elif o == '--system-item-list': |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1683 | logger.warning( |
| 1684 | '--system-item-list has been renamed to --framework-item-list') |
| 1685 | OPTIONS.framework_item_list = a |
| 1686 | elif o == '--framework-item-list': |
| 1687 | OPTIONS.framework_item_list = a |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 1688 | elif o == '--system-misc-info-keys': |
Daniel Norman | 4cc9df6 | 2019-07-18 10:11:07 -0700 | [diff] [blame] | 1689 | logger.warning('--system-misc-info-keys has been renamed to ' |
| 1690 | '--framework-misc-info-keys') |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1691 | OPTIONS.framework_misc_info_keys = a |
| 1692 | elif o == '--framework-misc-info-keys': |
| 1693 | OPTIONS.framework_misc_info_keys = a |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 1694 | elif o == '--other-target-files': |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1695 | logger.warning( |
| 1696 | '--other-target-files has been renamed to --vendor-target-files') |
| 1697 | OPTIONS.vendor_target_files = a |
| 1698 | elif o == '--vendor-target-files': |
| 1699 | OPTIONS.vendor_target_files = a |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 1700 | elif o == '--other-item-list': |
Daniel Norman | 2d7989a | 2021-04-05 17:40:47 +0000 | [diff] [blame] | 1701 | logger.warning('--other-item-list has been renamed to --vendor-item-list') |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1702 | OPTIONS.vendor_item_list = a |
| 1703 | elif o == '--vendor-item-list': |
| 1704 | OPTIONS.vendor_item_list = a |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 1705 | elif o == '--output-target-files': |
| 1706 | OPTIONS.output_target_files = a |
Daniel Norman | fdb3881 | 2019-04-15 09:47:24 -0700 | [diff] [blame] | 1707 | elif o == '--output-dir': |
| 1708 | OPTIONS.output_dir = a |
| 1709 | elif o == '--output-item-list': |
| 1710 | OPTIONS.output_item_list = a |
Daniel Norman | 3b64ce1 | 2019-04-16 16:11:35 -0700 | [diff] [blame] | 1711 | elif o == '--output-ota': |
| 1712 | OPTIONS.output_ota = a |
Daniel Norman | 1bd2a1d | 2019-04-18 12:32:18 -0700 | [diff] [blame] | 1713 | elif o == '--output-img': |
| 1714 | OPTIONS.output_img = a |
Daniel Norman | f031825 | 2019-04-15 11:34:56 -0700 | [diff] [blame] | 1715 | elif o == '--output-super-empty': |
| 1716 | OPTIONS.output_super_empty = a |
Daniel Norman | b0c7591 | 2020-09-24 14:30:21 -0700 | [diff] [blame] | 1717 | elif o == '--rebuild_recovery': # TODO(b/132730255): Warn |
Daniel Norman | a4911da | 2019-03-15 14:36:21 -0700 | [diff] [blame] | 1718 | OPTIONS.rebuild_recovery = True |
Daniel Norman | b0c7591 | 2020-09-24 14:30:21 -0700 | [diff] [blame] | 1719 | elif o == '--allow-duplicate-apkapex-keys': |
| 1720 | OPTIONS.allow_duplicate_apkapex_keys = True |
Daniel Norman | 571e182 | 2021-06-25 17:18:25 -0700 | [diff] [blame] | 1721 | elif o == '--vendor-otatools': |
| 1722 | OPTIONS.vendor_otatools = a |
| 1723 | elif o == '--rebuild-sepolicy': |
| 1724 | OPTIONS.rebuild_sepolicy = True |
Bill Peckham | 364c1cc | 2019-03-29 18:27:23 -0700 | [diff] [blame] | 1725 | elif o == '--keep-tmp': |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 1726 | OPTIONS.keep_tmp = True |
Jose Galmes | 9c8f6eb | 2021-07-21 09:34:08 -0700 | [diff] [blame] | 1727 | elif o == '--framework-dexpreopt-config': |
| 1728 | OPTIONS.framework_dexpreopt_config = a |
| 1729 | elif o == '--framework-dexpreopt-tools': |
| 1730 | OPTIONS.framework_dexpreopt_tools = a |
| 1731 | elif o == '--vendor-dexpreopt-config': |
| 1732 | OPTIONS.vendor_dexpreopt_config = a |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 1733 | else: |
| 1734 | return False |
| 1735 | return True |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1736 | |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 1737 | args = common.ParseOptions( |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 1738 | sys.argv[1:], |
| 1739 | __doc__, |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 1740 | extra_long_opts=[ |
| 1741 | 'system-target-files=', |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1742 | 'framework-target-files=', |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 1743 | 'system-item-list=', |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1744 | 'framework-item-list=', |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 1745 | 'system-misc-info-keys=', |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1746 | 'framework-misc-info-keys=', |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 1747 | 'other-target-files=', |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1748 | 'vendor-target-files=', |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 1749 | 'other-item-list=', |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1750 | 'vendor-item-list=', |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 1751 | 'output-target-files=', |
Daniel Norman | fdb3881 | 2019-04-15 09:47:24 -0700 | [diff] [blame] | 1752 | 'output-dir=', |
| 1753 | 'output-item-list=', |
Daniel Norman | 3b64ce1 | 2019-04-16 16:11:35 -0700 | [diff] [blame] | 1754 | 'output-ota=', |
Daniel Norman | 1bd2a1d | 2019-04-18 12:32:18 -0700 | [diff] [blame] | 1755 | 'output-img=', |
Daniel Norman | f031825 | 2019-04-15 11:34:56 -0700 | [diff] [blame] | 1756 | 'output-super-empty=', |
Jose Galmes | 9c8f6eb | 2021-07-21 09:34:08 -0700 | [diff] [blame] | 1757 | 'framework-dexpreopt-config=', |
| 1758 | 'framework-dexpreopt-tools=', |
| 1759 | 'vendor-dexpreopt-config=', |
Daniel Norman | a4911da | 2019-03-15 14:36:21 -0700 | [diff] [blame] | 1760 | 'rebuild_recovery', |
Daniel Norman | b0c7591 | 2020-09-24 14:30:21 -0700 | [diff] [blame] | 1761 | 'allow-duplicate-apkapex-keys', |
Daniel Norman | 571e182 | 2021-06-25 17:18:25 -0700 | [diff] [blame] | 1762 | 'vendor-otatools=', |
| 1763 | 'rebuild-sepolicy', |
Bill Peckham | 364c1cc | 2019-03-29 18:27:23 -0700 | [diff] [blame] | 1764 | 'keep-tmp', |
Bill Peckham | f753e15 | 2019-02-19 18:02:46 -0800 | [diff] [blame] | 1765 | ], |
| 1766 | extra_option_handler=option_handler) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1767 | |
Tao Bao | 2ad4b82 | 2019-06-27 16:52:12 -0700 | [diff] [blame] | 1768 | # pylint: disable=too-many-boolean-expressions |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1769 | if (args or OPTIONS.framework_target_files is None or |
| 1770 | OPTIONS.vendor_target_files is None or |
Daniel Norman | e5b134a | 2019-04-17 14:54:06 -0700 | [diff] [blame] | 1771 | (OPTIONS.output_target_files is None and OPTIONS.output_dir is None) or |
Daniel Norman | 2d7989a | 2021-04-05 17:40:47 +0000 | [diff] [blame] | 1772 | (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] | 1773 | common.Usage(__doc__) |
Bill Peckham | 889b0c6 | 2019-02-21 18:53:37 -0800 | [diff] [blame] | 1774 | sys.exit(1) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1775 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1776 | if OPTIONS.framework_item_list: |
Daniel Norman | 4cc9df6 | 2019-07-18 10:11:07 -0700 | [diff] [blame] | 1777 | framework_item_list = common.LoadListFromFile(OPTIONS.framework_item_list) |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 1778 | else: |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1779 | framework_item_list = DEFAULT_FRAMEWORK_ITEM_LIST |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 1780 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1781 | if OPTIONS.framework_misc_info_keys: |
Daniel Norman | 4cc9df6 | 2019-07-18 10:11:07 -0700 | [diff] [blame] | 1782 | framework_misc_info_keys = common.LoadListFromFile( |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1783 | OPTIONS.framework_misc_info_keys) |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 1784 | else: |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1785 | framework_misc_info_keys = DEFAULT_FRAMEWORK_MISC_INFO_KEYS |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 1786 | |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1787 | if OPTIONS.vendor_item_list: |
Daniel Norman | 4cc9df6 | 2019-07-18 10:11:07 -0700 | [diff] [blame] | 1788 | vendor_item_list = common.LoadListFromFile(OPTIONS.vendor_item_list) |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 1789 | else: |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1790 | vendor_item_list = DEFAULT_VENDOR_ITEM_LIST |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 1791 | |
Daniel Norman | fdb3881 | 2019-04-15 09:47:24 -0700 | [diff] [blame] | 1792 | if OPTIONS.output_item_list: |
Daniel Norman | 4cc9df6 | 2019-07-18 10:11:07 -0700 | [diff] [blame] | 1793 | output_item_list = common.LoadListFromFile(OPTIONS.output_item_list) |
Daniel Norman | fdb3881 | 2019-04-15 09:47:24 -0700 | [diff] [blame] | 1794 | else: |
| 1795 | output_item_list = None |
| 1796 | |
Daniel Norman | e596452 | 2019-03-19 10:32:03 -0700 | [diff] [blame] | 1797 | if not validate_config_lists( |
Daniel Norman | 2d7989a | 2021-04-05 17:40:47 +0000 | [diff] [blame] | 1798 | framework_item_list=framework_item_list, |
| 1799 | framework_misc_info_keys=framework_misc_info_keys, |
| 1800 | vendor_item_list=vendor_item_list): |
Daniel Norman | e596452 | 2019-03-19 10:32:03 -0700 | [diff] [blame] | 1801 | sys.exit(1) |
| 1802 | |
Daniel Norman | 2c99c5b | 2019-03-07 13:01:48 -0800 | [diff] [blame] | 1803 | call_func_with_temp_dir( |
| 1804 | lambda temp_dir: merge_target_files( |
| 1805 | temp_dir=temp_dir, |
Daniel Norman | d5d70ea | 2019-06-05 15:13:43 -0700 | [diff] [blame] | 1806 | framework_target_files=OPTIONS.framework_target_files, |
| 1807 | framework_item_list=framework_item_list, |
| 1808 | framework_misc_info_keys=framework_misc_info_keys, |
| 1809 | vendor_target_files=OPTIONS.vendor_target_files, |
| 1810 | vendor_item_list=vendor_item_list, |
Daniel Norman | a4911da | 2019-03-15 14:36:21 -0700 | [diff] [blame] | 1811 | output_target_files=OPTIONS.output_target_files, |
Daniel Norman | fdb3881 | 2019-04-15 09:47:24 -0700 | [diff] [blame] | 1812 | output_dir=OPTIONS.output_dir, |
| 1813 | output_item_list=output_item_list, |
Daniel Norman | 3b64ce1 | 2019-04-16 16:11:35 -0700 | [diff] [blame] | 1814 | output_ota=OPTIONS.output_ota, |
Daniel Norman | 1bd2a1d | 2019-04-18 12:32:18 -0700 | [diff] [blame] | 1815 | output_img=OPTIONS.output_img, |
Daniel Norman | f031825 | 2019-04-15 11:34:56 -0700 | [diff] [blame] | 1816 | output_super_empty=OPTIONS.output_super_empty, |
Daniel Norman | 571e182 | 2021-06-25 17:18:25 -0700 | [diff] [blame] | 1817 | rebuild_recovery=OPTIONS.rebuild_recovery, |
| 1818 | vendor_otatools=OPTIONS.vendor_otatools, |
Jose Galmes | 9c8f6eb | 2021-07-21 09:34:08 -0700 | [diff] [blame] | 1819 | rebuild_sepolicy=OPTIONS.rebuild_sepolicy, |
| 1820 | framework_dexpreopt_tools=OPTIONS.framework_dexpreopt_tools, |
| 1821 | framework_dexpreopt_config=OPTIONS.framework_dexpreopt_config, |
| 1822 | vendor_dexpreopt_config=OPTIONS.vendor_dexpreopt_config), OPTIONS.keep_tmp) |
Bill Peckham | e9eb5f9 | 2019-02-01 15:52:10 -0800 | [diff] [blame] | 1823 | |
| 1824 | |
| 1825 | if __name__ == '__main__': |
Bill Peckham | 889b0c6 | 2019-02-21 18:53:37 -0800 | [diff] [blame] | 1826 | main() |