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
This commit is contained in:
David Ostrovsky 2019-08-30 10:19:56 +02:00
parent efc0fe6f77
commit 20c2fd4f0b
82 changed files with 155 additions and 16 deletions

View File

@ -67,6 +67,18 @@ load("@bazel_skylib//lib:versions.bzl", "versions")
versions.check(minimum_bazel_version = "0.29.0")
# Rules Python
http_archive(
name = "rules_python",
sha256 = "b5bab4c47e863e0fbb77df4a40c45ca85f98f5a2826939181585644c9f31b97b",
strip_prefix = "rules_python-9d68f24659e8ce8b736590ba1e4418af06ec2552",
urls = ["https://github.com/bazelbuild/rules_python/archive/9d68f24659e8ce8b736590ba1e4418af06ec2552.tar.gz"],
)
load("@rules_python//python:repositories.bzl", "py_repositories")
py_repositories()
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_repositories")
# Prevent redundant loading of dependencies.

View File

@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "java_binary")
load("//tools/bzl:java.bzl", "java_library2")
load("//tools/bzl:javadoc.bzl", "java_doc")

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")
java_library(
name = "lib",
testonly = 1,

View File

@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "java_library")
load("//gerrit-acceptance-tests:tests.bzl", "acceptance_tests")
acceptance_tests(

View File

@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "java_library")
load("//gerrit-acceptance-tests:tests.bzl", "acceptance_tests")
[acceptance_tests(

View File

@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "java_library")
load("//gerrit-acceptance-tests:tests.bzl", "acceptance_tests")
acceptance_tests(

View File

@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "java_library")
load("//gerrit-acceptance-tests:tests.bzl", "acceptance_tests")
acceptance_tests(

View File

@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "java_library")
load("//gerrit-acceptance-tests:tests.bzl", "acceptance_tests")
SUBMIT_UTIL_SRCS = glob(["AbstractSubmit*.java"])

View File

@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "java_library")
load("//gerrit-acceptance-tests:tests.bzl", "acceptance_tests")
acceptance_tests(

View File

@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "java_library")
load("//gerrit-acceptance-tests:tests.bzl", "acceptance_tests")
DEPS = [

View File

@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "java_library")
load("//gerrit-acceptance-tests:tests.bzl", "acceptance_tests")
java_library(

View File

@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "java_library")
load("//tools/bzl:genrule2.bzl", "genrule2")
java_library(

View File

@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "java_library")
load("//tools/bzl:junit.bzl", "junit_tests")
java_library(

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")
java_library(
name = "mem",
srcs = glob(["src/main/java/**/*.java"]),

View File

@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "java_library")
load("//tools/bzl:gwt.bzl", "gwt_module")
load("//tools/bzl:junit.bzl", "junit_tests")

View File

@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "java_library")
load("//tools/bzl:junit.bzl", "junit_tests")
java_library(

View File

@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "java_binary", "java_library")
load("//lib/jgit:jgit.bzl", "JGIT_DOC_URL")
load("//lib:guava.bzl", "GUAVA_DOC_URL")
load("//tools/bzl:gwt.bzl", "gwt_module")

View File

@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "java_library")
load("//tools/bzl:junit.bzl", "junit_tests")
DEPS = [

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")
java_library(
name = "gwtdebug",
srcs = glob(["src/main/java/**/*.java"]),

View File

@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "java_library")
load("//tools/bzl:gwt.bzl", "gwt_module")
load("//tools/bzl:junit.bzl", "junit_tests")

View File

@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "java_library")
load("//tools/bzl:gwt.bzl", "gwt_module")
load("//tools/bzl:java.bzl", "java_library2")
load("//tools/bzl:junit.bzl", "junit_tests")

View File

@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "java_library")
load("//tools/bzl:junit.bzl", "junit_tests")
package(default_visibility = ["//visibility:public"])

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")
# NOTE: GerritLauncher must be a single, self-contained class. Do not add any
# additional srcs or deps to this rule.
java_library(

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")
QUERY_BUILDER = [
"src/main/java/com/google/gerrit/lucene/QueryBuilder.java",
]

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_binary", "java_library")
java_binary(
name = "main_bin",
main_class = "Main",

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")
SRCS = glob(
["src/main/java/**/*.java"],
)

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")
java_library(
name = "openid",
srcs = glob(["src/main/java/**/*.java"]),

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")
java_library(
name = "commons-net",
srcs = glob(["src/main/java/org/apache/commons/net/**/*.java"]),

View File

@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "java_library", "java_test")
load("//tools/bzl:genrule2.bzl", "genrule2")
load("//tools/bzl:gwt.bzl", "gwt_module")

View File

@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "java_library")
load("//tools/bzl:junit.bzl", "junit_tests")
load("//tools/bzl:license.bzl", "license_test")

View File

@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "java_binary", "java_library")
load("//tools/bzl:javadoc.bzl", "java_doc")
PLUGIN_API = [

View File

@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "java_binary")
load("//tools/bzl:java.bzl", "java_library2")
load("//tools/bzl:javadoc.bzl", "java_doc")

View File

@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "java_library")
load("//tools/bzl:gwt.bzl", "gwt_module")
SRC = "src/main/java/com/google/gerrit/prettify/"

