blob: 50cada3fb7c7502d5bbca611cd4301c7daafb45a [file] [log] [blame]
"""
Copyright ${year}-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.
"""
"""
Rules to build the ${artifactId} for GUI 2
"""
COMPILE_DEPS = CORE_DEPS + JACKSON + KRYO + [
"@javax_ws_rs_api//jar",
"@servlet_api//jar",
"@jetty_websocket//jar",
"@jetty_util//jar",
"@jersey_media_multipart//jar",
"@jersey_server//jar",
"//utils/rest:onlab-rest",
"//core/store/serializers:onos-core-serializers",
]
TEST_DEPS = TEST + [
"//core/api:onos-api-tests",
"//drivers/default:onos-drivers-default",
]
"""
Files that get put at the top level of the tar ball
"""
filegroup(
name = "_root_level_files",
srcs =
[
":angular.json",
":package.json",
":package-lock.json",
":tsconfig.json",
":tslint.json",
],
)
filegroup(
name = "_e2e_test_files",
srcs = [
":e2e/protractor.conf.js",
":e2e/src/app.e2e-spec.ts",
":e2e/src/app.po.ts",
":e2e/tsconfig.e2e.json",
],
)
"""
Run ng build to create ${artifactId} GUI 2 library in production mode
The output file ${artifactId}-gui-lib-ver.tgz is in the form that can be uploaded directly to https://www.npmjs.com/
See bazel-genfiles/apps/${artifactId}/web/${artifactId}-gui/${artifactId}-gui-lib.log for details of the Angular CLI output
"""
genrule(
name = "${artifactId}-gui-lib-build",
srcs = [
"@nodejs//:bin/npm",
"@nodejs//:bin/node",
"@nodejs//:bin/nodejs/bin/node",
"@nodejs//:bin/nodejs/bin/npm",
"//web/gui2-fw-lib:onos-gui2-fw-npm-install",
"//web/gui2-fw-lib:onos-gui2-fw-ng-build",
"//web/gui2-fw-lib:gui2_fw_lib_ext_css",
":_root_level_files",
":_${artifactId}_lib_src",
":_${artifactId}_tester_files",
],
outs = [
"${artifactId}-gui-lib.log",
"${artifactId}-gui-lib-ver.tgz",
],
cmd = "ROOT=`pwd` &&" +
" export HOME=. &&" +
" export XDG_CONFIG_HOME=$(@D)/config &&" +
" NODE=$(location @nodejs//:bin/node) &&" +
" INSTALL_FILES=($(locations //web/gui2-fw-lib:onos-gui2-fw-npm-install)) &&" + # An array of filenames - sorted by time created
" FWLIB_FILES=($(locations //web/gui2-fw-lib:onos-gui2-fw-ng-build)) &&" + # An array of filenames - sorted by time created
" mkdir -p apps/${artifactId}/web/${artifactId}-gui &&" +
" cd apps/${artifactId}/web/${artifactId}-gui &&" +
" jar xf $$ROOT/$${INSTALL_FILES[0]} &&" +
" tar xf $$ROOT/$${FWLIB_FILES[0]} &&" +
" mv package/ node_modules/gui2-fw-lib/ &&" +
" mkdir -p projects/${artifactId}-gui-lib/fw &&" +
" (cd projects/${artifactId}-gui-lib/fw &&" +
" jar xf $$ROOT/$(location //web/gui2-fw-lib:gui2_fw_lib_ext_css)) &&" +
" chmod +x node_modules/@angular/cli/bin/ng &&" +
" export PATH=$$ROOT/$$(dirname $${NODE}):$$ROOT/apps/${artifactId}/web/${artifactId}-gui/node_modules/@angular/cli/bin:$$PATH &&" +
" ng build ${artifactId}-gui-lib >> $$ROOT/$(location ${artifactId}-gui-lib.log) 2>&1 ||" +
" if [ $$? -eq 0 ]; then echo 'Successfully ran build';" +
" else " +
" echo 'Error running \'ng build ${artifactId}-gui-lib\' on \'//apps/${artifactId}/web/${artifactId}-gui:${artifactId}-gui-lib-build\'. \\\n" +
" See bazel-genfiles/apps/${artifactId}/web/${artifactId}-gui/${artifactId}-gui-lib.log for more details' >&2;" +
#" tail -n 100 ../../../../$(location onos-gui2-ng-test.log) >&2;" +
" exit 1;" +
" fi;" +
" cp README.md LICENSE dist/${artifactId}-gui-lib && " +
" npm pack ./dist/${artifactId}-gui-lib >> $$ROOT/$(location ${artifactId}-gui-lib.log) 2>&1 &&" +
" mv ${artifactId}-gui-lib-*.tgz $$ROOT/$(location ${artifactId}-gui-lib-ver.tgz) &&" +
" touch $$ROOT/$(location ${artifactId}-gui-lib.log)", # to get the log always as the 2nd file,
message = "Angular ${artifactId} Lib build",
visibility = ["//visibility:public"],
)
"""
Run 'ng test' to run Angular test and 'ng lint' for checkstyle
See bazel-genfiles/apps/${artifactId}/web/${artifactId}-gui/${artifactId}-gui-lib-lint.log or
bazel-genfiles/apps/${artifactId}/web/${artifactId}-gui/${artifactId}-gui-lib-test.log for details of the Angular CLI output
"""
genrule(
name = "_${artifactId}-gui-lib-test-genrule",
srcs = [
"@nodejs//:bin/npm",
"@nodejs//:bin/node",
"@nodejs//:bin/nodejs/bin/node",
"@nodejs//:bin/nodejs/bin/npm",
"//web/gui2-fw-lib:onos-gui2-fw-npm-install",
"//web/gui2-fw-lib:onos-gui2-fw-ng-build",
"//web/gui2-fw-lib:gui2_fw_lib_ext_css",
":_root_level_files",
":_${artifactId}_lib_src",
":_${artifactId}_lib_src_tests",
],
outs = [
"${artifactId}-gui-lib-ver.log",
"${artifactId}-gui-lib-lint.log",
"${artifactId}-gui-lib-test.log",
],
cmd = " ROOT=`pwd` &&" +
" export HOME=. &&" +
" export XDG_CONFIG_HOME=$(@D)/config &&" +
" NODE=$(location @nodejs//:bin/node) &&" +
" INSTALL_FILES=($(locations //web/gui2-fw-lib:onos-gui2-fw-npm-install)) &&" + # An array of filenames - sorted by time created
" FWLIB_FILES=($(locations //web/gui2-fw-lib:onos-gui2-fw-ng-build)) &&" + # An array of filenames - sorted by time created
" mkdir -p apps/${artifactId}/web/${artifactId}-gui &&" +
" cd apps/${artifactId}/web/${artifactId}-gui &&" +
" jar xf ../../../../$(location :_${artifactId}_lib_src_tests) &&" +
" jar xf $$ROOT/$${INSTALL_FILES[0]} &&" +
" tar xf $$ROOT/$${FWLIB_FILES[0]} &&" +
" mv package/ node_modules/gui2-fw-lib/ &&" +
" mkdir -p projects/${artifactId}-gui-lib/fw &&" +
" (cd projects/${artifactId}-gui-lib/fw &&" +
" jar xf $$ROOT/$(location //web/gui2-fw-lib:gui2_fw_lib_ext_css)) &&" +
" chmod +x $$ROOT/apps/${artifactId}/web/${artifactId}-gui/node_modules/@angular/cli/bin/ng &&" +
" export PATH=$$ROOT/$$(dirname $${NODE}):node_modules/@angular/cli/bin:$$PATH &&" +
" node -v > ../../../../$(location ${artifactId}-gui-lib-ver.log) &&" +
" npm -v >> ../../../../$(location ${artifactId}-gui-lib-ver.log) &&" +
" ng version >> ../../../../$(location ${artifactId}-gui-lib-ver.log) &&" +
" ng lint ${artifactId}-gui-lib > ../../../../$(location ${artifactId}-gui-lib-lint.log) 2>&1 ||" +
" if [ $$? -eq 0 ]; then echo 'Successfully ran lint';" +
" else " +
" echo 'Error running \'ng lint\' on \'//apps/${artifactId}/web/${artifactId}-gui:_${artifactId}-gui-lib-test-genrule\'. \\\n" +
" See bazel-genfiles/apps/${artifactId}/web/${artifactId}-gui/${artifactId}-gui-lib-lint.log for more details' >&2;" +
" exit 1;" +
" fi;" +
" if [ -f /usr/bin/chromium-browser ]; then " + # Add to this for Mac and Chrome
" export CHROME_BIN=/usr/bin/chromium-browser; " +
" elif [ -f /opt/google/chrome/chrome ]; then " +
" export CHROME_BIN=/opt/google/chrome/chrome; " +
" else " +
" MSG='Warning: Step ${artifactId}-gui-lib-tests skipped because \\n" +
" no binary for ChromeHeadless browser was found at /usr/bin/chromium-browser. \\n" +
" Install Google Chrome or Chromium Browser to allow this step to run.';" +
" echo -e $$MSG >&2;" +
" echo -e $$MSG > ../../../../$(location ${artifactId}-gui-lib-test.log);" +
" exit 0;" +
" fi;" +
" ng test ${artifactId}-gui-lib --preserve-symlinks --code-coverage --browsers=ChromeHeadless" +
" --watch=false > ../../../../$(location ${artifactId}-gui-lib-test.log) 2>&1 ||" +
" if [ $$? -eq 0 ]; then echo 'Successfully ran tests';" +
" else " +
" echo 'Error running \'ng test ${artifactId}-gui-lib\' on \'//apps/${artifactId}/web/${artifactId}-gui:_${artifactId}-gui-lib-test-genrule\'. \\\n" +
" See bazel-genfiles/apps/${artifactId}/web/${artifactId}-gui/${artifactId}-gui-lib-test.log for more details' >&2;" +
" exit 1;" +
" fi;",
message = "Angular ${appNameTitle} Lib lint and test",
)
"""
Make a group of all the webapp files.
"""
filegroup(
name = "_${artifactId}_lib_src",
srcs = glob(
[
"projects/${artifactId}-gui-lib/**/*",
"README.md",
"LICENSE",
],
exclude = [
"projects/${artifactId}-gui-lib/**/*.spec.*", # Don't track tests here
"projects/${artifactId}-gui-lib/karma.conf.js",
"projects/${artifactId}-gui-lib/src/test.ts",
"projects/${artifactId}-gui-lib/fw/**/*",
],
),
)
"""
Make a group of all the webapp qpp files.
"""
filegroup(
name = "_${artifactId}_tester_files",
srcs = glob(
[
"src/**/*",
],
),
)
"""
Make a jar file of all the webapp test (*.spec.ts) files.
"""
genrule(
name = "_${artifactId}_lib_src_tests",
srcs = glob(
[
"projects/${artifactId}-gui-lib/karma.conf.js",
"projects/${artifactId}-gui-lib/src/test.ts",
"projects/${artifactId}-gui-lib/tsconfig.spec.json",
"projects/${artifactId}-gui-lib/**/*.spec.ts",
],
exclude = [
"projects/${artifactId}-gui-lib/ng-package.json",
"projects/${artifactId}-gui-lib/ng-package.prod.json",
"projects/${artifactId}-gui-lib/package.json",
"projects/${artifactId}-gui-lib/tsconfig.lib.json",
"projects/${artifactId}-gui-lib/tslint.json",
"projects/${artifactId}-gui-lib/src/public_api.ts",
],
),
outs = ["${artifactId}_gui_lib_src_tests.jar"],
cmd = "cd apps/${artifactId}/web/${artifactId}-gui &&" +
" jar Mcf ../../../../$@ .",
)
"""
Make a jar file of all the webapp test (*.spec.ts) files.
"""
genrule(
name = "_${artifactId}_gui_lib_tests",
srcs = glob(
[
"projects/${artifactId}-gui-lib/**/*.spec.ts",
"projects/${artifactId}-gui-lib/**/*.spec.json",
],
exclude = [
"src/main/webapp/tests/**",
"src/main/webapp/node_modules/**",
"src/main/webapp/dist/**",
"src/main/webapp/doc/**",
],
),
outs = ["${artifactId}_gui_lib_tests.jar"],
cmd = "cd apps/${artifactId}/web/${artifactId}-gui &&" +
" find projects/${artifactId}-gui-lib/src/lib -type f -exec touch -t 201808280000 {} \; &&" +
" jar Mcf ../../../../$@ projects/${artifactId}-gui-lib/src/lib",
)
"""
Wrap the genrule for testing in a test
"""
sh_test(
name = "${artifactId}-gui-lib-tests",
size = "small",
srcs = [
":ng-test.sh",
],
data = [
":_${artifactId}-gui-lib-test-genrule",
],
deps = [
"@bazel_tools//tools/bash/runfiles",
],
)