load("//tools:defs.bzl", "cc_library", "cc_test", "gbenchmark", "gtest", "select_system")

package(
    default_visibility = ["//:sandbox"],
    licenses = ["notice"],
)

cc_library(
    name = "capability_util",
    testonly = 1,
    srcs = ["capability_util.cc"],
    hdrs = ["capability_util.h"],
    deps = [
        ":cleanup",
        ":memory_util",
        ":posix_error",
        ":save_util",
        ":test_util",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "eventfd_util",
    testonly = 1,
    hdrs = ["eventfd_util.h"],
    deps = [
        ":file_descriptor",
        ":posix_error",
        ":save_util",
    ],
)

cc_library(
    name = "file_descriptor",
    testonly = 1,
    hdrs = ["file_descriptor.h"],
    deps = [
        ":logging",
        ":posix_error",
        ":save_util",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        gtest,
    ],
)

cc_library(
    name = "proc_util",
    testonly = 1,
    srcs = ["proc_util.cc"],
    hdrs = ["proc_util.h"],
    deps = [
        ":fs_util",
        ":posix_error",
        ":test_util",
        "@com_google_absl//absl/strings",
        gtest,
    ],
)

cc_test(
    name = "proc_util_test",
    size = "small",
    srcs = ["proc_util_test.cc"],
    deps = [
        ":proc_util",
        ":test_main",
        ":test_util",
        gtest,
    ],
)

cc_library(
    name = "cleanup",
    testonly = 1,
    hdrs = ["cleanup.h"],
)

cc_library(
    name = "fs_util",
    testonly = 1,
    srcs = ["fs_util.cc"],
    hdrs = ["fs_util.h"],
    deps = [
        ":cleanup",
        ":file_descriptor",
        ":posix_error",
        "@com_google_absl//absl/strings",
        gtest,
    ],
)

cc_test(
    name = "fs_util_test",
    size = "small",
    srcs = ["fs_util_test.cc"],
    deps = [
        ":fs_util",
        ":posix_error",
        ":temp_path",
        ":test_main",
        ":test_util",
        gtest,
    ],
)

cc_library(
    name = "logging",
    testonly = 1,
    srcs = ["logging.cc"],
    hdrs = ["logging.h"],
)

cc_library(
    name = "memory_util",
    testonly = 1,
    hdrs = ["memory_util.h"],
    deps = [
        ":logging",
        ":posix_error",
        ":save_util",
        ":test_util",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
    ],
)

cc_library(
    name = "mount_util",
    testonly = 1,
    hdrs = ["mount_util.h"],
    deps = [
        ":cleanup",
        ":posix_error",
        ":test_util",
        gtest,
    ],
)

cc_library(
    name = "save_util",
    testonly = 1,
    srcs = [
        "save_util.cc",
        "save_util_linux.cc",
        "save_util_other.cc",
    ],
    hdrs = ["save_util.h"],
    defines = select_system(),
)

cc_library(
    name = "multiprocess_util",
    testonly = 1,
    srcs = ["multiprocess_util.cc"],
    hdrs = ["multiprocess_util.h"],
    deps = [
        ":cleanup",
        ":file_descriptor",
        ":posix_error",
        ":save_util",
        ":test_util",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "platform_util",
    testonly = 1,
    srcs = ["platform_util.cc"],
    hdrs = ["platform_util.h"],
    deps = [":test_util"],
)

cc_library(
    name = "posix_error",
    testonly = 1,
    srcs = ["posix_error.cc"],
    hdrs = ["posix_error.h"],
    deps = [
        ":logging",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:variant",
        gtest,
    ],
)

cc_test(
    name = "posix_error_test",
    size = "small",
    srcs = ["posix_error_test.cc"],
    deps = [
        ":posix_error",
        ":test_main",
        gtest,
    ],
)

cc_library(
    name = "pty_util",
    testonly = 1,
    srcs = ["pty_util.cc"],
    hdrs = ["pty_util.h"],
    deps = [
        ":file_descriptor",
        ":posix_error",
    ],
)

cc_library(
    name = "signal_util",
    testonly = 1,
    srcs = ["signal_util.cc"],
    hdrs = ["signal_util.h"],
    deps = [
        ":cleanup",
        ":posix_error",
        ":test_util",
        gtest,
    ],
)

cc_library(
    name = "temp_path",
    testonly = 1,
    srcs = ["temp_path.cc"],
    hdrs = ["temp_path.h"],
    deps = [
        ":fs_util",
        ":posix_error",
        ":test_util",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/time",
        gtest,
    ],
)

cc_library(
    name = "test_util",
    testonly = 1,
    srcs = [
        "test_util.cc",
        "test_util_impl.cc",
        "test_util_runfiles.cc",
    ],
    hdrs = ["test_util.h"],
    defines = select_system(),
    deps = [
        ":fs_util",
        ":logging",
        ":posix_error",
        ":save_util",
        "@bazel_tools//tools/cpp/runfiles",
        "@com_google_absl//absl/base:core_headers",
        "@com_google_absl//absl/flags:flag",
        "@com_google_absl//absl/flags:parse",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
        "@com_google_absl//absl/time",
        gtest,
        gbenchmark,
    ],
)

cc_library(
    name = "thread_util",
    testonly = 1,
    hdrs = ["thread_util.h"],
    deps = [":logging"],
)

cc_library(
    name = "time_util",
    testonly = 1,
    srcs = ["time_util.cc"],
    hdrs = ["time_util.h"],
    deps = [
        "@com_google_absl//absl/time",
    ],
)

cc_library(
    name = "timer_util",
    testonly = 1,
    srcs = ["timer_util.cc"],
    hdrs = ["timer_util.h"],
    deps = [
        ":cleanup",
        ":logging",
        ":posix_error",
        ":test_util",
        "@com_google_absl//absl/time",
        gtest,
    ],
)

cc_test(
    name = "test_util_test",
    size = "small",
    srcs = ["test_util_test.cc"],
    deps = [
        ":test_main",
        ":test_util",
        gtest,
    ],
)

cc_library(
    name = "test_main",
    testonly = 1,
    srcs = ["test_main.cc"],
    deps = [":test_util"],
)

cc_library(
    name = "epoll_util",
    testonly = 1,
    srcs = ["epoll_util.cc"],
    hdrs = ["epoll_util.h"],
    deps = [
        ":file_descriptor",
        ":posix_error",
        ":save_util",
        gtest,
    ],
)

cc_library(
    name = "rlimit_util",
    testonly = 1,
    srcs = ["rlimit_util.cc"],
    hdrs = ["rlimit_util.h"],
    deps = [
        ":cleanup",
        ":logging",
        ":posix_error",
        ":test_util",
    ],
)

cc_library(
    name = "uid_util",
    testonly = 1,
    srcs = ["uid_util.cc"],
    hdrs = ["uid_util.h"],
    deps = [
        ":posix_error",
        ":save_util",
    ],
)

cc_library(
    name = "temp_umask",
    testonly = 1,
    hdrs = ["temp_umask.h"],
)