################################################################################
# Protocol Buffers Compiler - ObjC code generator
################################################################################

load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("//build_defs:cpp_opts.bzl", "COPTS")

cc_library(
    name = "names",
    hdrs = ["names.h"],
    copts = COPTS,
    include_prefix = "google/protobuf/compiler/objectivec",
    visibility = ["//visibility:public"],
    deps = [
        ":names_internal",
    ],
)

cc_library(
    name = "names_internal",
    hdrs = [
        "names.h",
        "nsobject_methods.h",
    ],
    srcs = [
        "names.cc",
    ],
    copts = COPTS,
    include_prefix = "google/protobuf/compiler/objectivec",
    visibility = ["//pkg:__pkg__"],
    deps = [
        ":line_consumer",
        "//src/google/protobuf/compiler:code_generator",
        "//src/google/protobuf:protobuf_nowkt",
    ],
)

cc_library(
    name = "line_consumer",
    hdrs = ["line_consumer.h"],
    srcs = ["line_consumer.cc"],
    copts = COPTS,
    include_prefix = "google/protobuf/compiler/objectivec",
    visibility = ["//pkg:__pkg__"],
    deps = [
        "//src/google/protobuf/compiler:code_generator",
        "//src/google/protobuf:protobuf_nowkt",
    ],
)

cc_library(
    name = "objectivec",
    srcs = [
        "enum.cc",
        "enum_field.cc",
        "extension.cc",
        "field.cc",
        "file.cc",
        "generator.cc",
        "helpers.cc",
        "import_writer.cc",
        "map_field.cc",
        "message.cc",
        "message_field.cc",
        "oneof.cc",
        "primitive_field.cc",
        "text_format_decode_data.cc",
    ],
    hdrs = [
        "enum.h",
        "enum_field.h",
        "extension.h",
        "field.h",
        "file.h",
        "generator.h",
        "helpers.h",
        "import_writer.h",
        "map_field.h",
        "message.h",
        "message_field.h",
        "oneof.h",
        "options.h",
        "primitive_field.h",
        "text_format_decode_data.h",
    ],
    copts = COPTS,
    include_prefix = "google/protobuf/compiler/objectivec",
    visibility = [
        "//pkg:__pkg__",
        "//src/google/protobuf/compiler:__pkg__",
    ],
    deps = [
        ":line_consumer",
        ":names",
        "//src/google/protobuf:protobuf_nowkt",
        "//src/google/protobuf/compiler:code_generator",
        "@com_google_absl//absl/strings",
    ],
)

cc_test(
    name = "line_consumer_unittest",
    srcs = ["line_consumer_unittest.cc"],
    deps = [
        ":line_consumer",
        "//src/google/protobuf/io",
        "@com_google_googletest//:gtest",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "names_unittest",
    srcs = ["names_unittest.cc"],
    deps = [
        ":names",
        "//src/google/protobuf/io",
        "@com_google_googletest//:gtest",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "text_format_decode_data_unittest",
    srcs = ["text_format_decode_data_unittest.cc"],
    deps = [
        ":objectivec",
        "@com_google_googletest//:gtest",
        "@com_google_googletest//:gtest_main",
    ],
)

################################################################################
# Distribution packaging
################################################################################

pkg_files(
    name = "dist_files",
    srcs = glob(["**/*"]),
    strip_prefix = strip_prefix.from_root(""),
    visibility = ["//src:__pkg__"],
)

filegroup(
    name = "test_srcs",
    srcs = glob([
        "*_test.cc",
        "*unittest.cc",
    ]),
    visibility = ["//src/google/protobuf/compiler:__pkg__"],
)
