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

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

cf_cc_library(
    name = "config_path",
    srcs = ["config_path.cpp"],
    hdrs = ["config_path.h"],
    deps = [
        "//cuttlefish/common/libs/utils:files",
        "//cuttlefish/result",
        "//libbase",
    ],
)

proto_library(
    name = "cvd_persistent_data_proto",
    srcs = ["cvd_persistent_data.proto"],
)

cc_proto_library(
    name = "cvd_persistent_data",
    deps = [":cvd_persistent_data_proto"],
)

cf_cc_library(
    name = "data_viewer",
    srcs = ["data_viewer.cpp"],
    hdrs = ["data_viewer.h"],
    deps = [
        "//cuttlefish/common/libs/fs",
        "//cuttlefish/common/libs/utils:signals",
        "//cuttlefish/host/commands/cvd/instances:cvd_persistent_data",
        "//cuttlefish/result",
        "@abseil-cpp//absl/log:check",
    ],
)

cf_cc_library(
    name = "device_name",
    srcs = ["device_name.cpp"],
    hdrs = ["device_name.h"],
    deps = [
        "//cuttlefish/result",
        "//libbase",
        "@abseil-cpp//absl/strings",
    ],
)

cf_cc_library(
    name = "instance_database_helper",
    testonly = True,
    srcs = ["instance_database_helper.cpp"],
    hdrs = ["instance_database_helper.h"],
    clang_format_enabled = False,
    deps = [
        "//cuttlefish/common/libs/fs",
        "//cuttlefish/common/libs/utils:files",
        "//cuttlefish/host/commands/cvd/instances",
        "//cuttlefish/host/commands/cvd/instances:instance_manager",
        "//cuttlefish/posix:strerror",
        "//libbase",
        "@googletest//:gtest",
    ],
)

cf_cc_test(
    name = "instance_database_test",
    srcs = ["instance_database_test.cpp"],
    deps = [
        "//cuttlefish/common/libs/utils:files",
        "//cuttlefish/common/libs/utils:json",
        "//cuttlefish/host/commands/cvd/instances",
        "//cuttlefish/host/commands/cvd/instances:instance_database_helper",
        "//cuttlefish/result:result_matchers",
    ],
)

cf_cc_library(
    name = "instances",
    srcs = [
        "instance_database.cpp",
        "instance_database_types.cpp",
        "local_instance.cpp",
        "local_instance_group.cpp",
        "operator_client.cpp",
        "status_fetcher.cpp",
    ],
    hdrs = [
        "instance_database.h",
        "instance_database_types.h",
        "local_instance.h",
        "local_instance_group.h",
        "operator_client.h",
        "status_fetcher.h",
    ],
    clang_format_enabled = False,
    deps = [
        ":cvd_persistent_data",
        "//cuttlefish/common/libs/fs",
        "//cuttlefish/common/libs/utils:contains",
        "//cuttlefish/common/libs/utils:files",
        "//cuttlefish/common/libs/utils:gflags_xml_parser",
        "//cuttlefish/common/libs/utils:json",
        "//cuttlefish/common/libs/utils:proc_file_utils",
        "//cuttlefish/common/libs/utils:signals",
        "//cuttlefish/common/libs/utils:subprocess",
        "//cuttlefish/common/libs/utils:subprocess_managed_stdio",
        "//cuttlefish/common/libs/utils:users",
        "//cuttlefish/host/commands/cvd/cli:command_request",
        "//cuttlefish/host/commands/cvd/cli:types",
        "//cuttlefish/host/commands/cvd/cli:utils",
        "//cuttlefish/host/commands/cvd/cli/commands:host_tool_target",
        "//cuttlefish/host/commands/cvd/instances:config_path",
        "//cuttlefish/host/commands/cvd/instances:data_viewer",
        "//cuttlefish/host/commands/cvd/instances:device_name",
        "//cuttlefish/host/commands/cvd/instances:run_cvd_proc_collector",
        "//cuttlefish/host/commands/cvd/instances:stop",
        "//cuttlefish/host/commands/cvd/instances/lock",
        "//cuttlefish/host/commands/cvd/utils",
        "//cuttlefish/host/libs/command_util",
        "//cuttlefish/host/libs/config:config_constants",
        "//cuttlefish/host/libs/config:config_utils",
        "//cuttlefish/host/libs/config:cuttlefish_config",
        "//cuttlefish/host/libs/log_names",
        "//cuttlefish/host/libs/screen_recording_controls",
        "//cuttlefish/posix:symlink",
        "//cuttlefish/result",
        "//libbase",
        "@abseil-cpp//absl/log",
        "@abseil-cpp//absl/log:check",
        "@abseil-cpp//absl/strings",
        "@fmt",
        "@jsoncpp",
    ],
)

cf_cc_library(
    name = "instance_manager",
    srcs = [
        "instance_manager.cpp",
    ],
    hdrs = [
        "instance_manager.h",
    ],
    clang_format_enabled = False,
    deps = [
        ":cvd_persistent_data",
        ":instances",
        "//cuttlefish/common/libs/fs",
        "//cuttlefish/common/libs/utils:contains",
        "//cuttlefish/common/libs/utils:files",
        "//cuttlefish/common/libs/utils:json",
        "//cuttlefish/common/libs/utils:proc_file_utils",
        "//cuttlefish/common/libs/utils:signals",
        "//cuttlefish/common/libs/utils:subprocess",
        "//cuttlefish/common/libs/utils:subprocess_managed_stdio",
        "//cuttlefish/common/libs/utils:users",
        "//cuttlefish/host/commands/cvd/cli:command_request",
        "//cuttlefish/host/commands/cvd/cli:types",
        "//cuttlefish/host/commands/cvd/cli:utils",
        "//cuttlefish/host/commands/cvd/cli/commands:host_tool_target",
        "//cuttlefish/host/commands/cvd/instances:config_path",
        "//cuttlefish/host/commands/cvd/instances:data_viewer",
        "//cuttlefish/host/commands/cvd/instances:device_name",
        "//cuttlefish/host/commands/cvd/instances:run_cvd_proc_collector",
        "//cuttlefish/host/commands/cvd/instances:stop",
        "//cuttlefish/host/commands/cvd/instances/lock",
        "//cuttlefish/host/commands/cvd/utils",
        "//cuttlefish/host/libs/command_util",
        "//cuttlefish/host/libs/config:config_constants",
        "//cuttlefish/host/libs/config:config_utils",
        "//cuttlefish/host/libs/config:cuttlefish_config",
        "//cuttlefish/host/libs/metrics:device_metrics_orchestration",
        "//cuttlefish/host/libs/screen_recording_controls",
        "//cuttlefish/posix:symlink",
        "//cuttlefish/result",
        "//libbase",
        "@abseil-cpp//absl/log",
        "@abseil-cpp//absl/log:check",
        "@abseil-cpp//absl/strings",
        "@fmt",
        "@jsoncpp",
    ],
)

cf_cc_test(
    name = "local_instance_group_test",
    srcs = ["local_instance_group_test.cpp"],
    deps = [
        "//cuttlefish/host/commands/cvd/instances",
        "//cuttlefish/host/commands/cvd/instances:cvd_persistent_data",
        "//cuttlefish/result:result_matchers",
    ],
)

cf_cc_test(
    name = "local_instance_test",
    srcs = ["local_instance_test.cpp"],
    deps = ["//cuttlefish/host/commands/cvd/instances"],
)

cf_cc_library(
    name = "run_cvd_proc_collector",
    srcs = ["run_cvd_proc_collector.cpp"],
    hdrs = ["run_cvd_proc_collector.h"],
    clang_format_enabled = False,
    deps = [
        "//cuttlefish/common/libs/utils:contains",
        "//cuttlefish/common/libs/utils:files",
        "//cuttlefish/common/libs/utils:proc_file_utils",
        "//cuttlefish/host/commands/cvd/cli:types",
        "//cuttlefish/host/commands/cvd/utils:common",
        "//cuttlefish/host/libs/config:config_constants",
        "//cuttlefish/result",
        "//libbase",
        "@abseil-cpp//absl/log",
        "@abseil-cpp//absl/strings",
    ],
)

cf_cc_library(
    name = "stop",
    srcs = ["stop.cpp"],
    hdrs = ["stop.h"],
    clang_format_enabled = False,
    deps = [
        "//cuttlefish/common/libs/utils:contains",
        "//cuttlefish/common/libs/utils:files",
        "//cuttlefish/common/libs/utils:proc_file_utils",
        "//cuttlefish/common/libs/utils:subprocess",
        "//cuttlefish/common/libs/utils:subprocess_managed_stdio",
        "//cuttlefish/host/commands/cvd/instances:config_path",
        "//cuttlefish/host/commands/cvd/instances:run_cvd_proc_collector",
        "//cuttlefish/host/commands/cvd/utils",
        "//cuttlefish/host/libs/config:config_constants",
        "//cuttlefish/posix:strerror",
        "//cuttlefish/result",
        "//libbase",
        "@abseil-cpp//absl/log",
        "@abseil-cpp//absl/strings",
        "@fmt",
    ],
)
