Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 27cbdd98 authored by Daniel Norman's avatar Daniel Norman Committed by Gerrit Code Review
Browse files

Merge changes I1d1ec878,I25c1dc20

* changes:
  Remove unnecessary AddCareMapForAbOta() in merge_target_files.
  Run pyformat on merge_target_files.py
parents 07491322 a84d13bc
Loading
Loading
Loading
Loading
+58 −54
Original line number Original line Diff line number Diff line
@@ -127,7 +127,7 @@ import ota_from_target_files
import sparse_img
import sparse_img
import verity_utils
import verity_utils


from common import AddCareMapForAbOta, ExternalError, PARTITIONS_WITH_CARE_MAP
from common import ExternalError


logger = logging.getLogger(__name__)
logger = logging.getLogger(__name__)


@@ -826,10 +826,6 @@ def generate_care_map(partitions, output_target_files_dir):
        image_size = verity_image_builder.CalculateMaxImageSize(partition_size)
        image_size = verity_image_builder.CalculateMaxImageSize(partition_size)
        OPTIONS.info_dict[image_size_prop] = image_size
        OPTIONS.info_dict[image_size_prop] = image_size


  AddCareMapForAbOta(
      os.path.join(output_target_files_dir, 'META', 'care_map.pb'),
      PARTITIONS_WITH_CARE_MAP, partition_image_map)



def process_special_cases(temp_dir, framework_meta, vendor_meta,
def process_special_cases(temp_dir, framework_meta, vendor_meta,
                          output_target_files_temp_dir,
                          output_target_files_temp_dir,
@@ -843,11 +839,12 @@ def process_special_cases(temp_dir, framework_meta, vendor_meta,


  Args:
  Args:
    temp_dir: Location containing an 'output' directory where target files have
    temp_dir: Location containing an 'output' directory where target files have
      been extracted, e.g. <temp_dir>/output/SYSTEM, <temp_dir>/output/IMAGES, etc.
      been extracted, e.g. <temp_dir>/output/SYSTEM, <temp_dir>/output/IMAGES,
      etc.
    framework_meta: The name of a directory containing the special items
    framework_meta: The name of a directory containing the special items
      extracted from the framework target files package.
      extracted from the framework target files package.
    vendor_meta: The name of a directory containing the special items
    vendor_meta: The name of a directory containing the special items extracted
      extracted from the vendor target files package.
      from the vendor target files package.
    output_target_files_temp_dir: The name of a directory that will be used to
    output_target_files_temp_dir: The name of a directory that will be used to
      create the output target files package after all the special cases are
      create the output target files package after all the special cases are
      processed.
      processed.
@@ -858,9 +855,7 @@ def process_special_cases(temp_dir, framework_meta, vendor_meta,
      partitions. Used to filter apexkeys.txt and apkcerts.txt.
      partitions. Used to filter apexkeys.txt and apkcerts.txt.
    vendor_partition_set: Partitions that are considered vendor partitions. Used
    vendor_partition_set: Partitions that are considered vendor partitions. Used
      to filter apexkeys.txt and apkcerts.txt.
      to filter apexkeys.txt and apkcerts.txt.

  Args used if dexpreopt is applied:
    The following are only used if dexpreopt is applied:

    framework_dexpreopt_tools: Location of dexpreopt_tools.zip.
    framework_dexpreopt_tools: Location of dexpreopt_tools.zip.
    framework_dexpreopt_config: Location of framework's dexpreopt_config.zip.
    framework_dexpreopt_config: Location of framework's dexpreopt_config.zip.
    vendor_dexpreopt_config: Location of vendor's dexpreopt_config.zip.
    vendor_dexpreopt_config: Location of vendor's dexpreopt_config.zip.
@@ -915,14 +910,14 @@ def process_special_cases(temp_dir, framework_meta, vendor_meta,




def process_dexopt(temp_dir, framework_meta, vendor_meta,
def process_dexopt(temp_dir, framework_meta, vendor_meta,
                   output_target_files_temp_dir,
                   output_target_files_temp_dir, framework_dexpreopt_tools,
                   framework_dexpreopt_tools, framework_dexpreopt_config,
                   framework_dexpreopt_config, vendor_dexpreopt_config):
                   vendor_dexpreopt_config):
  """If needed, generates dexopt files for vendor apps.
  """If needed, generates dexopt files for vendor apps.


  Args:
  Args:
    temp_dir: Location containing an 'output' directory where target files have
    temp_dir: Location containing an 'output' directory where target files have
      been extracted, e.g. <temp_dir>/output/SYSTEM, <temp_dir>/output/IMAGES, etc.
      been extracted, e.g. <temp_dir>/output/SYSTEM, <temp_dir>/output/IMAGES,
      etc.
    framework_meta: The name of a directory containing the special items
    framework_meta: The name of a directory containing the special items
      extracted from the framework target files package.
      extracted from the framework target files package.
    vendor_meta: The name of a directory containing the special items extracted
    vendor_meta: The name of a directory containing the special items extracted
@@ -940,8 +935,7 @@ def process_dexopt(temp_dir, framework_meta, vendor_meta,
      os.path.join(vendor_meta, *misc_info_path))
      os.path.join(vendor_meta, *misc_info_path))


  if (vendor_misc_info_dict.get('building_with_vsdk') != 'true' or
  if (vendor_misc_info_dict.get('building_with_vsdk') != 'true' or
      framework_dexpreopt_tools is None or
      framework_dexpreopt_tools is None or framework_dexpreopt_config is None or
      framework_dexpreopt_config is None or
      vendor_dexpreopt_config is None):
      vendor_dexpreopt_config is None):
    return
    return


@@ -984,8 +978,10 @@ def process_dexopt(temp_dir, framework_meta, vendor_meta,
  #                 package.vdex
  #                 package.vdex
  #                 package.odex
  #                 package.odex
  dexpreopt_tools_files_temp_dir = os.path.join(temp_dir, 'tools')
  dexpreopt_tools_files_temp_dir = os.path.join(temp_dir, 'tools')
  dexpreopt_framework_config_files_temp_dir = os.path.join(temp_dir, 'system_config')
  dexpreopt_framework_config_files_temp_dir = os.path.join(
  dexpreopt_vendor_config_files_temp_dir = os.path.join(temp_dir, 'vendor_config')
      temp_dir, 'system_config')
  dexpreopt_vendor_config_files_temp_dir = os.path.join(temp_dir,
                                                        'vendor_config')


  extract_items(
  extract_items(
      target_files=OPTIONS.framework_dexpreopt_tools,
      target_files=OPTIONS.framework_dexpreopt_tools,
@@ -1000,10 +996,12 @@ def process_dexopt(temp_dir, framework_meta, vendor_meta,
      target_files_temp_dir=dexpreopt_vendor_config_files_temp_dir,
      target_files_temp_dir=dexpreopt_vendor_config_files_temp_dir,
      extract_item_list=('*',))
      extract_item_list=('*',))


  os.symlink(os.path.join(output_target_files_temp_dir, "SYSTEM"),
  os.symlink(
             os.path.join(temp_dir, "system"))
      os.path.join(output_target_files_temp_dir, 'SYSTEM'),
  os.symlink(os.path.join(output_target_files_temp_dir, "VENDOR"),
      os.path.join(temp_dir, 'system'))
             os.path.join(temp_dir, "vendor"))
  os.symlink(
      os.path.join(output_target_files_temp_dir, 'VENDOR'),
      os.path.join(temp_dir, 'vendor'))


  # The directory structure for flatteded APEXes is:
  # The directory structure for flatteded APEXes is:
  #
  #
@@ -1026,7 +1024,7 @@ def process_dexopt(temp_dir, framework_meta, vendor_meta,
  #         com.android.appsearch.apex
  #         com.android.appsearch.apex
  #         com.android.art.apex
  #         com.android.art.apex
  #         ...
  #         ...
  apex_root = os.path.join(output_target_files_temp_dir, "SYSTEM", "apex")
  apex_root = os.path.join(output_target_files_temp_dir, 'SYSTEM', 'apex')
  framework_misc_info_dict = common.LoadDictionaryFromFile(
  framework_misc_info_dict = common.LoadDictionaryFromFile(
      os.path.join(framework_meta, *misc_info_path))
      os.path.join(framework_meta, *misc_info_path))


@@ -1094,13 +1092,14 @@ def process_dexopt(temp_dir, framework_meta, vendor_meta,
    dex_img = 'VENDOR'
    dex_img = 'VENDOR'
    # Open vendor_filesystem_config to append the items generated by dexopt.
    # Open vendor_filesystem_config to append the items generated by dexopt.
    vendor_file_system_config = open(
    vendor_file_system_config = open(
        os.path.join(temp_dir, 'output', 'META', 'vendor_filesystem_config.txt'),
        os.path.join(temp_dir, 'output', 'META',
        'a')
                     'vendor_filesystem_config.txt'), 'a')


  # Dexpreopt vendor apps.
  # Dexpreopt vendor apps.
  dexpreopt_config_suffix = '_dexpreopt.config'
  dexpreopt_config_suffix = '_dexpreopt.config'
  for config in glob.glob(os.path.join(
  for config in glob.glob(
      dexpreopt_vendor_config_files_temp_dir, '*' + dexpreopt_config_suffix)):
      os.path.join(dexpreopt_vendor_config_files_temp_dir,
                   '*' + dexpreopt_config_suffix)):
    app = os.path.basename(config)[:-len(dexpreopt_config_suffix)]
    app = os.path.basename(config)[:-len(dexpreopt_config_suffix)]
    logging.info('dexpreopt config: %s %s', config, app)
    logging.info('dexpreopt config: %s %s', config, app)


@@ -1110,7 +1109,8 @@ def process_dexopt(temp_dir, framework_meta, vendor_meta,
      apk_dir = 'priv-app'
      apk_dir = 'priv-app'
      apk_path = os.path.join(temp_dir, 'vendor', apk_dir, app, app + '.apk')
      apk_path = os.path.join(temp_dir, 'vendor', apk_dir, app, app + '.apk')
      if not os.path.exists(apk_path):
      if not os.path.exists(apk_path):
        logging.warning('skipping dexpreopt for %s, no apk found in vendor/app '
        logging.warning(
            'skipping dexpreopt for %s, no apk found in vendor/app '
            'or vendor/priv-app', app)
            'or vendor/priv-app', app)
        continue
        continue


@@ -1121,10 +1121,11 @@ def process_dexopt(temp_dir, framework_meta, vendor_meta,
    command = [
    command = [
        os.path.join(dexpreopt_tools_files_temp_dir, 'dexpreopt_gen'),
        os.path.join(dexpreopt_tools_files_temp_dir, 'dexpreopt_gen'),
        '-global',
        '-global',
        os.path.join(dexpreopt_framework_config_files_temp_dir, 'dexpreopt.config'),
        os.path.join(dexpreopt_framework_config_files_temp_dir,
                     'dexpreopt.config'),
        '-global_soong',
        '-global_soong',
        os.path.join(
        os.path.join(dexpreopt_framework_config_files_temp_dir,
            dexpreopt_framework_config_files_temp_dir, 'dexpreopt_soong.config'),
                     'dexpreopt_soong.config'),
        '-module',
        '-module',
        config,
        config,
        '-dexpreopt_script',
        '-dexpreopt_script',
@@ -1137,12 +1138,12 @@ def process_dexopt(temp_dir, framework_meta, vendor_meta,
    ]
    ]


    # Run the command from temp_dir so all tool paths are its descendants.
    # Run the command from temp_dir so all tool paths are its descendants.
    logging.info("running %s", command)
    logging.info('running %s', command)
    subprocess.check_call(command, cwd=temp_dir)
    subprocess.check_call(command, cwd=temp_dir)


    # Call the generated script.
    # Call the generated script.
    command = ['sh', 'dexpreopt_app.sh', apk_path]
    command = ['sh', 'dexpreopt_app.sh', apk_path]
    logging.info("running %s", command)
    logging.info('running %s', command)
    subprocess.check_call(command, cwd=temp_dir)
    subprocess.check_call(command, cwd=temp_dir)


    # Output files are in:
    # Output files are in:
@@ -1171,13 +1172,16 @@ def process_dexopt(temp_dir, framework_meta, vendor_meta,
    # TODO(b/188179859): Support for other architectures.
    # TODO(b/188179859): Support for other architectures.
    arch = 'arm64'
    arch = 'arm64'


    dex_destination = os.path.join(temp_dir, 'output', dex_img, apk_dir, app, 'oat', arch)
    dex_destination = os.path.join(temp_dir, 'output', dex_img, apk_dir, app,
                                   'oat', arch)
    os.makedirs(dex_destination)
    os.makedirs(dex_destination)
    dex2oat_path = os.path.join(
    dex2oat_path = os.path.join(temp_dir, 'out', 'dex2oat_result', 'vendor',
        temp_dir, 'out', 'dex2oat_result', 'vendor', apk_dir, app, 'oat', arch)
                                apk_dir, app, 'oat', arch)
    shutil.copy(os.path.join(dex2oat_path, 'package.vdex'),
    shutil.copy(
        os.path.join(dex2oat_path, 'package.vdex'),
        os.path.join(dex_destination, app + '.vdex'))
        os.path.join(dex_destination, app + '.vdex'))
    shutil.copy(os.path.join(dex2oat_path, 'package.odex'),
    shutil.copy(
        os.path.join(dex2oat_path, 'package.odex'),
        os.path.join(dex_destination, app + '.odex'))
        os.path.join(dex_destination, app + '.odex'))


    # Append entries to vendor_file_system_config.txt, such as:
    # Append entries to vendor_file_system_config.txt, such as:
@@ -1192,8 +1196,10 @@ def process_dexopt(temp_dir, framework_meta, vendor_meta,
      vendor_file_system_config.writelines([
      vendor_file_system_config.writelines([
          vendor_app_prefix + ' 0 2000 755 ' + selabel + '\n',
          vendor_app_prefix + ' 0 2000 755 ' + selabel + '\n',
          vendor_app_prefix + '/' + arch + ' 0 2000 755 ' + selabel + '\n',
          vendor_app_prefix + '/' + arch + ' 0 2000 755 ' + selabel + '\n',
          vendor_app_prefix + '/' + arch + '/' + app + '.odex 0 0 644 ' + selabel + '\n',
          vendor_app_prefix + '/' + arch + '/' + app + '.odex 0 0 644 ' +
          vendor_app_prefix + '/' + arch + '/' + app + '.vdex 0 0 644 ' + selabel + '\n',
          selabel + '\n',
          vendor_app_prefix + '/' + arch + '/' + app + '.vdex 0 0 644 ' +
          selabel + '\n',
      ])
      ])


  if not use_system_other_odex:
  if not use_system_other_odex:
@@ -1202,7 +1208,8 @@ def process_dexopt(temp_dir, framework_meta, vendor_meta,
    # TODO(b/188179859): Rebuilding a vendor image in GRF mode (e.g., T(framework)
    # TODO(b/188179859): Rebuilding a vendor image in GRF mode (e.g., T(framework)
    #                    and S(vendor) may require logic similar to that in
    #                    and S(vendor) may require logic similar to that in
    #                    rebuild_image_with_sepolicy.
    #                    rebuild_image_with_sepolicy.
    vendor_img = os.path.join(output_target_files_temp_dir, 'IMAGES', 'vendor.img')
    vendor_img = os.path.join(output_target_files_temp_dir, 'IMAGES',
                              'vendor.img')
    if os.path.exists(vendor_img):
    if os.path.exists(vendor_img):
      logging.info('Deleting %s', vendor_img)
      logging.info('Deleting %s', vendor_img)
      os.remove(vendor_img)
      os.remove(vendor_img)
@@ -1236,9 +1243,7 @@ def create_merged_package(temp_dir, framework_target_files, framework_item_list,
      vendor instance.
      vendor instance.
    rebuild_recovery: If true, rebuild the recovery patch used by non-A/B
    rebuild_recovery: If true, rebuild the recovery patch used by non-A/B
      devices and write it to the system image.
      devices and write it to the system image.

  Args used if dexpreopt is applied:
    The following are only used if dexpreopt is applied:

    framework_dexpreopt_tools: Location of dexpreopt_tools.zip.
    framework_dexpreopt_tools: Location of dexpreopt_tools.zip.
    framework_dexpreopt_config: Location of framework's dexpreopt_config.zip.
    framework_dexpreopt_config: Location of framework's dexpreopt_config.zip.
    vendor_dexpreopt_config: Location of vendor's dexpreopt_config.zip.
    vendor_dexpreopt_config: Location of vendor's dexpreopt_config.zip.
@@ -1535,9 +1540,7 @@ def merge_target_files(temp_dir, framework_target_files, framework_item_list,
    vendor_otatools: Path to an otatools zip used for recompiling vendor images.
    vendor_otatools: Path to an otatools zip used for recompiling vendor images.
    rebuild_sepolicy: If true, rebuild odm.img (if target uses ODM) or
    rebuild_sepolicy: If true, rebuild odm.img (if target uses ODM) or
      vendor.img using a merged precompiled_sepolicy file.
      vendor.img using a merged precompiled_sepolicy file.

  Args used if dexpreopt is applied:
    The following are only used if dexpreopt is applied:

    framework_dexpreopt_tools: Location of dexpreopt_tools.zip.
    framework_dexpreopt_tools: Location of dexpreopt_tools.zip.
    framework_dexpreopt_config: Location of framework's dexpreopt_config.zip.
    framework_dexpreopt_config: Location of framework's dexpreopt_config.zip.
    vendor_dexpreopt_config: Location of vendor's dexpreopt_config.zip.
    vendor_dexpreopt_config: Location of vendor's dexpreopt_config.zip.
@@ -1820,7 +1823,8 @@ def main():
          rebuild_sepolicy=OPTIONS.rebuild_sepolicy,
          rebuild_sepolicy=OPTIONS.rebuild_sepolicy,
          framework_dexpreopt_tools=OPTIONS.framework_dexpreopt_tools,
          framework_dexpreopt_tools=OPTIONS.framework_dexpreopt_tools,
          framework_dexpreopt_config=OPTIONS.framework_dexpreopt_config,
          framework_dexpreopt_config=OPTIONS.framework_dexpreopt_config,
          vendor_dexpreopt_config=OPTIONS.vendor_dexpreopt_config), OPTIONS.keep_tmp)
          vendor_dexpreopt_config=OPTIONS.vendor_dexpreopt_config),
      OPTIONS.keep_tmp)




if __name__ == '__main__':
if __name__ == '__main__':