diff --git a/.bazelrc b/.bazelrc index 266386afc3..15df5105fd 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,7 +1,8 @@ -build --javabase=@bazel_tools//tools/jdk:remote_jdk11 -build --host_javabase=@bazel_tools//tools/jdk:remote_jdk11 +build --javabase=@org_onosproject_onos//tools/build/bazel:default_jdk +build --host_javabase=@org_onosproject_onos//tools/build/bazel:default_jdk build --java_toolchain=@org_onosproject_onos//tools/build/bazel:default_toolchain build --host_java_toolchain=@org_onosproject_onos//tools/build/bazel:default_toolchain + build --nouse_ijars build --experimental_strict_action_env diff --git a/.dockerignore b/.dockerignore index bd28f8bbc5..6006ef41e2 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,18 +2,19 @@ **/target **/*.iml **/*.pyc +**/*.ova **/.idea .javacp* +.git +.ijwb + + web/gui/src/main/webapp/tests/node_modules web/gui/src/test/_karma/node_modules web/gui/src/main/webapp/node_modules -bazel-bin -bazel-genfiles -bazel-out -bazel-testlogs -bazel-onos-next -bazel +bazel-* +target diff --git a/Dockerfile b/Dockerfile index 0810ae9476..517323e994 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,34 +1,55 @@ -# First stage is the build environment -FROM picoded/ubuntu-openjdk-8-jdk as builder -MAINTAINER Ray Milkey +ARG JDK_VER=11 +ARG BAZEL_VER=0.27.0 +ARG JOBS=2 -# Set the environment variables -ENV HOME /root +# First stage is the build environment. +FROM ubuntu:18.04 as builder + +ENV BUILD_DEPS \ + ca-certificates \ + zip \ + python \ + python3 \ + git \ + bzip2 \ + build-essential \ + curl \ + unzip +RUN apt-get update +RUN apt-get install -y ${BUILD_DEPS} + +# Install Bazel +ARG BAZEL_VER +RUN curl -L -o bazel.sh https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VER}/bazel-${BAZEL_VER}-installer-linux-x86_64.sh +RUN chmod +x bazel.sh && ./bazel.sh --user + +# Build-stage environment variables +ENV ONOS_ROOT=/src/onos ENV BUILD_NUMBER docker ENV JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8 -# Copy in the source -COPY . /src/onos/ +# Build ONOS. We extract the tar in the build environment to avoid having to put +# the tar in the runtime stage. This saves a lot of space. +# Note: we don't install a JDK but instead we rely on that provided by Bazel. -# Build ONOS -# We extract the tar in the build environment to avoid having to put the tar -# in the runtime environment - this saves a lot of space -# FIXME - dependence on ONOS_ROOT and git at build time is a hack to work around -# build problems -WORKDIR /src/onos -RUN apt-get update && apt-get install -y zip python git bzip2 build-essential && \ - curl -L -o bazel.sh https://github.com/bazelbuild/bazel/releases/download/0.23.0/bazel-0.23.0-installer-linux-x86_64.sh && \ - chmod +x bazel.sh && \ - ./bazel.sh --user && \ - export ONOS_ROOT=/src/onos && \ - ~/bin/bazel build onos --verbose_failures --jobs 2 && \ - mkdir -p /src/tar && \ - cd /src/tar && \ - tar -xf /src/onos/bazel-bin/onos.tar.gz --strip-components=1 && \ - rm -rf /src/onos/bazel-* .git +# Copy in the sources +COPY . ${ONOS_ROOT} +WORKDIR ${ONOS_ROOT} -# Second stage is the runtime environment -FROM adoptopenjdk/openjdk11:x86_64-ubuntu-jdk-11.0.1.13-slim +ARG JOBS +ENV BAZEL_BUILD_ARGS \ + --jobs ${JOBS} \ + --verbose_failures +RUN ~/bin/bazel build onos ${BAZEL_BUILD_ARGS} + +RUN mkdir /src/tar +RUN tar -xf bazel-bin/onos.tar.gz -C /src/tar --strip-components=1 + +# Second stage is the runtime environment. +# We use Amazon Corretto official Docker image, bazed on Amazon Linux 2 (rhel/fedora like) +FROM amazoncorretto:${JDK_VER} + +MAINTAINER Ray Milkey # Change to /root directory RUN mkdir -p /root/onos diff --git a/apps/cord-support/BUILD b/apps/cord-support/BUILD index 97ddc416f6..809b29df3a 100644 --- a/apps/cord-support/BUILD +++ b/apps/cord-support/BUILD @@ -3,7 +3,7 @@ COMPILE_DEPS = CORE_DEPS + JACKSON + REST + [ ] TEST_DEPS = TEST_REST + [ - "//lib:jersey-server", + "//deps:jersey-server", ] osgi_jar_with_tests( diff --git a/apps/faultmanagement/fm-gui2-lib/BUILD b/apps/faultmanagement/fm-gui2-lib/BUILD index 56e4888eff..82120f25d8 100644 --- a/apps/faultmanagement/fm-gui2-lib/BUILD +++ b/apps/faultmanagement/fm-gui2-lib/BUILD @@ -20,6 +20,8 @@ """ +load("//tools/build/bazel:jdk_genrule.bzl", genrule = "jdk_genrule") + COMPILE_DEPS = CORE_DEPS + JACKSON + KRYO + [ "@javax_ws_rs_api//jar", "@servlet_api//jar", diff --git a/apps/kafka-integration/BUILD b/apps/kafka-integration/BUILD index 6daeb1a6ba..60cb94cce0 100644 --- a/apps/kafka-integration/BUILD +++ b/apps/kafka-integration/BUILD @@ -1,6 +1,6 @@ BUNDLES = [ "@kafka_clients//jar", - "//lib:com_google_protobuf_protobuf_java", + "//deps:com_google_protobuf_protobuf_java", "//core/protobuf/models:onos-core-protobuf-models", "//core/protobuf/models/proto:onos-core-protobuf-models-proto", "//apps/kafka-integration/api:onos-apps-kafka-integration-api", diff --git a/apps/kafka-integration/app/BUILD b/apps/kafka-integration/app/BUILD index 4cf8eaadee..b1b7c65e7c 100644 --- a/apps/kafka-integration/app/BUILD +++ b/apps/kafka-integration/app/BUILD @@ -4,7 +4,7 @@ COMPILE_DEPS = CORE_DEPS + JACKSON + KRYO + CLI + [ "@kafka_clients//jar", "@javax_ws_rs_api//jar", "//utils/rest:onlab-rest", - "//lib:com_google_protobuf_protobuf_java", + "//deps:com_google_protobuf_protobuf_java", "//core/protobuf/models:onos-core-protobuf-models", "//core/protobuf/models/proto:onos-core-protobuf-models-proto", ] diff --git a/apps/onlp-demo/BUILD b/apps/onlp-demo/BUILD index 8bae7464e1..1dd802d19e 100644 --- a/apps/onlp-demo/BUILD +++ b/apps/onlp-demo/BUILD @@ -1,8 +1,8 @@ COMPILE_DEPS = CORE_DEPS + JACKSON + [ - "//lib:com_google_protobuf_protobuf_java", - "//lib:io_grpc_grpc_api_context", - "//lib:io_grpc_grpc_netty", - "//lib:io_grpc_grpc_stub", + "//deps:com_google_protobuf_protobuf_java", + "//deps:io_grpc_grpc_api_context", + "//deps:io_grpc_grpc_netty", + "//deps:io_grpc_grpc_stub", "//core/store/serializers:onos-core-serializers", "//protocols/gnmi/stub:onos-protocols-gnmi-stub", "//protocols/gnmi/api:onos-protocols-gnmi-api", diff --git a/apps/openstacktelemetry/BUILD b/apps/openstacktelemetry/BUILD index 11a1d3d6bf..1f9748d013 100644 --- a/apps/openstacktelemetry/BUILD +++ b/apps/openstacktelemetry/BUILD @@ -16,13 +16,13 @@ BUNDLES = [ "@simpleclient_hotspot//jar", "@simpleclient_servlet//jar", # gRPC dependencies (with patched core) - "//lib:io_grpc_grpc_api_context", - "//lib:io_grpc_grpc_stub", - "//lib:io_grpc_grpc_netty", - "//lib:io_grpc_grpc_auth", - "//lib:io_grpc_grpc_protobuf", - "//lib:io_grpc_grpc_protobuf_lite", - "//lib:com_google_protobuf_protobuf_java", + "//deps:io_grpc_grpc_api_context", + "//deps:io_grpc_grpc_stub", + "//deps:io_grpc_grpc_netty", + "//deps:io_grpc_grpc_auth", + "//deps:io_grpc_grpc_protobuf", + "//deps:io_grpc_grpc_protobuf_lite", + "//deps:com_google_protobuf_protobuf_java", "@com_google_api_grpc_proto_google_common_protos//jar", "@com_google_errorprone_error_prone_annotations//jar", "@com_google_auth_google_auth_library_credentials//jar", diff --git a/apps/openstacktelemetry/app/BUILD b/apps/openstacktelemetry/app/BUILD index 76f124706d..2c6db95319 100644 --- a/apps/openstacktelemetry/app/BUILD +++ b/apps/openstacktelemetry/app/BUILD @@ -12,8 +12,8 @@ COMPILE_DEPS = CORE_DEPS + JACKSON + KRYO + CLI + REST + [ "@jetty_util//jar", "@jetty_websocket//jar", "@servlet_api//jar", - "//lib:io_grpc_grpc_api_context", - "//lib:io_grpc_grpc_protobuf_lite", + "//deps:io_grpc_grpc_api_context", + "//deps:io_grpc_grpc_protobuf_lite", "//core/store/serializers:onos-core-serializers", "//apps/openstacknode/api:onos-apps-openstacknode-api", "//apps/openstacknetworking/api:onos-apps-openstacknetworking-api", diff --git a/apps/roadm/web/roadm-gui/BUILD b/apps/roadm/web/roadm-gui/BUILD index 6c75291e67..e40092b59a 100644 --- a/apps/roadm/web/roadm-gui/BUILD +++ b/apps/roadm/web/roadm-gui/BUILD @@ -20,6 +20,8 @@ """ +load("//tools/build/bazel:jdk_genrule.bzl", genrule = "jdk_genrule") + COMPILE_DEPS = CORE_DEPS + JACKSON + KRYO + [ "@javax_ws_rs_api//jar", "@servlet_api//jar", diff --git a/core/net/BUILD b/core/net/BUILD index 8047609e57..fbc6fb6fc0 100644 --- a/core/net/BUILD +++ b/core/net/BUILD @@ -18,6 +18,9 @@ osgi_jar_with_tests( exclude_tests = [ "org.onosproject.net.intent.impl.compiler.AbstractLinkCollectionTest", "org.onosproject.net.intent.impl.installer.AbstractIntentInstallerTest", + # FIXME: re-enable CoreEventDispatcherTest + # Failing on Jenkins after switching to Bazel remote JDK 11 + "org.onosproject.event.impl.CoreEventDispatcherTest", ], medium_tests = ["//core/net:src/test/java/org/onosproject/net/flowobjective/impl/InOrderFlowObjectiveManagerTest"], test_deps = TEST_DEPS, diff --git a/lib/BUILD b/deps/BUILD similarity index 100% rename from lib/BUILD rename to deps/BUILD diff --git a/lib/LICENSE-Apache2.0 b/deps/LICENSE-Apache2.0 similarity index 100% rename from lib/LICENSE-Apache2.0 rename to deps/LICENSE-Apache2.0 diff --git a/lib/deps.json b/deps/deps.json similarity index 100% rename from lib/deps.json rename to deps/deps.json diff --git a/drivers/bmv2/BUILD b/drivers/bmv2/BUILD index 2b42bdba60..a74688851d 100644 --- a/drivers/bmv2/BUILD +++ b/drivers/bmv2/BUILD @@ -4,16 +4,16 @@ COMPILE_DEPS = CORE_DEPS + KRYO + JACKSON + [ "//pipelines/basic:onos-pipelines-basic", "//protocols/p4runtime/api:onos-protocols-p4runtime-api", "//protocols/p4runtime/model:onos-protocols-p4runtime-model", - "//lib:io_grpc_grpc_api_context", - "//lib:io_grpc_grpc_netty", + "//deps:io_grpc_grpc_api_context", + "//deps:io_grpc_grpc_netty", "@minimal_json//jar", # "//protocols/bmv2/thrift-api:onos-protocols-bmv2-thrift-api", - #"//lib:libthrift", + #"//deps:libthrift", ] BUNDLES = [ ":onos-drivers-bmv2", - # "//lib:libthrift", + # "//deps:libthrift", # "//protocols/bmv2/thrift-api:onos-protocols-bmv2-thrift-api", ] diff --git a/drivers/gnmi/BUILD b/drivers/gnmi/BUILD index de00da9866..772ae885b8 100644 --- a/drivers/gnmi/BUILD +++ b/drivers/gnmi/BUILD @@ -1,8 +1,8 @@ COMPILE_DEPS = CORE_DEPS + KRYO + [ - "//lib:com_google_protobuf_protobuf_java", - "//lib:io_grpc_grpc_api_context", - "//lib:io_grpc_grpc_netty", - "//lib:io_grpc_grpc_stub", + "//deps:com_google_protobuf_protobuf_java", + "//deps:io_grpc_grpc_api_context", + "//deps:io_grpc_grpc_netty", + "//deps:io_grpc_grpc_stub", "//core/store/serializers:onos-core-serializers", "//protocols/gnmi/stub:onos-protocols-gnmi-stub", "//protocols/gnmi/api:onos-protocols-gnmi-api", diff --git a/drivers/gnoi/BUILD b/drivers/gnoi/BUILD index 70b3c83ed3..a1680a964e 100644 --- a/drivers/gnoi/BUILD +++ b/drivers/gnoi/BUILD @@ -1,8 +1,8 @@ COMPILE_DEPS = CORE_DEPS + KRYO + [ - "//lib:com_google_protobuf_protobuf_java", - "//lib:io_grpc_grpc_api_context", - "//lib:io_grpc_grpc_netty", - "//lib:io_grpc_grpc_stub", + "//deps:com_google_protobuf_protobuf_java", + "//deps:io_grpc_grpc_api_context", + "//deps:io_grpc_grpc_netty", + "//deps:io_grpc_grpc_stub", "//protocols/gnoi/stub:onos-protocols-gnoi-stub", "//protocols/gnoi/api:onos-protocols-gnoi-api", "//protocols/grpc/api:onos-protocols-grpc-api", diff --git a/drivers/p4runtime/BUILD b/drivers/p4runtime/BUILD index ded88427ef..f4f909ccfd 100644 --- a/drivers/p4runtime/BUILD +++ b/drivers/p4runtime/BUILD @@ -3,7 +3,7 @@ COMPILE_DEPS = CORE_DEPS + KRYO + [ "//protocols/grpc/api:onos-protocols-grpc-api", "//protocols/grpc/utils:onos-protocols-grpc-utils", "//protocols/p4runtime/api:onos-protocols-p4runtime-api", - "//lib:io_grpc_grpc_api_context", + "//deps:io_grpc_grpc_api_context", ] BUNDLES = [ diff --git a/drivers/stratum/BUILD b/drivers/stratum/BUILD index e6e84d8adf..df5263fe0c 100644 --- a/drivers/stratum/BUILD +++ b/drivers/stratum/BUILD @@ -1,5 +1,5 @@ COMPILE_DEPS = CORE_DEPS + KRYO + JACKSON + [ - "//lib:io_grpc_grpc_api_context", + "//deps:io_grpc_grpc_api_context", "//drivers/p4runtime:onos-drivers-p4runtime", "//drivers/gnmi:onos-drivers-gnmi", "//drivers/gnoi:onos-drivers-gnoi", diff --git a/protocols/gnmi/ctl/BUILD b/protocols/gnmi/ctl/BUILD index a82dafd2a1..405701d26d 100644 --- a/protocols/gnmi/ctl/BUILD +++ b/protocols/gnmi/ctl/BUILD @@ -3,18 +3,18 @@ COMPILE_DEPS = CORE_DEPS + KRYO + [ "//protocols/gnmi/stub:onos-protocols-gnmi-stub", "//protocols/grpc/api:onos-protocols-grpc-api", "//protocols/grpc/ctl:onos-protocols-grpc-ctl", - "//lib:io_grpc_grpc_api_context", - "//lib:com_google_protobuf_protobuf_java", - "//lib:io_grpc_grpc_netty", - "//lib:io_grpc_grpc_protobuf_lite", - "//lib:io_grpc_grpc_stub", + "//deps:io_grpc_grpc_api_context", + "//deps:com_google_protobuf_protobuf_java", + "//deps:io_grpc_grpc_netty", + "//deps:io_grpc_grpc_protobuf_lite", + "//deps:io_grpc_grpc_stub", "@com_google_api_grpc_proto_google_common_protos//jar", ] TEST_DEPS = TEST + [ "@minimal_json//jar", - "//lib:io_grpc_grpc_api_context", - "//lib:io_grpc_grpc_protobuf_lite", + "//deps:io_grpc_grpc_api_context", + "//deps:io_grpc_grpc_protobuf_lite", ] osgi_jar_with_tests( diff --git a/protocols/gnoi/ctl/BUILD b/protocols/gnoi/ctl/BUILD index d3659d344a..6befde7bf7 100644 --- a/protocols/gnoi/ctl/BUILD +++ b/protocols/gnoi/ctl/BUILD @@ -3,18 +3,18 @@ COMPILE_DEPS = CORE_DEPS + KRYO + [ "//protocols/gnoi/stub:onos-protocols-gnoi-stub", "//protocols/grpc/api:onos-protocols-grpc-api", "//protocols/grpc/ctl:onos-protocols-grpc-ctl", - "//lib:io_grpc_grpc_api_context", - "//lib:com_google_protobuf_protobuf_java", - "//lib:io_grpc_grpc_netty", - "//lib:io_grpc_grpc_protobuf_lite", - "//lib:io_grpc_grpc_stub", + "//deps:io_grpc_grpc_api_context", + "//deps:com_google_protobuf_protobuf_java", + "//deps:io_grpc_grpc_netty", + "//deps:io_grpc_grpc_protobuf_lite", + "//deps:io_grpc_grpc_stub", "@com_google_api_grpc_proto_google_common_protos//jar", ] TEST_DEPS = TEST + [ "@minimal_json//jar", - "//lib:io_grpc_grpc_api_context", - "//lib:io_grpc_grpc_protobuf_lite", + "//deps:io_grpc_grpc_api_context", + "//deps:io_grpc_grpc_protobuf_lite", ] osgi_jar_with_tests( diff --git a/protocols/grpc/BUILD b/protocols/grpc/BUILD index 3fa5169e1a..ed61365f0a 100644 --- a/protocols/grpc/BUILD +++ b/protocols/grpc/BUILD @@ -3,17 +3,17 @@ BUNDLES = [ "//protocols/grpc/ctl:onos-protocols-grpc-ctl", "//protocols/grpc/utils:onos-protocols-grpc-utils", # gRPC dependencies (with patched core) - "//lib:io_grpc_grpc_api_context", - "//lib:io_grpc_grpc_core_internal", - "//lib:io_grpc_grpc_core_inprocess", - "//lib:io_grpc_grpc_core_util", - "//lib:io_grpc_grpc_core_perfmark", - "//lib:io_grpc_grpc_stub", - "//lib:io_grpc_grpc_netty", - "//lib:io_grpc_grpc_auth", - "//lib:io_grpc_grpc_protobuf", - "//lib:io_grpc_grpc_protobuf_lite", - "//lib:com_google_protobuf_protobuf_java", + "//deps:io_grpc_grpc_api_context", + "//deps:io_grpc_grpc_core_internal", + "//deps:io_grpc_grpc_core_inprocess", + "//deps:io_grpc_grpc_core_util", + "//deps:io_grpc_grpc_core_perfmark", + "//deps:io_grpc_grpc_stub", + "//deps:io_grpc_grpc_netty", + "//deps:io_grpc_grpc_auth", + "//deps:io_grpc_grpc_protobuf", + "//deps:io_grpc_grpc_protobuf_lite", + "//deps:com_google_protobuf_protobuf_java", "@com_google_api_grpc_proto_google_common_protos//jar", "@com_google_errorprone_error_prone_annotations//jar", "@com_google_auth_google_auth_library_credentials//jar", diff --git a/protocols/grpc/api/BUILD b/protocols/grpc/api/BUILD index 3247fcdbb7..8b1157ef6e 100644 --- a/protocols/grpc/api/BUILD +++ b/protocols/grpc/api/BUILD @@ -1,3 +1,3 @@ osgi_jar( - deps = CORE_DEPS + ["//lib:io_grpc_grpc_api_context"], + deps = CORE_DEPS + ["//deps:io_grpc_grpc_api_context"], ) diff --git a/protocols/grpc/ctl/BUILD b/protocols/grpc/ctl/BUILD index 77239e4504..b81258f4fe 100644 --- a/protocols/grpc/ctl/BUILD +++ b/protocols/grpc/ctl/BUILD @@ -1,10 +1,10 @@ COMPILE_DEPS = CORE_DEPS + [ "//protocols/grpc/api:onos-protocols-grpc-api", - "//lib:io_grpc_grpc_api_context", - "//lib:io_grpc_grpc_core_internal", - "//lib:io_grpc_grpc_netty", - "//lib:io_grpc_grpc_protobuf_lite", - "//lib:com_google_protobuf_protobuf_java", + "//deps:io_grpc_grpc_api_context", + "//deps:io_grpc_grpc_core_internal", + "//deps:io_grpc_grpc_netty", + "//deps:io_grpc_grpc_protobuf_lite", + "//deps:com_google_protobuf_protobuf_java", "@com_google_api_grpc_proto_google_common_protos//jar", "@io_netty_netty_handler//jar", ] diff --git a/protocols/grpc/utils/BUILD b/protocols/grpc/utils/BUILD index c3e6e77b81..2627aadf30 100644 --- a/protocols/grpc/utils/BUILD +++ b/protocols/grpc/utils/BUILD @@ -1,6 +1,6 @@ COMPILE_DEPS = CORE_DEPS + [ "//protocols/grpc/api:onos-protocols-grpc-api", - "//lib:io_grpc_grpc_api_context", + "//deps:io_grpc_grpc_api_context", ] osgi_jar( diff --git a/protocols/p4runtime/api/BUILD b/protocols/p4runtime/api/BUILD index b95804513d..28d48a313b 100644 --- a/protocols/p4runtime/api/BUILD +++ b/protocols/p4runtime/api/BUILD @@ -1,6 +1,6 @@ COMPILE_DEPS = CORE_DEPS + [ "//protocols/grpc/api:onos-protocols-grpc-api", - "//lib:io_grpc_grpc_api_context", + "//deps:io_grpc_grpc_api_context", ] TEST_DEPS = TEST + [ diff --git a/protocols/p4runtime/ctl/BUILD b/protocols/p4runtime/ctl/BUILD index 5f8db80728..5fbbd6896a 100644 --- a/protocols/p4runtime/ctl/BUILD +++ b/protocols/p4runtime/ctl/BUILD @@ -4,20 +4,20 @@ COMPILE_DEPS = CORE_DEPS + KRYO + [ "//protocols/grpc/ctl:onos-protocols-grpc-ctl", "//protocols/p4runtime/api:onos-protocols-p4runtime-api", "//protocols/p4runtime/proto:onos-protocols-p4runtime-proto", - "//lib:com_google_protobuf_protobuf_java", - "//lib:io_grpc_grpc_api_context", - "//lib:io_grpc_grpc_netty", - "//lib:io_grpc_grpc_protobuf_lite", - "//lib:io_grpc_grpc_stub", + "//deps:com_google_protobuf_protobuf_java", + "//deps:io_grpc_grpc_api_context", + "//deps:io_grpc_grpc_netty", + "//deps:io_grpc_grpc_protobuf_lite", + "//deps:io_grpc_grpc_stub", "@com_google_api_grpc_proto_google_common_protos//jar", ] TEST_DEPS = TEST + [ "@minimal_json//jar", - "//lib:io_grpc_grpc_api_context", - "//lib:io_grpc_grpc_core_internal", - "//lib:io_grpc_grpc_core_inprocess", - "//lib:io_grpc_grpc_protobuf_lite", + "//deps:io_grpc_grpc_api_context", + "//deps:io_grpc_grpc_core_internal", + "//deps:io_grpc_grpc_core_inprocess", + "//deps:io_grpc_grpc_protobuf_lite", ] osgi_jar_with_tests( diff --git a/protocols/p4runtime/model/BUILD b/protocols/p4runtime/model/BUILD index 9e36b6d501..a521bbbf8b 100644 --- a/protocols/p4runtime/model/BUILD +++ b/protocols/p4runtime/model/BUILD @@ -1,6 +1,6 @@ COMPILE_DEPS = CORE_DEPS + [ "//protocols/p4runtime/proto:onos-protocols-p4runtime-proto", - "//lib:com_google_protobuf_protobuf_java", + "//deps:com_google_protobuf_protobuf_java", ] osgi_jar_with_tests( diff --git a/providers/general/device/BUILD b/providers/general/device/BUILD index d8d39299e8..511201a838 100644 --- a/providers/general/device/BUILD +++ b/providers/general/device/BUILD @@ -1,7 +1,7 @@ COMPILE_DEPS = CORE_DEPS + JACKSON + [ "//protocols/gnmi/stub:onos-protocols-gnmi-stub", "//protocols/gnmi/api:onos-protocols-gnmi-api", - "//lib:com_google_protobuf_protobuf_java", + "//deps:com_google_protobuf_protobuf_java", "//protocols/grpc/api:onos-protocols-grpc-api", ] diff --git a/tools/build/bazel/BUILD b/tools/build/bazel/BUILD index cf2024640e..57f700db1f 100644 --- a/tools/build/bazel/BUILD +++ b/tools/build/bazel/BUILD @@ -1,15 +1,20 @@ load("@bazel_tools//tools/jdk:default_java_toolchain.bzl", "default_java_toolchain") -# This is where we define the language source and target values passed to javac -# when building ONOS. This toolchain should be used when invoking bazel build +# This is where we define the JDK used to build ONOS, as well as the language +# source and target values passed to javac. The :default_toolchain and +# :default_jdk are expected to be passed as arguments when invoking bazel build # (see onos/.bazelrc) default_java_toolchain( name = "default_toolchain", source_version = "11", target_version = "11", - visibility = [ - "//visibility:public", - ], + visibility = ["//visibility:public"], +) + +alias( + name = "default_jdk", + actual = "@bazel_tools//tools/jdk:remote_jdk11", + visibility = ["//visibility:public"], ) py_binary( diff --git a/tools/build/bazel/checkstyle.bzl b/tools/build/bazel/checkstyle.bzl index b651dd249f..8e6e37fc51 100644 --- a/tools/build/bazel/checkstyle.bzl +++ b/tools/build/bazel/checkstyle.bzl @@ -27,8 +27,11 @@ def _checkstyle_impl(ctx): need_colon = True classpath += file.path + java_runtime = ctx.attr._jdk[java_common.JavaRuntimeInfo] + java_exe_path = java_runtime.java_executable_runfiles_path + cmd = " ".join( - ["java -cp %s com.puppycrawl.tools.checkstyle.Main" % classpath] + + ["%s -cp %s com.puppycrawl.tools.checkstyle.Main" % (java_exe_path, classpath)] + ["-c %s" % ctx.attr._config.files.to_list()[0].path] + [src_file.path for src_file in ctx.files.srcs], ) @@ -44,7 +47,10 @@ def _checkstyle_impl(ctx): ctx.attr._suppressions.files.to_list() + ctx.attr._java_header.files.to_list()) - runfiles = ctx.runfiles(files = inputs) + runfiles = ctx.runfiles( + files = inputs, + transitive_files = java_runtime.files, + ) return [DefaultInfo(runfiles = runfiles)] """ @@ -66,6 +72,10 @@ _execute_checkstyle_test = rule( "_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")), + "_jdk": attr.label( + default = Label("@bazel_tools//tools/jdk:current_java_runtime"), + providers = [java_common.JavaRuntimeInfo], + ), }, implementation = _checkstyle_impl, ) diff --git a/tools/build/bazel/java_sources.bzl b/tools/build/bazel/java_sources.bzl index a45ae6078a..1381a057dc 100644 --- a/tools/build/bazel/java_sources.bzl +++ b/tools/build/bazel/java_sources.bzl @@ -13,24 +13,28 @@ # limitations under the License. def _impl(ctx): - jar = ctx.outputs.jar + outjar = ctx.outputs.jar src_list = "" for src in ctx.files.srcs: if src.path.endswith(".srcjar"): src_list += " " + src.path + java_runtime = ctx.attr._jdk[java_common.JavaRuntimeInfo] + jar_path = "%s/bin/jar" % java_runtime.java_home + cmd = [ - "for sj in %s; do jar xf $sj; done" % src_list, + "for sj in %s; do %s xf $sj; done" % (src_list, jar_path), "dir=$(find . -type d -name java)", - "[ -n \"$dir\" -a -d \"$dir\" ] && jar cf %s -C $dir ." % jar.path, + "[ -n \"$dir\" -a -d \"$dir\" ] && %s cf %s -C $dir ." % (jar_path, outjar.path), ] ctx.action( inputs = ctx.files.srcs, - outputs = [jar], + outputs = [outjar], progress_message = "Generating source jar for %s" % ctx.attr.name, command = ";\n".join(cmd), + tools = java_runtime.files, ) def _impl_alt(ctx): @@ -68,6 +72,10 @@ Args: java_sources = rule( attrs = { "srcs": attr.label_list(allow_files = True), + "_jdk": attr.label( + default = Label("@bazel_tools//tools/jdk:current_java_runtime"), + providers = [java_common.JavaRuntimeInfo], + ), }, implementation = _impl, outputs = {"jar": "%{name}.jar"}, diff --git a/tools/build/bazel/javadoc.bzl b/tools/build/bazel/javadoc.bzl index 87e5592fcc..c459f7d75b 100644 --- a/tools/build/bazel/javadoc.bzl +++ b/tools/build/bazel/javadoc.bzl @@ -12,11 +12,11 @@ # 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/11/docs/api/" def _impl(ctx): dir = ctx.label.name - jar = ctx.outputs.jar + outjar = ctx.outputs.jar dep_list = [] for dep in ctx.files.deps: @@ -26,24 +26,32 @@ def _impl(ctx): for src in ctx.files.srcs: src_list += [src.path] + java_runtime = ctx.attr._jdk[java_common.JavaRuntimeInfo] + jar_exe_path = "%s/bin/jar" % java_runtime.java_home + 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), + "%s cf %s -C %s ." % (jar_exe_path, outjar.path, dir), ] ctx.action( inputs = ctx.files.srcs + ctx.files.deps, - outputs = [jar], + outputs = [outjar], progress_message = "Generating javadocs jar for %s" % ctx.attr.name, command = ";\n".join(cmd), + tools = java_runtime.files, ) javadoc = rule( attrs = { "deps": attr.label_list(allow_files = True), "srcs": attr.label_list(allow_files = True), + "_jdk": attr.label( + default = Label("@bazel_tools//tools/jdk:current_java_runtime"), + providers = [java_common.JavaRuntimeInfo], + ), }, implementation = _impl, outputs = {"jar": "%{name}.jar"}, diff --git a/tools/build/bazel/jdk_genrule.bzl b/tools/build/bazel/jdk_genrule.bzl new file mode 100644 index 0000000000..14e5aa2b53 --- /dev/null +++ b/tools/build/bazel/jdk_genrule.bzl @@ -0,0 +1,40 @@ +""" + Copyright 2018-present Open Networking Foundation + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +""" + +""" +Extension to genrule that has the JDK bin directory in the PATH, thus allowing +to invoke commands like jar directly in the genrule "cmd" attribute. +This allows using JDK-related tools on a host system that does not have the JDK +installed, instead using the current JDK used by Bazel, e.g. the embedded or +remote one. +""" + +def jdk_genrule( + cmd, + tools = [], + toolchains = [], + **kwargs): + new_tools = tools + ["@bazel_tools//tools/jdk:current_java_runtime"] + new_toolchains = toolchains + ["@bazel_tools//tools/jdk:current_java_runtime"] + new_cmd = "echo \"export PATH=$$PWD/$(JAVABASE)/bin:$$PATH:\" > jdk_genrule_setup.sh; " + \ + "source jdk_genrule_setup.sh; " + cmd + + native.genrule( + cmd = new_cmd, + tools = new_tools, + toolchains = new_toolchains, + **kwargs + ) diff --git a/tools/build/bazel/minimal_jar.bzl b/tools/build/bazel/minimal_jar.bzl index ccc0c65959..6615ec9183 100644 --- a/tools/build/bazel/minimal_jar.bzl +++ b/tools/build/bazel/minimal_jar.bzl @@ -13,19 +13,29 @@ # limitations under the License. def _impl(ctx): - jar = ctx.outputs.jar + outjar = ctx.outputs.jar + + java_runtime = ctx.attr._jdk[java_common.JavaRuntimeInfo] + jar_exe_path = "%s/bin/jar" % java_runtime.java_home cmd = [ - "mkdir readme && touch readme/README && jar cf %s readme/README" % (jar.path), + "mkdir readme && touch readme/README && %s cf %s readme/README" % (jar_exe_path, outjar.path), ] ctx.action( - outputs = [jar], + outputs = [outjar], progress_message = "Generating minimal jar for %s" % ctx.attr.name, command = ";\n".join(cmd), + tools = java_runtime.files, ) minimal_jar = rule( + attrs = { + "_jdk": attr.label( + default = Label("@bazel_tools//tools/jdk:current_java_runtime"), + providers = [java_common.JavaRuntimeInfo], + ), + }, implementation = _impl, outputs = {"jar": "%{name}.jar"}, ) diff --git a/tools/build/bazel/osgi_java_library.bzl b/tools/build/bazel/osgi_java_library.bzl index 8296fcf71d..0ca20478a7 100644 --- a/tools/build/bazel/osgi_java_library.bzl +++ b/tools/build/bazel/osgi_java_library.bzl @@ -714,7 +714,7 @@ def osgi_proto_jar( proto_name + "-srcjar", ] base_deps = [ - "//lib:com_google_protobuf_protobuf_java", + "//deps:com_google_protobuf_protobuf_java", ] if grpc_proto_lib != None: grpc_name = name + "-java-grpc" @@ -732,9 +732,9 @@ def osgi_proto_jar( ) base_deps.extend([ "@com_google_guava_guava//jar", - "//lib:io_grpc_grpc_api_context", - "//lib:io_grpc_grpc_stub", - "//lib:io_grpc_grpc_protobuf", + "//deps:io_grpc_grpc_api_context", + "//deps:io_grpc_grpc_stub", + "//deps:io_grpc_grpc_protobuf", "@javax_annotation_javax_annotation_api//jar", ]) osgi_jar( diff --git a/tools/build/bazel/project_javadoc.bzl b/tools/build/bazel/project_javadoc.bzl index 171b846ef3..7c706d0bac 100644 --- a/tools/build/bazel/project_javadoc.bzl +++ b/tools/build/bazel/project_javadoc.bzl @@ -12,7 +12,7 @@ # 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/11/docs/api/" def dump(obj): print(dir(obj)) @@ -21,7 +21,7 @@ def dump(obj): def _impl(ctx): dir = ctx.label.name - jar = ctx.outputs.jar + outjar = ctx.outputs.jar classpath = "" for dep in ctx.files.deps: @@ -39,9 +39,13 @@ def _impl(ctx): packages += ":" + p group_list += " -group \"%s\" %s" % (group, packages.replace(":", "", 1)) + java_runtime = ctx.attr._jdk[java_common.JavaRuntimeInfo] + jar_exe_path = "%s/bin/jar" % java_runtime.java_home + javadoc_exe_path = "%s/bin/javadoc" % java_runtime.java_home + cmd = [ "mkdir src; cd src", - "for s in %s; do jar xf ../$s; done" % src_list, + "for s in %s; do ../%s xf ../$s; done" % (src_list, jar_exe_path), "rm -f META-INF/MANIFEST.MF", "cd ..", "cp -r docs/src/main/javadoc/* .", @@ -54,17 +58,18 @@ def _impl(ctx): 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), + "%s -encoding UTF-8 -overview overview.html -doctitle '%s' -windowtitle '%s' %s -d apidocs -classpath %s -sourcepath src %s @FILES" % + (javadoc_exe_path, 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, + "%s cf %s apidocs" % (jar_exe_path, outjar.path), ] - ctx.action( + ctx.actions.run_shell( inputs = ctx.files.srcs + ctx.files.deps, - outputs = [jar], + outputs = [outjar], progress_message = "Generating javadocs jar for %s" % ctx.attr.name, command = ";\n".join(cmd), + tools = java_runtime.files, ) project_javadoc = rule( @@ -75,6 +80,10 @@ project_javadoc = rule( "deps": attr.label_list(allow_files = True), "srcs": attr.label_list(allow_files = True), "internal": attr.bool(default = False), + "_jdk": attr.label( + default = Label("@bazel_tools//tools/jdk:current_java_runtime"), + providers = [java_common.JavaRuntimeInfo], + ), }, implementation = _impl, outputs = {"jar": "%{name}.jar"}, diff --git a/tools/build/bazel/yang.bzl b/tools/build/bazel/yang.bzl index 18b60e76f8..d96000f41f 100644 --- a/tools/build/bazel/yang.bzl +++ b/tools/build/bazel/yang.bzl @@ -69,6 +69,9 @@ def _yang_library_impl(ctx): executable = ctx.executable._yang_compiler, ) + java_runtime = ctx.attr._jdk[java_common.JavaRuntimeInfo] + jar_path = "%s/bin/jar" % java_runtime.java_home + ctx.actions.run_shell( inputs = [generated_sources], outputs = [ctx.outputs.srcjar], @@ -76,7 +79,8 @@ def _yang_library_impl(ctx): ctx.outputs.srcjar.path, generated_sources.path, ], - command = "jar cf $1 -C $2 src", + tools = java_runtime.files, + command = "%s cf $1 -C $2 src" % jar_path, progress_message = "Assembling YANG Java sources: %s" % ctx.attr.name, ) @@ -87,7 +91,8 @@ def _yang_library_impl(ctx): ctx.outputs.schema.path, generated_sources.path, ], - command = "jar cf $1 -C $2 schema", + tools = java_runtime.files, + command = "%s cf $1 -C $2 schema" % jar_path, progress_message = "Assembling YANG compiled schema: %s" % ctx.attr.name, ) @@ -103,6 +108,10 @@ _yang_library = rule( allow_files = True, default = Label("//tools/build/bazel:onos_yang_compiler"), ), + "_jdk": attr.label( + default = Label("@bazel_tools//tools/jdk:current_java_runtime"), + providers = [java_common.JavaRuntimeInfo], + ), }, outputs = { "srcjar": "model.srcjar", @@ -139,13 +148,18 @@ def yang_library( srcs = [name + "-generate"] if len(java_srcs): - srcs += [name + "-srcjar"] - native.genrule( - name = name + "-srcjar", - srcs = java_srcs, - outs = [name + ".srcjar"], - cmd = "jar cf $(location %s.srcjar) $(SRCS)" % name, - ) + srcs.extend(java_srcs) + # FIXME (carmelo): is this genrule really needed? + # srcs += [name + "-srcjar"] + # native.genrule( + # name = name + "-srcjar", + # srcs = java_srcs, + # outs = [name + ".srcjar"], + # cmd = "$(location //external:jar) cf $(location %s.srcjar) $(SRCS)" % name, + # tools = [ + # "//external:jar", + # ] + # ) if not custom_registrator: srcs += [name + "-registrator"] diff --git a/tools/build/onos-lib-gen b/tools/build/onos-lib-gen index 052543833b..7e6c951430 100755 --- a/tools/build/onos-lib-gen +++ b/tools/build/onos-lib-gen @@ -21,4 +21,4 @@ if [ ! -f $JAR ]; then [ -f $JAR ] && printf "Done.\n" fi -java -jar $JAR lib/deps.json tools/build/bazel/generate_workspace.bzl --bazel \ No newline at end of file +java -jar $JAR deps/deps.json tools/build/bazel/generate_workspace.bzl --bazel \ No newline at end of file diff --git a/tools/build/onos-validate-change-version.excludes b/tools/build/onos-validate-change-version.excludes index 856a1f4fdd..59eb74582b 100755 --- a/tools/build/onos-validate-change-version.excludes +++ b/tools/build/onos-validate-change-version.excludes @@ -25,7 +25,7 @@ \./drivers/p4runtime \./drivers/bmv2 \./lib/BUCK -\./lib/deps.json +\./deps/deps.json \./models/openroadm/pom.xml \./out \./pom.xml.versionsBackup diff --git a/tools/gui/BUILD b/tools/gui/BUILD index d55964376b..0cec9eaa1d 100644 --- a/tools/gui/BUILD +++ b/tools/gui/BUILD @@ -1,3 +1,5 @@ +load("//tools/build/bazel:jdk_genrule.bzl", genrule = "jdk_genrule") + filegroup( name = "_tools-gui-gulp-files", srcs = [ diff --git a/web/gui/BUILD b/web/gui/BUILD index 31c83e14a0..1834586a56 100644 --- a/web/gui/BUILD +++ b/web/gui/BUILD @@ -28,6 +28,8 @@ the sandbox at the proper locations and then returned as a tar ball. """ +load("//tools/build/bazel:jdk_genrule.bzl", genrule = "jdk_genrule") + COMPILE_DEPS = CORE_DEPS + JACKSON + KRYO + CLI + [ "@javax_ws_rs_api//jar", "@servlet_api//jar", diff --git a/web/gui2-fw-lib/BUILD b/web/gui2-fw-lib/BUILD index 2debb284f0..bbf39175f6 100644 --- a/web/gui2-fw-lib/BUILD +++ b/web/gui2-fw-lib/BUILD @@ -37,6 +37,8 @@ the build is still hermetic since those files are referred to as dependencies in the genrule. """ +load("//tools/build/bazel:jdk_genrule.bzl", genrule = "jdk_genrule") + COMPILE_DEPS = CORE_DEPS + JACKSON + KRYO + [ "@javax_ws_rs_api//jar", "@servlet_api//jar", diff --git a/web/gui2-topo-lib/BUILD b/web/gui2-topo-lib/BUILD index eff1dcdb59..6fe640529f 100644 --- a/web/gui2-topo-lib/BUILD +++ b/web/gui2-topo-lib/BUILD @@ -20,6 +20,8 @@ """ +load("//tools/build/bazel:jdk_genrule.bzl", genrule = "jdk_genrule") + COMPILE_DEPS = CORE_DEPS + JACKSON + KRYO + [ "@javax_ws_rs_api//jar", "@servlet_api//jar", diff --git a/web/gui2/BUILD b/web/gui2/BUILD index ec71d3bcb0..dbb531181f 100644 --- a/web/gui2/BUILD +++ b/web/gui2/BUILD @@ -37,6 +37,8 @@ the build is still hermetic since those files are referred to as dependencies in the genrule. """ +load("//tools/build/bazel:jdk_genrule.bzl", genrule = "jdk_genrule") + COMPILE_DEPS = CORE_DEPS + JACKSON + KRYO + CLI + [ "@javax_ws_rs_api//jar", "@servlet_api//jar",