blob: fec16c8a9bbc5af9b11cc8aa4ab580fe3e9cfd8c [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",
47 "//utils/rest:onlab-rest",
48 "//core/store/serializers:onos-core-serializers",
49]
50
51TEST_DEPS = TEST + [
52 "//core/api:onos-api-tests",
53 "//drivers/default:onos-drivers-default",
54]
55
56"""
57 Files that get put at the top level of the tar ball
58"""
59
60filegroup(
61 name = "_root_level_files",
62 srcs =
63 [
64 ":angular.json",
65 ":karma.conf.js",
66 ":package.json",
67 ":package-lock.json",
68 ":protractor.conf.js",
69 ":src/main/tsconfig.json",
70 ":src/main/tslint.json",
71 ":tsconfig.json",
72 ],
73)
74
75filegroup(
76 name = "_e2e_test_files",
77 srcs = [
78 ":e2e/app.e2e-spec.ts",
79 ":e2e/app.po.ts",
80 ":e2e/tsconfig.e2e.json",
81 ],
82)
83
84"""
85 Files that get put into the WEB-INF directory of the tar ball
86"""
87
88filegroup(
89 name = "_web_inf_classes_files",
90 srcs =
91 [
92 ":src/main/webapp/error.html",
93 ":src/main/webapp/login.html",
94 ":src/main/webapp/nav.html",
95 ":src/main/webapp/not-ready.html",
96 ":src/main/webapp/onos.theme.css",
97 ],
98)
99
100"""
101 Install npm packages listed in package.json in web/gui2
102 See bazel-genfiles/web/gui2/onos-gui2-npm-install.log for details of the 'npm install'
103"""
104
105genrule(
106 name = "_onos-gui2-npm-install",
107 srcs = [
108 "@nodejs//:bin/npm",
109 "@nodejs//:bin/node",
110 "@nodejs//:bin/node.js",
111 "@nodejs//:bin/nodejs/bin/node",
112 "@nodejs//:bin/nodejs/bin/npm",
113 ":_root_level_files",
114 ],
115 outs = [
116 "onos-gui2-npm-install.jar",
117 "onos-gui2-npm-install.log",
118 ],
119 cmd = " ROOT=`pwd` &&" +
120 " export HOME=. &&" +
121 " export XDG_CONFIG_HOME=$(@D)/config &&" + # npm config cache to the sandbox
122 " export BABEL_DISABLE_CACHE=1 &&" + # turn off babel cache
Sean Condon3c8e5582018-08-28 23:22:43 +0100123 ' if [[ ! -z $${HTTP_PROXY-} ]]; then NPM_ARGS="--proxy $$HTTP_PROXY --without-ssl --insecure"; else NPM_ARGS=""; fi &&' +
Sean Condon2f1fb8d2018-08-31 16:05:02 +0100124 " NPM=$(location @nodejs//:bin/npm) &&" +
125 " export PATH=$$ROOT/$$(dirname $${NPM}):$$PATH &&" +
Sean Condonf6af2a52018-08-19 10:43:24 +0100126 " mkdir -p web/gui2 &&" +
127 " cd web/gui2 &&" +
Sean Condon2f1fb8d2018-08-31 16:05:02 +0100128 " npm -v > $$ROOT/$(location onos-gui2-npm-install.log) 2>&1 &&" +
129 " npm $$NPM_ARGS install --no-cache >> $$ROOT/$(location onos-gui2-npm-install.log) 2>&1 &&" +
Sean Condonf6af2a52018-08-19 10:43:24 +0100130 " jar Mcf $$ROOT/$(location onos-gui2-npm-install.jar) . &&" +
131 " touch $$ROOT/$(location onos-gui2-npm-install.log)", # to get the log always as the 2nd file
Sean Condon2f1fb8d2018-08-31 16:05:02 +0100132 message = "NodeJS npm install in web/gui2",
Sean Condonf6af2a52018-08-19 10:43:24 +0100133 visibility = ["//visibility:public"],
134)
135
136"""
137 Run ng build to create outputs in production mode
138 See bazel-genfiles/web/gui2/onos-gui2-ng-build-prod.log for details of the Angular CLI output
139"""
140
141genrule(
142 name = "_onos-gui2-ng-build",
143 srcs = [
144 "@nodejs//:bin/npm",
145 "@nodejs//:bin/node",
146 "@nodejs//:bin/node.js",
147 "@nodejs//:bin/nodejs/bin/node",
148 "@nodejs//:bin/nodejs/bin/npm",
149 ":_onos-gui2-npm-install",
150 ":_web_app_all",
151 ],
152 outs = [
153 "onos-gui2-ng-build-prod.log",
154 "onos-gui2-ng-build.jar",
155 ],
156 cmd = "ROOT=`pwd` &&" +
157 " export HOME=. &&" +
158 " export XDG_CONFIG_HOME=$(@D)/config &&" +
159 " NODE=$(location @nodejs//:bin/node) &&" +
160 " INSTALL_FILES=($(locations :_onos-gui2-npm-install)) &&" + # An array of filenames - sorted by time created
161 " mkdir -p web/gui2 && cd web/gui2 &&" +
162 " jar xf ../../$(location :_web_app_all) &&" +
163 " jar xf $$ROOT/$${INSTALL_FILES[0]} &&" +
164 " chmod +x $$ROOT/web/gui2/node_modules/@angular/cli/bin/ng &&" +
Thomas Vachuska0c19e652018-08-28 10:57:07 -0700165 " export PATH=$$ROOT/$$(dirname $${NODE}):$$ROOT/web/gui2/node_modules/@angular/cli/bin:$$PATH &&" +
Sean Condonf6af2a52018-08-19 10:43:24 +0100166 " node -v > ../../$(location onos-gui2-ng-build-prod.log) &&" +
167 " npm -v >> ../../$(location onos-gui2-ng-build-prod.log) &&" +
168 " ng -v >> ../../$(location onos-gui2-ng-build-prod.log) &&" +
169 # 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
170 " ng build --extract-css --prod --optimization=false --preserve-symlinks --base-href /onos/ui2/ --deploy-url /onos/ui2/ >> $$ROOT/$(location onos-gui2-ng-build-prod.log) 2>&1 &&" +
171 " cd src/main/webapp/dist && jar Mcf $$ROOT/$(location onos-gui2-ng-build.jar) .",
172 message = "Angular CLI 6 build",
173)
174
175"""
176 Run 'ng test' to run Angular test and 'ng lint' for checkstyle
177 See bazel-genfiles/web/gui2/onos-gui2-ng-lint.log or
178 bazel-genfiles/web/gui2/onos-gui2-ng-test.log for details of the Angular CLI output
179"""
180
181genrule(
182 name = "_onos-gui2-ng-test-genrule",
183 srcs = [
184 "@nodejs//:bin/npm",
185 "@nodejs//:bin/node",
186 "@nodejs//:bin/node.js",
187 "@nodejs//:bin/nodejs/bin/node",
188 "@nodejs//:bin/nodejs/bin/npm",
189 ":_onos-gui2-npm-install",
190 ":_web_app_all",
191 ":_web_app_tests",
192 ":_angular_all",
193 ],
194 outs = [
195 "onos-gui2-ng-ver.log",
196 "onos-gui2-ng-lint.log",
197 "onos-gui2-ng-test.log",
198 ],
199 cmd = " ROOT=`pwd` &&" +
200 " export HOME=. &&" +
201 " export XDG_CONFIG_HOME=$(@D)/config &&" +
202 " NODE=$(location @nodejs//:bin/node) &&" +
203 " INSTALL_FILES=($(locations :_onos-gui2-npm-install)) &&" + # An array of filenames - sorted by time created
204 " mkdir -p web/gui2 &&" +
205 " cd web/gui2 &&" +
206 " jar xf ../../$(location :_angular_all) &&" +
207 " jar xf ../../$(location :_web_app_all) &&" +
208 " jar xf ../../$(location :_web_app_tests) &&" +
209 " jar xf $$ROOT/$${INSTALL_FILES[0]} &&" +
210 " chmod +x $$ROOT/web/gui2/node_modules/@angular/cli/bin/ng &&" +
Thomas Vachuska0c19e652018-08-28 10:57:07 -0700211 " export PATH=$$ROOT/$$(dirname $${NODE}):$$ROOT/web/gui2/node_modules/@angular/cli/bin:$$PATH &&" +
Sean Condonf6af2a52018-08-19 10:43:24 +0100212 " node -v > ../../$(location onos-gui2-ng-ver.log) &&" +
213 " npm -v >> ../../$(location onos-gui2-ng-ver.log) &&" +
214 " ng -v >> ../../$(location onos-gui2-ng-ver.log) &&" +
215 " ng lint > ../../$(location onos-gui2-ng-lint.log);" +
216 " if [ -f /usr/bin/chromium-browser ]; then " + # Add to this for Mac and Chrome
217 " export CHROME_BIN=/usr/bin/chromium-browser; " +
218 " elif [ -f /opt/google/chrome/chrome ]; then " +
219 " export CHROME_BIN=/opt/google/chrome/chrome; " +
220 " else " +
221 " MSG='Warning: Step onos-gui2-ng-test skipped because \\n" +
222 " no binary for ChromeHeadless browser was found at /usr/bin/chromium-browser. \\n" +
223 " Install Google Chrome or Chromium Browser to allow this step to run.';" +
224 " echo -e $$MSG >&2;" +
225 " echo -e $$MSG > ../../$(location onos-gui2-ng-test.log);" +
226 " exit 0;" +
227 " fi;" +
228 " ng test --preserve-symlinks --code-coverage --browsers=ChromeHeadless" +
229 " --watch=false > ../../$(location onos-gui2-ng-test.log) 2>&1 ||" +
230 " if [ $$? -eq 0 ]; then echo 'Successfully ran tests';" +
231 " else " +
232 " echo 'Error running \'ng test\' on \'//web/gui2:onos-gui2-ng-test\'. \\\n" +
233 " See bazel-genfiles/web/gui2/onos-gui2-ng-test.log for more details' >&2;" +
234 #" tail -n 100 ../../$(location onos-gui2-ng-test.log) >&2;" +
235 " exit 1;" +
236 " fi;",
237 message = "Angular CLI 6 lint and test",
238)
239
240"""
241 Make a jar file of all the webapp files. Useful for breaking symblic links in the sandbox
242"""
243
244genrule(
245 name = "_web_app_all",
246 srcs = glob(
247 [
248 "src/main/webapp/**",
249 ],
250 exclude = [
251 "src/main/webapp/**/*.spec.ts", # Don't track tests here
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 = ["web_app_all.jar"],
259 cmd = "cd web/gui2 &&" +
260 " find src/main/webapp -type f -exec touch -t 201808280000 {} \; &&" +
261 " jar Mcf ../../$@ src/main/webapp",
262)
263
264"""
265 Make a jar file of all the webapp test (*.spec.ts) files.
266"""
267
268genrule(
269 name = "_web_app_tests",
270 srcs = glob(
271 [
272 "src/main/webapp/**/*.spec.ts",
273 ],
274 exclude = [
275 "src/main/webapp/tests/**",
276 "src/main/webapp/node_modules/**",
277 "src/main/webapp/dist/**",
278 "src/main/webapp/doc/**",
279 ],
280 ),
281 outs = ["web_app_tests.jar"],
282 cmd = "cd web/gui2 &&" +
283 " find src/main/webapp -type f -exec touch -t 201808280000 {} \; &&" +
284 " jar Mcf ../../$@ src/main/webapp",
285)
286
287"""
288 Make a jar file of all the supporting files. Useful for breaking symblic links in the sandbox
289"""
290
291genrule(
292 name = "_angular_all",
293 srcs = [
294 ":_e2e_test_files",
295 ":_root_level_files",
296 ],
297 outs = ["angular_all.jar"],
298 cmd = " cd web/gui2 && jar Mcf ../../$@ .",
299)
300
301"""
302 Builds the java jar for the java code provided by the GUI2
303"""
304
305osgi_jar_with_tests(
306 name = "_onos-gui2-base-jar",
Sean Condon3c8e5582018-08-28 23:22:43 +0100307 srcs = [
308 "src/main/java/org/onosproject/ui/impl/gui2/LogoutResource.java",
309 "//web/gui:onos-gui-java-for-gui2",
Sean Condonf6af2a52018-08-19 10:43:24 +0100310 ],
Sean Condon3c8e5582018-08-28 23:22:43 +0100311 suppress_checkstyle = True,
Sean Condonf6af2a52018-08-19 10:43:24 +0100312 test_deps = TEST_DEPS,
313 web_context = "/onos/ui2",
314 deps = COMPILE_DEPS,
315)
316
317"""
318 Builds the tar ball for the ONOS GUI2
319"""
320
321genrule(
322 name = "onos-gui2",
323 srcs = [
324 ":_onos-gui2-ng-build",
325 ":_onos-gui2-base-jar",
326 ":_web_inf_classes_files",
Sean Condon3c8e5582018-08-28 23:22:43 +0100327 "src/main/webapp/WEB-INF/web.xml",
Sean Condonf6af2a52018-08-19 10:43:24 +0100328 ],
329 outs = ["onos-gui2.jar"],
330 cmd = " ROOT=`pwd` &&" +
331 " mkdir -p web/gui2/WEB-INF/classes &&" +
332 " cd web/gui2 &&" +
333 " BUILD_FILES=($(locations :_onos-gui2-ng-build)) &&" + # An array of filenames - sorted by time created
334 " for i in $(locations :_web_inf_classes_files); do cp $$ROOT/$$i ./WEB-INF/classes/; done &&" +
335 " (cd WEB-INF/classes && jar xf $$ROOT/$${BUILD_FILES[1]}) &&" +
336 " jar xf $$ROOT/$(location :_onos-gui2-base-jar) &&" +
337 " find . -type f -exec touch -t 201808280000 {} \; &&" +
Sean Condon3c8e5582018-08-28 23:22:43 +0100338 " jar cmf META-INF/MANIFEST.MF $$ROOT/$@ WEB-INF/web.xml WEB-INF/classes",
Sean Condonf6af2a52018-08-19 10:43:24 +0100339 output_to_bindir = 1,
340 visibility = ["//visibility:public"],
341)
342
343"""
344 Wrap the genrule for testing in a test
345"""
346
347sh_test(
348 name = "onos-gui2-ng-tests",
349 size = "small",
350 srcs = [
351 ":ng-test.sh",
352 ],
353 data = [
354 ":_onos-gui2-ng-test-genrule",
355 ],
356 deps = [
357 "@bazel_tools//tools/bash/runfiles",
358 ],
359)