Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 1 | """ |
| 2 | Copyright 2018-present Open Networking Foundation |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | """ |
| 16 | |
| 17 | """ |
| 18 | Rules to build the ONOS GUI 2 FW Lib |
| 19 | |
Sean Condon | 7d27516 | 2018-11-02 16:29:06 +0000 | [diff] [blame] | 20 | The GUI2 Angular 7 elements are built here with Angular CLI 'ng' |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 21 | Some work is being done in the Bazel community to integrate Bazel and |
Sean Condon | 7d27516 | 2018-11-02 16:29:06 +0000 | [diff] [blame] | 22 | Angular 7, (Angular Buildtools Convergence - |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 23 | https://docs.google.com/document/d/1OlyiUnoTirUj4gecGxJeZBcjHcFr36RvLsvpBl2mxA8/preview) |
| 24 | but it is in the very early stages (Aug'18) and not yet fit |
| 25 | for production and at present it works as a replacement for Angular CLI |
| 26 | (which is not desirable). |
| 27 | |
| 28 | There are plans to extend Bazel it to work with Angular CLI, and if works |
| 29 | well this Bazel file may be rearchiteced in future. |
| 30 | |
| 31 | Bazel and npm are incompatibe in how they deal with files. npm likes to |
| 32 | follow links to get back to the original canonical path names, and bazel |
| 33 | uses links extensively when populating the sandbox. To get around these |
| 34 | problems, the rules that follow use filegroups to specify the files as |
| 35 | dependencies and then use a genrule to convert the files into a tar ball. |
| 36 | Once the tar ball is unrolled into the sandbox, the links are broken, but |
| 37 | the build is still hermetic since those files are referred to as dependencies in the genrule. |
| 38 | """ |
| 39 | |
Carmelo Cascone | d33d3b4 | 2019-06-18 12:12:36 -0700 | [diff] [blame] | 40 | load("//tools/build/bazel:jdk_genrule.bzl", genrule = "jdk_genrule") |
| 41 | |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 42 | COMPILE_DEPS = CORE_DEPS + JACKSON + KRYO + [ |
| 43 | "@javax_ws_rs_api//jar", |
| 44 | "@servlet_api//jar", |
| 45 | "@jetty_websocket//jar", |
| 46 | "@jetty_util//jar", |
| 47 | "@jersey_media_multipart//jar", |
| 48 | "@jersey_server//jar", |
| 49 | "//utils/rest:onlab-rest", |
| 50 | "//core/store/serializers:onos-core-serializers", |
| 51 | ] |
| 52 | |
| 53 | TEST_DEPS = TEST + [ |
| 54 | "//core/api:onos-api-tests", |
| 55 | "//drivers/default:onos-drivers-default", |
| 56 | ] |
| 57 | |
| 58 | """ |
| 59 | Files that get put at the top level of the tar ball |
| 60 | """ |
| 61 | |
| 62 | filegroup( |
| 63 | name = "_root_level_files", |
| 64 | srcs = |
| 65 | [ |
| 66 | ":angular.json", |
| 67 | ":package.json", |
| 68 | ":package-lock.json", |
| 69 | ":tsconfig.json", |
| 70 | ":tslint.json", |
| 71 | ], |
| 72 | ) |
| 73 | |
| 74 | filegroup( |
| 75 | name = "_e2e_test_files", |
| 76 | srcs = [ |
| 77 | ":e2e/protractor.conf.js", |
| 78 | ":e2e/src/app.e2e-spec.ts", |
| 79 | ":e2e/src/app.po.ts", |
| 80 | ":e2e/tsconfig.e2e.json", |
| 81 | ], |
| 82 | ) |
| 83 | |
| 84 | """ |
| 85 | Make a group file of all the webapp files. |
| 86 | """ |
| 87 | |
| 88 | filegroup( |
| 89 | name = "_gui2_fw_lib_src", |
| 90 | srcs = glob( |
| 91 | [ |
| 92 | "projects/gui2-fw-lib/**", |
Sean Condon | 4b7818d | 2019-05-23 07:45:14 +0100 | [diff] [blame] | 93 | "README.md", |
| 94 | "LICENSE", |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 95 | ], |
| 96 | exclude = [ |
| 97 | "projects/gui2-fw-lib/**/*.spec.*", # Don't track tests here |
| 98 | "projects/gui2-fw-lib/karma.conf.js", |
| 99 | "projects/gui2-fw-lib/src/test.ts", |
| 100 | ], |
| 101 | ), |
| 102 | ) |
| 103 | |
| 104 | """ |
| 105 | Make a group of all the webapp qpp files. |
| 106 | """ |
| 107 | |
| 108 | filegroup( |
| 109 | name = "_gui2_app_files", |
| 110 | srcs = glob( |
| 111 | [ |
| 112 | "src/**/*", |
| 113 | ], |
| 114 | ), |
| 115 | ) |
| 116 | |
| 117 | """ |
| 118 | Make a jar file of all the webapp test (*.spec.ts) files. |
| 119 | """ |
| 120 | |
| 121 | genrule( |
| 122 | name = "_gui2_fw_lib_tests", |
| 123 | srcs = glob( |
| 124 | [ |
| 125 | "projects/gui2-fw-lib/karma.conf.js", |
| 126 | "projects/gui2-fw-lib/src/test.ts", |
| 127 | "projects/gui2-fw-lib/tsconfig.spec.json", |
| 128 | "projects/gui2-fw-lib/**/*.spec.ts", |
| 129 | ], |
| 130 | exclude = [ |
| 131 | "projects/gui2-fw-lib/ng-package.json", |
| 132 | "projects/gui2-fw-lib/ng-package.prod.json", |
| 133 | "projects/gui2-fw-lib/package.json", |
| 134 | "projects/gui2-fw-lib/tsconfig.lib.json", |
| 135 | "projects/gui2-fw-lib/tslint.json", |
| 136 | "projects/gui2-fw-lib/src/public_api.ts", |
| 137 | ], |
| 138 | ), |
| 139 | outs = ["gui2_fw_lib_tests.jar"], |
| 140 | cmd = "cd web/gui2-fw-lib &&" + |
| 141 | " jar Mcf ../../$@ .", |
| 142 | ) |
| 143 | |
| 144 | """ |
| 145 | Make a jar file of all the CSS files we want to reuse in the target. |
| 146 | """ |
| 147 | |
| 148 | genrule( |
| 149 | name = "gui2_fw_lib_ext_css", |
| 150 | srcs = glob( |
| 151 | [ |
| 152 | "projects/gui2-fw-lib/src/lib/widget/panel.css", |
| 153 | "projects/gui2-fw-lib/src/lib/widget/panel-theme.css", |
| 154 | "projects/gui2-fw-lib/src/lib/widget/table.css", |
| 155 | "projects/gui2-fw-lib/src/lib/widget/table.theme.css", |
| 156 | "projects/gui2-fw-lib/src/lib/widget/table.theme.css", |
| 157 | "projects/gui2-fw-lib/src/lib/layer/loading.service.css", |
| 158 | ], |
| 159 | ), |
| 160 | outs = ["gui2_fw_lib_css.jar"], |
| 161 | cmd = " ROOT=`pwd` &&" + |
| 162 | " cd web/gui2-fw-lib/projects/gui2-fw-lib/src/lib &&" + |
| 163 | " jar Mcf $$ROOT/$@ .", |
| 164 | visibility = ["//visibility:public"], |
| 165 | ) |
| 166 | |
| 167 | """ |
| 168 | Install npm packages listed in package.json in web/gui2 |
Sean Condon | c687ccb | 2019-10-25 12:27:54 +0100 | [diff] [blame] | 169 | See bazel-out/k8-fastbuild/bin/web/gui2/onos-gui2-npm-install.log for details of the 'npm install' |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 170 | """ |
| 171 | |
| 172 | genrule( |
| 173 | name = "onos-gui2-fw-npm-install", |
| 174 | srcs = [ |
| 175 | "@nodejs//:bin/npm", |
| 176 | "@nodejs//:bin/node", |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 177 | "@nodejs//:bin/nodejs/bin/node", |
| 178 | "@nodejs//:bin/nodejs/bin/npm", |
| 179 | ":_root_level_files", |
| 180 | ], |
| 181 | outs = [ |
| 182 | "onos-gui2-npm-install.jar", |
| 183 | "onos-gui2-npm-install.log", |
| 184 | ], |
| 185 | cmd = " ROOT=`pwd` &&" + |
| 186 | " export HOME=. &&" + |
| 187 | " export XDG_CONFIG_HOME=$(@D)/config &&" + # npm config cache to the sandbox |
| 188 | " export BABEL_DISABLE_CACHE=1 &&" + # turn off babel cache |
| 189 | ' if [[ ! -z $${HTTP_PROXY-} ]]; then NPM_ARGS="--proxy $$HTTP_PROXY --without-ssl --insecure"; else NPM_ARGS=""; fi &&' + |
| 190 | " NPM=$(location @nodejs//:bin/npm) &&" + |
| 191 | " export PATH=$$ROOT/$$(dirname $${NPM}):$$PATH &&" + |
| 192 | " npm -v > $$ROOT/$(location onos-gui2-npm-install.log) 2>&1 &&" + |
| 193 | " cd web/gui2-fw-lib && " + |
| 194 | " npm $$NPM_ARGS install --no-cache >> $$ROOT/$(location onos-gui2-npm-install.log) 2>&1 &&" + |
| 195 | " jar Mcf $$ROOT/$(location onos-gui2-npm-install.jar) node_modules &&" + |
| 196 | " touch $$ROOT/$(location onos-gui2-npm-install.log)", # to get the log always as the 2nd file |
| 197 | message = "NodeJS npm install", |
| 198 | visibility = ["//visibility:public"], |
| 199 | ) |
| 200 | |
| 201 | """ |
| 202 | Run ng build to create outputs in production mode |
Sean Condon | c687ccb | 2019-10-25 12:27:54 +0100 | [diff] [blame] | 203 | See bazel-out/k8-fastbuild/bin/web/gui2/onos-gui2-ng-build-prod.log for details of the Angular CLI output |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 204 | """ |
| 205 | |
| 206 | genrule( |
| 207 | name = "onos-gui2-fw-ng-build", |
| 208 | srcs = [ |
| 209 | "@nodejs//:bin/npm", |
| 210 | "@nodejs//:bin/node", |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 211 | "@nodejs//:bin/nodejs/bin/node", |
| 212 | "@nodejs//:bin/nodejs/bin/npm", |
| 213 | ":onos-gui2-fw-npm-install", |
Sean Condon | 95fb574 | 2019-04-02 12:16:55 +0100 | [diff] [blame] | 214 | "//web/gui:onos-gui-data-for-gui2", |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 215 | ":_root_level_files", |
| 216 | ":_gui2_fw_lib_src", |
| 217 | ], |
| 218 | outs = [ |
| 219 | "gui2-fw-ng-build-prod.log", |
| 220 | "gui2-fw-lib-ver.tgz", |
| 221 | ], |
| 222 | cmd = "ROOT=`pwd` &&" + |
| 223 | " export HOME=. &&" + |
| 224 | " export XDG_CONFIG_HOME=$(@D)/config &&" + |
| 225 | " NODE=$(location @nodejs//:bin/node) &&" + |
| 226 | " INSTALL_FILES=($(locations :onos-gui2-fw-npm-install)) &&" + # An array of filenames - sorted by time created |
| 227 | " cd web/gui2-fw-lib &&" + |
| 228 | " jar xf $$ROOT/$${INSTALL_FILES[0]} &&" + |
| 229 | " chmod +x $$ROOT/web/gui2-fw-lib/node_modules/@angular/cli/bin/ng &&" + |
| 230 | " export PATH=$$ROOT/$$(dirname $${NODE}):$$ROOT/web/gui2-fw-lib/node_modules/@angular/cli/bin:$$PATH &&" + |
| 231 | " node -v > ../../$(location gui2-fw-ng-build-prod.log) &&" + |
| 232 | " npm -v >> ../../$(location gui2-fw-ng-build-prod.log) &&" + |
Sean Condon | 7d27516 | 2018-11-02 16:29:06 +0000 | [diff] [blame] | 233 | " ng version >> ../../$(location gui2-fw-ng-build-prod.log);" + |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 234 | " ng build --prod gui2-fw-lib >> $$ROOT/$(location gui2-fw-ng-build-prod.log) 2>&1 ||" + |
| 235 | " if [ $$? -eq 0 ]; then echo 'Successfully built GUI FW library';" + |
| 236 | " else " + |
| 237 | " echo 'Error running \'ng build gui2-fw-lib\' on \'//web/gui2-fw-lib:onos-gui2-fw-ng-build\'. \\\n" + |
Sean Condon | c687ccb | 2019-10-25 12:27:54 +0100 | [diff] [blame] | 238 | " See bazel-out/k8-fastbuild/bin/web/gui2-fw-lib/gui2-fw-ng-build-prod.log for more details' >&2;" + |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 239 | " exit 1;" + |
| 240 | " fi;" + |
Sean Condon | 95fb574 | 2019-04-02 12:16:55 +0100 | [diff] [blame] | 241 | # see https://github.com/angular/angular-cli/issues/11071 - Angular CLI does not yet copy across assets |
| 242 | " unzip -q $$ROOT/$(location //web/gui:onos-gui-data-for-gui2) web/gui/src/main/webapp/data/img/loading/* &&" + |
| 243 | " mkdir -p dist/gui2-fw-lib/assets &&" + |
| 244 | " mv web/gui/src/main/webapp/data/img/loading dist/gui2-fw-lib/assets &&" + |
Sean Condon | 4b7818d | 2019-05-23 07:45:14 +0100 | [diff] [blame] | 245 | " cp README.md LICENSE dist/gui2-fw-lib &&" + |
| 246 | " npm pack ./dist/gui2-fw-lib >> $$ROOT/$(location gui2-fw-ng-build-prod.log) 2>&1 &&" + |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 247 | " mv gui2-fw-lib-*.tgz $$ROOT/$(location gui2-fw-lib-ver.tgz) &&" + |
| 248 | " touch $$ROOT/$(location gui2-fw-ng-build-prod.log)", # to get the log always as the 2nd file |
| 249 | message = "GUI FW Lib build", |
| 250 | visibility = ["//visibility:public"], |
| 251 | ) |
| 252 | |
| 253 | """ |
| 254 | Run 'ng test' to run Angular test and 'ng lint' for checkstyle |
Sean Condon | c687ccb | 2019-10-25 12:27:54 +0100 | [diff] [blame] | 255 | See bazel-out/k8-fastbuild/bin/web/gui2/onos-gui2-fw-ng-lint.log or |
| 256 | bazel-out/k8-fastbuild/bin/web/gui2/onos-gui2-fw-ng-test.log for details of the Angular CLI output |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 257 | """ |
| 258 | |
| 259 | genrule( |
| 260 | name = "_onos-gui2-fw-ng-test", |
| 261 | srcs = [ |
| 262 | "@nodejs//:bin/npm", |
| 263 | "@nodejs//:bin/node", |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 264 | "@nodejs//:bin/nodejs/bin/node", |
| 265 | "@nodejs//:bin/nodejs/bin/npm", |
| 266 | ":onos-gui2-fw-npm-install", |
Sean Condon | ee5d4b9 | 2019-03-11 19:57:34 +0000 | [diff] [blame] | 267 | "//web/gui:onos-gui-data-for-gui2", |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 268 | ":_root_level_files", |
| 269 | ":_gui2_fw_lib_src", |
| 270 | ":_gui2_fw_lib_tests", |
| 271 | ":_e2e_test_files", |
| 272 | ], |
| 273 | outs = [ |
| 274 | "onos-gui2-fw-ng-ver.log", |
| 275 | "onos-gui2-fw-ng-lint.log", |
| 276 | "onos-gui2-fw-ng-test.log", |
| 277 | ], |
| 278 | cmd = " ROOT=`pwd` &&" + |
| 279 | " export HOME=. &&" + |
| 280 | " export XDG_CONFIG_HOME=$(@D)/config &&" + |
| 281 | " NODE=$(location @nodejs//:bin/node) &&" + |
| 282 | " INSTALL_FILES=($(locations :onos-gui2-fw-npm-install)) &&" + # An array of filenames - sorted by time created |
| 283 | " mkdir -p web/gui2-fw-lib &&" + |
| 284 | " cd web/gui2-fw-lib &&" + |
| 285 | " jar xf ../../$(location :_gui2_fw_lib_tests) &&" + |
| 286 | " jar xf $$ROOT/$${INSTALL_FILES[0]} &&" + |
Sean Condon | ee5d4b9 | 2019-03-11 19:57:34 +0000 | [diff] [blame] | 287 | # next 2 lines needed for png file referenced from mast.component.css |
| 288 | " unzip -q $$ROOT/$(location //web/gui:onos-gui-data-for-gui2) web/gui/src/main/webapp/data/img/dropdown-icon.png &&" + |
| 289 | " mv web/gui/src/main/webapp/data projects/gui2-fw-lib/src/lib/mast/mast/ &&" + |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 290 | " chmod +x $$ROOT/web/gui2-fw-lib/node_modules/@angular/cli/bin/ng &&" + |
| 291 | " export PATH=$$ROOT/$$(dirname $${NODE}):$$ROOT/web/gui2-fw-lib/node_modules/@angular/cli/bin:$$PATH &&" + |
| 292 | " node -v > ../../$(location onos-gui2-fw-ng-ver.log) &&" + |
| 293 | " npm -v >> ../../$(location onos-gui2-fw-ng-ver.log) &&" + |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 294 | " ng version >> ../../$(location onos-gui2-fw-ng-ver.log);" + |
| 295 | " ng lint gui2-fw-lib > ../../$(location onos-gui2-fw-ng-lint.log) 2>&1 ||" + |
| 296 | " if [ $$? -eq 0 ]; then echo 'Successfully ran lint';" + |
| 297 | " else " + |
| 298 | " echo 'Error running \'ng lint\' on \'//web/gui2-fw-lib:_onos-gui2-fw-ng-test\'. \\\n" + |
Sean Condon | c687ccb | 2019-10-25 12:27:54 +0100 | [diff] [blame] | 299 | " See bazel-out/k8-fastbuild/bin/web/gui2-fw-lib/onos-gui2-fw-ng-lint.log for more details' >&2;" + |
| 300 | " cat ../../$(location onos-gui2-fw-ng-lint.log) >&2 ||" + |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 301 | " exit 1;" + |
| 302 | " fi;" + |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 303 | " if [ -f /usr/bin/chromium-browser ]; then " + # Add to this for Mac and Chrome |
| 304 | " export CHROME_BIN=/usr/bin/chromium-browser; " + |
| 305 | " elif [ -f /opt/google/chrome/chrome ]; then " + |
| 306 | " export CHROME_BIN=/opt/google/chrome/chrome; " + |
| 307 | " else " + |
| 308 | " MSG='Warning: Step _onos-gui2-fw-ng-test skipped because \\n" + |
| 309 | " no binary for ChromeHeadless browser was found at /usr/bin/chromium-browser. \\n" + |
| 310 | " Install Google Chrome or Chromium Browser to allow this step to run.';" + |
| 311 | " echo -e $$MSG >&2;" + |
| 312 | " echo -e $$MSG > ../../$(location onos-gui2-fw-ng-test.log);" + |
| 313 | " exit 0;" + |
| 314 | " fi;" + |
Sean Condon | 7d27516 | 2018-11-02 16:29:06 +0000 | [diff] [blame] | 315 | " ng test gui2-fw-lib --preserve-symlinks --code-coverage --browsers=ChromeHeadless" + |
| 316 | " --watch=false > ../../$(location onos-gui2-fw-ng-test.log) 2>&1 ||" + |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 317 | " if [ $$? -eq 0 ]; then echo 'Successfully ran tests';" + |
| 318 | " else " + |
| 319 | " echo 'Error running \'ng test\' on \'//web/gui2-fw-lib:onos-gui2-fw-ng-test\'. \\\n" + |
Sean Condon | c687ccb | 2019-10-25 12:27:54 +0100 | [diff] [blame] | 320 | " See bazel-out/k8-fastbuild/bin/web/gui2-fw-lib/onos-gui2-fw-ng-test.log for more details' >&2;" + |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 321 | #" tail -n 100 ../../$(location onos-gui2-fw-ng-test.log) >&2;" + |
| 322 | " exit 1;" + |
| 323 | " fi;", |
| 324 | message = "GUI FW lib lint and test", |
| 325 | ) |
| 326 | |
| 327 | """ |
| 328 | Wrap the genrule for testing in a test |
| 329 | """ |
| 330 | |
| 331 | sh_test( |
| 332 | name = "onos-gui2-ng-tests", |
| 333 | size = "small", |
| 334 | srcs = [ |
| 335 | ":ng-test.sh", |
| 336 | ], |
| 337 | data = [ |
| 338 | ":_onos-gui2-fw-ng-test", |
| 339 | ], |
| 340 | deps = [ |
| 341 | "@bazel_tools//tools/bash/runfiles", |
| 342 | ], |
| 343 | ) |