blob: 7ce7cf70fc7032acd999b699e628947fd9d83499 [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
20 The GUI2 Angular 6 elements are built here with Angular CLI 'ng'
21 Some work is being done in the Bazel community to integrate Bazel and
22 Angular 6, (Angular Buildtools Convergence -
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
40COMPILE_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",
Ray Milkey427e9752018-11-15 16:34:48 -080047 "@jersey_hk2//jar",
Sean Condonf6af2a52018-08-19 10:43:24 +010048 "//utils/rest:onlab-rest",
49 "//core/store/serializers:onos-core-serializers",
50]
51
52TEST_DEPS = TEST + [
53 "//core/api:onos-api-tests",
54 "//drivers/default:onos-drivers-default",
55]
56
57"""
58 Files that get put at the top level of the tar ball
59"""
60
61filegroup(
62 name = "_root_level_files",
63 srcs =
64 [
65 ":angular.json",
66 ":karma.conf.js",
67 ":package.json",
68 ":package-lock.json",
69 ":protractor.conf.js",
70 ":src/main/tsconfig.json",
71 ":src/main/tslint.json",
72 ":tsconfig.json",
73 ],
74)
75
76filegroup(
77 name = "_e2e_test_files",
78 srcs = [
79 ":e2e/app.e2e-spec.ts",
80 ":e2e/app.po.ts",
81 ":e2e/tsconfig.e2e.json",
82 ],
83)
84
85"""
86 Files that get put into the WEB-INF directory of the tar ball
87"""
88
89filegroup(
90 name = "_web_inf_classes_files",
91 srcs =
92 [
93 ":src/main/webapp/error.html",
94 ":src/main/webapp/login.html",
95 ":src/main/webapp/nav.html",
96 ":src/main/webapp/not-ready.html",
Sean Condon55c30532018-10-29 12:26:57 +000097 ":src/main/webapp/onos.global.css",
Sean Condonf6af2a52018-08-19 10:43:24 +010098 ],
99)
100
101"""
Sean Condonf6af2a52018-08-19 10:43:24 +0100102 Run ng build to create outputs in production mode
103 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 +0100104
105 To avoid the overhead of having several "npm install" invocations, we just do
106 it once in the //web/gui2-fw-lib which is really the core for the whole Angular 6
107 structure in ONOS. This copies files in to node_modules, but because the gui2-fw-lib
108 has not been generated at that time we copy it in separately below with the 'tar' cmd
109 and then 'mv'
Sean Condonf6af2a52018-08-19 10:43:24 +0100110"""
111
112genrule(
113 name = "_onos-gui2-ng-build",
114 srcs = [
115 "@nodejs//:bin/npm",
116 "@nodejs//:bin/node",
117 "@nodejs//:bin/node.js",
118 "@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 Condon87b78502018-09-17 20:53:24 +0100123 "//apps/faultmanagement/fm-gui2-lib:fm-gui2-lib-build",
Sean Condon5ca00262018-09-06 17:55:25 +0100124 ":_root_level_files",
Sean Condonf6af2a52018-08-19 10:43:24 +0100125 ":_web_app_all",
126 ],
127 outs = [
128 "onos-gui2-ng-build-prod.log",
129 "onos-gui2-ng-build.jar",
130 ],
131 cmd = "ROOT=`pwd` &&" +
132 " export HOME=. &&" +
133 " export XDG_CONFIG_HOME=$(@D)/config &&" +
134 " NODE=$(location @nodejs//:bin/node) &&" +
Sean Condon5ca00262018-09-06 17:55:25 +0100135 " INSTALL_FILES=($(locations //web/gui2-fw-lib:onos-gui2-fw-npm-install)) &&" + # An array of filenames - sorted by time created
136 " 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 +0100137 " mkdir -p web/gui2 && cd web/gui2 &&" +
138 " jar xf ../../$(location :_web_app_all) &&" +
139 " jar xf $$ROOT/$${INSTALL_FILES[0]} &&" +
Sean Condon5ca00262018-09-06 17:55:25 +0100140 " tar xf $$ROOT/$${FWLIB_FILES[0]} &&" +
141 " mv package/ node_modules/gui2-fw-lib/ &&" +
Sean Condon87b78502018-09-17 20:53:24 +0100142 # Add in modules from external packages
143 " FM_GUI2_LIB_FILES=($(locations //apps/faultmanagement/fm-gui2-lib:fm-gui2-lib-build)) &&" + # An array of filenames - sorted by time created
144 " tar xf $$ROOT/$${FM_GUI2_LIB_FILES[0]} &&" +
145 " mv package/ node_modules/fm-gui2-lib/ &&" +
146 # End of add in modules from external packages
Sean Condon5ca00262018-09-06 17:55:25 +0100147 " mkdir -p src/main/webapp/app/fw &&" +
148 " (cd src/main/webapp/app/fw &&" +
149 " jar xf $$ROOT/$(location //web/gui2-fw-lib:gui2_fw_lib_ext_css)) &&" +
Sean Condonf6af2a52018-08-19 10:43:24 +0100150 " chmod +x $$ROOT/web/gui2/node_modules/@angular/cli/bin/ng &&" +
Thomas Vachuska0c19e652018-08-28 10:57:07 -0700151 " export PATH=$$ROOT/$$(dirname $${NODE}):$$ROOT/web/gui2/node_modules/@angular/cli/bin:$$PATH &&" +
Sean Condonf6af2a52018-08-19 10:43:24 +0100152 " node -v > ../../$(location onos-gui2-ng-build-prod.log) &&" +
153 " npm -v >> ../../$(location onos-gui2-ng-build-prod.log) &&" +
154 " ng -v >> ../../$(location onos-gui2-ng-build-prod.log) &&" +
155 # Build it in production mode - optimization is turned off because of Angular CLI 6.0.x bug https://github.com/angular/angular-cli/issues/7799
Sean Condon5ca00262018-09-06 17:55:25 +0100156 " ng build --extract-css --prod --optimization=false --preserve-symlinks" +
Sean Condon87b78502018-09-17 20:53:24 +0100157 " --base-href /onos/ui2/ --deploy-url /onos/ui2/ >> $$ROOT/$(location onos-gui2-ng-build-prod.log) 2>&1 ||" +
158 " if [ $$? -eq 0 ]; then echo 'Successfully ran build';" +
159 " else " +
160 " echo 'Error running \'ng build\' on \'//web/gui2:_onos-gui2-ng-build\'. \\\n" +
161 " See bazel-genfiles/web/gui2/onos-gui2-ng-build-prod.log for more details' >&2;" +
162 #" tail -n 100 ../../$(location onos-gui2-ng-test.log) >&2;" +
163 " exit 1;" +
164 " fi;" +
Sean Condonf6af2a52018-08-19 10:43:24 +0100165 " cd src/main/webapp/dist && jar Mcf $$ROOT/$(location onos-gui2-ng-build.jar) .",
166 message = "Angular CLI 6 build",
167)
168
169"""
170 Run 'ng test' to run Angular test and 'ng lint' for checkstyle
171 See bazel-genfiles/web/gui2/onos-gui2-ng-lint.log or
172 bazel-genfiles/web/gui2/onos-gui2-ng-test.log for details of the Angular CLI output
173"""
174
175genrule(
176 name = "_onos-gui2-ng-test-genrule",
177 srcs = [
178 "@nodejs//:bin/npm",
179 "@nodejs//:bin/node",
180 "@nodejs//:bin/node.js",
181 "@nodejs//:bin/nodejs/bin/node",
182 "@nodejs//:bin/nodejs/bin/npm",
Sean Condon5ca00262018-09-06 17:55:25 +0100183 "//web/gui2-fw-lib:onos-gui2-fw-npm-install",
184 "//web/gui2-fw-lib:onos-gui2-fw-ng-build",
185 "//web/gui2-fw-lib:gui2_fw_lib_ext_css",
Sean Condonf6af2a52018-08-19 10:43:24 +0100186 ":_web_app_all",
187 ":_web_app_tests",
188 ":_angular_all",
189 ],
190 outs = [
191 "onos-gui2-ng-ver.log",
192 "onos-gui2-ng-lint.log",
193 "onos-gui2-ng-test.log",
194 ],
195 cmd = " ROOT=`pwd` &&" +
196 " export HOME=. &&" +
197 " export XDG_CONFIG_HOME=$(@D)/config &&" +
198 " NODE=$(location @nodejs//:bin/node) &&" +
Sean Condon5ca00262018-09-06 17:55:25 +0100199 " INSTALL_FILES=($(locations //web/gui2-fw-lib:onos-gui2-fw-npm-install)) &&" + # An array of filenames - sorted by time created
200 " 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 +0100201 " mkdir -p web/gui2 &&" +
202 " cd web/gui2 &&" +
203 " jar xf ../../$(location :_angular_all) &&" +
204 " jar xf ../../$(location :_web_app_all) &&" +
205 " jar xf ../../$(location :_web_app_tests) &&" +
206 " jar xf $$ROOT/$${INSTALL_FILES[0]} &&" +
Sean Condon5ca00262018-09-06 17:55:25 +0100207 " tar xf $$ROOT/$${FWLIB_FILES[0]} &&" +
208 " mv package/ node_modules/gui2-fw-lib/ &&" +
209 " mkdir -p src/main/webapp/app/fw &&" +
210 " (cd src/main/webapp/app/fw &&" +
211 " jar xf $$ROOT/$(location //web/gui2-fw-lib:gui2_fw_lib_ext_css)) &&" +
Sean Condonf6af2a52018-08-19 10:43:24 +0100212 " chmod +x $$ROOT/web/gui2/node_modules/@angular/cli/bin/ng &&" +
Thomas Vachuska0c19e652018-08-28 10:57:07 -0700213 " export PATH=$$ROOT/$$(dirname $${NODE}):$$ROOT/web/gui2/node_modules/@angular/cli/bin:$$PATH &&" +
Sean Condonf6af2a52018-08-19 10:43:24 +0100214 " node -v > ../../$(location onos-gui2-ng-ver.log) &&" +
215 " npm -v >> ../../$(location onos-gui2-ng-ver.log) &&" +
216 " ng -v >> ../../$(location onos-gui2-ng-ver.log) &&" +
217 " ng lint > ../../$(location onos-gui2-ng-lint.log);" +
218 " if [ -f /usr/bin/chromium-browser ]; then " + # Add to this for Mac and Chrome
219 " export CHROME_BIN=/usr/bin/chromium-browser; " +
220 " elif [ -f /opt/google/chrome/chrome ]; then " +
221 " export CHROME_BIN=/opt/google/chrome/chrome; " +
222 " else " +
223 " MSG='Warning: Step onos-gui2-ng-test skipped because \\n" +
224 " no binary for ChromeHeadless browser was found at /usr/bin/chromium-browser. \\n" +
225 " Install Google Chrome or Chromium Browser to allow this step to run.';" +
226 " echo -e $$MSG >&2;" +
227 " echo -e $$MSG > ../../$(location onos-gui2-ng-test.log);" +
228 " exit 0;" +
229 " fi;" +
230 " ng test --preserve-symlinks --code-coverage --browsers=ChromeHeadless" +
231 " --watch=false > ../../$(location onos-gui2-ng-test.log) 2>&1 ||" +
232 " if [ $$? -eq 0 ]; then echo 'Successfully ran tests';" +
233 " else " +
234 " echo 'Error running \'ng test\' on \'//web/gui2:onos-gui2-ng-test\'. \\\n" +
235 " See bazel-genfiles/web/gui2/onos-gui2-ng-test.log for more details' >&2;" +
236 #" tail -n 100 ../../$(location onos-gui2-ng-test.log) >&2;" +
237 " exit 1;" +
238 " fi;",
239 message = "Angular CLI 6 lint and test",
240)
241
242"""
243 Make a jar file of all the webapp files. Useful for breaking symblic links in the sandbox
244"""
245
246genrule(
247 name = "_web_app_all",
248 srcs = glob(
249 [
250 "src/main/webapp/**",
251 ],
252 exclude = [
253 "src/main/webapp/**/*.spec.ts", # Don't track tests here
254 "src/main/webapp/tests/**",
255 "src/main/webapp/node_modules/**",
256 "src/main/webapp/dist/**",
257 "src/main/webapp/doc/**",
Sean Condon87b78502018-09-17 20:53:24 +0100258 "src/main/webapp/app/fw/**",
Sean Condonf6af2a52018-08-19 10:43:24 +0100259 ],
260 ),
261 outs = ["web_app_all.jar"],
262 cmd = "cd web/gui2 &&" +
263 " find src/main/webapp -type f -exec touch -t 201808280000 {} \; &&" +
264 " jar Mcf ../../$@ src/main/webapp",
265)
266
267"""
268 Make a jar file of all the webapp test (*.spec.ts) files.
269"""
270
271genrule(
272 name = "_web_app_tests",
273 srcs = glob(
274 [
275 "src/main/webapp/**/*.spec.ts",
276 ],
277 exclude = [
278 "src/main/webapp/tests/**",
279 "src/main/webapp/node_modules/**",
280 "src/main/webapp/dist/**",
281 "src/main/webapp/doc/**",
282 ],
283 ),
284 outs = ["web_app_tests.jar"],
285 cmd = "cd web/gui2 &&" +
286 " find src/main/webapp -type f -exec touch -t 201808280000 {} \; &&" +
287 " jar Mcf ../../$@ src/main/webapp",
288)
289
290"""
291 Make a jar file of all the supporting files. Useful for breaking symblic links in the sandbox
292"""
293
294genrule(
295 name = "_angular_all",
296 srcs = [
297 ":_e2e_test_files",
298 ":_root_level_files",
299 ],
300 outs = ["angular_all.jar"],
301 cmd = " cd web/gui2 && jar Mcf ../../$@ .",
302)
303
304"""
305 Builds the java jar for the java code provided by the GUI2
306"""
307
308osgi_jar_with_tests(
309 name = "_onos-gui2-base-jar",
Sean Condon87b78502018-09-17 20:53:24 +0100310 srcs =
311 glob([
312 "src/main/java/**",
313 ]) + [
314 "//web/gui:onos-gui-java-for-gui2",
315 ],
Sean Condon3c8e5582018-08-28 23:22:43 +0100316 suppress_checkstyle = True,
Sean Condonf6af2a52018-08-19 10:43:24 +0100317 test_deps = TEST_DEPS,
318 web_context = "/onos/ui2",
319 deps = COMPILE_DEPS,
320)
321
322"""
323 Builds the tar ball for the ONOS GUI2
324"""
325
326genrule(
327 name = "onos-gui2",
328 srcs = [
329 ":_onos-gui2-ng-build",
330 ":_onos-gui2-base-jar",
331 ":_web_inf_classes_files",
Sean Condon3c8e5582018-08-28 23:22:43 +0100332 "src/main/webapp/WEB-INF/web.xml",
Sean Condonf6af2a52018-08-19 10:43:24 +0100333 ],
334 outs = ["onos-gui2.jar"],
335 cmd = " ROOT=`pwd` &&" +
336 " mkdir -p web/gui2/WEB-INF/classes &&" +
337 " cd web/gui2 &&" +
338 " BUILD_FILES=($(locations :_onos-gui2-ng-build)) &&" + # An array of filenames - sorted by time created
339 " for i in $(locations :_web_inf_classes_files); do cp $$ROOT/$$i ./WEB-INF/classes/; done &&" +
340 " (cd WEB-INF/classes && jar xf $$ROOT/$${BUILD_FILES[1]}) &&" +
341 " jar xf $$ROOT/$(location :_onos-gui2-base-jar) &&" +
342 " find . -type f -exec touch -t 201808280000 {} \; &&" +
Sean Condon3c8e5582018-08-28 23:22:43 +0100343 " jar cmf META-INF/MANIFEST.MF $$ROOT/$@ WEB-INF/web.xml WEB-INF/classes",
Sean Condonf6af2a52018-08-19 10:43:24 +0100344 output_to_bindir = 1,
345 visibility = ["//visibility:public"],
346)
347
348"""
349 Wrap the genrule for testing in a test
350"""
351
352sh_test(
353 name = "onos-gui2-ng-tests",
354 size = "small",
355 srcs = [
356 ":ng-test.sh",
357 ],
358 data = [
359 ":_onos-gui2-ng-test-genrule",
360 ],
361 deps = [
362 "@bazel_tools//tools/bash/runfiles",
363 ],
364)