def CreateImage(input_dir, info_dict, what, output_file, block_list=None):
    logger.info("creating %s.img...", what)

    image_props = build_image.ImagePropFromGlobalDict(info_dict, what)
    image_props["timestamp"] = FIXED_FILE_TIMESTAMP

    if what == "system":
        fs_config_prefix = ""
    else:
        fs_config_prefix = what + "_"

    fs_config = os.path.join(
        input_dir, "META/" + fs_config_prefix + "filesystem_config.txt")
    if not os.path.exists(fs_config):
        fs_config = None

    # Override values loaded from info_dict.
    if fs_config:
        image_props["fs_config"] = fs_config
    if block_list:
        image_props["block_list"] = block_list.name

    # Use repeatable ext4 FS UUID and hash_seed UUID (based on partition name and
    # build fingerprint).
    build_info = common.BuildInfo(info_dict)
    uuid_seed = what
    if what != "modules":
        uuid_seed += "-" + build_info.GetPartitionFingerprint(what)
    image_props["uuid"] = str(uuid.uuid5(uuid.NAMESPACE_URL, uuid_seed))
    hash_seed = "hash_seed-" + uuid_seed
    image_props["hash_seed"] = str(uuid.uuid5(uuid.NAMESPACE_URL, hash_seed))

    build_image.BuildImage(os.path.join(input_dir, what.upper()), image_props,
                           output_file.name)

    output_file.Write()
    if block_list:
        block_list.Write()

    # Set the '_image_size' for given image size.
    is_verity_partition = "verity_block_device" in image_props
    verity_supported = (image_props.get("verity") == "true"
                        or image_props.get("avb_enable") == "true")
    is_avb_enable = image_props.get("avb_hashtree_enable") == "true"
    if verity_supported and (is_verity_partition or is_avb_enable):
        image_size = image_props.get("image_size")
        if image_size:
            image_size_key = what + "_image_size"
            info_dict[image_size_key] = int(image_size)

    use_dynamic_size = (info_dict.get("use_dynamic_partition_size") == "true"
                        and what in shlex.split(
                            info_dict.get("dynamic_partition_list",
                                          "").strip()))
    if use_dynamic_size:
        info_dict.update(build_image.GlobalDictFromImageProp(
            image_props, what))
def CreateImage(input_dir, info_dict, what, output_file, block_list=None):
    logger.info("creating " + what + ".img...")

    image_props = build_image.ImagePropFromGlobalDict(info_dict, what)
    fstab = info_dict["fstab"]
    mount_point = "/" + what
    if fstab and mount_point in fstab:
        image_props["fs_type"] = fstab[mount_point].fs_type

    image_props["timestamp"] = FIXED_FILE_TIMESTAMP

    if what == "system":
        fs_config_prefix = ""
    else:
        fs_config_prefix = what + "_"

    fs_config = os.path.join(
        input_dir, "META/" + fs_config_prefix + "filesystem_config.txt")
    if not os.path.exists(fs_config):
        fs_config = None

    # Override values loaded from info_dict.
    if fs_config:
        image_props["fs_config"] = fs_config
    if block_list:
        image_props["block_list"] = block_list.name

    # Use repeatable ext4 FS UUID and hash_seed UUID (based on partition name and
    # build fingerprint).
    uuid_seed = what + "-"
    if "build.prop" in info_dict:
        build_prop = info_dict["build.prop"]
        if "ro.build.fingerprint" in build_prop:
            uuid_seed += build_prop["ro.build.fingerprint"]
        elif "ro.build.thumbprint" in build_prop:
            uuid_seed += build_prop["ro.build.thumbprint"]
    image_props["uuid"] = str(uuid.uuid5(uuid.NAMESPACE_URL, uuid_seed))
    hash_seed = "hash_seed-" + uuid_seed
    image_props["hash_seed"] = str(uuid.uuid5(uuid.NAMESPACE_URL, hash_seed))

    build_image.BuildImage(os.path.join(input_dir, what.upper()), image_props,
                           output_file.name)

    output_file.Write()
    if block_list:
        block_list.Write()

    # Set the '_image_blocks' that excludes the verity metadata blocks of the
    # given image. When AVB is enabled, this size is the max image size returned
    # by the AVB tool.
    is_verity_partition = "verity_block_device" in image_props
    verity_supported = (image_props.get("verity") == "true"
                        or image_props.get("avb_enable") == "true")
    is_avb_enable = image_props.get("avb_hashtree_enable") == "true"
    if verity_supported and (is_verity_partition or is_avb_enable):
        image_size = image_props.get("image_size")
        if image_size:
            image_blocks_key = what + "_image_blocks"
            info_dict[image_blocks_key] = int(image_size) / 4096 - 1

    use_dynamic_size = (info_dict.get("use_dynamic_partition_size") == "true"
                        and what in shlex.split(
                            info_dict.get("dynamic_partition_list",
                                          "").strip()))
    if use_dynamic_size:
        info_dict.update(build_image.GlobalDictFromImageProp(
            image_props, what))