Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flipping of --incompatible_no_transitive_loads bit broke standalone plugin build mode in Gerrit Code Review #8334

Closed
davido opened this issue May 15, 2019 · 2 comments

Comments

@davido
Copy link
Contributor

davido commented May 15, 2019

It turns out that flipping of --incompatible_no_transitive_loads in #5636 broke standalone build mode for plugins in Gerrit Code Review. Issue upstream: https://bugs.chromium.org/p/gerrit/issues/detail?id=10855.

We use bazlets repository to expose gerrit_plugin.bzl Skylark rule, store in bazlets//gerrit_plugin.bzl.

In Gerrit core, we use a different (native) implementation of gerrit_plugin.bzl stored in gerrit//tools/bzl/plugin.bzl.

In the plugin's BUILD file we say something like this:

load("//tools/bzl:junit.bzl", "junit_tests")
load(
    "//tools/bzl:plugin.bzl",
    "PLUGIN_DEPS",
    "PLUGIN_TEST_DEPS",
    "gerrit_plugin",
)

gerrit_plugin(
    name = "reviewers",
    srcs = glob(["src/main/java/**/*.java"]),
    manifest_entries = [
        "Gerrit-PluginName: reviewers",
        "Gerrit-Module: com.googlesource.gerrit.plugins.reviewers.Module",
    ],
    resources = glob(["src/main/resources/**/*"]),
)

[...]

This plugin can be built in two build modes with Bazel:

  1. Standalone build mode, by loading bazlets repository from github or local directory, by doing this from the WORKSPACE:
$ cat WORKSPACE 
workspace(name = "admin_console")

load("//:bazlets.bzl", "load_bazlets")

load_bazlets(
    commit = "298b25cf8c5ef0f27caa215cbc128e530f68d9f4",
    local_path = "/home/davido/projects/bazlets",
)

# Release Plugin API
load(
    "@com_googlesource_gerrit_bazlets//:gerrit_api.bzl",
    "gerrit_api",
)

# Load release Plugin API
gerrit_api()

Where bazlets.bzl is defined as follow:

$ cat bazlets.bzl 
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

NAME = "com_googlesource_gerrit_bazlets"

def load_bazlets(
        commit,
        local_path = None):
    if not local_path:
        git_repository(
            name = NAME,
            remote = "https://gerrit.googlesource.com/bazlets",
            commit = commit,
        )
    else:
        native.local_repository(
            name = NAME,
            path = local_path,
        )

But for this we need the transitive loading feature, because //tools/bzl:plugin.bzl is defined as follow in plugin workspace:

load(
    "@com_googlesource_gerrit_bazlets//:gerrit_plugin.bzl",
    "PLUGIN_DEPS",
    "PLUGIN_TEST_DEPS",
    "gerrit_plugin",
)

This is needed, because in gerrit workspace plugin Skylark is defined in tools/bzl/plugin.bzl. What we want to achieve is that we can drop the above plugin in gerrit workspace in plugins directory and it would just work, until Bazel 0.25.

After migrating to 0.25 the above setting is broken, with:

$ bazel build :admin-console 
ERROR: /home/davido/projects/admin-console/BUILD:1:1: file '//tools/bzl:plugin.bzl' does not contain symbol 'gerrit_plugin'
ERROR: /home/davido/projects/admin-console/BUILD:3:1: name 'gerrit_plugin' is not defined
ERROR: Skipping ':admin-console': no such target '//:admin-console': target 'admin-console' not declared in package '' defined by /home/davido/projects/admin-console/BUILD
WARNING: Target pattern parsing failed.
ERROR: no such target '//:admin-console': target 'admin-console' not declared in package '' defined by /home/davido/projects/admin-console/BUILD
INFO: Elapsed time: 0.090s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded)

Workaround is to use --incompatible_no_transitive_loads=false:

$ bazel build --incompatible_no_transitive_loads=false admin-console
INFO: Analyzed target //:admin-console (19 packages loaded, 483 targets configured).
INFO: Found 1 target...
Target //:admin-console up-to-date:
  bazel-bin/admin-console.jar
INFO: Elapsed time: 14.027s, Critical Path: 2.60s
INFO: 2 processes: 1 linux-sandbox, 1 worker.
INFO: Build completed successfully, 3 total actions
@hanwen
Copy link
Contributor

hanwen commented May 17, 2019

@davido
Copy link
Contributor Author

davido commented May 17, 2019

Thanks!

@davido davido closed this as completed May 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants