################################################################################
# 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 = ["ruby_generator.cc"],
    hdrs = ["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",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log:absl_log",
        "@com_google_absl//absl/strings",
    ],
)

cc_test(
    name = "generator_unittest",
    srcs = ["ruby_generator_unittest.cc"],
    data = [
        "ruby_generated_code.proto",
        "ruby_generated_code_pb.rb",
        "ruby_generated_code_proto2.proto",
        "ruby_generated_code_proto2_import.proto",
        "ruby_generated_code_proto2_pb.rb",
        "ruby_generated_pkg_explicit.proto",
        "ruby_generated_pkg_explicit_legacy.proto",
        "ruby_generated_pkg_explicit_legacy_pb.rb",
        "ruby_generated_pkg_explicit_pb.rb",
        "ruby_generated_pkg_implicit.proto",
        "ruby_generated_pkg_implicit_pb.rb",
        "//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",
        "@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",
        ],
        allow_empty = True,
    ),
    visibility = ["//src/google/protobuf/compiler:__pkg__"],
)
