Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 1 | """ |
| 2 | Copyright 2019-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 Topology app for GUI 2 |
| 19 | |
| 20 | |
| 21 | """ |
| 22 | |
Carmelo Cascone | d33d3b4 | 2019-06-18 12:12:36 -0700 | [diff] [blame] | 23 | load("//tools/build/bazel:jdk_genrule.bzl", genrule = "jdk_genrule") |
| 24 | |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 25 | COMPILE_DEPS = CORE_DEPS + JACKSON + KRYO + [ |
| 26 | "@javax_ws_rs_api//jar", |
| 27 | "@servlet_api//jar", |
| 28 | "@jetty_websocket//jar", |
| 29 | "@jetty_util//jar", |
| 30 | "@jersey_media_multipart//jar", |
| 31 | "@jersey_server//jar", |
| 32 | "//utils/rest:onlab-rest", |
| 33 | "//core/store/serializers:onos-core-serializers", |
| 34 | ] |
| 35 | |
| 36 | TEST_DEPS = TEST + [ |
| 37 | "//core/api:onos-api-tests", |
| 38 | "//drivers/default:onos-drivers-default", |
| 39 | ] |
| 40 | |
| 41 | """ |
| 42 | Files that get put at the top level of the tar ball |
| 43 | """ |
| 44 | |
| 45 | filegroup( |
| 46 | name = "_root_level_files", |
| 47 | srcs = |
| 48 | [ |
| 49 | ":angular.json", |
| 50 | ":package.json", |
| 51 | ":package-lock.json", |
| 52 | ":tsconfig.json", |
| 53 | ":tslint.json", |
| 54 | ], |
| 55 | ) |
| 56 | |
| 57 | filegroup( |
| 58 | name = "_e2e_test_files", |
| 59 | srcs = [ |
| 60 | ":e2e/protractor.conf.js", |
| 61 | ":e2e/src/app.e2e-spec.ts", |
| 62 | ":e2e/src/app.po.ts", |
| 63 | ":e2e/tsconfig.e2e.json", |
| 64 | ], |
| 65 | ) |
| 66 | |
| 67 | """ |
| 68 | Run ng build to create Topo GUI 2 library in production mode |
| 69 | The output file gui2-topo-lib-ver.tgz is in the form that can be uploaded directly to https://www.npmjs.com/ |
Sean Condon | c687ccb | 2019-10-25 12:27:54 +0100 | [diff] [blame] | 70 | See bazel-out/k8-fastbuild/bin/web/gui2-topo-lib/gui2-topo-lib.log for details of the Angular CLI output |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 71 | """ |
| 72 | |
| 73 | genrule( |
| 74 | name = "gui2-topo-lib-build", |
| 75 | srcs = [ |
| 76 | "@nodejs//:bin/npm", |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 77 | "@nodejs//:bin/nodejs/bin/node", |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 78 | "//web/gui2-fw-lib:onos-gui2-fw-npm-install", |
| 79 | "//web/gui2-fw-lib:onos-gui2-fw-ng-build", |
| 80 | "//web/gui2-fw-lib:gui2_fw_lib_ext_css", |
| 81 | ":_root_level_files", |
| 82 | ":_gui2_topo_lib_src", |
| 83 | ":_gui2_topo_tester_files", |
| 84 | ], |
| 85 | outs = [ |
| 86 | "gui2-topo-lib.log", |
| 87 | "gui2-topo-lib-ver.tgz", |
| 88 | ], |
| 89 | cmd = "ROOT=`pwd` &&" + |
| 90 | " export HOME=. &&" + |
| 91 | " export XDG_CONFIG_HOME=$(@D)/config &&" + |
Sean Condon | 0a884ad | 2019-10-28 17:57:21 +0000 | [diff] [blame] | 92 | " NODE=$(location @nodejs//:bin/nodejs/bin/node) &&" + |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 93 | " INSTALL_FILES=($(locations //web/gui2-fw-lib:onos-gui2-fw-npm-install)) &&" + # An array of filenames - sorted by time created |
| 94 | " TOPOLIB_FILES=($(locations //web/gui2-fw-lib:onos-gui2-fw-ng-build)) &&" + # An array of filenames - sorted by time created |
| 95 | " mkdir -p web/gui2-topo-lib &&" + |
| 96 | " cd web/gui2-topo-lib &&" + |
| 97 | " jar xf $$ROOT/$${INSTALL_FILES[0]} &&" + |
| 98 | " tar xf $$ROOT/$${TOPOLIB_FILES[0]} &&" + |
| 99 | " mv package/ node_modules/gui2-fw-lib/ &&" + |
| 100 | " mkdir -p projects/gui2-topo-lib/fw &&" + |
| 101 | " (cd projects/gui2-topo-lib/fw &&" + |
| 102 | " jar xf $$ROOT/$(location //web/gui2-fw-lib:gui2_fw_lib_ext_css)) &&" + |
| 103 | " chmod +x node_modules/@angular/cli/bin/ng &&" + |
| 104 | " export PATH=$$ROOT/$$(dirname $${NODE}):$$ROOT/web/gui2-topo-lib/node_modules/@angular/cli/bin:$$PATH &&" + |
| 105 | " ng build gui2-topo-lib >> $$ROOT/$(location gui2-topo-lib.log) 2>&1 ||" + |
| 106 | " if [ $$? -eq 0 ]; then echo 'Successfully ran build';" + |
| 107 | " else " + |
| 108 | " echo 'Error running \'ng build gui2-topo-lib\' on \'//web/gui2-topo-lib:gui2-topo-lib-build\'. \\\n" + |
Sean Condon | c687ccb | 2019-10-25 12:27:54 +0100 | [diff] [blame] | 109 | " See bazel-out/k8-fastbuild/bin/web/gui2-topo-lib/gui2-topo-lib.log for more details' >&2;" + |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 110 | #" tail -n 100 ../../$(location onos-gui2-ng-test.log) >&2;" + |
| 111 | " exit 1;" + |
| 112 | " fi;" + |
Sean Condon | 4b7818d | 2019-05-23 07:45:14 +0100 | [diff] [blame] | 113 | " cp README.md LICENSE dist/gui2-topo-lib && " + |
Sean Condon | 0a884ad | 2019-10-28 17:57:21 +0000 | [diff] [blame] | 114 | " $$ROOT/$(location @nodejs//:bin/npm) pack ./dist/gui2-topo-lib >> $$ROOT/$(location gui2-topo-lib.log) 2>&1 &&" + |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 115 | " mv gui2-topo-lib-*.tgz $$ROOT/$(location gui2-topo-lib-ver.tgz) &&" + |
| 116 | " touch $$ROOT/$(location gui2-topo-lib.log)", # to get the log always as the 2nd file, |
| 117 | message = "Angular Topo GUI2 build", |
| 118 | visibility = ["//visibility:public"], |
| 119 | ) |
| 120 | |
| 121 | """ |
| 122 | Run 'ng test' to run Angular test and 'ng lint' for checkstyle |
Sean Condon | c687ccb | 2019-10-25 12:27:54 +0100 | [diff] [blame] | 123 | See bazel-out/k8-fastbuild/bin/web/gui2-topo-lib/gui2-topo-lib-lint.log or |
| 124 | bazel-out/k8-fastbuild/bin/web/gui2-topo-lib/gui2-topo-lib-test.log for details of the Angular CLI output |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 125 | """ |
| 126 | |
| 127 | genrule( |
| 128 | name = "_gui2-topo-lib-test-genrule", |
| 129 | srcs = [ |
| 130 | "@nodejs//:bin/npm", |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 131 | "@nodejs//:bin/nodejs/bin/node", |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 132 | "//web/gui2-fw-lib:onos-gui2-fw-npm-install", |
| 133 | "//web/gui2-fw-lib:onos-gui2-fw-ng-build", |
| 134 | "//web/gui2-fw-lib:gui2_fw_lib_ext_css", |
| 135 | ":_root_level_files", |
| 136 | ":_gui2_topo_lib_src", |
| 137 | ":_gui2_topo_lib_src_tests", |
| 138 | ], |
| 139 | outs = [ |
| 140 | "gui2-topo-lib-ver.log", |
| 141 | "gui2-topo-lib-lint.log", |
| 142 | "gui2-topo-lib-test.log", |
| 143 | ], |
| 144 | cmd = " ROOT=`pwd` &&" + |
| 145 | " export HOME=. &&" + |
| 146 | " export XDG_CONFIG_HOME=$(@D)/config &&" + |
Sean Condon | 0a884ad | 2019-10-28 17:57:21 +0000 | [diff] [blame] | 147 | " NODE=$(location @nodejs//:bin/nodejs/bin/node) &&" + |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 148 | " INSTALL_FILES=($(locations //web/gui2-fw-lib:onos-gui2-fw-npm-install)) &&" + # An array of filenames - sorted by time created |
| 149 | " FWLIB_FILES=($(locations //web/gui2-fw-lib:onos-gui2-fw-ng-build)) &&" + # An array of filenames - sorted by time created |
| 150 | " mkdir -p web/gui2-topo-lib &&" + |
| 151 | " cd web/gui2-topo-lib &&" + |
| 152 | " jar xf ../../$(location :_gui2_topo_lib_src_tests) &&" + |
| 153 | " jar xf $$ROOT/$${INSTALL_FILES[0]} &&" + |
| 154 | " tar xf $$ROOT/$${FWLIB_FILES[0]} &&" + |
| 155 | " mv package/ node_modules/gui2-fw-lib/ &&" + |
| 156 | " mkdir -p projects/gui2-topo-lib/fw &&" + |
| 157 | " (cd projects/gui2-topo-lib/fw &&" + |
| 158 | " jar xf $$ROOT/$(location //web/gui2-fw-lib:gui2_fw_lib_ext_css)) &&" + |
| 159 | " chmod +x $$ROOT/web/gui2-topo-lib/node_modules/@angular/cli/bin/ng &&" + |
| 160 | " export PATH=$$ROOT/$$(dirname $${NODE}):node_modules/@angular/cli/bin:$$PATH &&" + |
| 161 | " node -v > ../../$(location gui2-topo-lib-ver.log) &&" + |
Sean Condon | 0a884ad | 2019-10-28 17:57:21 +0000 | [diff] [blame] | 162 | " $$ROOT/$(location @nodejs//:bin/npm) -v >> ../../$(location gui2-topo-lib-ver.log) &&" + |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 163 | " ng version >> ../../$(location gui2-topo-lib-ver.log) &&" + |
| 164 | " ng lint gui2-topo-lib > ../../$(location gui2-topo-lib-lint.log) 2>&1 ||" + |
| 165 | " if [ $$? -eq 0 ]; then echo 'Successfully ran lint';" + |
| 166 | " else " + |
| 167 | " echo 'Error running \'ng lint\' on \'//web/gui2-topo-lib:_gui2-topo-lib-test-genrule\'. \\\n" + |
Sean Condon | c687ccb | 2019-10-25 12:27:54 +0100 | [diff] [blame] | 168 | " See bazel-out/k8-fastbuild/bin/web/gui2-topo-lib/gui2-topo-lib-lint.log for more details' >&2;" + |
| 169 | " cat ../../$(location gui2-topo-lib-lint.log) >&2 ||" + |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 170 | " exit 1;" + |
| 171 | " fi;" + |
| 172 | " if [ -f /usr/bin/chromium-browser ]; then " + # Add to this for Mac and Chrome |
| 173 | " export CHROME_BIN=/usr/bin/chromium-browser; " + |
| 174 | " elif [ -f /opt/google/chrome/chrome ]; then " + |
| 175 | " export CHROME_BIN=/opt/google/chrome/chrome; " + |
| 176 | " else " + |
| 177 | " MSG='Warning: Step gui2-topo-lib-tests skipped because \\n" + |
| 178 | " no binary for ChromeHeadless browser was found at /usr/bin/chromium-browser. \\n" + |
| 179 | " Install Google Chrome or Chromium Browser to allow this step to run.';" + |
| 180 | " echo -e $$MSG >&2;" + |
| 181 | " echo -e $$MSG > ../../$(location gui2-topo-lib-test.log);" + |
| 182 | " exit 0;" + |
| 183 | " fi;" + |
| 184 | " ng test gui2-topo-lib --preserve-symlinks --code-coverage --browsers=ChromeHeadless" + |
| 185 | " --watch=false > ../../$(location gui2-topo-lib-test.log) 2>&1 ||" + |
| 186 | " if [ $$? -eq 0 ]; then echo 'Successfully ran tests';" + |
| 187 | " else " + |
| 188 | " echo 'Error running \'ng test gui2-topo-lib\' on \'//web/gui2-topo-lib:_gui2-topo-lib-test-genrule\'. \\\n" + |
Sean Condon | c687ccb | 2019-10-25 12:27:54 +0100 | [diff] [blame] | 189 | " See bazel-out/k8-fastbuild/bin/web/gui2-topo-lib/gui2-topo-lib-test.log for more details' >&2;" + |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 190 | " exit 1;" + |
| 191 | " fi;", |
| 192 | message = "Angular Topo GUI2 Lib lint and test", |
| 193 | ) |
| 194 | |
| 195 | """ |
| 196 | Make a group of all the webapp files. |
| 197 | """ |
| 198 | |
| 199 | filegroup( |
| 200 | name = "_gui2_topo_lib_src", |
| 201 | srcs = glob( |
| 202 | [ |
| 203 | "projects/gui2-topo-lib/**/*", |
Sean Condon | 4b7818d | 2019-05-23 07:45:14 +0100 | [diff] [blame] | 204 | "README.md", |
| 205 | "LICENSE", |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 206 | ], |
| 207 | exclude = [ |
| 208 | "projects/gui2-topo-lib/**/*.spec.*", # Don't track tests here |
| 209 | "projects/gui2-topo-lib/karma.conf.js", |
| 210 | "projects/gui2-topo-lib/src/test.ts", |
| 211 | "projects/gui2-topo-lib/fw/**/*", |
| 212 | ], |
| 213 | ), |
| 214 | ) |
| 215 | |
| 216 | """ |
| 217 | Make a group of all the webapp qpp files. |
| 218 | """ |
| 219 | |
| 220 | filegroup( |
| 221 | name = "_gui2_topo_tester_files", |
| 222 | srcs = glob( |
| 223 | [ |
| 224 | "src/**/*", |
| 225 | ], |
| 226 | ), |
| 227 | ) |
| 228 | |
| 229 | """ |
| 230 | Make a jar file of all the webapp test (*.spec.ts) files. |
| 231 | """ |
| 232 | |
| 233 | genrule( |
| 234 | name = "_gui2_topo_lib_src_tests", |
| 235 | srcs = glob( |
| 236 | [ |
| 237 | "projects/gui2-topo-lib/karma.conf.js", |
| 238 | "projects/gui2-topo-lib/src/test.ts", |
| 239 | "projects/gui2-topo-lib/tsconfig.spec.json", |
| 240 | "projects/gui2-topo-lib/**/*.spec.ts", |
| 241 | ], |
| 242 | exclude = [ |
| 243 | "projects/gui2-topo-lib/ng-package.json", |
| 244 | "projects/gui2-topo-lib/ng-package.prod.json", |
| 245 | "projects/gui2-topo-lib/package.json", |
| 246 | "projects/gui2-topo-lib/tsconfig.lib.json", |
| 247 | "projects/gui2-topo-lib/tslint.json", |
| 248 | "projects/gui2-topo-lib/src/public_api.ts", |
| 249 | ], |
| 250 | ), |
| 251 | outs = ["gui2_topo_lib_src_tests.jar"], |
| 252 | cmd = "cd web/gui2-topo-lib &&" + |
| 253 | " jar Mcf ../../$@ .", |
| 254 | ) |
| 255 | |
| 256 | """ |
| 257 | Make a jar file of all the webapp test (*.spec.ts) files. |
| 258 | """ |
| 259 | |
| 260 | genrule( |
| 261 | name = "_gui2_topo_lib_tests", |
| 262 | srcs = glob( |
| 263 | [ |
| 264 | "projects/gui2-topo-lib/**/*.spec.ts", |
| 265 | "projects/gui2-topo-lib/**/*.spec.json", |
| 266 | ], |
| 267 | exclude = [ |
| 268 | "src/main/webapp/tests/**", |
| 269 | "src/main/webapp/node_modules/**", |
| 270 | "src/main/webapp/dist/**", |
| 271 | "src/main/webapp/doc/**", |
| 272 | ], |
| 273 | ), |
| 274 | outs = ["gui2_topo_lib_tests.jar"], |
| 275 | cmd = "cd web/gui2-topo-lib &&" + |
| 276 | " find projects/gui2-topo-lib/src/lib -type f -exec touch -t 201808280000 {} \; &&" + |
| 277 | " jar Mcf ../../$@ projects/gui2-topo-lib/src/lib", |
| 278 | ) |
| 279 | |
| 280 | """ |
| 281 | Wrap the genrule for testing in a test |
| 282 | """ |
| 283 | |
| 284 | sh_test( |
| 285 | name = "gui2-topo-lib-tests", |
| 286 | size = "small", |
| 287 | srcs = [ |
| 288 | ":ng-test.sh", |
| 289 | ], |
| 290 | data = [ |
| 291 | ":_gui2-topo-lib-test-genrule", |
| 292 | ], |
| 293 | deps = [ |
| 294 | "@bazel_tools//tools/bash/runfiles", |
| 295 | ], |
| 296 | ) |