Refactor of the OSGI bazel rules
- renamed the .bzl file to match the accepted snake case naming standard
- removed an uneccesary veneer method inside the rule implementation
Change-Id: I1e0f5aecf1d4b7b73e7376c1bb4c296960aaa5fc
diff --git a/protocols/p4runtime/proto/BUILD b/protocols/p4runtime/proto/BUILD
index 73c65b0..2f5e7fd 100644
--- a/protocols/p4runtime/proto/BUILD
+++ b/protocols/p4runtime/proto/BUILD
@@ -4,14 +4,14 @@
deps = ["@p4lang_pi//:p4_runtime_proto"],
)
-wrapped_osgi_library(
+wrapped_osgi_jar(
name = "rpc_java_proto-osgi",
jar = "@google_rpc//:rpc_java_proto",
visibility = ["//visibility:public"],
deps = CORE_DEPS + ["@protobuf_java_3_2_0//jar"],
)
-wrapped_osgi_library(
+wrapped_osgi_jar(
name = "p4_runtime_java_proto-osgi",
jar = ":p4_runtime_java_proto",
visibility = ["//visibility:public"],
diff --git a/tools/build/bazel/osgi-java-library.bzl b/tools/build/bazel/osgi_java_library.bzl
similarity index 87%
rename from tools/build/bazel/osgi-java-library.bzl
rename to tools/build/bazel/osgi_java_library.bzl
index 274ed25..de8c28c 100644
--- a/tools/build/bazel/osgi-java-library.bzl
+++ b/tools/build/bazel/osgi_java_library.bzl
@@ -18,16 +18,16 @@
load("//tools/build/bazel:variables.bzl", "ONOS_VERSION")
load("//tools/build/bazel:generate_test_rules.bzl", "generate_test_rules")
-def all_java_sources():
+def _all_java_sources():
return native.glob(["src/main/java/**/*.java"])
-def all_java_test_sources():
+def _all_java_test_sources():
return native.glob(["src/test/java/**/*.java"])
-def all_test_resources():
+def _all_test_resources():
return native.glob(["src/test/resources/**"])
-def all_resources(resources_root):
+def _all_resources(resources_root):
if resources_root == None:
return native.glob(["src/main/resources/**"])
else:
@@ -110,7 +110,7 @@
executable = ctx.executable._bnd_exe,
)
-bnd = rule(
+_bnd = rule(
attrs = {
"deps": attr.label_list(),
"version": attr.string(),
@@ -130,11 +130,8 @@
implementation = _bnd_impl,
)
-def _fwd_bnd(name, source, deps, version, package_name_root, visibility):
- bnd(name = name, source = source, deps = deps, version = version, package_name_root = package_name_root, visibility = visibility)
-
-def wrapped_osgi_library(name, jar, deps, version = ONOS_VERSION, package_name_root = "org.onosproject", visibility = ["//visibility:private"]):
- _fwd_bnd(name, jar, deps, version, package_name_root, visibility)
+def wrapped_osgi_jar(name, jar, deps, version = ONOS_VERSION, package_name_root = "org.onosproject", visibility = ["//visibility:private"]):
+ _bnd(name = name, source = jar, deps = deps, version = version, package_name_root = package_name_root, visibility = visibility)
def osgi_jar_with_tests(
name = None,
@@ -152,13 +149,13 @@
if name == None:
name = "onos-" + native.package_name().replace("/", "-")
if srcs == None:
- srcs = all_java_sources()
+ srcs = _all_java_sources()
if resources == None:
- resources = all_resources(resources_root)
+ resources = _all_resources(resources_root)
if test_srcs == None:
- test_srcs = all_java_test_sources()
+ test_srcs = _all_java_test_sources()
if test_resources == None:
- test_resources = all_test_resources()
+ test_resources = _all_test_resources()
if exclude_tests == None:
exclude_tests = []
if deps == None:
@@ -170,7 +167,14 @@
all_test_deps = tests_jar_deps + [tests_name]
native.java_library(name = name, srcs = srcs, resources = resources, deps = deps, visibility = visibility)
- _fwd_bnd(name + "-osgi", name, deps, version, package_name_root, visibility)
+ _bnd(
+ name = name + "-osgi",
+ source = name,
+ deps = deps,
+ version = version,
+ package_name_root = package_name_root,
+ visibility = visibility,
+ )
if test_srcs != []:
native.java_library(
name = tests_name,
@@ -197,7 +201,7 @@
visibility = ["//visibility:public"],
version = ONOS_VERSION):
if srcs == None:
- srcs = all_java_sources()
+ srcs = _all_java_sources()
if deps == None:
deps = COMPILE
diff --git a/tools/build_rules/prelude_bazel b/tools/build_rules/prelude_bazel
index abdd0db..6114082 100644
--- a/tools/build_rules/prelude_bazel
+++ b/tools/build_rules/prelude_bazel
@@ -2,7 +2,7 @@
"generated_java_libraries", "COMPILE", "CORE_DEPS", "JACKSON",
"TEST_ADAPTERS", "TEST", "TEST_REST", "METRICS", "KRYO", "NETTY", "GRPC_1_3")
-load("//tools/build/bazel:osgi-java-library.bzl", "osgi_jar_with_tests", "osgi_jar", "wrapped_osgi_library")
+load("//tools/build/bazel:osgi_java_library.bzl", "osgi_jar_with_tests", "osgi_jar", "wrapped_osgi_jar")
load("//tools/build/bazel:osgi_features.bzl", "osgi_feature")
generated_java_libraries()