Sean Condon | f6af2a5 | 2018-08-19 10:43:24 +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 |
| 19 | |
| 20 | The GUI2 Angular 6 elements are built here with Angular CLI 'ng' |
| 21 | Some work is being done in the Bazel community to integrate Bazel and |
| 22 | Angular 6, (Angular Buildtools Convergence - |
| 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 | |
| 40 | COMPILE_DEPS = CORE_DEPS + JACKSON + KRYO + [ |
| 41 | "@javax_ws_rs_api//jar", |
| 42 | "@servlet_api//jar", |
| 43 | "@jetty_websocket//jar", |
| 44 | "@jetty_util//jar", |
| 45 | "@jersey_media_multipart//jar", |
| 46 | "@jersey_server//jar", |
| 47 | "//utils/rest:onlab-rest", |
| 48 | "//core/store/serializers:onos-core-serializers", |
| 49 | ] |
| 50 | |
| 51 | TEST_DEPS = TEST + [ |
| 52 | "//core/api:onos-api-tests", |
| 53 | "//drivers/default:onos-drivers-default", |
| 54 | ] |
| 55 | |
| 56 | """ |
| 57 | Files that get put at the top level of the tar ball |
| 58 | """ |
| 59 | |
| 60 | filegroup( |
| 61 | name = "_root_level_files", |
| 62 | srcs = |
| 63 | [ |
| 64 | ":angular.json", |
| 65 | ":karma.conf.js", |
| 66 | ":package.json", |
| 67 | ":package-lock.json", |
| 68 | ":protractor.conf.js", |
| 69 | ":src/main/tsconfig.json", |
| 70 | ":src/main/tslint.json", |
| 71 | ":tsconfig.json", |
| 72 | ], |
| 73 | ) |
| 74 | |
| 75 | filegroup( |
| 76 | name = "_e2e_test_files", |
| 77 | srcs = [ |
| 78 | ":e2e/app.e2e-spec.ts", |
| 79 | ":e2e/app.po.ts", |
| 80 | ":e2e/tsconfig.e2e.json", |
| 81 | ], |
| 82 | ) |
| 83 | |
| 84 | """ |
| 85 | Files that get put into the WEB-INF directory of the tar ball |
| 86 | """ |
| 87 | |
| 88 | filegroup( |
| 89 | name = "_web_inf_classes_files", |
| 90 | srcs = |
| 91 | [ |
| 92 | ":src/main/webapp/error.html", |
| 93 | ":src/main/webapp/login.html", |
| 94 | ":src/main/webapp/nav.html", |
| 95 | ":src/main/webapp/not-ready.html", |
| 96 | ":src/main/webapp/onos.theme.css", |
| 97 | ], |
| 98 | ) |
| 99 | |
| 100 | """ |
Sean Condon | f6af2a5 | 2018-08-19 10:43:24 +0100 | [diff] [blame] | 101 | Run ng build to create outputs in production mode |
| 102 | See bazel-genfiles/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] | 103 | |
| 104 | To avoid the overhead of having several "npm install" invocations, we just do |
| 105 | it once in the //web/gui2-fw-lib which is really the core for the whole Angular 6 |
| 106 | structure in ONOS. This copies files in to node_modules, but because the gui2-fw-lib |
| 107 | has not been generated at that time we copy it in separately below with the 'tar' cmd |
| 108 | and then 'mv' |
Sean Condon | f6af2a5 | 2018-08-19 10:43:24 +0100 | [diff] [blame] | 109 | """ |
| 110 | |
| 111 | genrule( |
| 112 | name = "_onos-gui2-ng-build", |
| 113 | srcs = [ |
| 114 | "@nodejs//:bin/npm", |
| 115 | "@nodejs//:bin/node", |
| 116 | "@nodejs//:bin/node.js", |
| 117 | "@nodejs//:bin/nodejs/bin/node", |
| 118 | "@nodejs//:bin/nodejs/bin/npm", |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 119 | "//web/gui2-fw-lib:onos-gui2-fw-npm-install", |
| 120 | "//web/gui2-fw-lib:onos-gui2-fw-ng-build", |
| 121 | "//web/gui2-fw-lib:gui2_fw_lib_ext_css", |
| 122 | ":_root_level_files", |
Sean Condon | f6af2a5 | 2018-08-19 10:43:24 +0100 | [diff] [blame] | 123 | ":_web_app_all", |
| 124 | ], |
| 125 | outs = [ |
| 126 | "onos-gui2-ng-build-prod.log", |
| 127 | "onos-gui2-ng-build.jar", |
| 128 | ], |
| 129 | cmd = "ROOT=`pwd` &&" + |
| 130 | " export HOME=. &&" + |
| 131 | " export XDG_CONFIG_HOME=$(@D)/config &&" + |
| 132 | " NODE=$(location @nodejs//:bin/node) &&" + |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 133 | " INSTALL_FILES=($(locations //web/gui2-fw-lib:onos-gui2-fw-npm-install)) &&" + # An array of filenames - sorted by time created |
| 134 | " FWLIB_FILES=($(locations //web/gui2-fw-lib:onos-gui2-fw-ng-build)) &&" + # An array of filenames - sorted by time created |
Sean Condon | f6af2a5 | 2018-08-19 10:43:24 +0100 | [diff] [blame] | 135 | " mkdir -p web/gui2 && cd web/gui2 &&" + |
| 136 | " jar xf ../../$(location :_web_app_all) &&" + |
| 137 | " jar xf $$ROOT/$${INSTALL_FILES[0]} &&" + |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 138 | " tar xf $$ROOT/$${FWLIB_FILES[0]} &&" + |
| 139 | " mv package/ node_modules/gui2-fw-lib/ &&" + |
| 140 | " mkdir -p src/main/webapp/app/fw &&" + |
| 141 | " (cd src/main/webapp/app/fw &&" + |
| 142 | " jar xf $$ROOT/$(location //web/gui2-fw-lib:gui2_fw_lib_ext_css)) &&" + |
Sean Condon | f6af2a5 | 2018-08-19 10:43:24 +0100 | [diff] [blame] | 143 | " chmod +x $$ROOT/web/gui2/node_modules/@angular/cli/bin/ng &&" + |
Thomas Vachuska | 0c19e65 | 2018-08-28 10:57:07 -0700 | [diff] [blame] | 144 | " export PATH=$$ROOT/$$(dirname $${NODE}):$$ROOT/web/gui2/node_modules/@angular/cli/bin:$$PATH &&" + |
Sean Condon | f6af2a5 | 2018-08-19 10:43:24 +0100 | [diff] [blame] | 145 | " node -v > ../../$(location onos-gui2-ng-build-prod.log) &&" + |
| 146 | " npm -v >> ../../$(location onos-gui2-ng-build-prod.log) &&" + |
| 147 | " ng -v >> ../../$(location onos-gui2-ng-build-prod.log) &&" + |
| 148 | # Build it in production mode - optimization is turned off because of Angular CLI 6.0.x bug https://github.com/angular/angular-cli/issues/7799 |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 149 | " ng build --extract-css --prod --optimization=false --preserve-symlinks" + |
| 150 | " --base-href /onos/ui2/ --deploy-url /onos/ui2/ >> $$ROOT/$(location onos-gui2-ng-build-prod.log) 2>&1 &&" + |
Sean Condon | f6af2a5 | 2018-08-19 10:43:24 +0100 | [diff] [blame] | 151 | " cd src/main/webapp/dist && jar Mcf $$ROOT/$(location onos-gui2-ng-build.jar) .", |
| 152 | message = "Angular CLI 6 build", |
| 153 | ) |
| 154 | |
| 155 | """ |
| 156 | Run 'ng test' to run Angular test and 'ng lint' for checkstyle |
| 157 | See bazel-genfiles/web/gui2/onos-gui2-ng-lint.log or |
| 158 | bazel-genfiles/web/gui2/onos-gui2-ng-test.log for details of the Angular CLI output |
| 159 | """ |
| 160 | |
| 161 | genrule( |
| 162 | name = "_onos-gui2-ng-test-genrule", |
| 163 | srcs = [ |
| 164 | "@nodejs//:bin/npm", |
| 165 | "@nodejs//:bin/node", |
| 166 | "@nodejs//:bin/node.js", |
| 167 | "@nodejs//:bin/nodejs/bin/node", |
| 168 | "@nodejs//:bin/nodejs/bin/npm", |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 169 | "//web/gui2-fw-lib:onos-gui2-fw-npm-install", |
| 170 | "//web/gui2-fw-lib:onos-gui2-fw-ng-build", |
| 171 | "//web/gui2-fw-lib:gui2_fw_lib_ext_css", |
Sean Condon | f6af2a5 | 2018-08-19 10:43:24 +0100 | [diff] [blame] | 172 | ":_web_app_all", |
| 173 | ":_web_app_tests", |
| 174 | ":_angular_all", |
| 175 | ], |
| 176 | outs = [ |
| 177 | "onos-gui2-ng-ver.log", |
| 178 | "onos-gui2-ng-lint.log", |
| 179 | "onos-gui2-ng-test.log", |
| 180 | ], |
| 181 | cmd = " ROOT=`pwd` &&" + |
| 182 | " export HOME=. &&" + |
| 183 | " export XDG_CONFIG_HOME=$(@D)/config &&" + |
| 184 | " NODE=$(location @nodejs//:bin/node) &&" + |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 185 | " INSTALL_FILES=($(locations //web/gui2-fw-lib:onos-gui2-fw-npm-install)) &&" + # An array of filenames - sorted by time created |
| 186 | " FWLIB_FILES=($(locations //web/gui2-fw-lib:onos-gui2-fw-ng-build)) &&" + # An array of filenames - sorted by time created |
Sean Condon | f6af2a5 | 2018-08-19 10:43:24 +0100 | [diff] [blame] | 187 | " mkdir -p web/gui2 &&" + |
| 188 | " cd web/gui2 &&" + |
| 189 | " jar xf ../../$(location :_angular_all) &&" + |
| 190 | " jar xf ../../$(location :_web_app_all) &&" + |
| 191 | " jar xf ../../$(location :_web_app_tests) &&" + |
| 192 | " jar xf $$ROOT/$${INSTALL_FILES[0]} &&" + |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 193 | " tar xf $$ROOT/$${FWLIB_FILES[0]} &&" + |
| 194 | " mv package/ node_modules/gui2-fw-lib/ &&" + |
| 195 | " mkdir -p src/main/webapp/app/fw &&" + |
| 196 | " (cd src/main/webapp/app/fw &&" + |
| 197 | " jar xf $$ROOT/$(location //web/gui2-fw-lib:gui2_fw_lib_ext_css)) &&" + |
Sean Condon | f6af2a5 | 2018-08-19 10:43:24 +0100 | [diff] [blame] | 198 | " chmod +x $$ROOT/web/gui2/node_modules/@angular/cli/bin/ng &&" + |
Thomas Vachuska | 0c19e65 | 2018-08-28 10:57:07 -0700 | [diff] [blame] | 199 | " export PATH=$$ROOT/$$(dirname $${NODE}):$$ROOT/web/gui2/node_modules/@angular/cli/bin:$$PATH &&" + |
Sean Condon | f6af2a5 | 2018-08-19 10:43:24 +0100 | [diff] [blame] | 200 | " node -v > ../../$(location onos-gui2-ng-ver.log) &&" + |
| 201 | " npm -v >> ../../$(location onos-gui2-ng-ver.log) &&" + |
| 202 | " ng -v >> ../../$(location onos-gui2-ng-ver.log) &&" + |
| 203 | " ng lint > ../../$(location onos-gui2-ng-lint.log);" + |
| 204 | " if [ -f /usr/bin/chromium-browser ]; then " + # Add to this for Mac and Chrome |
| 205 | " export CHROME_BIN=/usr/bin/chromium-browser; " + |
| 206 | " elif [ -f /opt/google/chrome/chrome ]; then " + |
| 207 | " export CHROME_BIN=/opt/google/chrome/chrome; " + |
| 208 | " else " + |
| 209 | " MSG='Warning: Step onos-gui2-ng-test skipped because \\n" + |
| 210 | " no binary for ChromeHeadless browser was found at /usr/bin/chromium-browser. \\n" + |
| 211 | " Install Google Chrome or Chromium Browser to allow this step to run.';" + |
| 212 | " echo -e $$MSG >&2;" + |
| 213 | " echo -e $$MSG > ../../$(location onos-gui2-ng-test.log);" + |
| 214 | " exit 0;" + |
| 215 | " fi;" + |
| 216 | " ng test --preserve-symlinks --code-coverage --browsers=ChromeHeadless" + |
| 217 | " --watch=false > ../../$(location onos-gui2-ng-test.log) 2>&1 ||" + |
| 218 | " if [ $$? -eq 0 ]; then echo 'Successfully ran tests';" + |
| 219 | " else " + |
| 220 | " echo 'Error running \'ng test\' on \'//web/gui2:onos-gui2-ng-test\'. \\\n" + |
| 221 | " See bazel-genfiles/web/gui2/onos-gui2-ng-test.log for more details' >&2;" + |
| 222 | #" tail -n 100 ../../$(location onos-gui2-ng-test.log) >&2;" + |
| 223 | " exit 1;" + |
| 224 | " fi;", |
| 225 | message = "Angular CLI 6 lint and test", |
| 226 | ) |
| 227 | |
| 228 | """ |
| 229 | Make a jar file of all the webapp files. Useful for breaking symblic links in the sandbox |
| 230 | """ |
| 231 | |
| 232 | genrule( |
| 233 | name = "_web_app_all", |
| 234 | srcs = glob( |
| 235 | [ |
| 236 | "src/main/webapp/**", |
| 237 | ], |
| 238 | exclude = [ |
| 239 | "src/main/webapp/**/*.spec.ts", # Don't track tests here |
| 240 | "src/main/webapp/tests/**", |
| 241 | "src/main/webapp/node_modules/**", |
| 242 | "src/main/webapp/dist/**", |
| 243 | "src/main/webapp/doc/**", |
| 244 | ], |
| 245 | ), |
| 246 | outs = ["web_app_all.jar"], |
| 247 | cmd = "cd web/gui2 &&" + |
| 248 | " find src/main/webapp -type f -exec touch -t 201808280000 {} \; &&" + |
| 249 | " jar Mcf ../../$@ src/main/webapp", |
| 250 | ) |
| 251 | |
| 252 | """ |
| 253 | Make a jar file of all the webapp test (*.spec.ts) files. |
| 254 | """ |
| 255 | |
| 256 | genrule( |
| 257 | name = "_web_app_tests", |
| 258 | srcs = glob( |
| 259 | [ |
| 260 | "src/main/webapp/**/*.spec.ts", |
| 261 | ], |
| 262 | exclude = [ |
| 263 | "src/main/webapp/tests/**", |
| 264 | "src/main/webapp/node_modules/**", |
| 265 | "src/main/webapp/dist/**", |
| 266 | "src/main/webapp/doc/**", |
| 267 | ], |
| 268 | ), |
| 269 | outs = ["web_app_tests.jar"], |
| 270 | cmd = "cd web/gui2 &&" + |
| 271 | " find src/main/webapp -type f -exec touch -t 201808280000 {} \; &&" + |
| 272 | " jar Mcf ../../$@ src/main/webapp", |
| 273 | ) |
| 274 | |
| 275 | """ |
| 276 | Make a jar file of all the supporting files. Useful for breaking symblic links in the sandbox |
| 277 | """ |
| 278 | |
| 279 | genrule( |
| 280 | name = "_angular_all", |
| 281 | srcs = [ |
| 282 | ":_e2e_test_files", |
| 283 | ":_root_level_files", |
| 284 | ], |
| 285 | outs = ["angular_all.jar"], |
| 286 | cmd = " cd web/gui2 && jar Mcf ../../$@ .", |
| 287 | ) |
| 288 | |
| 289 | """ |
| 290 | Builds the java jar for the java code provided by the GUI2 |
| 291 | """ |
| 292 | |
| 293 | osgi_jar_with_tests( |
| 294 | name = "_onos-gui2-base-jar", |
Sean Condon | 3c8e558 | 2018-08-28 23:22:43 +0100 | [diff] [blame] | 295 | srcs = [ |
| 296 | "src/main/java/org/onosproject/ui/impl/gui2/LogoutResource.java", |
| 297 | "//web/gui:onos-gui-java-for-gui2", |
Sean Condon | f6af2a5 | 2018-08-19 10:43:24 +0100 | [diff] [blame] | 298 | ], |
Sean Condon | 3c8e558 | 2018-08-28 23:22:43 +0100 | [diff] [blame] | 299 | suppress_checkstyle = True, |
Sean Condon | f6af2a5 | 2018-08-19 10:43:24 +0100 | [diff] [blame] | 300 | test_deps = TEST_DEPS, |
| 301 | web_context = "/onos/ui2", |
| 302 | deps = COMPILE_DEPS, |
| 303 | ) |
| 304 | |
| 305 | """ |
| 306 | Builds the tar ball for the ONOS GUI2 |
| 307 | """ |
| 308 | |
| 309 | genrule( |
| 310 | name = "onos-gui2", |
| 311 | srcs = [ |
| 312 | ":_onos-gui2-ng-build", |
| 313 | ":_onos-gui2-base-jar", |
| 314 | ":_web_inf_classes_files", |
Sean Condon | 3c8e558 | 2018-08-28 23:22:43 +0100 | [diff] [blame] | 315 | "src/main/webapp/WEB-INF/web.xml", |
Sean Condon | f6af2a5 | 2018-08-19 10:43:24 +0100 | [diff] [blame] | 316 | ], |
| 317 | outs = ["onos-gui2.jar"], |
| 318 | cmd = " ROOT=`pwd` &&" + |
| 319 | " mkdir -p web/gui2/WEB-INF/classes &&" + |
| 320 | " cd web/gui2 &&" + |
| 321 | " BUILD_FILES=($(locations :_onos-gui2-ng-build)) &&" + # An array of filenames - sorted by time created |
| 322 | " for i in $(locations :_web_inf_classes_files); do cp $$ROOT/$$i ./WEB-INF/classes/; done &&" + |
| 323 | " (cd WEB-INF/classes && jar xf $$ROOT/$${BUILD_FILES[1]}) &&" + |
| 324 | " jar xf $$ROOT/$(location :_onos-gui2-base-jar) &&" + |
| 325 | " find . -type f -exec touch -t 201808280000 {} \; &&" + |
Sean Condon | 3c8e558 | 2018-08-28 23:22:43 +0100 | [diff] [blame] | 326 | " jar cmf META-INF/MANIFEST.MF $$ROOT/$@ WEB-INF/web.xml WEB-INF/classes", |
Sean Condon | f6af2a5 | 2018-08-19 10:43:24 +0100 | [diff] [blame] | 327 | output_to_bindir = 1, |
| 328 | visibility = ["//visibility:public"], |
| 329 | ) |
| 330 | |
| 331 | """ |
| 332 | Wrap the genrule for testing in a test |
| 333 | """ |
| 334 | |
| 335 | sh_test( |
| 336 | name = "onos-gui2-ng-tests", |
| 337 | size = "small", |
| 338 | srcs = [ |
| 339 | ":ng-test.sh", |
| 340 | ], |
| 341 | data = [ |
| 342 | ":_onos-gui2-ng-test-genrule", |
| 343 | ], |
| 344 | deps = [ |
| 345 | "@bazel_tools//tools/bash/runfiles", |
| 346 | ], |
| 347 | ) |