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