Files
gerrit/tools/bzl/plugin.bzl
David Ostrovsky 20c2fd4f0b Bazel: Add fixes for --incompatible_load_{java|python}_rules_from_bzl
This change is fixing "All Java build rules should be loaded from
Starlark" warning flagged by latest buildifier version: [1]. Python
rules are now also loaded from the Starlark.

Also extract codemirror library import to BUILD file. This is needed to
avoid cycle in the workspace file, after importing java rules from
Starlark.

[1] https://github.com/bazelbuild/buildtools/blob/master/WARNINGS.md#native-java

Change-Id: I36192c9465d988b25cf09c250e110f15850910cd
2019-09-02 00:42:25 +02:00

101 lines
3.2 KiB
Python

load("@rules_java//java:defs.bzl", "java_binary", "java_library")
load("//tools/bzl:genrule2.bzl", "genrule2")
load(
"//tools/bzl:gwt.bzl",
"GWT_COMPILER_ARGS",
"GWT_JVM_ARGS",
"GWT_PLUGIN_DEPS_NEVERLINK",
"GWT_TRANSITIVE_DEPS",
"gwt_binary",
_gwt_plugin_deps = "GWT_PLUGIN_DEPS",
)
GWT_PLUGIN_DEPS = _gwt_plugin_deps
PLUGIN_DEPS = ["//gerrit-plugin-api:lib"]
PLUGIN_DEPS_NEVERLINK = ["//gerrit-plugin-api:lib-neverlink"]
PLUGIN_TEST_DEPS = [
"//gerrit-acceptance-framework:lib",
"//lib/bouncycastle:bcpg",
"//lib/bouncycastle:bcpkix",
"//lib/bouncycastle:bcprov",
]
def gerrit_plugin(
name,
deps = [],
provided_deps = [],
srcs = [],
gwt_module = [],
resources = [],
manifest_entries = [],
target_suffix = "",
**kwargs):
java_library(
name = name + "__plugin",
srcs = srcs,
resources = resources,
deps = provided_deps + deps + GWT_PLUGIN_DEPS_NEVERLINK + PLUGIN_DEPS_NEVERLINK,
visibility = ["//visibility:public"],
**kwargs
)
static_jars = []
if gwt_module:
static_jars = [":%s-static" % name]
java_binary(
name = "%s__non_stamped" % name,
deploy_manifest_lines = manifest_entries + ["Gerrit-ApiType: plugin"],
main_class = "Dummy",
runtime_deps = [
":%s__plugin" % name,
] + static_jars,
visibility = ["//visibility:public"],
**kwargs
)
if gwt_module:
java_library(
name = name + "__gwt_module",
resources = depset(srcs + resources).to_list(),
runtime_deps = deps + GWT_PLUGIN_DEPS,
visibility = ["//visibility:public"],
**kwargs
)
genrule2(
name = "%s-static" % name,
cmd = " && ".join([
"mkdir -p $$TMP/static",
"unzip -qd $$TMP/static $(location %s__gwt_application)" % name,
"cd $$TMP",
"zip -qr $$ROOT/$@ .",
]),
tools = [":%s__gwt_application" % name],
outs = ["%s-static.jar" % name],
)
gwt_binary(
name = name + "__gwt_application",
module = [gwt_module],
deps = GWT_PLUGIN_DEPS + GWT_TRANSITIVE_DEPS + ["//lib/gwt:dev"],
module_deps = [":%s__gwt_module" % name],
compiler_args = GWT_COMPILER_ARGS,
jvm_args = GWT_JVM_ARGS,
)
# TODO(davido): Remove manual merge of manifest file when this feature
# request is implemented: https://github.com/bazelbuild/bazel/issues/2009
genrule2(
name = name + target_suffix,
stamp = 1,
srcs = ["%s__non_stamped_deploy.jar" % name],
cmd = " && ".join([
"GEN_VERSION=$$(cat bazel-out/stable-status.txt | grep -w STABLE_BUILD_%s_LABEL | cut -d ' ' -f 2)" % name.upper(),
"cd $$TMP",
"unzip -q $$ROOT/$<",
"echo \"Implementation-Version: $$GEN_VERSION\n$$(cat META-INF/MANIFEST.MF)\" > META-INF/MANIFEST.MF",
"zip -qr $$ROOT/$@ .",
]),
outs = ["%s%s.jar" % (name, target_suffix)],
visibility = ["//visibility:public"],
)