blob: ddc91db4e3d40ceb6b91ae0c6a3211eff84e9f0c [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 Condonf6af2a52018-08-19 10:43:24 +0100124 " NPM=$$ROOT/$(location @nodejs//:bin/npm) &&" +
125 " mkdir -p web/gui2 &&" +
126 " cd web/gui2 &&" +
Sean Condon3c8e5582018-08-28 23:22:43 +0100127 " $$NPM $$NPM_ARGS install --no-cache --loglevel=error > $$ROOT/$(location onos-gui2-npm-install.log) 2>&1 &&" +
Sean Condonf6af2a52018-08-19 10:43:24 +0100128 " jar Mcf $$ROOT/$(location onos-gui2-npm-install.jar) . &&" +
129 " touch $$ROOT/$(location onos-gui2-npm-install.log)", # to get the log always as the 2nd file
130 visibility = ["//visibility:public"],
131)
132
133"""
134 Run ng build to create outputs in production mode
135 See bazel-genfiles/web/gui2/onos-gui2-ng-build-prod.log for details of the Angular CLI output
136"""
137
138genrule(
139 name = "_onos-gui2-ng-build",
140 srcs = [
141 "@nodejs//:bin/npm",
142 "@nodejs//:bin/node",
143 "@nodejs//:bin/node.js",
144 "@nodejs//:bin/nodejs/bin/node",
145 "@nodejs//:bin/nodejs/bin/npm",
146 ":_onos-gui2-npm-install",
147 ":_web_app_all",
148 ],
149 outs = [
150 "onos-gui2-ng-build-prod.log",
151 "onos-gui2-ng-build.jar",
152 ],
153 cmd = "ROOT=`pwd` &&" +
154 " export HOME=. &&" +
155 " export XDG_CONFIG_HOME=$(@D)/config &&" +
156 " NODE=$(location @nodejs//:bin/node) &&" +
157 " INSTALL_FILES=($(locations :_onos-gui2-npm-install)) &&" + # An array of filenames - sorted by time created
158 " mkdir -p web/gui2 && cd web/gui2 &&" +
159 " jar xf ../../$(location :_web_app_all) &&" +
160 " jar xf $$ROOT/$${INSTALL_FILES[0]} &&" +
161 " chmod +x $$ROOT/web/gui2/node_modules/@angular/cli/bin/ng &&" +
Thomas Vachuska0c19e652018-08-28 10:57:07 -0700162 " export PATH=$$ROOT/$$(dirname $${NODE}):$$ROOT/web/gui2/node_modules/@angular/cli/bin:$$PATH &&" +
Sean Condonf6af2a52018-08-19 10:43:24 +0100163 " node -v > ../../$(location onos-gui2-ng-build-prod.log) &&" +
164 " npm -v >> ../../$(location onos-gui2-ng-build-prod.log) &&" +
165 " ng -v >> ../../$(location onos-gui2-ng-build-prod.log) &&" +
166 # 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
167 " 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 &&" +
168 " cd src/main/webapp/dist && jar Mcf $$ROOT/$(location onos-gui2-ng-build.jar) .",
169 message = "Angular CLI 6 build",
170)
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",
183 "@nodejs//:bin/node.js",
184 "@nodejs//:bin/nodejs/bin/node",
185 "@nodejs//:bin/nodejs/bin/npm",
186 ":_onos-gui2-npm-install",
187 ":_web_app_all",
188 ":_web_app_tests",
189 ":_angular_all",
190 ],
191 outs = [
192 "onos-gui2-ng-ver.log",
193 "onos-gui2-ng-lint.log",
194 "onos-gui2-ng-test.log",
195 ],
196 cmd = " ROOT=`pwd` &&" +
197 " export HOME=. &&" +
198 " export XDG_CONFIG_HOME=$(@D)/config &&" +
199 " NODE=$(location @nodejs//:bin/node) &&" +
200 " INSTALL_FILES=($(locations :_onos-gui2-npm-install)) &&" + # An array of filenames - sorted by time created
201 " 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]} &&" +
207 " chmod +x $$ROOT/web/gui2/node_modules/@angular/cli/bin/ng &&" +
Thomas Vachuska0c19e652018-08-28 10:57:07 -0700208 " export PATH=$$ROOT/$$(dirname $${NODE}):$$ROOT/web/gui2/node_modules/@angular/cli/bin:$$PATH &&" +
Sean Condonf6af2a52018-08-19 10:43:24 +0100209 " node -v > ../../$(location onos-gui2-ng-ver.log) &&" +
210 " npm -v >> ../../$(location onos-gui2-ng-ver.log) &&" +
211 " ng -v >> ../../$(location onos-gui2-ng-ver.log) &&" +
212 " ng lint > ../../$(location onos-gui2-ng-lint.log);" +
213 " if [ -f /usr/bin/chromium-browser ]; then " + # Add to this for Mac and Chrome
214 " export CHROME_BIN=/usr/bin/chromium-browser; " +
215 " elif [ -f /opt/google/chrome/chrome ]; then " +
216 " export CHROME_BIN=/opt/google/chrome/chrome; " +
217 " else " +
218 " MSG='Warning: Step onos-gui2-ng-test skipped because \\n" +
219 " no binary for ChromeHeadless browser was found at /usr/bin/chromium-browser. \\n" +
220 " Install Google Chrome or Chromium Browser to allow this step to run.';" +
221 " echo -e $$MSG >&2;" +
222 " echo -e $$MSG > ../../$(location onos-gui2-ng-test.log);" +
223 " exit 0;" +
224 " fi;" +
225 " ng test --preserve-symlinks --code-coverage --browsers=ChromeHeadless" +
226 " --watch=false > ../../$(location onos-gui2-ng-test.log) 2>&1 ||" +
227 " if [ $$? -eq 0 ]; then echo 'Successfully ran tests';" +
228 " else " +
229 " echo 'Error running \'ng test\' on \'//web/gui2:onos-gui2-ng-test\'. \\\n" +
230 " See bazel-genfiles/web/gui2/onos-gui2-ng-test.log for more details' >&2;" +
231 #" tail -n 100 ../../$(location onos-gui2-ng-test.log) >&2;" +
232 " exit 1;" +
233 " fi;",
234 message = "Angular CLI 6 lint and test",
235)
236
237"""
238 Make a jar file of all the webapp files. Useful for breaking symblic links in the sandbox
239"""
240
241genrule(
242 name = "_web_app_all",
243 srcs = glob(
244 [
245 "src/main/webapp/**",
246 ],
247 exclude = [
248 "src/main/webapp/**/*.spec.ts", # Don't track tests here
249 "src/main/webapp/tests/**",
250 "src/main/webapp/node_modules/**",
251 "src/main/webapp/dist/**",
252 "src/main/webapp/doc/**",
253 ],
254 ),
255 outs = ["web_app_all.jar"],
256 cmd = "cd web/gui2 &&" +
257 " find src/main/webapp -type f -exec touch -t 201808280000 {} \; &&" +
258 " jar Mcf ../../$@ src/main/webapp",
259)
260
261"""
262 Make a jar file of all the webapp test (*.spec.ts) files.
263"""
264
265genrule(
266 name = "_web_app_tests",
267 srcs = glob(
268 [
269 "src/main/webapp/**/*.spec.ts",
270 ],
271 exclude = [
272 "src/main/webapp/tests/**",
273 "src/main/webapp/node_modules/**",
274 "src/main/webapp/dist/**",
275 "src/main/webapp/doc/**",
276 ],
277 ),
278 outs = ["web_app_tests.jar"],
279 cmd = "cd web/gui2 &&" +
280 " find src/main/webapp -type f -exec touch -t 201808280000 {} \; &&" +
281 " jar Mcf ../../$@ src/main/webapp",
282)
283
284"""
285 Make a jar file of all the supporting files. Useful for breaking symblic links in the sandbox
286"""
287
288genrule(
289 name = "_angular_all",
290 srcs = [
291 ":_e2e_test_files",
292 ":_root_level_files",
293 ],
294 outs = ["angular_all.jar"],
295 cmd = " cd web/gui2 && jar Mcf ../../$@ .",
296)
297
298"""
299 Builds the java jar for the java code provided by the GUI2
300"""
301
302osgi_jar_with_tests(
303 name = "_onos-gui2-base-jar",
Sean Condon3c8e5582018-08-28 23:22:43 +0100304 srcs = [
305 "src/main/java/org/onosproject/ui/impl/gui2/LogoutResource.java",
306 "//web/gui:onos-gui-java-for-gui2",
Sean Condonf6af2a52018-08-19 10:43:24 +0100307 ],
Sean Condon3c8e5582018-08-28 23:22:43 +0100308 suppress_checkstyle = True,
Sean Condonf6af2a52018-08-19 10:43:24 +0100309 test_deps = TEST_DEPS,
310 web_context = "/onos/ui2",
311 deps = COMPILE_DEPS,
312)
313
314"""
315 Builds the tar ball for the ONOS GUI2
316"""
317
318genrule(
319 name = "onos-gui2",
320 srcs = [
321 ":_onos-gui2-ng-build",
322 ":_onos-gui2-base-jar",
323 ":_web_inf_classes_files",
Sean Condon3c8e5582018-08-28 23:22:43 +0100324 "src/main/webapp/WEB-INF/web.xml",
Sean Condonf6af2a52018-08-19 10:43:24 +0100325 ],
326 outs = ["onos-gui2.jar"],
327 cmd = " ROOT=`pwd` &&" +
328 " mkdir -p web/gui2/WEB-INF/classes &&" +
329 " cd web/gui2 &&" +
330 " BUILD_FILES=($(locations :_onos-gui2-ng-build)) &&" + # An array of filenames - sorted by time created
331 " for i in $(locations :_web_inf_classes_files); do cp $$ROOT/$$i ./WEB-INF/classes/; done &&" +
332 " (cd WEB-INF/classes && jar xf $$ROOT/$${BUILD_FILES[1]}) &&" +
333 " jar xf $$ROOT/$(location :_onos-gui2-base-jar) &&" +
334 " find . -type f -exec touch -t 201808280000 {} \; &&" +
Sean Condon3c8e5582018-08-28 23:22:43 +0100335 " jar cmf META-INF/MANIFEST.MF $$ROOT/$@ WEB-INF/web.xml WEB-INF/classes",
Sean Condonf6af2a52018-08-19 10:43:24 +0100336 output_to_bindir = 1,
337 visibility = ["//visibility:public"],
338)
339
340"""
341 Wrap the genrule for testing in a test
342"""
343
344sh_test(
345 name = "onos-gui2-ng-tests",
346 size = "small",
347 srcs = [
348 ":ng-test.sh",
349 ],
350 data = [
351 ":_onos-gui2-ng-test-genrule",
352 ],
353 deps = [
354 "@bazel_tools//tools/bash/runfiles",
355 ],
356)