blob: c1d78c532aa006bd55b036a361fdda9d60c22f67 [file] [log] [blame]
Sean Condonf6af2a52018-08-19 10:43:24 +01001"""
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
Sean Condon0c577f62018-11-18 22:40:05 +000020 The GUI2 Angular 7 elements are built here with Angular CLI 'ng'
Sean Condonf6af2a52018-08-19 10:43:24 +010021 Some work is being done in the Bazel community to integrate Bazel and
Sean Condon0c577f62018-11-18 22:40:05 +000022 Angular 7, (Angular Buildtools Convergence -
Sean Condonf6af2a52018-08-19 10:43:24 +010023 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
Sean Condonb2c483c2019-01-16 20:28:55 +000040COMPILE_DEPS = CORE_DEPS + JACKSON + KRYO + CLI + [
Sean Condonf6af2a52018-08-19 10:43:24 +010041 "@javax_ws_rs_api//jar",
42 "@servlet_api//jar",
43 "@jetty_websocket//jar",
Sean Condonb2c483c2019-01-16 20:28:55 +000044 "@jetty_websocket_api//jar",
Sean Condonf6af2a52018-08-19 10:43:24 +010045 "@jetty_util//jar",
46 "@jersey_media_multipart//jar",
47 "@jersey_server//jar",
Ray Milkey427e9752018-11-15 16:34:48 -080048 "@jersey_hk2//jar",
Sean Condonf6af2a52018-08-19 10:43:24 +010049 "//utils/rest:onlab-rest",
50 "//core/store/serializers:onos-core-serializers",
51]
52
53TEST_DEPS = TEST + [
54 "//core/api:onos-api-tests",
55 "//drivers/default:onos-drivers-default",
56]
57
58"""
59 Files that get put at the top level of the tar ball
60"""
61
62filegroup(
63 name = "_root_level_files",
64 srcs =
65 [
66 ":angular.json",
67 ":karma.conf.js",
68 ":package.json",
69 ":package-lock.json",
70 ":protractor.conf.js",
71 ":src/main/tsconfig.json",
72 ":src/main/tslint.json",
73 ":tsconfig.json",
74 ],
75)
76
77filegroup(
78 name = "_e2e_test_files",
79 srcs = [
80 ":e2e/app.e2e-spec.ts",
81 ":e2e/app.po.ts",
82 ":e2e/tsconfig.e2e.json",
83 ],
84)
85
86"""
87 Files that get put into the WEB-INF directory of the tar ball
88"""
89
90filegroup(
91 name = "_web_inf_classes_files",
92 srcs =
93 [
94 ":src/main/webapp/error.html",
95 ":src/main/webapp/login.html",
96 ":src/main/webapp/nav.html",
97 ":src/main/webapp/not-ready.html",
Sean Condon55c30532018-10-29 12:26:57 +000098 ":src/main/webapp/onos.global.css",
Sean Condonf6af2a52018-08-19 10:43:24 +010099 ],
100)
101
102"""
Sean Condonf6af2a52018-08-19 10:43:24 +0100103 Run ng build to create outputs in production mode
104 See bazel-genfiles/web/gui2/onos-gui2-ng-build-prod.log for details of the Angular CLI output
Sean Condon5ca00262018-09-06 17:55:25 +0100105
106 To avoid the overhead of having several "npm install" invocations, we just do
Sean Condon0c577f62018-11-18 22:40:05 +0000107 it once in the //web/gui2-fw-lib which is really the core for the whole Angular 7
Sean Condon5ca00262018-09-06 17:55:25 +0100108 structure in ONOS. This copies files in to node_modules, but because the gui2-fw-lib
109 has not been generated at that time we copy it in separately below with the 'tar' cmd
110 and then 'mv'
Sean Condonf6af2a52018-08-19 10:43:24 +0100111"""
112
113genrule(
114 name = "_onos-gui2-ng-build",
115 srcs = [
116 "@nodejs//:bin/npm",
117 "@nodejs//:bin/node",
Sean Condonf6af2a52018-08-19 10:43:24 +0100118 "@nodejs//:bin/nodejs/bin/node",
119 "@nodejs//:bin/nodejs/bin/npm",
Sean Condon5ca00262018-09-06 17:55:25 +0100120 "//web/gui2-fw-lib:onos-gui2-fw-npm-install",
121 "//web/gui2-fw-lib:onos-gui2-fw-ng-build",
122 "//web/gui2-fw-lib:gui2_fw_lib_ext_css",
Sean Condonff85fbe2019-03-16 14:28:46 +0000123 "//web/gui2-topo-lib:gui2-topo-lib-build",
Sean Condon87b78502018-09-17 20:53:24 +0100124 "//apps/faultmanagement/fm-gui2-lib:fm-gui2-lib-build",
Sean Condon5ca00262018-09-06 17:55:25 +0100125 ":_root_level_files",
Sean Condonf6af2a52018-08-19 10:43:24 +0100126 ":_web_app_all",
127 ],
128 outs = [
129 "onos-gui2-ng-build-prod.log",
130 "onos-gui2-ng-build.jar",
131 ],
132 cmd = "ROOT=`pwd` &&" +
133 " export HOME=. &&" +
134 " export XDG_CONFIG_HOME=$(@D)/config &&" +
135 " NODE=$(location @nodejs//:bin/node) &&" +
Sean Condon5ca00262018-09-06 17:55:25 +0100136 " INSTALL_FILES=($(locations //web/gui2-fw-lib:onos-gui2-fw-npm-install)) &&" + # An array of filenames - sorted by time created
137 " FWLIB_FILES=($(locations //web/gui2-fw-lib:onos-gui2-fw-ng-build)) &&" + # An array of filenames - sorted by time created
Sean Condonf6af2a52018-08-19 10:43:24 +0100138 " mkdir -p web/gui2 && cd web/gui2 &&" +
139 " jar xf ../../$(location :_web_app_all) &&" +
140 " jar xf $$ROOT/$${INSTALL_FILES[0]} &&" +
Sean Condon5ca00262018-09-06 17:55:25 +0100141 " tar xf $$ROOT/$${FWLIB_FILES[0]} &&" +
142 " mv package/ node_modules/gui2-fw-lib/ &&" +
Sean Condon87b78502018-09-17 20:53:24 +0100143 # Add in modules from external packages
Sean Condonff85fbe2019-03-16 14:28:46 +0000144 " GUI2_TOPO_LIB_FILES=($(locations //web/gui2-topo-lib:gui2-topo-lib-build)) &&" + # An array of filenames - sorted by time created
145 " tar xf $$ROOT/$${GUI2_TOPO_LIB_FILES[0]} &&" +
146 " mv package/ node_modules/gui2-topo-lib/ &&" +
Sean Condon87b78502018-09-17 20:53:24 +0100147 " FM_GUI2_LIB_FILES=($(locations //apps/faultmanagement/fm-gui2-lib:fm-gui2-lib-build)) &&" + # An array of filenames - sorted by time created
148 " tar xf $$ROOT/$${FM_GUI2_LIB_FILES[0]} &&" +
149 " mv package/ node_modules/fm-gui2-lib/ &&" +
150 # End of add in modules from external packages
Sean Condon5ca00262018-09-06 17:55:25 +0100151 " mkdir -p src/main/webapp/app/fw &&" +
152 " (cd src/main/webapp/app/fw &&" +
153 " jar xf $$ROOT/$(location //web/gui2-fw-lib:gui2_fw_lib_ext_css)) &&" +
Sean Condonf6af2a52018-08-19 10:43:24 +0100154 " chmod +x $$ROOT/web/gui2/node_modules/@angular/cli/bin/ng &&" +
Thomas Vachuska0c19e652018-08-28 10:57:07 -0700155 " export PATH=$$ROOT/$$(dirname $${NODE}):$$ROOT/web/gui2/node_modules/@angular/cli/bin:$$PATH &&" +
Sean Condonf6af2a52018-08-19 10:43:24 +0100156 " node -v > ../../$(location onos-gui2-ng-build-prod.log) &&" +
157 " npm -v >> ../../$(location onos-gui2-ng-build-prod.log) &&" +
Sean Condon0c577f62018-11-18 22:40:05 +0000158 " ng version >> ../../$(location onos-gui2-ng-build-prod.log) &&" +
159 " ng build --extract-css --prod --preserve-symlinks" +
Sean Condonbf7ff4f2019-03-17 16:18:42 +0000160 " --base-href /onos/ui/ --deploy-url /onos/ui/ >> $$ROOT/$(location onos-gui2-ng-build-prod.log) 2>&1 ||" +
Sean Condon87b78502018-09-17 20:53:24 +0100161 " if [ $$? -eq 0 ]; then echo 'Successfully ran build';" +
162 " else " +
163 " echo 'Error running \'ng build\' on \'//web/gui2:_onos-gui2-ng-build\'. \\\n" +
164 " See bazel-genfiles/web/gui2/onos-gui2-ng-build-prod.log for more details' >&2;" +
165 #" tail -n 100 ../../$(location onos-gui2-ng-test.log) >&2;" +
166 " exit 1;" +
167 " fi;" +
Sean Condonf6af2a52018-08-19 10:43:24 +0100168 " cd src/main/webapp/dist && jar Mcf $$ROOT/$(location onos-gui2-ng-build.jar) .",
Sean Condon0c577f62018-11-18 22:40:05 +0000169 message = "Angular CLI 7 build",
Sean Condonf6af2a52018-08-19 10:43:24 +0100170)
171
172"""
173 Run 'ng test' to run Angular test and 'ng lint' for checkstyle
174 See bazel-genfiles/web/gui2/onos-gui2-ng-lint.log or
175 bazel-genfiles/web/gui2/onos-gui2-ng-test.log for details of the Angular CLI output
176"""
177
178genrule(
179 name = "_onos-gui2-ng-test-genrule",
180 srcs = [
181 "@nodejs//:bin/npm",
182 "@nodejs//:bin/node",
Sean Condonf6af2a52018-08-19 10:43:24 +0100183 "@nodejs//:bin/nodejs/bin/node",
184 "@nodejs//:bin/nodejs/bin/npm",
Sean Condon5ca00262018-09-06 17:55:25 +0100185 "//web/gui2-fw-lib:onos-gui2-fw-npm-install",
186 "//web/gui2-fw-lib:onos-gui2-fw-ng-build",
187 "//web/gui2-fw-lib:gui2_fw_lib_ext_css",
Sean Condonf6af2a52018-08-19 10:43:24 +0100188 ":_web_app_all",
189 ":_web_app_tests",
190 ":_angular_all",
191 ],
192 outs = [
193 "onos-gui2-ng-ver.log",
194 "onos-gui2-ng-lint.log",
195 "onos-gui2-ng-test.log",
196 ],
197 cmd = " ROOT=`pwd` &&" +
198 " export HOME=. &&" +
199 " export XDG_CONFIG_HOME=$(@D)/config &&" +
200 " NODE=$(location @nodejs//:bin/node) &&" +
Sean Condon5ca00262018-09-06 17:55:25 +0100201 " INSTALL_FILES=($(locations //web/gui2-fw-lib:onos-gui2-fw-npm-install)) &&" + # An array of filenames - sorted by time created
202 " FWLIB_FILES=($(locations //web/gui2-fw-lib:onos-gui2-fw-ng-build)) &&" + # An array of filenames - sorted by time created
Sean Condonf6af2a52018-08-19 10:43:24 +0100203 " mkdir -p web/gui2 &&" +
204 " cd web/gui2 &&" +
205 " jar xf ../../$(location :_angular_all) &&" +
206 " jar xf ../../$(location :_web_app_all) &&" +
207 " jar xf ../../$(location :_web_app_tests) &&" +
208 " jar xf $$ROOT/$${INSTALL_FILES[0]} &&" +
Sean Condon5ca00262018-09-06 17:55:25 +0100209 " tar xf $$ROOT/$${FWLIB_FILES[0]} &&" +
210 " mv package/ node_modules/gui2-fw-lib/ &&" +
211 " mkdir -p src/main/webapp/app/fw &&" +
212 " (cd src/main/webapp/app/fw &&" +
213 " jar xf $$ROOT/$(location //web/gui2-fw-lib:gui2_fw_lib_ext_css)) &&" +
Sean Condonf6af2a52018-08-19 10:43:24 +0100214 " chmod +x $$ROOT/web/gui2/node_modules/@angular/cli/bin/ng &&" +
Thomas Vachuska0c19e652018-08-28 10:57:07 -0700215 " export PATH=$$ROOT/$$(dirname $${NODE}):$$ROOT/web/gui2/node_modules/@angular/cli/bin:$$PATH &&" +
Sean Condonf6af2a52018-08-19 10:43:24 +0100216 " node -v > ../../$(location onos-gui2-ng-ver.log) &&" +
217 " npm -v >> ../../$(location onos-gui2-ng-ver.log) &&" +
Sean Condon50855cf2018-12-23 15:37:42 +0000218 " ng version >> ../../$(location onos-gui2-ng-ver.log);" +
219 " ng lint > ../../$(location onos-gui2-ng-lint.log) 2>&1 ||" +
220 " if [ $$? -eq 0 ]; then echo 'Successfully ran lint';" +
221 " else " +
222 " echo 'Error running \'ng lint\' on \'//web/gui2:onos-gui2-ng-test\'. \\\n" +
223 " See bazel-genfiles/web/gui2/onos-gui2-ng-lint.log for more details' >&2;" +
224 " exit 1;" +
225 " fi;" +
Sean Condonf6af2a52018-08-19 10:43:24 +0100226 " if [ -f /usr/bin/chromium-browser ]; then " + # Add to this for Mac and Chrome
227 " export CHROME_BIN=/usr/bin/chromium-browser; " +
228 " elif [ -f /opt/google/chrome/chrome ]; then " +
229 " export CHROME_BIN=/opt/google/chrome/chrome; " +
230 " else " +
231 " MSG='Warning: Step onos-gui2-ng-test skipped because \\n" +
232 " no binary for ChromeHeadless browser was found at /usr/bin/chromium-browser. \\n" +
233 " Install Google Chrome or Chromium Browser to allow this step to run.';" +
234 " echo -e $$MSG >&2;" +
235 " echo -e $$MSG > ../../$(location onos-gui2-ng-test.log);" +
236 " exit 0;" +
237 " fi;" +
238 " ng test --preserve-symlinks --code-coverage --browsers=ChromeHeadless" +
239 " --watch=false > ../../$(location onos-gui2-ng-test.log) 2>&1 ||" +
240 " if [ $$? -eq 0 ]; then echo 'Successfully ran tests';" +
241 " else " +
242 " echo 'Error running \'ng test\' on \'//web/gui2:onos-gui2-ng-test\'. \\\n" +
243 " See bazel-genfiles/web/gui2/onos-gui2-ng-test.log for more details' >&2;" +
244 #" tail -n 100 ../../$(location onos-gui2-ng-test.log) >&2;" +
245 " exit 1;" +
246 " fi;",
Sean Condon0c577f62018-11-18 22:40:05 +0000247 message = "Angular CLI 7 lint and test",
Sean Condonf6af2a52018-08-19 10:43:24 +0100248)
249
250"""
251 Make a jar file of all the webapp files. Useful for breaking symblic links in the sandbox
252"""
253
254genrule(
255 name = "_web_app_all",
256 srcs = glob(
257 [
258 "src/main/webapp/**",
259 ],
260 exclude = [
261 "src/main/webapp/**/*.spec.ts", # Don't track tests here
262 "src/main/webapp/tests/**",
263 "src/main/webapp/node_modules/**",
264 "src/main/webapp/dist/**",
265 "src/main/webapp/doc/**",
Sean Condon87b78502018-09-17 20:53:24 +0100266 "src/main/webapp/app/fw/**",
Sean Condonf6af2a52018-08-19 10:43:24 +0100267 ],
268 ),
269 outs = ["web_app_all.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 webapp test (*.spec.ts) files.
277"""
278
279genrule(
280 name = "_web_app_tests",
281 srcs = glob(
282 [
283 "src/main/webapp/**/*.spec.ts",
284 ],
285 exclude = [
286 "src/main/webapp/tests/**",
287 "src/main/webapp/node_modules/**",
288 "src/main/webapp/dist/**",
289 "src/main/webapp/doc/**",
290 ],
291 ),
292 outs = ["web_app_tests.jar"],
293 cmd = "cd web/gui2 &&" +
294 " find src/main/webapp -type f -exec touch -t 201808280000 {} \; &&" +
295 " jar Mcf ../../$@ src/main/webapp",
296)
297
298"""
299 Make a jar file of all the supporting files. Useful for breaking symblic links in the sandbox
300"""
301
302genrule(
303 name = "_angular_all",
304 srcs = [
305 ":_e2e_test_files",
306 ":_root_level_files",
307 ],
308 outs = ["angular_all.jar"],
309 cmd = " cd web/gui2 && jar Mcf ../../$@ .",
310)
311
312"""
313 Builds the java jar for the java code provided by the GUI2
314"""
315
316osgi_jar_with_tests(
317 name = "_onos-gui2-base-jar",
Sean Condon87b78502018-09-17 20:53:24 +0100318 srcs =
319 glob([
320 "src/main/java/**",
321 ]) + [
322 "//web/gui:onos-gui-java-for-gui2",
323 ],
Sean Condonb2c483c2019-01-16 20:28:55 +0000324 exclude_tests = [
325 "org.onosproject.ui.impl.AbstractUiImplTest",
326 "org.onosproject.ui.impl.topo.model.AbstractTopoModelTest",
327 ],
328 karaf_command_packages = [
329 "org.onosproject.ui.impl.cli",
330 "org.onosproject.ui.impl.topo",
331 ],
Sean Condon3c8e5582018-08-28 23:22:43 +0100332 suppress_checkstyle = True,
Sean Condonf6af2a52018-08-19 10:43:24 +0100333 test_deps = TEST_DEPS,
Sean Condonbf7ff4f2019-03-17 16:18:42 +0000334 web_context = "/onos/ui",
Sean Condonf6af2a52018-08-19 10:43:24 +0100335 deps = COMPILE_DEPS,
336)
337
338"""
339 Builds the tar ball for the ONOS GUI2
340"""
341
342genrule(
Sean Condonbf7ff4f2019-03-17 16:18:42 +0000343 name = "onos-web-gui2",
Sean Condonf6af2a52018-08-19 10:43:24 +0100344 srcs = [
345 ":_onos-gui2-ng-build",
346 ":_onos-gui2-base-jar",
347 ":_web_inf_classes_files",
Sean Condonb2c483c2019-01-16 20:28:55 +0000348 "//web/gui:onos-gui-lion-for-gui2",
Sean Condon0d064ec2019-02-04 21:53:53 +0000349 "//web/gui:onos-gui-data-for-gui2",
Sean Condon3c8e5582018-08-28 23:22:43 +0100350 "src/main/webapp/WEB-INF/web.xml",
Sean Condonf6af2a52018-08-19 10:43:24 +0100351 ],
352 outs = ["onos-gui2.jar"],
353 cmd = " ROOT=`pwd` &&" +
354 " mkdir -p web/gui2/WEB-INF/classes &&" +
355 " cd web/gui2 &&" +
356 " BUILD_FILES=($(locations :_onos-gui2-ng-build)) &&" + # An array of filenames - sorted by time created
357 " for i in $(locations :_web_inf_classes_files); do cp $$ROOT/$$i ./WEB-INF/classes/; done &&" +
358 " (cd WEB-INF/classes && jar xf $$ROOT/$${BUILD_FILES[1]}) &&" +
359 " jar xf $$ROOT/$(location :_onos-gui2-base-jar) &&" +
Sean Condonb2c483c2019-01-16 20:28:55 +0000360 " unzip -q $$ROOT/$(location //web/gui:onos-gui-lion-for-gui2) web/gui/src/main/resources/**/* &&" +
361 " mv web/gui/src/main/resources/org/onosproject/ui/lion* WEB-INF/classes/org/onosproject/ui/ &&" +
362 " mv web/gui/src/main/resources/core WEB-INF/classes/ &&" +
Sean Condon0d064ec2019-02-04 21:53:53 +0000363 " unzip -q $$ROOT/$(location //web/gui:onos-gui-data-for-gui2) web/gui/src/main/webapp/data/**/* &&" +
364 " mv web/gui/src/main/webapp/data WEB-INF/classes/ &&" +
Sean Condonb2c483c2019-01-16 20:28:55 +0000365 " find . -type f -exec touch -t 201901200000 {} \; &&" +
366 " jar cmf META-INF/MANIFEST.MF $$ROOT/$@ WEB-INF/web.xml WEB-INF/classes OSGI-INF/*.xml",
Sean Condonf6af2a52018-08-19 10:43:24 +0100367 output_to_bindir = 1,
368 visibility = ["//visibility:public"],
369)
370
371"""
372 Wrap the genrule for testing in a test
373"""
374
375sh_test(
376 name = "onos-gui2-ng-tests",
377 size = "small",
378 srcs = [
379 ":ng-test.sh",
380 ],
381 data = [
382 ":_onos-gui2-ng-test-genrule",
383 ],
384 deps = [
385 "@bazel_tools//tools/bash/runfiles",
386 ],
387)
Sean Condonbf7ff4f2019-03-17 16:18:42 +0000388
389onos_app(
390 category = "Graphical User Interface",
391 description = "ONOS GUI2 - a reengineered version of the original ONOS GUI " +
392 "based on the latest Angular framework components",
393 title = "ONOS GUI2",
394 url = "http://onosproject.org",
395)