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 | |
| 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 | ":package.json", |
| 66 | ":package-lock.json", |
| 67 | ":tsconfig.json", |
| 68 | ":tslint.json", |
| 69 | ], |
| 70 | ) |
| 71 | |
| 72 | filegroup( |
| 73 | name = "_e2e_test_files", |
| 74 | srcs = [ |
| 75 | ":e2e/protractor.conf.js", |
| 76 | ":e2e/src/app.e2e-spec.ts", |
| 77 | ":e2e/src/app.po.ts", |
| 78 | ":e2e/tsconfig.e2e.json", |
| 79 | ], |
| 80 | ) |
| 81 | |
| 82 | """ |
| 83 | Make a group file of all the webapp files. |
| 84 | """ |
| 85 | |
| 86 | filegroup( |
| 87 | name = "_gui2_fw_lib_src", |
| 88 | srcs = glob( |
| 89 | [ |
| 90 | "projects/gui2-fw-lib/**", |
| 91 | ], |
| 92 | exclude = [ |
| 93 | "projects/gui2-fw-lib/**/*.spec.*", # Don't track tests here |
| 94 | "projects/gui2-fw-lib/karma.conf.js", |
| 95 | "projects/gui2-fw-lib/src/test.ts", |
| 96 | ], |
| 97 | ), |
| 98 | ) |
| 99 | |
| 100 | """ |
| 101 | Make a group of all the webapp qpp files. |
| 102 | """ |
| 103 | |
| 104 | filegroup( |
| 105 | name = "_gui2_app_files", |
| 106 | srcs = glob( |
| 107 | [ |
| 108 | "src/**/*", |
| 109 | ], |
| 110 | ), |
| 111 | ) |
| 112 | |
| 113 | """ |
| 114 | Make a jar file of all the webapp test (*.spec.ts) files. |
| 115 | """ |
| 116 | |
| 117 | genrule( |
| 118 | name = "_gui2_fw_lib_tests", |
| 119 | srcs = glob( |
| 120 | [ |
| 121 | "projects/gui2-fw-lib/karma.conf.js", |
| 122 | "projects/gui2-fw-lib/src/test.ts", |
| 123 | "projects/gui2-fw-lib/tsconfig.spec.json", |
| 124 | "projects/gui2-fw-lib/**/*.spec.ts", |
| 125 | ], |
| 126 | exclude = [ |
| 127 | "projects/gui2-fw-lib/ng-package.json", |
| 128 | "projects/gui2-fw-lib/ng-package.prod.json", |
| 129 | "projects/gui2-fw-lib/package.json", |
| 130 | "projects/gui2-fw-lib/tsconfig.lib.json", |
| 131 | "projects/gui2-fw-lib/tslint.json", |
| 132 | "projects/gui2-fw-lib/src/public_api.ts", |
| 133 | ], |
| 134 | ), |
| 135 | outs = ["gui2_fw_lib_tests.jar"], |
| 136 | cmd = "cd web/gui2-fw-lib &&" + |
| 137 | " jar Mcf ../../$@ .", |
| 138 | ) |
| 139 | |
| 140 | """ |
| 141 | Make a jar file of all the CSS files we want to reuse in the target. |
| 142 | """ |
| 143 | |
| 144 | genrule( |
| 145 | name = "gui2_fw_lib_ext_css", |
| 146 | srcs = glob( |
| 147 | [ |
| 148 | "projects/gui2-fw-lib/src/lib/widget/panel.css", |
| 149 | "projects/gui2-fw-lib/src/lib/widget/panel-theme.css", |
| 150 | "projects/gui2-fw-lib/src/lib/widget/table.css", |
| 151 | "projects/gui2-fw-lib/src/lib/widget/table.theme.css", |
| 152 | "projects/gui2-fw-lib/src/lib/widget/table.theme.css", |
| 153 | "projects/gui2-fw-lib/src/lib/layer/loading.service.css", |
| 154 | ], |
| 155 | ), |
| 156 | outs = ["gui2_fw_lib_css.jar"], |
| 157 | cmd = " ROOT=`pwd` &&" + |
| 158 | " cd web/gui2-fw-lib/projects/gui2-fw-lib/src/lib &&" + |
| 159 | " jar Mcf $$ROOT/$@ .", |
| 160 | visibility = ["//visibility:public"], |
| 161 | ) |
| 162 | |
| 163 | """ |
| 164 | Install npm packages listed in package.json in web/gui2 |
| 165 | See bazel-genfiles/web/gui2/onos-gui2-npm-install.log for details of the 'npm install' |
| 166 | """ |
| 167 | |
| 168 | genrule( |
| 169 | name = "onos-gui2-fw-npm-install", |
| 170 | srcs = [ |
| 171 | "@nodejs//:bin/npm", |
| 172 | "@nodejs//:bin/node", |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 173 | "@nodejs//:bin/nodejs/bin/node", |
| 174 | "@nodejs//:bin/nodejs/bin/npm", |
| 175 | ":_root_level_files", |
| 176 | ], |
| 177 | outs = [ |
| 178 | "onos-gui2-npm-install.jar", |
| 179 | "onos-gui2-npm-install.log", |
| 180 | ], |
| 181 | cmd = " ROOT=`pwd` &&" + |
| 182 | " export HOME=. &&" + |
| 183 | " export XDG_CONFIG_HOME=$(@D)/config &&" + # npm config cache to the sandbox |
| 184 | " export BABEL_DISABLE_CACHE=1 &&" + # turn off babel cache |
| 185 | ' if [[ ! -z $${HTTP_PROXY-} ]]; then NPM_ARGS="--proxy $$HTTP_PROXY --without-ssl --insecure"; else NPM_ARGS=""; fi &&' + |
| 186 | " NPM=$(location @nodejs//:bin/npm) &&" + |
| 187 | " export PATH=$$ROOT/$$(dirname $${NPM}):$$PATH &&" + |
| 188 | " npm -v > $$ROOT/$(location onos-gui2-npm-install.log) 2>&1 &&" + |
| 189 | " cd web/gui2-fw-lib && " + |
| 190 | " npm $$NPM_ARGS install --no-cache >> $$ROOT/$(location onos-gui2-npm-install.log) 2>&1 &&" + |
| 191 | " jar Mcf $$ROOT/$(location onos-gui2-npm-install.jar) node_modules &&" + |
| 192 | " touch $$ROOT/$(location onos-gui2-npm-install.log)", # to get the log always as the 2nd file |
| 193 | message = "NodeJS npm install", |
| 194 | visibility = ["//visibility:public"], |
| 195 | ) |
| 196 | |
| 197 | """ |
| 198 | Run ng build to create outputs in production mode |
| 199 | See bazel-genfiles/web/gui2/onos-gui2-ng-build-prod.log for details of the Angular CLI output |
| 200 | """ |
| 201 | |
| 202 | genrule( |
| 203 | name = "onos-gui2-fw-ng-build", |
| 204 | srcs = [ |
| 205 | "@nodejs//:bin/npm", |
| 206 | "@nodejs//:bin/node", |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 207 | "@nodejs//:bin/nodejs/bin/node", |
| 208 | "@nodejs//:bin/nodejs/bin/npm", |
| 209 | ":onos-gui2-fw-npm-install", |
| 210 | ":_root_level_files", |
| 211 | ":_gui2_fw_lib_src", |
| 212 | ], |
| 213 | outs = [ |
| 214 | "gui2-fw-ng-build-prod.log", |
| 215 | "gui2-fw-lib-ver.tgz", |
| 216 | ], |
| 217 | cmd = "ROOT=`pwd` &&" + |
| 218 | " export HOME=. &&" + |
| 219 | " export XDG_CONFIG_HOME=$(@D)/config &&" + |
| 220 | " NODE=$(location @nodejs//:bin/node) &&" + |
| 221 | " INSTALL_FILES=($(locations :onos-gui2-fw-npm-install)) &&" + # An array of filenames - sorted by time created |
| 222 | " cd web/gui2-fw-lib &&" + |
| 223 | " jar xf $$ROOT/$${INSTALL_FILES[0]} &&" + |
| 224 | " chmod +x $$ROOT/web/gui2-fw-lib/node_modules/@angular/cli/bin/ng &&" + |
| 225 | " export PATH=$$ROOT/$$(dirname $${NODE}):$$ROOT/web/gui2-fw-lib/node_modules/@angular/cli/bin:$$PATH &&" + |
| 226 | " node -v > ../../$(location gui2-fw-ng-build-prod.log) &&" + |
| 227 | " npm -v >> ../../$(location gui2-fw-ng-build-prod.log) &&" + |
Sean Condon | 7d27516 | 2018-11-02 16:29:06 +0000 | [diff] [blame] | 228 | " ng version >> ../../$(location gui2-fw-ng-build-prod.log);" + |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 229 | " ng build --prod gui2-fw-lib >> $$ROOT/$(location gui2-fw-ng-build-prod.log) 2>&1 ||" + |
| 230 | " if [ $$? -eq 0 ]; then echo 'Successfully built GUI FW library';" + |
| 231 | " else " + |
| 232 | " echo 'Error running \'ng build gui2-fw-lib\' on \'//web/gui2-fw-lib:onos-gui2-fw-ng-build\'. \\\n" + |
| 233 | " See bazel-genfiles/web/gui2-fw-lib/gui2-fw-ng-build-prod.log for more details' >&2;" + |
| 234 | " exit 1;" + |
| 235 | " fi;" + |
| 236 | " cd dist/gui2-fw-lib &&" + |
| 237 | " npm pack &&" + |
| 238 | " mv gui2-fw-lib-*.tgz $$ROOT/$(location gui2-fw-lib-ver.tgz) &&" + |
| 239 | " touch $$ROOT/$(location gui2-fw-ng-build-prod.log)", # to get the log always as the 2nd file |
| 240 | message = "GUI FW Lib build", |
| 241 | visibility = ["//visibility:public"], |
| 242 | ) |
| 243 | |
| 244 | """ |
| 245 | Run 'ng test' to run Angular test and 'ng lint' for checkstyle |
| 246 | See bazel-genfiles/web/gui2/onos-gui2-fw-ng-lint.log or |
| 247 | bazel-genfiles/web/gui2/onos-gui2-fw-ng-test.log for details of the Angular CLI output |
| 248 | """ |
| 249 | |
| 250 | genrule( |
| 251 | name = "_onos-gui2-fw-ng-test", |
| 252 | srcs = [ |
| 253 | "@nodejs//:bin/npm", |
| 254 | "@nodejs//:bin/node", |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 255 | "@nodejs//:bin/nodejs/bin/node", |
| 256 | "@nodejs//:bin/nodejs/bin/npm", |
| 257 | ":onos-gui2-fw-npm-install", |
Sean Condon | ee5d4b9 | 2019-03-11 19:57:34 +0000 | [diff] [blame^] | 258 | "//web/gui:onos-gui-data-for-gui2", |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 259 | ":_root_level_files", |
| 260 | ":_gui2_fw_lib_src", |
| 261 | ":_gui2_fw_lib_tests", |
| 262 | ":_e2e_test_files", |
| 263 | ], |
| 264 | outs = [ |
| 265 | "onos-gui2-fw-ng-ver.log", |
| 266 | "onos-gui2-fw-ng-lint.log", |
| 267 | "onos-gui2-fw-ng-test.log", |
| 268 | ], |
| 269 | cmd = " ROOT=`pwd` &&" + |
| 270 | " export HOME=. &&" + |
| 271 | " export XDG_CONFIG_HOME=$(@D)/config &&" + |
| 272 | " NODE=$(location @nodejs//:bin/node) &&" + |
| 273 | " INSTALL_FILES=($(locations :onos-gui2-fw-npm-install)) &&" + # An array of filenames - sorted by time created |
| 274 | " mkdir -p web/gui2-fw-lib &&" + |
| 275 | " cd web/gui2-fw-lib &&" + |
| 276 | " jar xf ../../$(location :_gui2_fw_lib_tests) &&" + |
| 277 | " jar xf $$ROOT/$${INSTALL_FILES[0]} &&" + |
Sean Condon | ee5d4b9 | 2019-03-11 19:57:34 +0000 | [diff] [blame^] | 278 | # next 2 lines needed for png file referenced from mast.component.css |
| 279 | " unzip -q $$ROOT/$(location //web/gui:onos-gui-data-for-gui2) web/gui/src/main/webapp/data/img/dropdown-icon.png &&" + |
| 280 | " 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] | 281 | " chmod +x $$ROOT/web/gui2-fw-lib/node_modules/@angular/cli/bin/ng &&" + |
| 282 | " export PATH=$$ROOT/$$(dirname $${NODE}):$$ROOT/web/gui2-fw-lib/node_modules/@angular/cli/bin:$$PATH &&" + |
| 283 | " node -v > ../../$(location onos-gui2-fw-ng-ver.log) &&" + |
| 284 | " npm -v >> ../../$(location onos-gui2-fw-ng-ver.log) &&" + |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 285 | " ng version >> ../../$(location onos-gui2-fw-ng-ver.log);" + |
| 286 | " ng lint gui2-fw-lib > ../../$(location onos-gui2-fw-ng-lint.log) 2>&1 ||" + |
| 287 | " if [ $$? -eq 0 ]; then echo 'Successfully ran lint';" + |
| 288 | " else " + |
| 289 | " echo 'Error running \'ng lint\' on \'//web/gui2-fw-lib:_onos-gui2-fw-ng-test\'. \\\n" + |
| 290 | " See bazel-genfiles/web/gui2-fw-lib/onos-gui2-fw-ng-lint.log for more details' >&2;" + |
| 291 | " exit 1;" + |
| 292 | " fi;" + |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 293 | " if [ -f /usr/bin/chromium-browser ]; then " + # Add to this for Mac and Chrome |
| 294 | " export CHROME_BIN=/usr/bin/chromium-browser; " + |
| 295 | " elif [ -f /opt/google/chrome/chrome ]; then " + |
| 296 | " export CHROME_BIN=/opt/google/chrome/chrome; " + |
| 297 | " else " + |
| 298 | " MSG='Warning: Step _onos-gui2-fw-ng-test skipped because \\n" + |
| 299 | " no binary for ChromeHeadless browser was found at /usr/bin/chromium-browser. \\n" + |
| 300 | " Install Google Chrome or Chromium Browser to allow this step to run.';" + |
| 301 | " echo -e $$MSG >&2;" + |
| 302 | " echo -e $$MSG > ../../$(location onos-gui2-fw-ng-test.log);" + |
| 303 | " exit 0;" + |
| 304 | " fi;" + |
Sean Condon | 7d27516 | 2018-11-02 16:29:06 +0000 | [diff] [blame] | 305 | " ng test gui2-fw-lib --preserve-symlinks --code-coverage --browsers=ChromeHeadless" + |
| 306 | " --watch=false > ../../$(location onos-gui2-fw-ng-test.log) 2>&1 ||" + |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 307 | " if [ $$? -eq 0 ]; then echo 'Successfully ran tests';" + |
| 308 | " else " + |
| 309 | " echo 'Error running \'ng test\' on \'//web/gui2-fw-lib:onos-gui2-fw-ng-test\'. \\\n" + |
| 310 | " See bazel-genfiles/web/gui2-fw-lib/onos-gui2-fw-ng-test.log for more details' >&2;" + |
| 311 | #" tail -n 100 ../../$(location onos-gui2-fw-ng-test.log) >&2;" + |
| 312 | " exit 1;" + |
| 313 | " fi;", |
| 314 | message = "GUI FW lib lint and test", |
| 315 | ) |
| 316 | |
| 317 | """ |
| 318 | Wrap the genrule for testing in a test |
| 319 | """ |
| 320 | |
| 321 | sh_test( |
| 322 | name = "onos-gui2-ng-tests", |
| 323 | size = "small", |
| 324 | srcs = [ |
| 325 | ":ng-test.sh", |
| 326 | ], |
| 327 | data = [ |
| 328 | ":_onos-gui2-fw-ng-test", |
| 329 | ], |
| 330 | deps = [ |
| 331 | "@bazel_tools//tools/bash/runfiles", |
| 332 | ], |
| 333 | ) |