View File

@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "java_library")
load("//tools/bzl:gwt.bzl", "gwt_module")
load("//tools/bzl:junit.bzl", "junit_tests")

View File

@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "java_library")
load("//tools/bzl:javadoc.bzl", "java_doc")
load("//tools/bzl:junit.bzl", "junit_tests")

View File

@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "java_library")
load("//tools/bzl:junit.bzl", "junit_tests")
SRCS = glob(["src/main/java/**/*.java"])

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")
java_library(
name = "test_util",
testonly = 1,

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")
java_library(
name = "cli",
srcs = glob(["src/main/java/**/*.java"]),

View File

@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "java_library")
load("//tools/bzl:junit.bzl", "junit_tests")
java_library(

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")
java_library(
name = "ssl",
srcs = glob(["src/main/java/**/*.java"]),

View File

@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "java_import", "java_library")
load("//tools/bzl:genrule2.bzl", "genrule2")
java_library(

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")
exports_files(glob([
"LICENSE-*",
]))

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_binary", "java_library")
[java_library(
name = n,
data = ["//lib:LICENSE-antlr"],

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_binary", "java_library")
java_binary(
name = "asciidoc",
main_class = "AsciiDoctor",

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library", "java_plugin")
java_plugin(
name = "auto-annotation-plugin",
processor_class = "com.google.auto.value.processor.AutoAnnotationProcessor",

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")
java_library(
name = "bcprov",
data = ["//lib:LICENSE-bouncycastle"],

View File

@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "java_import", "java_library")
load("//lib/codemirror:cm.bzl", "pkg_cm")
# This library is only used to insert a license statement into
@ -9,3 +10,17 @@ java_library(
)
pkg_cm()
LICENSE = "//lib:LICENSE-codemirror-original"
LICENSE_MINIFIED = "//lib:LICENSE-codemirror-minified"
[java_import(
name = "codemirror" + suffix,
data = [license],
jars = [":jar%s" % suffix],
visibility = ["//visibility:public"],
) for suffix, license in [
("", LICENSE),
("_r", LICENSE_MINIFIED),
]]

View File

@ -362,10 +362,3 @@ def pkg_cm():
],
outs = ["codemirror%s.jar" % suffix],
)
native.java_import(
name = "codemirror" + suffix,
jars = [":jar%s" % suffix],
visibility = ["//visibility:public"],
data = [license],
)

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")
package(default_visibility = ["//visibility:public"])
java_library(

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")
java_library(
name = "dropwizard-core",
data = ["//lib:LICENSE-Apache2.0"],

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")
java_library(
name = "easymock",
data = ["//lib:LICENSE-DO_NOT_DISTRIBUTE"],

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")
package(default_visibility = ["//visibility:public"])
java_library(

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")
package(default_visibility = ["//visibility:public"])
java_library(

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")
java_library(
name = "guice",
data = ["//lib:LICENSE-Apache2.0"],

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")
[java_library(
name = n,
data = ["//lib:LICENSE-Apache2.0"],

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")
package(default_visibility = ["//visibility:public"])
java_library(

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")
java_library(
name = "jackson-core",
data = ["//lib:LICENSE-Apache2.0"],

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")
java_library(
name = "servlet",
data = ["//lib:LICENSE-Apache2.0"],

View File

@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "java_library")
load("//lib/jgit:jgit.bzl", "jgit_dep")
java_library(

View File

@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "java_library")
load("//lib/jgit:jgit.bzl", "jgit_dep")
java_library(

View File

@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "java_library")
load("//lib/jgit:jgit.bzl", "jgit_dep")
java_library(

View File

@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "java_library")
load("//lib/jgit:jgit.bzl", "jgit_dep")
java_library(

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")
java_library(
name = "joda-time",
data = ["//lib:LICENSE-Apache2.0"],

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")
java_library(
name = "jsoup",
data = ["//lib:LICENSE-jsoup"],

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")
java_library(
name = "api",
data = ["//lib:LICENSE-slf4j"],

View File

@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "java_library")
load("//tools/bzl:maven.bzl", "merge_maven_jars")
package(default_visibility = ["//visibility:public"])

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")
java_library(
name = "mail",
data = ["//lib:LICENSE-DO_NOT_DISTRIBUTE"],

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")
java_library(
name = "core",
data = ["//lib:LICENSE-Apache2.0"],

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")
java_library(
name = "sshd",
data = ["//lib:LICENSE-Apache2.0"],

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")
java_library(
name = "consumer",
data = ["//lib:LICENSE-Apache2.0"],

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")
java_library(
name = "ow2-asm",
data = ["//lib:LICENSE-ow2"],

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")
java_library(
name = "powermock-module-junit4",
data = ["//lib:LICENSE-DO_NOT_DISTRIBUTE"],

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_binary", "java_library")
java_library(
name = "runtime",
data = ["//lib:LICENSE-prologcafe"],

View File

@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
load("@rules_java//java:defs.bzl", "java_library")
load("//tools/bzl:genrule2.bzl", "genrule2")
def prolog_cafe_library(
@ -28,7 +29,7 @@ def prolog_cafe_library(
tools = ["//lib/prolog:compiler-bin"],
outs = [name + ".srcjar"],
)
native.java_library(
java_library(
name = name,
srcs = [":" + name + "__pl2j"],
deps = ["//lib/prolog:runtime-neverlink"] + deps,

View File

@ -1,3 +1,5 @@
load("@rules_java//java:defs.bzl", "java_library")
java_library(
name = "duct-tape",
testonly = True,

@ -1 +1 @@
Subproject commit 4a1755eb46f65a812c99a0c552095f4322fc08a3
Subproject commit ae3fdcd6df46a6b5076c2860b2a76ea3f0cee4a9

View File

@ -1,3 +1,5 @@
load("@rules_python//python:defs.bzl", "py_binary")
load("@rules_java//java:defs.bzl", "java_package_configuration")
load(
"@bazel_tools//tools/jdk:default_java_toolchain.bzl",
"JDK9_JVM_OPTS",

View File

@ -15,11 +15,13 @@
# Syntactic sugar for native java_library() rule:
# accept exported_deps attributes
load("@rules_java//java:defs.bzl", "java_library")
def java_library2(deps = [], exported_deps = [], exports = [], **kwargs):
if exported_deps:
deps = deps + exported_deps
exports = exports + exported_deps
native.java_library(
java_library(
deps = deps,
exports = exports,
**kwargs

View File

@ -18,6 +18,8 @@
# See https://github.com/bazelbuild/bazel/issues/1017 for background.
load("@rules_java//java:defs.bzl", "java_test")
_OUTPUT = """import org.junit.runners.Suite;
import org.junit.runner.RunWith;
@ -71,7 +73,7 @@ def junit_tests(name, srcs, **kwargs):
srcs = srcs,
outname = s_name,
)
native.java_test(
java_test(
name = name,
test_class = s_name,
srcs = srcs + [":" + s_name],

View File

@ -14,6 +14,8 @@
# Merge maven files
load("@rules_java//java:defs.bzl", "java_import")
def cmd(jars):
return ("$(location //tools:merge_jars) $@ " +
" ".join(["$(location %s)" % j for j in jars]))
@ -25,7 +27,7 @@ def merge_maven_jars(name, srcs, **kwargs):
tools = srcs + ["//tools:merge_jars"],
outs = ["%s__merged.jar" % name],
)
native.java_import(
java_import(
name = name,
jars = [":%s__merged_bin" % name],
**kwargs

View File

@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "java_binary", "java_library")
load("//tools/bzl:genrule2.bzl", "genrule2")
load(
"//tools/bzl:gwt.bzl",
@ -30,7 +31,7 @@ def gerrit_plugin(
manifest_entries = [],
target_suffix = "",
**kwargs):
native.java_library(
java_library(
name = name + "__plugin",
srcs = srcs,
resources = resources,
@ -42,8 +43,7 @@ def gerrit_plugin(
static_jars = []
if gwt_module:
static_jars = [":%s-static" % name]
native.java_binary(
java_binary(
name = "%s__non_stamped" % name,
deploy_manifest_lines = manifest_entries + ["Gerrit-ApiType: plugin"],
main_class = "Dummy",
@ -55,7 +55,7 @@ def gerrit_plugin(
)
if gwt_module:
native.java_library(
java_library(
name = name + "__gwt_module",
resources = depset(srcs + resources).to_list(),
runtime_deps = deps + GWT_PLUGIN_DEPS,

View File

@ -1,3 +1,4 @@
load("@rules_java//java:defs.bzl", "java_library")
load("//tools/bzl:classpath.bzl", "classpath_collector")
load("//tools/bzl:pkg_war.bzl", "LIBS", "PGMLIBS")
load(