Exemplo n.º 1
0
def BuildSuperEmpty():
    framework_dict = common.LoadDictionaryFromFile(
        os.path.join(OPTIONS.product_out_framework, "misc_info.txt"))
    vendor_dict = common.LoadDictionaryFromFile(
        os.path.join(OPTIONS.product_out_vendor, "misc_info.txt"))
    # Regenerate super_empty.img if both partial builds enable DAP. If only the
    # the vendor build enables DAP, the vendor build's existing super_empty.img
    # will be reused. If only the framework build should enable DAP, super_empty
    # should be included in the --framework_images flag to copy the existing
    # super_empty.img from the framework build.
    if (framework_dict.get("use_dynamic_partitions")
            == "true") and (vendor_dict.get("use_dynamic_partitions")
                            == "true"):
        logger.info("Building super_empty.img.")
        merged_dict = dict(vendor_dict)
        merged_dict.update(
            common.MergeDynamicPartitionInfoDicts(
                framework_dict=framework_dict,
                vendor_dict=vendor_dict,
                size_prefix="super_",
                size_suffix="_group_size",
                list_prefix="super_",
                list_suffix="_partition_list"))
        output_super_empty_path = os.path.join(OPTIONS.product_out_vendor,
                                               "super_empty.img")
        build_super_image.BuildSuperImage(merged_dict, output_super_empty_path)
def process_dynamic_partitions_info_txt(framework_target_files_dir,
                                        vendor_target_files_dir,
                                        output_target_files_dir):
    """Performs special processing for META/dynamic_partitions_info.txt.

  This function merges the contents of the META/dynamic_partitions_info.txt
  files from the framework directory and the vendor directory, placing the
  merged result in the output directory.

  This function does nothing if META/dynamic_partitions_info.txt from the vendor
  directory does not exist.

  Args:
    framework_target_files_dir: The name of a directory containing the special
      items extracted from the framework target files package.
    vendor_target_files_dir: The name of a directory containing the special
      items extracted from the vendor target files package.
    output_target_files_dir: The name of a directory that will be used to create
      the output target files package after all the special cases are processed.
  """

    if not os.path.exists(
            os.path.join(vendor_target_files_dir, 'META',
                         'dynamic_partitions_info.txt')):
        return

    dynamic_partitions_info_path = ['META', 'dynamic_partitions_info.txt']

    framework_dynamic_partitions_dict = common.LoadDictionaryFromFile(
        os.path.join(framework_target_files_dir,
                     *dynamic_partitions_info_path))
    vendor_dynamic_partitions_dict = common.LoadDictionaryFromFile(
        os.path.join(vendor_target_files_dir, *dynamic_partitions_info_path))

    merged_dynamic_partitions_dict = common.MergeDynamicPartitionInfoDicts(
        framework_dict=framework_dynamic_partitions_dict,
        vendor_dict=vendor_dynamic_partitions_dict,
        # META/dynamic_partitions_info.txt does not use dynamic_partition_list.
        include_dynamic_partition_list=False,
        size_suffix='_size',
        list_suffix='_partition_list')

    output_dynamic_partitions_info_txt = os.path.join(
        output_target_files_dir, 'META', 'dynamic_partitions_info.txt')
    write_sorted_data(data=merged_dynamic_partitions_dict,
                      path=output_dynamic_partitions_info_txt)
def process_misc_info_txt(framework_target_files_temp_dir,
                          vendor_target_files_temp_dir,
                          output_target_files_temp_dir,
                          framework_misc_info_keys):
    """Performs special processing for META/misc_info.txt.

  This function merges the contents of the META/misc_info.txt files from the
  framework directory and the vendor directory, placing the merged result in the
  output directory. The precondition in that the files are already extracted.
  The post condition is that the output META/misc_info.txt contains the merged
  content.

  Args:
    framework_target_files_temp_dir: The name of a directory containing the
      special items extracted from the framework target files package.
    vendor_target_files_temp_dir: The name of a directory containing the special
      items extracted from the vendor target files package.
    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
      processed.
    framework_misc_info_keys: A list of keys to obtain from the framework
      instance of META/misc_info.txt. The remaining keys from the vendor
      instance.
  """

    misc_info_path = ['META', 'misc_info.txt']
    framework_dict = common.LoadDictionaryFromFile(
        os.path.join(framework_target_files_temp_dir, *misc_info_path))

    # We take most of the misc info from the vendor target files.

    merged_dict = common.LoadDictionaryFromFile(
        os.path.join(vendor_target_files_temp_dir, *misc_info_path))

    # Replace certain values in merged_dict with values from
    # framework_dict.

    for key in framework_misc_info_keys:
        merged_dict[key] = framework_dict[key]

    # Merge misc info keys used for Dynamic Partitions.
    if (merged_dict.get('use_dynamic_partitions')
            == 'true') and (framework_dict.get('use_dynamic_partitions')
                            == 'true'):
        merged_dynamic_partitions_dict = common.MergeDynamicPartitionInfoDicts(
            framework_dict=framework_dict,
            vendor_dict=merged_dict,
            size_prefix='super_',
            size_suffix='_group_size',
            list_prefix='super_',
            list_suffix='_partition_list')
        merged_dict.update(merged_dynamic_partitions_dict)
        # Ensure that add_img_to_target_files rebuilds super split images for
        # devices that retrofit dynamic partitions. This flag may have been set to
        # false in the partial builds to prevent duplicate building of super.img.
        merged_dict['build_super_partition'] = 'true'

    # Replace <image>_selinux_fc values with framework or vendor file_contexts.bin
    # depending on which dictionary the key came from.
    # Only the file basename is required because all selinux_fc properties are
    # replaced with the full path to the file under META/ when misc_info.txt is
    # loaded from target files for repacking. See common.py LoadInfoDict().
    for key in merged_dict:
        if key.endswith('_selinux_fc'):
            merged_dict[key] = 'vendor_file_contexts.bin'
    for key in framework_dict:
        if key.endswith('_selinux_fc'):
            merged_dict[key] = 'framework_file_contexts.bin'

    output_misc_info_txt = os.path.join(output_target_files_temp_dir, 'META',
                                        'misc_info.txt')
    write_sorted_data(data=merged_dict, path=output_misc_info_txt)