load("//:java_grpc_library.bzl", "java_grpc_library")

java_library(
    name = "alts_internal",
    srcs = glob([
        "src/main/java/io/grpc/alts/internal/*.java",
    ]),
    deps = [
        ":handshaker_java_grpc",
        ":handshaker_java_proto",
        "//core",
        "//core:internal",
        "//netty",
        "//stub",
        "@com_google_code_findbugs_jsr305//jar",
        "@com_google_guava_guava//jar",
        "@com_google_protobuf//:protobuf_java",
        "@com_google_protobuf//:protobuf_java_util",
        "@io_netty_netty_buffer//jar",
        "@io_netty_netty_codec//jar",
        "@io_netty_netty_common//jar",
        "@io_netty_netty_handler//jar",
        "@io_netty_netty_transport//jar",
    ],
)

java_library(
    name = "alts",
    srcs = glob([
        "src/main/java/io/grpc/alts/*.java",
    ]),
    visibility = ["//visibility:public"],
    runtime_deps = ["//grpclb"],
    deps = [
        ":alts_internal",
        ":handshaker_java_grpc",
        "//core",
        "//core:internal",
        "//auth",
        "//netty",
        "@com_google_auth_google_auth_library_oauth2_http//jar",
        "@com_google_code_findbugs_jsr305//jar",
        "@com_google_guava_guava//jar",
        "@io_netty_netty_common//jar",
        "@io_netty_netty_handler//jar",
        "@io_netty_netty_transport//jar",
        "@org_apache_commons_commons_lang3//jar",
    ],
)

# bazel only accepts proto import with absolute path.
genrule(
    name = "protobuf_imports",
    srcs = glob(["src/main/proto/grpc/gcp/*.proto"]),
    outs = [
        "protobuf_out/grpc/gcp/altscontext.proto",
        "protobuf_out/grpc/gcp/handshaker.proto",
        "protobuf_out/grpc/gcp/transport_security_common.proto",
    ],
    cmd = "for fname in $(SRCS); do " +
          "sed 's,import \",import \"alts/protobuf_out/,g' $$fname > " +
          "$(@D)/protobuf_out/grpc/gcp/$$(basename $$fname); done",
)

proto_library(
    name = "handshaker_proto",
    srcs = [
        "protobuf_out/grpc/gcp/altscontext.proto",
        "protobuf_out/grpc/gcp/handshaker.proto",
        "protobuf_out/grpc/gcp/transport_security_common.proto",
    ],
)

java_proto_library(
    name = "handshaker_java_proto",
    deps = [":handshaker_proto"],
)

java_grpc_library(
    name = "handshaker_java_grpc",
    srcs = [":handshaker_proto"],
    deps = [":handshaker_java_proto"],
)