Add bazel rule to run buildifier; fix up formatting problems in bazel files
Change-Id: Ifa8ab12ed564fa2eaf5edd781281aa5cae52d17a
diff --git a/BUILD b/BUILD
index 16f97da..16ee973 100644
--- a/BUILD
+++ b/BUILD
@@ -94,3 +94,15 @@
output_to_bindir = True,
visibility = ["//visibility:public"],
)
+
+load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier")
+
+buildifier(
+ name = "buildifier_check",
+ mode = "check",
+)
+
+buildifier(
+ name = "buildifier_fix",
+ mode = "fix",
+)
diff --git a/WORKSPACE b/WORKSPACE
index 989b02c..d827270 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -1,28 +1,29 @@
workspace(name = "org_onosproject_onos")
load("//tools/build/bazel:bazel_version.bzl", "check_bazel_version")
+
check_bazel_version()
load("//tools/build/bazel:generate_workspace.bzl", "generated_maven_jars")
+
generated_maven_jars()
load("//tools/build/bazel:protobuf_workspace.bzl", "generate_protobuf")
+
generate_protobuf()
load("//tools/build/bazel:grpc_workspace.bzl", "generate_grpc")
+
generate_grpc()
load("@io_grpc_grpc_java//:repositories.bzl", "grpc_java_repositories")
-grpc_java_repositories(
- omit_javax_annotation = False,
+grpc_java_repositories(
omit_com_google_api_grpc_google_common_protos = True,
- omit_com_google_errorprone_error_prone_annotations = True,
omit_com_google_auth_google_auth_library_credentials = True,
- omit_io_opencensus_api = True,
- omit_io_opencensus_grpc_metrics = True,
omit_com_google_code_findbugs_jsr305 = True,
omit_com_google_code_gson = True,
+ omit_com_google_errorprone_error_prone_annotations = True,
omit_com_google_guava = True,
omit_com_google_protobuf = True,
omit_com_google_protobuf_javalite = True,
@@ -32,31 +33,59 @@
omit_com_squareup_okhttp = True,
omit_com_squareup_okio = True,
omit_io_netty_buffer = True,
- omit_io_netty_common = True,
- omit_io_netty_transport = True,
omit_io_netty_codec = True,
- omit_io_netty_codec_socks = True,
omit_io_netty_codec_http = True,
omit_io_netty_codec_http2 = True,
+ omit_io_netty_codec_socks = True,
+ omit_io_netty_common = True,
omit_io_netty_handler = True,
omit_io_netty_handler_proxy = True,
omit_io_netty_resolver = True,
omit_io_netty_tcnative_boringssl_static = True,
+ omit_io_netty_transport = True,
+ omit_io_opencensus_api = True,
+ omit_io_opencensus_grpc_metrics = True,
+ omit_javax_annotation = False,
omit_junit_junit = True,
- omit_org_apache_commons_lang3 = True
+ omit_org_apache_commons_lang3 = True,
)
load("//tools/build/bazel:p4lang_workspace.bzl", "generate_p4lang")
-generate_p4lang()
+generate_p4lang()
git_repository(
name = "build_bazel_rules_nodejs",
remote = "https://github.com/bazelbuild/rules_nodejs.git",
- tag = "0.10.0", # check for the latest tag when you install
+ tag = "0.10.0", # check for the latest tag when you install
)
load("@build_bazel_rules_nodejs//:defs.bzl", "node_repositories")
+
node_repositories(package_json = ["//tools/gui:package.json"])
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
+
+# buildifier is written in Go and hence needs rules_go to be built.
+# See https://github.com/bazelbuild/rules_go for the up to date setup instructions.
+http_archive(
+ name = "io_bazel_rules_go",
+ url = "https://github.com/bazelbuild/rules_go/releases/download/0.14.0/rules_go-0.14.0.tar.gz",
+)
+
+http_archive(
+ name = "com_github_bazelbuild_buildtools",
+ strip_prefix = "buildtools-a90c3a9f00e27973d3e759d17f2e2e7d9702d91b",
+ url = "https://github.com/bazelbuild/buildtools/archive/a90c3a9f00e27973d3e759d17f2e2e7d9702d91b.zip",
+)
+
+load("@io_bazel_rules_go//go:def.bzl", "go_register_toolchains", "go_rules_dependencies")
+load("@com_github_bazelbuild_buildtools//buildifier:deps.bzl", "buildifier_dependencies")
+
+go_rules_dependencies()
+
+go_register_toolchains()
+
+buildifier_dependencies()
+
ONOS_VERSION = "1.14.0-SNAPSHOT"
diff --git a/apps/openstacknode/openstack4j.bzl b/apps/openstacknode/openstack4j.bzl
index fc68a41..096b700 100644
--- a/apps/openstacknode/openstack4j.bzl
+++ b/apps/openstacknode/openstack4j.bzl
@@ -3,39 +3,37 @@
ALL_PACKAGES = "*"
def get_openstack4j_deps_path():
-
- WEB_INF_PATH = 'WEB-INF/classes/deps/'
+ WEB_INF_PATH = "WEB-INF/classes/deps/"
OPENSTACK4J_DEPS = [
- 'openstack4j-core',
- 'openstack4j-http-connector',
- 'openstack4j-httpclient',
+ "openstack4j-core",
+ "openstack4j-http-connector",
+ "openstack4j-httpclient",
]
- OPENSTACK4J_VER = '3.1.0'
+ OPENSTACK4J_VER = "3.1.0"
- openstack_deps_path = ''
+ openstack_deps_path = ""
for dep in OPENSTACK4J_DEPS:
- name = dep + '-' + OPENSTACK4J_VER + '.jar'
+ name = dep + "-" + OPENSTACK4J_VER + ".jar"
path = WEB_INF_PATH + name
- openstack_deps_path = openstack_deps_path + path + ','
+ openstack_deps_path = openstack_deps_path + path + ","
return openstack_deps_path
def get_jackson_deps_path():
-
- WEB_INF_PATH = 'WEB-INF/classes/deps/'
+ WEB_INF_PATH = "WEB-INF/classes/deps/"
JACKSON_DEPS_WITH_VER = [
- 'json-patch-1.9.jar',
- 'jackson-coreutils-1.6.jar',
- 'msg-simple-1.1.jar',
- 'btf-1.2.jar',
- 'snakeyaml-1.15.jar'
+ "json-patch-1.9.jar",
+ "jackson-coreutils-1.6.jar",
+ "msg-simple-1.1.jar",
+ "btf-1.2.jar",
+ "snakeyaml-1.15.jar",
]
- jackson_deps_path = ''
+ jackson_deps_path = ""
for dep in JACKSON_DEPS_WITH_VER:
path = WEB_INF_PATH + dep
- jackson_deps_path = jackson_deps_path + path + ','
+ jackson_deps_path = jackson_deps_path + path + ","
- return jackson_deps_path
\ No newline at end of file
+ return jackson_deps_path
diff --git a/tools/build/bazel/bazel_version.bzl b/tools/build/bazel/bazel_version.bzl
index 4aa4b1c..cd175b0 100644
--- a/tools/build/bazel/bazel_version.bzl
+++ b/tools/build/bazel/bazel_version.bzl
@@ -15,12 +15,12 @@
"""
def check_bazel_version():
- if "bazel_version" not in dir(native):
- fail("\nBazel version is too old; please use 0.15.* official release!\n\n")
- elif not native.bazel_version:
- print("\nBazel is not a release version; please use 0.15.* official release!\n\n")
- return
+ if "bazel_version" not in dir(native):
+ fail("\nBazel version is too old; please use 0.15.* official release!\n\n")
+ elif not native.bazel_version:
+ print("\nBazel is not a release version; please use 0.15.* official release!\n\n")
+ return
- if not native.bazel_version.startswith("0.15."):
- fail("\nBazel version %s is not supported; please use 0.15.* official release!\n\n"
- % native.bazel_version)
+ if not native.bazel_version.startswith("0.15."):
+ fail("\nBazel version %s is not supported; please use 0.15.* official release!\n\n" %
+ native.bazel_version)
diff --git a/tools/build/bazel/checkstyle.bzl b/tools/build/bazel/checkstyle.bzl
index 92d3adb..bd8eeb1 100644
--- a/tools/build/bazel/checkstyle.bzl
+++ b/tools/build/bazel/checkstyle.bzl
@@ -14,10 +14,10 @@
limitations under the License.
"""
-
"""
Implementation of the rule to call checkstyle
"""
+
def _checkstyle_impl(ctx):
classpath = ""
need_colon = False
@@ -28,9 +28,10 @@
classpath += file.path
cmd = " ".join(
- ["java -cp %s com.puppycrawl.tools.checkstyle.Main" % classpath] +
- ["-c %s" % ctx.attr._config.files.to_list()[0].path] +
- [src_file.path for src_file in ctx.files.srcs])
+ ["java -cp %s com.puppycrawl.tools.checkstyle.Main" % classpath] +
+ ["-c %s" % ctx.attr._config.files.to_list()[0].path] +
+ [src_file.path for src_file in ctx.files.srcs],
+ )
ctx.actions.write(
output = ctx.outputs.executable,
@@ -46,28 +47,26 @@
runfiles = ctx.runfiles(files = inputs)
return [DefaultInfo(runfiles = runfiles)]
-
"""
Rule definition for calling checkstyle
"""
_execute_checkstyle_test = rule(
test = True,
attrs = {
- "_classpath": attr.label_list(default=[
- Label("@checkstyle//jar"),
- Label("@commons_beanutils//jar"),
- Label("@commons_cli//jar"),
- Label("@commons_collections//jar"),
- Label("@antlr//jar"),
- Label("@com_google_guava_guava//jar"),
- Label("@commons_logging//jar"),
- ]),
+ "_classpath": attr.label_list(default = [
+ Label("@checkstyle//jar"),
+ Label("@commons_beanutils//jar"),
+ Label("@commons_cli//jar"),
+ Label("@commons_collections//jar"),
+ Label("@antlr//jar"),
+ Label("@com_google_guava_guava//jar"),
+ Label("@commons_logging//jar"),
+ ]),
"srcs": attr.label_list(allow_files = FileType([".java"])),
- "_config": attr.label(default=Label("//tools/build/conf:checkstyle_xml")),
- "_suppressions": attr.label(default=Label("//tools/build/conf:suppressions_xml")),
- "_java_header": attr.label(default=Label("//tools/build/conf:onos_java_header")),
+ "_config": attr.label(default = Label("//tools/build/conf:checkstyle_xml")),
+ "_suppressions": attr.label(default = Label("//tools/build/conf:suppressions_xml")),
+ "_java_header": attr.label(default = Label("//tools/build/conf:onos_java_header")),
},
-
implementation = _checkstyle_impl,
)
@@ -79,7 +78,6 @@
srcs: list of source file targets to run checkstyle on. Required.
size: test size constraint. Optional, defaults to "small"
"""
+
def checkstyle_test(name, srcs):
_execute_checkstyle_test(name = name, srcs = srcs, size = "small")
-
-
diff --git a/tools/build/bazel/generate_workspace.bzl b/tools/build/bazel/generate_workspace.bzl
index afc9768..8d2f855 100644
--- a/tools/build/bazel/generate_workspace.bzl
+++ b/tools/build/bazel/generate_workspace.bzl
@@ -2709,4 +2709,3 @@
if type(label) == "string":
return "mvn:%s:%s:%s" % (ONOS_GROUP_ID, label_string, ONOS_VERSION)
return "mvn:%s:%s:%s" % (ONOS_GROUP_ID, label.name, ONOS_VERSION)
-
diff --git a/tools/build/bazel/grpc_workspace.bzl b/tools/build/bazel/grpc_workspace.bzl
index 72b5769..a14b1a5 100644
--- a/tools/build/bazel/grpc_workspace.bzl
+++ b/tools/build/bazel/grpc_workspace.bzl
@@ -14,11 +14,12 @@
sha256 = GRPC_SHA,
strip_prefix = "grpc-java-%s-patched" % GRPC_VER,
)
+
# Google APIs protos (status.proto, etc.)
http_archive(
name = "com_github_googleapis",
urls = ["https://github.com/googleapis/googleapis/archive/%s.zip" % GAPIS_COMMIT],
sha256 = GAPIS_SHA,
strip_prefix = "googleapis-" + GAPIS_COMMIT,
- build_file = "//tools/build/bazel:googleapis_BUILD"
+ build_file = "//tools/build/bazel:googleapis_BUILD",
)
diff --git a/tools/build/bazel/java_sources.bzl b/tools/build/bazel/java_sources.bzl
index 734d048..a45ae60 100644
--- a/tools/build/bazel/java_sources.bzl
+++ b/tools/build/bazel/java_sources.bzl
@@ -13,25 +13,25 @@
# limitations under the License.
def _impl(ctx):
- jar = ctx.outputs.jar
+ jar = ctx.outputs.jar
- src_list = ""
- for src in ctx.files.srcs:
- if src.path.endswith(".srcjar"):
- src_list += " " + src.path
+ src_list = ""
+ for src in ctx.files.srcs:
+ if src.path.endswith(".srcjar"):
+ src_list += " " + src.path
- cmd = [
- "for sj in %s; do jar xf $sj; done" % src_list,
- "dir=$(find . -type d -name java)",
- "[ -n \"$dir\" -a -d \"$dir\" ] && jar cf %s -C $dir ." % jar.path,
- ]
+ cmd = [
+ "for sj in %s; do jar xf $sj; done" % src_list,
+ "dir=$(find . -type d -name java)",
+ "[ -n \"$dir\" -a -d \"$dir\" ] && jar cf %s -C $dir ." % jar.path,
+ ]
- ctx.action(
- inputs = ctx.files.srcs,
- outputs = [jar],
- progress_message = "Generating source jar for %s" % ctx.attr.name,
- command = ";\n".join(cmd)
- )
+ ctx.action(
+ inputs = ctx.files.srcs,
+ outputs = [jar],
+ progress_message = "Generating source jar for %s" % ctx.attr.name,
+ command = ";\n".join(cmd),
+ )
def _impl_alt(ctx):
ending = "-src.jar"
@@ -46,15 +46,15 @@
out_file = ctx.actions.declare_file(prefix + ".srcjar")
out_files.append(out_file)
if len(src_files) == 0:
- fail("None of the given input files is a valid source jar (%s)"
- % ", ".join([s.path for s in ctx.files.srcs]))
+ fail("None of the given input files is a valid source jar (%s)" %
+ ", ".join([s.path for s in ctx.files.srcs]))
for i in range(len(src_files)):
cmd = "cp %s %s" % (src_files[i].path, out_files[i].path)
ctx.actions.run_shell(
inputs = [src_files[i]],
outputs = [out_files[i]],
- progress_message = "Generating source jar %s" % out_files[i].basename,
- command = cmd
+ progress_message = "Generating source jar %s" % out_files[i].basename,
+ command = cmd,
)
return DefaultInfo(files = depset(out_files))
@@ -70,7 +70,7 @@
"srcs": attr.label_list(allow_files = True),
},
implementation = _impl,
- outputs = {"jar" : "%{name}.jar"},
+ outputs = {"jar": "%{name}.jar"},
)
"""
diff --git a/tools/build/bazel/javadoc.bzl b/tools/build/bazel/javadoc.bzl
index e073426..87e5592 100644
--- a/tools/build/bazel/javadoc.bzl
+++ b/tools/build/bazel/javadoc.bzl
@@ -12,33 +12,33 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-JAVA_DOCS="-link https://docs.oracle.com/javase/8/docs/api/"
+JAVA_DOCS = "-link https://docs.oracle.com/javase/8/docs/api/"
def _impl(ctx):
- dir = ctx.label.name
- jar = ctx.outputs.jar
+ dir = ctx.label.name
+ jar = ctx.outputs.jar
- dep_list = []
- for dep in ctx.files.deps:
- dep_list += [dep.path]
+ dep_list = []
+ for dep in ctx.files.deps:
+ dep_list += [dep.path]
- src_list = []
- for src in ctx.files.srcs:
- src_list += [src.path]
+ src_list = []
+ for src in ctx.files.srcs:
+ src_list += [src.path]
- cmd = [
- "mkdir %s" % dir,
- "javadoc -encoding UTF-8 -quiet -tag onos.rsModel:a:\"onos model\" %s -d %s -cp %s %s" \
- % (JAVA_DOCS, dir, ":".join(dep_list), " ".join(src_list)),
- "jar cf %s -C %s ." % (jar.path, dir),
- ]
+ cmd = [
+ "mkdir %s" % dir,
+ "javadoc -encoding UTF-8 -quiet -tag onos.rsModel:a:\"onos model\" %s -d %s -cp %s %s" %
+ (JAVA_DOCS, dir, ":".join(dep_list), " ".join(src_list)),
+ "jar cf %s -C %s ." % (jar.path, dir),
+ ]
- ctx.action(
- inputs = ctx.files.srcs + ctx.files.deps,
- outputs = [jar],
- progress_message = "Generating javadocs jar for %s" % ctx.attr.name,
- command = ";\n".join(cmd)
- )
+ ctx.action(
+ inputs = ctx.files.srcs + ctx.files.deps,
+ outputs = [jar],
+ progress_message = "Generating javadocs jar for %s" % ctx.attr.name,
+ command = ";\n".join(cmd),
+ )
javadoc = rule(
attrs = {
@@ -46,6 +46,5 @@
"srcs": attr.label_list(allow_files = True),
},
implementation = _impl,
- outputs = {"jar" : "%{name}.jar"},
+ outputs = {"jar": "%{name}.jar"},
)
-
diff --git a/tools/build/bazel/onos_app.bzl b/tools/build/bazel/onos_app.bzl
index c5563b1..6bf8df3 100644
--- a/tools/build/bazel/onos_app.bzl
+++ b/tools/build/bazel/onos_app.bzl
@@ -60,14 +60,22 @@
def _onos_app_xml_impl(ctx):
# Build-up arguments for the app.xml and feature.xml generator
arguments = [
- "-n", ctx.attr.feature_coords,
- "-a", ctx.attr.app_name,
- "-o", ctx.attr.origin,
- "-c", ctx.attr.category,
- "-u", ctx.attr.url,
- "-v", ctx.attr.version,
- "-t", ctx.attr.title,
- "-D", ctx.attr.description,
+ "-n",
+ ctx.attr.feature_coords,
+ "-a",
+ ctx.attr.app_name,
+ "-o",
+ ctx.attr.origin,
+ "-c",
+ ctx.attr.category,
+ "-u",
+ ctx.attr.url,
+ "-v",
+ ctx.attr.version,
+ "-t",
+ ctx.attr.title,
+ "-D",
+ ctx.attr.description,
]
for bundle in ctx.attr.included_bundles:
@@ -83,7 +91,7 @@
ctx.actions.run(
inputs = [],
outputs = [ctx.outputs.app_xml],
- arguments = arguments + [ "-A", "-O", ctx.outputs.app_xml.path ],
+ arguments = arguments + ["-A", "-O", ctx.outputs.app_xml.path],
progress_message = "Generating app.xml descriptor for app: %s" % ctx.attr.name,
executable = ctx.executable._onos_app_tools,
)
@@ -92,12 +100,18 @@
def _onos_feature_xml_impl(ctx):
# Build-up arguments
arguments = [
- "-n", ctx.attr.feature_coords,
- "-a", ctx.attr.app_name,
- "-u", ctx.attr.url,
- "-v", ctx.attr.version,
- "-t", ctx.attr.title,
- "-D", ctx.attr.description,
+ "-n",
+ ctx.attr.feature_coords,
+ "-a",
+ ctx.attr.app_name,
+ "-u",
+ ctx.attr.url,
+ "-v",
+ ctx.attr.version,
+ "-t",
+ ctx.attr.title,
+ "-D",
+ ctx.attr.description,
]
for bundle in ctx.attr.included_bundles:
@@ -108,12 +122,11 @@
ctx.actions.run(
inputs = [],
outputs = [ctx.outputs.feature_xml],
- arguments = arguments + [ "-F", "-O", ctx.outputs.feature_xml.path ],
+ arguments = arguments + ["-F", "-O", ctx.outputs.feature_xml.path],
progress_message = "Generating feature.xml for app: %s" % ctx.attr.name,
executable = ctx.executable._onos_app_tools,
)
-
# Rule to generate the ONOS app OAR file.
_onos_oar = rule(
attrs = {
@@ -269,7 +282,7 @@
required_apps = required_apps,
)
- # Generate feature.xml file
+ # Generate feature.xml file
_onos_feature_xml(
name = name + "-feature-xml",
app_name = app_name,
diff --git a/tools/build/bazel/osgi_java_library.bzl b/tools/build/bazel/osgi_java_library.bzl
index 43873a4..b2505a4 100644
--- a/tools/build/bazel/osgi_java_library.bzl
+++ b/tools/build/bazel/osgi_java_library.bzl
@@ -443,15 +443,27 @@
native_srcs = srcs + [name + "_swagger_java"]
native_resources.append(name + "_swagger_json")
- javacopts = [ "-XepDisableAllChecks" ] if suppress_errorprone else []
+ javacopts = ["-XepDisableAllChecks"] if suppress_errorprone else []
# compile the Java code
if len(resource_jars) > 0:
- native.java_library(name = name + "-native", srcs = native_srcs, resource_jars = resource_jars,
- deps = deps, visibility = visibility, javacopts = javacopts)
+ native.java_library(
+ name = name + "-native",
+ srcs = native_srcs,
+ resource_jars = resource_jars,
+ deps = deps,
+ visibility = visibility,
+ javacopts = javacopts,
+ )
else:
- native.java_library(name = name + "-native", srcs = native_srcs, resources = native_resources,
- deps = deps, visibility = visibility, javacopts = javacopts)
+ native.java_library(
+ name = name + "-native",
+ srcs = native_srcs,
+ resources = native_resources,
+ deps = deps,
+ visibility = visibility,
+ javacopts = javacopts,
+ )
_bnd(
name = name,
@@ -472,11 +484,11 @@
# rule for building source jar
if not suppress_javadocs:
- java_sources(name = name + "-sources", srcs = srcs, visibility = visibility)
+ java_sources(name = name + "-sources", srcs = srcs, visibility = visibility)
# rule for building javadocs
if not suppress_javadocs:
- javadoc(name = name + "-javadoc", deps = deps, srcs = srcs, visibility = visibility)
+ javadoc(name = name + "-javadoc", deps = deps, srcs = srcs, visibility = visibility)
if test_srcs != []:
native.java_library(
@@ -579,7 +591,6 @@
bundle_classpath = bundle_classpath,
)
-
"""
Creates an OSGI jar file from a set of protobuf and gRPC libraries.
@@ -621,8 +632,7 @@
deps = [],
group = "org.onosproject",
visibility = ["//visibility:public"],
- version = ONOS_VERSION
- ):
+ version = ONOS_VERSION):
if name == None:
name = _auto_name()
native.java_proto_library(
@@ -646,7 +656,7 @@
deps = [":%s-java-proto" % name],
)
osgi_srcs.append(
- ":%s-java-grpc__do_not_reference__srcjar" % name
+ ":%s-java-grpc__do_not_reference__srcjar" % name,
)
base_deps.extend([
"@com_google_guava_guava//jar",
diff --git a/tools/build/bazel/p4lang_workspace.bzl b/tools/build/bazel/p4lang_workspace.bzl
index abf4c5c..d4d966c 100644
--- a/tools/build/bazel/p4lang_workspace.bzl
+++ b/tools/build/bazel/p4lang_workspace.bzl
@@ -12,13 +12,14 @@
urls = ["https://github.com/p4lang/p4runtime/archive/%s.zip" % P4RUNTIME_COMMIT],
sha256 = P4RUNTIME_SHA,
strip_prefix = "p4runtime-%s/proto" % P4RUNTIME_COMMIT,
- build_file = "//tools/build/bazel:p4runtime_BUILD"
+ build_file = "//tools/build/bazel:p4runtime_BUILD",
)
+
# Needed for PI/proto/p4/tmp/p4config.proto
http_archive(
name = "com_github_p4lang_pi",
urls = ["https://github.com/p4lang/PI/archive/%s.zip" % PI_COMMIT],
sha256 = PI_SHA,
strip_prefix = "PI-%s/proto" % PI_COMMIT,
- build_file = "//tools/build/bazel:pi_BUILD"
+ build_file = "//tools/build/bazel:pi_BUILD",
)
diff --git a/tools/build/bazel/pom_file.bzl b/tools/build/bazel/pom_file.bzl
index 792d35a..e3c5689 100644
--- a/tools/build/bazel/pom_file.bzl
+++ b/tools/build/bazel/pom_file.bzl
@@ -15,21 +15,21 @@
load("//tools/build/bazel:generate_workspace.bzl", "maven_coordinates")
def _impl(ctx):
- arguments = [
- ctx.outputs.pom.path,
- maven_coordinates(ctx.attr.artifact)
- ]
+ arguments = [
+ ctx.outputs.pom.path,
+ maven_coordinates(ctx.attr.artifact),
+ ]
- for dep in ctx.attr.deps:
- arguments += [ maven_coordinates(dep.label) ]
+ for dep in ctx.attr.deps:
+ arguments += [maven_coordinates(dep.label)]
- ctx.actions.run(
- inputs = ctx.files.deps,
- outputs = [ctx.outputs.pom],
- progress_message = "Generating pom file for %s" % ctx.attr.name,
- arguments = arguments,
- executable = ctx.executable._pom_generator,
- )
+ ctx.actions.run(
+ inputs = ctx.files.deps,
+ outputs = [ctx.outputs.pom],
+ progress_message = "Generating pom file for %s" % ctx.attr.name,
+ arguments = arguments,
+ executable = ctx.executable._pom_generator,
+ )
pom_file = rule(
attrs = {
@@ -40,9 +40,8 @@
cfg = "host",
allow_files = True,
default = Label("//tools/build/bazel:pom_generator"),
- )
+ ),
},
implementation = _impl,
- outputs = {"pom" : "%{name}.pom"},
+ outputs = {"pom": "%{name}.pom"},
)
-
diff --git a/tools/build/bazel/project_javadoc.bzl b/tools/build/bazel/project_javadoc.bzl
index 86b61d5..171b846 100644
--- a/tools/build/bazel/project_javadoc.bzl
+++ b/tools/build/bazel/project_javadoc.bzl
@@ -12,10 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-JAVA_DOCS="-link https://docs.oracle.com/javase/8/docs/api/"
+JAVA_DOCS = "-link https://docs.oracle.com/javase/8/docs/api/"
def dump(obj):
- print (dir(obj))
+ print(dir(obj))
for attr in dir(obj):
print("obj.%s = %r" % (attr, getattr(obj, attr)))
@@ -54,8 +54,8 @@
cmd += ["find src -type f | egrep -v 'src/(OSGI|WEB)-INF' | egrep -v '/(impl|internal)/' >> FILES"]
cmd += [
- "javadoc -encoding UTF-8 -overview overview.html -doctitle '%s' -windowtitle '%s' %s -d apidocs -classpath %s -sourcepath src %s @FILES" \
- % (ctx.attr.title, ctx.attr.title, group_list, classpath.replace(":", "", 1), JAVA_DOCS),
+ "javadoc -encoding UTF-8 -overview overview.html -doctitle '%s' -windowtitle '%s' %s -d apidocs -classpath %s -sourcepath src %s @FILES" %
+ (ctx.attr.title, ctx.attr.title, group_list, classpath.replace(":", "", 1), JAVA_DOCS),
"cp -r doc-files apidocs/doc-files",
"jar cf %s apidocs" % jar.path,
]
@@ -63,8 +63,8 @@
ctx.action(
inputs = ctx.files.srcs + ctx.files.deps,
outputs = [jar],
- progress_message = "Generating javadocs jar for %s" % ctx.attr.name,
- command = ";\n".join(cmd)
+ progress_message = "Generating javadocs jar for %s" % ctx.attr.name,
+ command = ";\n".join(cmd),
)
project_javadoc = rule(
@@ -77,6 +77,5 @@
"internal": attr.bool(default = False),
},
implementation = _impl,
- outputs = {"jar" : "%{name}.jar"},
+ outputs = {"jar": "%{name}.jar"},
)
-
diff --git a/tools/build/bazel/protobuf_workspace.bzl b/tools/build/bazel/protobuf_workspace.bzl
index 1932b57..4a65eab 100644
--- a/tools/build/bazel/protobuf_workspace.bzl
+++ b/tools/build/bazel/protobuf_workspace.bzl
@@ -6,8 +6,8 @@
def generate_protobuf():
http_archive(
name = "com_google_protobuf",
- urls = ["https://github.com/google/protobuf/releases/download/v%s/protobuf-all-%s.zip"
- % (PROTOBUF_VER, PROTOBUF_VER)],
+ urls = ["https://github.com/google/protobuf/releases/download/v%s/protobuf-all-%s.zip" %
+ (PROTOBUF_VER, PROTOBUF_VER)],
sha256 = SHA,
strip_prefix = "protobuf-" + PROTOBUF_VER,
)
diff --git a/tools/build/bazel/publish_catalog.bzl b/tools/build/bazel/publish_catalog.bzl
index ef277e8..edf9569 100644
--- a/tools/build/bazel/publish_catalog.bzl
+++ b/tools/build/bazel/publish_catalog.bzl
@@ -8,7 +8,7 @@
def _remote(group_id, artifact_id, version, packaging, classifier):
p = group_id.replace(".", "/") + "/" + artifact_id + "/" + version + "/" + artifact_id + "-" + version
if classifier != None:
- p += "-" + classifier
+ p += "-" + classifier
p += "." + packaging
return p
@@ -26,15 +26,15 @@
c = artifact_id.split("-")
- if len(c) > 1 and c[len(c)-1] in ("javadoc", "sources", "tests", "pom"):
- classifier = c[len(c)-1]
- artifact_id = "-".join(c[:len(c)-1])
+ if len(c) > 1 and c[len(c) - 1] in ("javadoc", "sources", "tests", "pom"):
+ classifier = c[len(c) - 1]
+ artifact_id = "-".join(c[:len(c) - 1])
if classifier == "pom":
packaging = classifier
classifier = None
for f in target.files:
- print ("%s\t%s" % (f.path, _remote(group_id, artifact_id, version, packaging, classifier)))
+ print("%s\t%s" % (f.path, _remote(group_id, artifact_id, version, packaging, classifier)))
return []
publish_catalog = aspect(
diff --git a/tools/build/bazel/yang.bzl b/tools/build/bazel/yang.bzl
index 3b123b2..93b619c 100644
--- a/tools/build/bazel/yang.bzl
+++ b/tools/build/bazel/yang.bzl
@@ -85,13 +85,12 @@
outputs = [ctx.outputs.schema],
arguments = [
ctx.outputs.schema.path,
- generated_sources.path
+ generated_sources.path,
],
command = "jar cf $1 -C $2 schema",
progress_message = "Assembling YANG compiled schema: %s" % ctx.attr.name,
)
-
# Rule to generate YANG library from the specified set of YANG models.
_yang_library = rule(
attrs = {
@@ -114,13 +113,12 @@
)
def yang_library(
- name = None,
- deps = None,
- yang_srcs = None,
- java_srcs = None,
- custom_registrator = False,
- visibility = ["//visibility:public"]):
-
+ name = None,
+ deps = None,
+ yang_srcs = None,
+ java_srcs = None,
+ custom_registrator = False,
+ visibility = ["//visibility:public"]):
if name == None:
name = "onos-" + native.package_name().replace("/", "-")
if yang_srcs == None:
@@ -132,7 +130,7 @@
deps += CORE_DEPS + ONOS_YANG + [
"@onos_yang_runtime//jar",
- "//apps/yang:onos-apps-yang"
+ "//apps/yang:onos-apps-yang",
]
# Generate the Java sources from YANG model
@@ -146,7 +144,7 @@
name = name + "-srcjar",
srcs = java_srcs,
outs = [name + ".srcjar"],
- cmd = "jar cf $(location %s.srcjar) $(SRCS)" % name
+ cmd = "jar cf $(location %s.srcjar) $(SRCS)" % name,
)
if not custom_registrator:
@@ -154,38 +152,44 @@
native.genrule(
name = name + "-registrator",
outs = [REGISTRATOR_FILE],
- cmd = "echo '%s' > $(location %s)" % (REGISTRATOR, REGISTRATOR_FILE)
+ cmd = "echo '%s' > $(location %s)" % (REGISTRATOR, REGISTRATOR_FILE),
)
# Produce a Java library from the generated Java sources
- osgi_jar(name = name, srcs = srcs,
- resource_jars = [name + "-generate"], deps = deps,
- visibility = ["//visibility:public"],
- suppress_errorprone = True,
- suppress_checkstyle = True,
- suppress_javadocs = True,
+ osgi_jar(
+ name = name,
+ srcs = srcs,
+ resource_jars = [name + "-generate"],
+ deps = deps,
+ visibility = ["//visibility:public"],
+ suppress_errorprone = True,
+ suppress_checkstyle = True,
+ suppress_javadocs = True,
)
def yang_model(
- name = None,
- app_name = None,
- title = None,
- description = None,
- url = "http://onosproject.org/",
- custom_registrator = False,
- deps = None,
- yang_srcs = None,
- java_srcs = None,
- required_apps = [],
- visibility = ["//visibility:public"]):
-
+ name = None,
+ app_name = None,
+ title = None,
+ description = None,
+ url = "http://onosproject.org/",
+ custom_registrator = False,
+ deps = None,
+ yang_srcs = None,
+ java_srcs = None,
+ required_apps = [],
+ visibility = ["//visibility:public"]):
if name == None:
name = "onos-" + native.package_name().replace("/", "-")
- yang_library(name = name, deps = deps,
- yang_srcs = yang_srcs, java_srcs = java_srcs,
- custom_registrator = custom_registrator,
- visibility = ["//visibility:public"])
+ yang_library(
+ name = name,
+ deps = deps,
+ yang_srcs = yang_srcs,
+ java_srcs = java_srcs,
+ custom_registrator = custom_registrator,
+ visibility = ["//visibility:public"],
+ )
onos_app(
app_name = app_name,
@@ -195,7 +199,7 @@
version = ONOS_VERSION,
url = url,
category = "Models",
- included_bundles = [ name ],
+ included_bundles = [name],
required_apps = required_apps + ["org.onosproject.yang"],
visibility = ["//visibility:public"],
- )
\ No newline at end of file
+ )
diff --git a/tools/dev/bash_profile b/tools/dev/bash_profile
index 88fb517..8fe5d5c 100644
--- a/tools/dev/bash_profile
+++ b/tools/dev/bash_profile
@@ -60,7 +60,7 @@
# Short-hand for ONOS build, package and test.
alias op="SHLVL=1 bazel build //:onos"
-alias ot="bazel query 'tests(//...)' | SHLVL=1 xargs bazel test"
+alias ot="bazel run //:buildifier_check && bazel query 'tests(//...)' | SHLVL=1 xargs bazel test"
alias ob="op && ot"
alias obd="SHLVL=1 bazel build //docs:external //docs:internal"