Boyuan Yan | 6b23b38 | 2019-06-04 11:59:35 -0700 | [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 roadm 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 | |
Boyuan Yan | 6b23b38 | 2019-06-04 11:59:35 -0700 | [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 roadm GUI 2 library in production mode |
| 69 | The output file roadm-gui-lib-ver.tgz is in the form that can be uploaded directly to https://www.npmjs.com/ |
| 70 | See bazel-genfiles/apps/roadm/web/roadm-gui/roadm-gui-lib.log for details of the Angular CLI output |
| 71 | """ |
| 72 | |
| 73 | genrule( |
| 74 | name = "roadm-gui-lib-build", |
| 75 | srcs = [ |
| 76 | "@nodejs//:bin/npm", |
| 77 | "@nodejs//:bin/node", |
| 78 | "@nodejs//:bin/nodejs/bin/node", |
| 79 | "@nodejs//:bin/nodejs/bin/npm", |
| 80 | "//web/gui2-fw-lib:onos-gui2-fw-npm-install", |
| 81 | "//web/gui2-fw-lib:onos-gui2-fw-ng-build", |
| 82 | "//web/gui2-fw-lib:gui2_fw_lib_ext_css", |
| 83 | ":_root_level_files", |
| 84 | ":_roadm_lib_src", |
| 85 | ":_roadm_tester_files", |
| 86 | ], |
| 87 | outs = [ |
| 88 | "roadm-gui-lib.log", |
| 89 | "roadm-gui-lib-ver.tgz", |
| 90 | ], |
| 91 | cmd = "ROOT=`pwd` &&" + |
| 92 | " export HOME=. &&" + |
| 93 | " export XDG_CONFIG_HOME=$(@D)/config &&" + |
| 94 | " NODE=$(location @nodejs//:bin/node) &&" + |
| 95 | " INSTALL_FILES=($(locations //web/gui2-fw-lib:onos-gui2-fw-npm-install)) &&" + # An array of filenames - sorted by time created |
| 96 | " FWLIB_FILES=($(locations //web/gui2-fw-lib:onos-gui2-fw-ng-build)) &&" + # An array of filenames - sorted by time created |
| 97 | " mkdir -p apps/roadm/web/roadm-gui &&" + |
| 98 | " cd apps/roadm/web/roadm-gui &&" + |
| 99 | " jar xf $$ROOT/$${INSTALL_FILES[0]} &&" + |
| 100 | " tar xf $$ROOT/$${FWLIB_FILES[0]} &&" + |
| 101 | " mv package/ node_modules/gui2-fw-lib/ &&" + |
| 102 | " mkdir -p projects/roadm-gui-lib/fw &&" + |
| 103 | " (cd projects/roadm-gui-lib/fw &&" + |
| 104 | " jar xf $$ROOT/$(location //web/gui2-fw-lib:gui2_fw_lib_ext_css)) &&" + |
| 105 | " chmod +x node_modules/@angular/cli/bin/ng &&" + |
| 106 | " export PATH=$$ROOT/$$(dirname $${NODE}):$$ROOT/apps/roadm/web/roadm-gui/node_modules/@angular/cli/bin:$$PATH &&" + |
| 107 | " ng build roadm-gui-lib >> $$ROOT/$(location roadm-gui-lib.log) 2>&1 ||" + |
| 108 | " if [ $$? -eq 0 ]; then echo 'Successfully ran build';" + |
| 109 | " else " + |
| 110 | " echo 'Error running \'ng build roadm-gui-lib\' on \'//apps/roadm/web/roadm-gui:roadm-gui-lib-build\'. \\\n" + |
| 111 | " See bazel-genfiles/apps/roadm/web/roadm-gui/roadm-gui-lib.log for more details' >&2;" + |
| 112 | #" tail -n 100 ../../../../$(location onos-gui2-ng-test.log) >&2;" + |
| 113 | " exit 1;" + |
| 114 | " fi;" + |
| 115 | " cp README.md LICENSE dist/roadm-gui-lib && " + |
| 116 | " npm pack ./dist/roadm-gui-lib >> $$ROOT/$(location roadm-gui-lib.log) 2>&1 &&" + |
| 117 | " mv roadm-gui-lib-*.tgz $$ROOT/$(location roadm-gui-lib-ver.tgz) &&" + |
| 118 | " touch $$ROOT/$(location roadm-gui-lib.log)", # to get the log always as the 2nd file, |
| 119 | message = "Angular roadm Lib build", |
| 120 | visibility = ["//visibility:public"], |
| 121 | ) |
| 122 | |
| 123 | """ |
| 124 | Run 'ng test' to run Angular test and 'ng lint' for checkstyle |
| 125 | See bazel-genfiles/apps/roadm/web/roadm-gui/roadm-gui-lib-lint.log or |
| 126 | bazel-genfiles/apps/roadm/web/roadm-gui/roadm-gui-lib-test.log for details of the Angular CLI output |
| 127 | """ |
| 128 | |
| 129 | genrule( |
| 130 | name = "_roadm-gui-lib-test-genrule", |
| 131 | srcs = [ |
| 132 | "@nodejs//:bin/npm", |
| 133 | "@nodejs//:bin/node", |
| 134 | "@nodejs//:bin/nodejs/bin/node", |
| 135 | "@nodejs//:bin/nodejs/bin/npm", |
| 136 | "//web/gui2-fw-lib:onos-gui2-fw-npm-install", |
| 137 | "//web/gui2-fw-lib:onos-gui2-fw-ng-build", |
| 138 | "//web/gui2-fw-lib:gui2_fw_lib_ext_css", |
| 139 | ":_root_level_files", |
| 140 | ":_roadm_lib_src", |
| 141 | ":_roadm_lib_src_tests", |
| 142 | ], |
| 143 | outs = [ |
| 144 | "roadm-gui-lib-ver.log", |
| 145 | "roadm-gui-lib-lint.log", |
| 146 | "roadm-gui-lib-test.log", |
| 147 | ], |
| 148 | cmd = " ROOT=`pwd` &&" + |
| 149 | " export HOME=. &&" + |
| 150 | " export XDG_CONFIG_HOME=$(@D)/config &&" + |
| 151 | " NODE=$(location @nodejs//:bin/node) &&" + |
| 152 | " INSTALL_FILES=($(locations //web/gui2-fw-lib:onos-gui2-fw-npm-install)) &&" + # An array of filenames - sorted by time created |
| 153 | " FWLIB_FILES=($(locations //web/gui2-fw-lib:onos-gui2-fw-ng-build)) &&" + # An array of filenames - sorted by time created |
| 154 | " mkdir -p apps/roadm/web/roadm-gui &&" + |
| 155 | " cd apps/roadm/web/roadm-gui &&" + |
| 156 | " jar xf ../../../../$(location :_roadm_lib_src_tests) &&" + |
| 157 | " jar xf $$ROOT/$${INSTALL_FILES[0]} &&" + |
| 158 | " tar xf $$ROOT/$${FWLIB_FILES[0]} &&" + |
| 159 | " mv package/ node_modules/gui2-fw-lib/ &&" + |
| 160 | " mkdir -p projects/roadm-gui-lib/fw &&" + |
| 161 | " (cd projects/roadm-gui-lib/fw &&" + |
| 162 | " jar xf $$ROOT/$(location //web/gui2-fw-lib:gui2_fw_lib_ext_css)) &&" + |
| 163 | " chmod +x $$ROOT/apps/roadm/web/roadm-gui/node_modules/@angular/cli/bin/ng &&" + |
| 164 | " export PATH=$$ROOT/$$(dirname $${NODE}):node_modules/@angular/cli/bin:$$PATH &&" + |
| 165 | " node -v > ../../../../$(location roadm-gui-lib-ver.log) &&" + |
| 166 | " npm -v >> ../../../../$(location roadm-gui-lib-ver.log) &&" + |
| 167 | " ng version >> ../../../../$(location roadm-gui-lib-ver.log) &&" + |
| 168 | " ng lint roadm-gui-lib > ../../../../$(location roadm-gui-lib-lint.log) 2>&1 ||" + |
| 169 | " if [ $$? -eq 0 ]; then echo 'Successfully ran lint';" + |
| 170 | " else " + |
| 171 | " echo 'Error running \'ng lint\' on \'//apps/roadm/web/roadm-gui:_roadm-gui-lib-test-genrule\'. \\\n" + |
| 172 | " See bazel-genfiles/apps/roadm/web/roadm-gui/roadm-gui-lib-lint.log for more details' >&2;" + |
| 173 | " exit 1;" + |
| 174 | " fi;" + |
| 175 | " echo -e 'Skipping unit tests temporarily for roadm-gui-lib' > ../../../../$(location roadm-gui-lib-test.log);", |
| 176 | message = "Angular Roadm Lib lint and test", |
| 177 | ) |
| 178 | |
| 179 | """ |
| 180 | Make a group of all the webapp files. |
| 181 | """ |
| 182 | |
| 183 | filegroup( |
| 184 | name = "_roadm_lib_src", |
| 185 | srcs = glob( |
| 186 | [ |
| 187 | "projects/roadm-gui-lib/**/*", |
| 188 | "README.md", |
| 189 | "LICENSE", |
| 190 | ], |
| 191 | exclude = [ |
| 192 | "projects/roadm-gui-lib/**/*.spec.*", # Don't track tests here |
| 193 | "projects/roadm-gui-lib/karma.conf.js", |
| 194 | "projects/roadm-gui-lib/src/test.ts", |
| 195 | "projects/roadm-gui-lib/fw/**/*", |
| 196 | ], |
| 197 | ), |
| 198 | ) |
| 199 | |
| 200 | """ |
| 201 | Make a group of all the webapp qpp files. |
| 202 | """ |
| 203 | |
| 204 | filegroup( |
| 205 | name = "_roadm_tester_files", |
| 206 | srcs = glob( |
| 207 | [ |
| 208 | "src/**/*", |
| 209 | ], |
| 210 | ), |
| 211 | ) |
| 212 | |
| 213 | """ |
| 214 | Make a jar file of all the webapp test (*.spec.ts) files. |
| 215 | """ |
| 216 | |
| 217 | genrule( |
| 218 | name = "_roadm_lib_src_tests", |
| 219 | srcs = glob( |
| 220 | [ |
| 221 | "projects/roadm-gui-lib/karma.conf.js", |
| 222 | "projects/roadm-gui-lib/src/test.ts", |
| 223 | "projects/roadm-gui-lib/tsconfig.spec.json", |
| 224 | "projects/roadm-gui-lib/**/*.spec.ts", |
| 225 | ], |
| 226 | exclude = [ |
| 227 | "projects/roadm-gui-lib/ng-package.json", |
| 228 | "projects/roadm-gui-lib/ng-package.prod.json", |
| 229 | "projects/roadm-gui-lib/package.json", |
| 230 | "projects/roadm-gui-lib/tsconfig.lib.json", |
| 231 | "projects/roadm-gui-lib/tslint.json", |
| 232 | "projects/roadm-gui-lib/src/public_api.ts", |
| 233 | ], |
| 234 | ), |
| 235 | outs = ["roadm_gui_lib_src_tests.jar"], |
| 236 | cmd = "cd apps/roadm/web/roadm-gui &&" + |
| 237 | " jar Mcf ../../../../$@ .", |
| 238 | ) |
| 239 | |
| 240 | """ |
| 241 | Make a jar file of all the webapp test (*.spec.ts) files. |
| 242 | """ |
| 243 | |
| 244 | genrule( |
| 245 | name = "_roadm_gui_lib_tests", |
| 246 | srcs = glob( |
| 247 | [ |
| 248 | "projects/roadm-gui-lib/**/*.spec.ts", |
| 249 | "projects/roadm-gui-lib/**/*.spec.json", |
| 250 | ], |
| 251 | exclude = [ |
| 252 | "src/main/webapp/tests/**", |
| 253 | "src/main/webapp/node_modules/**", |
| 254 | "src/main/webapp/dist/**", |
| 255 | "src/main/webapp/doc/**", |
| 256 | ], |
| 257 | ), |
| 258 | outs = ["roadm_gui_lib_tests.jar"], |
| 259 | cmd = "cd apps/roadm/web/roadm-gui &&" + |
| 260 | " find projects/roadm-gui-lib/src/lib -type f -exec touch -t 201808280000 {} \; &&" + |
| 261 | " jar Mcf ../../../../$@ projects/roadm-gui-lib/src/lib", |
| 262 | ) |
| 263 | |
| 264 | """ |
| 265 | Wrap the genrule for testing in a test |
| 266 | """ |
| 267 | |
| 268 | sh_test( |
| 269 | name = "roadm-gui-lib-tests", |
| 270 | size = "small", |
| 271 | srcs = [ |
| 272 | ":ng-test.sh", |
| 273 | ], |
| 274 | data = [ |
| 275 | ":_roadm-gui-lib-test-genrule", |
| 276 | ], |
| 277 | deps = [ |
| 278 | "@bazel_tools//tools/bash/runfiles", |
| 279 | ], |
| 280 | ) |