load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("//build_defs:internal_shell.bzl", "inline_sh_test")
load("//:protobuf.bzl", "internal_ruby_proto_library")

filegroup(
  name = "tests",
  srcs = glob(["tests/*.rb"]),
)

filegroup(
  name = "test_protos",
  srcs = glob(["tests/*.proto"]),
)

internal_ruby_proto_library(
    name = "test_ruby_protos",
    srcs = [":test_protos"],
    includes = ["."],
)

inline_sh_test(
    name = "test",
    srcs = [
        "Rakefile",
    ],
    deps = [
        ":test_ruby_protos",
        ":tests",
        "//:well_known_ruby_protos",
        "//ruby:protobuf",
    ],
    cmd = """
        pushd `dirname $(location Rakefile)`
        RUBYLIB=.:tests:../../lib:../../../src BAZEL=true rake test
        popd
    """,
)

################################################################################
# Distribution files
############################################################################

pkg_files(
    name = "dist_files",
    srcs = glob([
        "**/*.rb",
        "**/*.proto"
    ]) + [
        "BUILD.bazel",
        "Rakefile",
        "README.md",
        "test.sh",
    ],
    strip_prefix = strip_prefix.from_root(""),
    visibility = ["//pkg:__pkg__"],
)
