Skip to content

local_repository: external dependencies not resolved #2391

@davido

Description

@davido

It's related to #2224.

I'm trying a different approach. Instead of linking the Gerrit plugin into Gerrit tree, I'm trying to consume the Gerrit Plugin API through workspace rule local_repository from withing plugin. The difference between standalone build is to be able to consume unpublished plugin API (bleeding edge) from plugin. Without needing to build gerrit locally, and publish Gerrit plugin API to local Maven repository and consume the API over Maven.

So the situation is, I have two independent projects directories, without any symbolic linking between them:

  • /home/davido/projects/gerrit
  • /home/davido/projects/gerrit-oauth-provider

For this to work I extended the bazlets with this new gerrit_api_gerrit_local.bzl content to support this scenario: ``:

def gerrit_api_gerrit_local(path):
  native.local_repository(
    name = "gerrit",
    path = path,
  )
  native.bind(
    name = 'gerrit-plugin-api',
    actual = '@gerrit//gerrit-plugin-api:lib')
  native.bind(
    name = 'gerrit-plugin-gwtui',
    actual = '@gerrit//gerrit-plugin-gwtui:gwtui-api-lib')
  native.bind(
    name = 'gerrit-acceptance-framework',
    actual = '@gerrit//gerrit-acceptance-framework:lib')
  native.bind(
    name = 'gerrit-plugin-api-neverlink',
    actual = '@gerrit//gerrit-plugin-api:lib-neverlink')
  native.bind(
    name = 'gerrit-plugin-gwtui-neverlink',
    actual = '@gerrit//gerrit-plugin-gwtui:gwtui-api-lib-neverlink')
  # Neverlink is missing here, use regular library
  native.bind(
    name = 'gerrit-acceptance-framework-neverlink',
    actual = '@gerrit//gerrit-acceptance-framework:lib')

And invoke it from gerrit-oauth-provider plugin's, WORKSPACE file:

[...]
# In Gerrit tree build
load(
    "@com_googlesource_gerrit_bazlets//:gerrit_api_gerrit_local.bzl",
    "gerrit_api_gerrit_local",
)

gerrit_api_gerrit_local("/home/davido/projects/gerrit")

Now, trying to build the plugin and consume the plugin API from local_repository rule is failing to resolve external dependencies, defined in Gerrit plugin API definition:

davido@wizball:~/projects/gerrit-oauth-provider (master *%=)$ bazel build gerrit-oauth-provider --verbose_failures 
ERROR: /home/davido/.cache/bazel/_bazel_davido/f2ec7cf5b8dc484010bd5d650d1db155/external/gerrit/lib/guice/BUILD:12:1: no such package '@guice_library//jar': error loading package 'external': The repository named 'guice_library' could not be resolved and referenced by '@gerrit//lib/guice:guice_library'.
ERROR: Analysis of target '//:gerrit-oauth-provider' failed; build aborted.

Where guice_library//jar is defined in @gerrit//lib/guice as following in gerrit repository:

java_library(
    name = "guice_library",
    data = ["//lib:LICENSE-Apache2.0"],
    visibility = ["//visibility:public"],
    exports = ["@guice_library//jar"],
    runtime_deps = ["aopalliance"],
)

As workaround, I could paste the whole WORKSPACE content from gerrit repository to my plugin's WORKSPACE file, then it works:

$ bazel build gerrit-oauth-provider
INFO: Found 1 target...
INFO: From Building external/gerrit/gerrit-server/libserver.jar (1294 source files, 41 resources):
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Target //:gerrit-oauth-provider up-to-date:
  bazel-genfiles/gerrit-oauth-provider.jar
INFO: Elapsed time: 25.499s, Critical Path: 20.16s

But why is this needed? I'm consuming gerrit-plugin-api:lib artifact from local_repository rule from gerrit directory and @gerrit//gerrit-plugin-api:lib transitively depends on dozens of external packages in gerrit (!) repository, as can be seen with this query command

$ bazel query --noimplicit_deps "deps(@gerrit//gerrit-plugin-api:lib)" | grep -v "@gerrit" | sed 's#//.*##' | sed 's/@//' | sort | uniq
antlr27
aopalliance
args4j
automaton
auto_value
backward_codecs
bazel_tools
bcprov
blame_cache
commons_codec
commons_collections
commons_compress
commons_dbcp
commons_lang
commons_net
commons_oro
commons_pool
commons_validator
dropwizard_core
grappa
gson
guava
guava_retrying
guice_assistedinject
guice_library
guice_servlet
gwtjsonrpc
gwtorm_client
h2
httpclient
httpcore
icu4j
javaewah
java_runtime
javax_inject
jcl_over_slf4j
jgit
jgit_archive
jgit_servlet
jitescript
joda_convert
joda_time
jsch
jsonevent_layout
json_smart
jsoup
jsr305
juniversalchardet
log4j
log_api
lucene_analyzers_common
lucene_core
lucene_misc
lucene_queryparser
mime4j_core
mime4j_dom
mime_util
mina_core
multibindings
org_antlr
ow2_asm
ow2_asm_analysis
ow2_asm_commons
ow2_asm_tree
ow2_asm_util
pegdown
prolog_runtime
protobuf
servlet_api_3_1
soy
sshd
stringtemplate
tukaani_xz
velocity

Shouldn't Bazel realize, that those are comming from gerrit and be rellocated to it, instead of trying to locate them in my plugin's own WORKSPACE?

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3We're not considering working on this, but happy to review a PR. (No assignee)team-ExternalDepsExternal dependency handling, remote repositiories, WORKSPACE file.type: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions