bazelbuild / migration-tooling

Migration tools for Bazel
Apache License 2.0
45 stars 30 forks source link

generate_workspace with `--artifact` arg sometimes results in duplicate exports in generated rules #15

Closed petroseskinder closed 7 years ago

petroseskinder commented 7 years ago

Migrated from issue 3089 in main repository.

Description of the problem

Sometimes the generate_workspace tool generates a BUILD file that fails to build, complaining about a duplicate export label.

e.g. the artifact io.grpc:grpc-protobuf:1.3.0 results in the error

Label '@io_grpc_grpc_protobuf//jar:jar' is duplicated in the 'exports' attribute of rule 'io_grpc_grpc_protobuf'.

If possible, provide a minimal example to reproduce the problem:

To reproduce this problem, first build the generate_workspace tool from the bazel repo (I built from tag 0.4.5 @ 037b9b9).

Then run (in an empty directory):

$ /path/to/generate_workspace -o $(pwd) --artifact io.grpc:grpc-protobuf:1.3.0
ERROR: Could not resolve dependency io.netty:netty-codec-http2:[4.1.3.Final]: Could not find any repositories that knew how to resolve io.netty:netty-codec-http2:[4.1.3.Final] (checked https://oss.sonatype.org/content/repositories/snapshots, https://repo1.maven.org/maven2/)
Wrote:
/Users/jguenther/Projects/tmp/WORKSPACE
/Users/jguenther/Projects/tmp/BUILD

(It looks like the Could not resolve dependency error has already been reported in #1794. We've been working around it by manually removing the square brackets in the version spec, which has worked for us so far)

Running bazel build now fails with the duplicate label error:

$ bazel build //...
ERROR: /Users/jguenther/Projects/tmp/BUILD:122:1: Label '@io_grpc_grpc_protobuf//jar:jar' is duplicated in the 'exports' attribute of rule 'io_grpc_grpc_protobuf'.
ERROR: package contains errors: .
ERROR: error loading package '': Package '' contains errors.
INFO: Elapsed time: 0.136s

And here is the relevant rule from the generated BUILD file:

java_library(
    name = "io_grpc_grpc_protobuf",
    visibility = ["//visibility:public"],
    exports = [
        "@io_grpc_grpc_protobuf//jar",  # here
        "@aopalliance_aopalliance//jar",
        "@com_google_api_api_common//jar",
        "@com_google_api_grpc_grpc_google_common_protos//jar",
        "@com_google_auth_google_auth_library_credentials//jar",
        "@com_google_auto_value_auto_value//jar",
        "@com_google_code_findbugs_jsr305//jar",
        "@com_google_code_gson_gson//jar",
        "@com_google_errorprone_error_prone_annotations//jar",
        "@com_google_guava_guava//jar",
        "@com_google_inject_guice//jar",
        "@com_google_instrumentation_instrumentation_api//jar",
        "@com_google_protobuf_nano_protobuf_javanano//jar",
        "@com_google_protobuf_protobuf_java//jar",
        "@com_google_protobuf_protobuf_java_util//jar",
        "@com_google_protobuf_protobuf_lite//jar",
        "@com_squareup_okhttp_okhttp//jar",
        "@com_squareup_okio_okio//jar",
        "@io_grpc_grpc_all//jar",
        "@io_grpc_grpc_auth//jar",
        "@io_grpc_grpc_context//jar",
        "@io_grpc_grpc_core//jar",
        "@io_grpc_grpc_netty//jar",
        "@io_grpc_grpc_okhttp//jar",
        "@io_grpc_grpc_protobuf//jar",  # and here
        "@io_grpc_grpc_protobuf_lite//jar",
        "@io_grpc_grpc_protobuf_nano//jar",
        "@io_grpc_grpc_stub//jar",
        "@javax_inject_javax_inject//jar",
        "@joda_time_joda_time//jar",
    ],
)

Environment info

Operating System: MacOS El Capitan 10.11.6

Bazel version (output of bazel info release): release 0.4.5-homebrew

(generate_workspace is not included in this distribution, so I built it from the 0.4.5 tag @ 037b9b9)

Have you found anything relevant by searching the web?

(e.g. StackOverflow answers, GitHub issues, email threads on the bazel-discuss Google group)

I looked but didn't find anything relevant to this issue.

Anything else, information or logs or outputs that would be helpful?

An archive of the generated BUILD and WORKSPACE files is attached

petroseskinder commented 7 years ago

There are two problems at hand here. First, the versioning issue with the brackets around the issue (handled in #1 ), and the second being the duplicate exports statements. The latter needs to be investigated.

kchodorow commented 7 years ago

Fixing the versioning in #1 seems to have resolved the duplicate entries as well. Please lmk if you see this again.