################################################################################
# Protocol Buffers Compiler - Ruby code generator
################################################################################

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

cc_library(
    name = "ruby",
    srcs = [
        "rbs_generator.cc",
        "ruby_generator.cc",
    ],
    hdrs = [
        "rbs_generator.h",
        "ruby_generator.h",
    ],
    copts = COPTS,
    strip_include_prefix = "/src",
    visibility = [
        "//pkg:__pkg__",
        "//src/google/protobuf/compiler:__pkg__",
    ],
    deps = [
        "//src/google/protobuf",
        "//src/google/protobuf:port",
        "//src/google/protobuf/compiler:code_generator",
        "//src/google/protobuf/compiler:retention",
        "//src/google/protobuf/io",
        "//src/google/protobuf/io:printer",
        "@abseil-cpp//absl/container:flat_hash_map",
        "@abseil-cpp//absl/container:flat_hash_set",
        "@abseil-cpp//absl/log:absl_log",
        "@abseil-cpp//absl/strings",
    ],
)

cc_test(
    name = "generator_unittest",
    srcs = [
        "rbs_generator_unittest.cc",
        "ruby_generator_unittest.cc",
    ],
    data = [
        "ruby_generated_code.proto",
        "ruby_generated_code_pb.rb",
        "ruby_generated_code_pb.rbs",
        "ruby_generated_code_proto2.proto",
        "ruby_generated_code_proto2_import.proto",
        "ruby_generated_code_proto2_pb.rb",
        "ruby_generated_code_proto2_pb.rbs",
        "ruby_generated_pkg_explicit.proto",
        "ruby_generated_pkg_explicit_legacy.proto",
        "ruby_generated_pkg_explicit_legacy_pb.rb",
        "ruby_generated_pkg_explicit_legacy_pb.rbs",
        "ruby_generated_pkg_explicit_pb.rb",
        "ruby_generated_pkg_explicit_pb.rbs",
        "ruby_generated_pkg_implicit.proto",
        "ruby_generated_pkg_implicit_pb.rb",
        "ruby_generated_pkg_implicit_pb.rbs",
        "//src/google/protobuf:testdata",
    ],
    deps = [
        ":ruby",
        "//src/google/protobuf/compiler:command_line_interface",
        "//src/google/protobuf/io",
        "//src/google/protobuf/io:printer",
        "//src/google/protobuf/testing",
        "//src/google/protobuf/testing:file",
        "@googletest//:gtest",
        "@googletest//:gtest_main",
    ],
)

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

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