bazeltools / bazel-deps

Generate bazel dependencies for maven artifacts
MIT License
249 stars 121 forks source link

--disable-3rdparty-in-repo sometimes generates empty BUILD files for Kotlin deps #290

Open pbsf opened 4 years ago

pbsf commented 4 years ago

I have the following dependencies.yaml:

options:
  buildHeader: [ "load(\"@io_bazel_rules_kotlin//kotlin:kotlin.bzl\", \"kt_jvm_import\")",
    "licenses([\"notice\"])" ]
  languages: [ "kotlin" ]
  resolverType: "coursier"
  resolvers:
    - id: "mavencentral"
      type: "default"
      url: https://repo.maven.apache.org/maven2/
  thirdPartyDirectory: "3rdparty"

dependencies:
  com.github.ajalt:
    clikt:
      lang: kotlin
      version: "2.3.0"

And the following WORKSPACE:

workspace(name = "project")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# ----------------------------------------------------------------------------
# Kotlin.

rules_kotlin_version = "legacy-1.3.0-rc4"
rules_kotlin_sha = "fe32ced5273bcc2f9e41cea65a28a9184a77f3bc30fea8a5c47b3d3bfc801dff"
http_archive(
    name = "io_bazel_rules_kotlin",
    urls = [
        "https://github.com/bazelbuild/rules_kotlin/archive/%s.zip" % rules_kotlin_version,
    ],
    strip_prefix = "rules_kotlin-%s" % rules_kotlin_version,
    sha256 = rules_kotlin_sha,
)

load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains")

kotlin_repositories()
kt_register_toolchains()

# ----------------------------------------------------------------------------
# Bazel-deps.

load("//3rdparty:workspace.bzl", "maven_dependencies")
maven_dependencies()

load("//3rdparty:target_file.bzl", "build_external_workspace")
build_external_workspace(name = "3rdparty")

I modified update_dependencies.sh to receive --disable-3rdparty-in-repo as a flag.

The following works:

./update_dependencies.sh
bazel build //3rdparty/com/github/ajalt:clikt

The following doesn't:

./update_dependencies.sh --disable-3rdparty-in-repo
bazel build @3rdparty//3rdparty/com/github/ajalt:clikt

Here is the error message:

ERROR: no such target '@3rdparty//3rdparty/com/github/ajalt:clikt': target 'clikt' not declared in package '3rdparty/com/github/ajalt' defined by /root/.cache/bazel/_bazel_root/a254c33c1cf4cabb64a59c0bfb96da7c/external/3rdparty/3rdparty/com/github/ajalt/BUILD

Here is the content of the generated BUILD file on the second attempt:

 $ cat  /root/.cache/bazel/_bazel_root/a254c33c1cf4cabb64a59c0bfb96da7c/external/3rdparty/3rdparty/com/github/ajalt/BUILD
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_import")
licenses(["notice"])

I did succeed importing some Kotlin dependencies disabling the 3rd party folders, but not this one, which is weird. Is the second command incorrect? I can create a repository that reproduces the issue if that helps.