load("@protobuf//bazel:cc_proto_library.bzl", "cc_proto_library")
load("@protobuf//bazel:proto_library.bzl", "proto_library")
load("//cuttlefish/bazel:rules.bzl", "COPTS", "cf_cc_library")

package(
    default_visibility = ["//:android_cuttlefish"],
)

proto_library(
    name = "cdisk_spec_proto",
    srcs = ["cdisk_spec.proto"],
)

cc_proto_library(
    name = "cdisk_spec_cc_proto",
    deps = [":cdisk_spec_proto"],
)

cf_cc_library(
    name = "composite_disk",
    srcs = ["composite_disk.cc"],
    hdrs = ["composite_disk.h"],
    clang_format_enabled = False,
    deps = [
        "//cuttlefish/common/libs/fs",
        "//cuttlefish/host/libs/image_aggregator:cdisk_spec_cc_proto",
        "//cuttlefish/host/libs/image_aggregator:disk_image",
        "//cuttlefish/io",
        "//cuttlefish/io:read_exact",
        "//cuttlefish/io:shared_fd",
        "//cuttlefish/io:string",
        "//cuttlefish/posix:strerror",
        "//cuttlefish/result",
    ],
)

cf_cc_library(
    name = "disk_image",
    hdrs = ["disk_image.h"],
    deps = [
        "//cuttlefish/result",
    ],
)

cf_cc_library(
    name = "gpt",
    hdrs = ["gpt.h"],
    deps = [
        "//cuttlefish/common/libs/utils:size_utils",
        "//cuttlefish/host/libs/image_aggregator:mbr",
    ],
)

cf_cc_library(
    name = "gpt_type_guid",
    srcs = ["gpt_type_guid.cc"],
    hdrs = ["gpt_type_guid.h"],
    deps = [
        "//cuttlefish/result",
    ],
)

cf_cc_library(
    name = "image_from_file",
    srcs = ["image_from_file.cc"],
    hdrs = ["image_from_file.h"],
    clang_format_enabled = False,
    deps = [
        "//cuttlefish/common/libs/fs",
        "//cuttlefish/common/libs/utils:files",
        "//cuttlefish/host/libs/image_aggregator:composite_disk",
        "//cuttlefish/host/libs/image_aggregator:disk_image",
        "//cuttlefish/host/libs/image_aggregator:qcow2",
        "//cuttlefish/host/libs/image_aggregator:raw",
        "//cuttlefish/host/libs/image_aggregator:sparse_image",
        "//cuttlefish/result",
        "@abseil-cpp//absl/strings",
    ],
)

cf_cc_library(
    name = "image_aggregator",
    srcs = ["image_aggregator.cc"],
    hdrs = ["image_aggregator.h"],
    copts = COPTS + [
        "-Wno-packed-non-pod",
    ],
    deps = [
        "//cuttlefish/common/libs/fs",
        "//cuttlefish/common/libs/utils:files",
        "//cuttlefish/common/libs/utils:size_utils",
        "//cuttlefish/common/libs/utils:subprocess",
        "//cuttlefish/host/libs/image_aggregator:cdisk_spec_cc_proto",
        "//cuttlefish/host/libs/image_aggregator:composite_disk",
        "//cuttlefish/host/libs/image_aggregator:gpt",
        "//cuttlefish/host/libs/image_aggregator:gpt_type_guid",
        "//cuttlefish/host/libs/image_aggregator:image_from_file",
        "//cuttlefish/host/libs/image_aggregator:mbr",
        "//cuttlefish/host/libs/image_aggregator:sparse_image",
        "//cuttlefish/result",
        "//libbase",
        "@android_system_core//:libsparse",
        "@protobuf",
        "@protobuf//:differencer",
        "@zlib",
    ],
)

cf_cc_library(
    name = "mbr",
    srcs = ["mbr.cc"],
    hdrs = ["mbr.h"],
)

cf_cc_library(
    name = "raw",
    srcs = ["raw.cc"],
    hdrs = ["raw.h"],
    deps = [
        "//cuttlefish/common/libs/utils:files",
        "//cuttlefish/host/libs/image_aggregator:disk_image",
        "//cuttlefish/posix:strerror",
        "//cuttlefish/result",
    ],
)

cf_cc_library(
    name = "sparse_image",
    srcs = ["sparse_image.cc"],
    hdrs = ["sparse_image.h"],
    clang_format_enabled = False,
    deps = [
        "//cuttlefish/common/libs/fs",
        "//cuttlefish/common/libs/utils:files",
        "//cuttlefish/common/libs/utils:subprocess",
        "//cuttlefish/host/libs/config:known_paths",
        "//cuttlefish/host/libs/image_aggregator:disk_image",
        "//cuttlefish/posix:rename",
        "//cuttlefish/result",
        "//libbase",
        "@android_system_core//:libsparse",
    ],
)

cf_cc_library(
    name = "super_builder",
    srcs = ["super_builder.cc"],
    hdrs = ["super_builder.h"],
    deps = [
        "//cuttlefish/common/libs/fs",
        "//cuttlefish/host/libs/config:log_string_to_dir",
        "//cuttlefish/host/libs/image_aggregator:cdisk_spec_cc_proto",
        "//cuttlefish/host/libs/image_aggregator:composite_disk",
        "//cuttlefish/host/libs/image_aggregator:disk_image",
        "//cuttlefish/host/libs/image_aggregator:image_from_file",
        "//cuttlefish/pretty:unique_ptr",
        "//cuttlefish/pretty/liblp",
        "//cuttlefish/result",
        "@abseil-cpp//absl/log",
        "@abseil-cpp//absl/strings",
        "@android_system_core//:liblp",
        "@boringssl//:crypto",
    ],
)

cf_cc_library(
    name = "qcow2",
    srcs = ["qcow2.cc"],
    hdrs = ["qcow2.h"],
    copts = COPTS + [
        "-Wno-packed-non-pod",
    ],
    deps = [
        "//cuttlefish/common/libs/fs",
        "//cuttlefish/common/libs/utils:cf_endian",
        "//cuttlefish/common/libs/utils:subprocess",
        "//cuttlefish/common/libs/utils:subprocess_managed_stdio",
        "//cuttlefish/host/libs/image_aggregator:disk_image",
        "//cuttlefish/result",
    ],
)
