blob: bbf39175f64361a01c63f17cf260e5d7699b47d5 [file] [log] [blame]
Sean Condon5ca00262018-09-06 17:55:25 +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 FW Lib
19
Sean Condon7d275162018-11-02 16:29:06 +000020 The GUI2 Angular 7 elements are built here with Angular CLI 'ng'
Sean Condon5ca00262018-09-06 17:55:25 +010021 Some work is being done in the Bazel community to integrate Bazel and
Sean Condon7d275162018-11-02 16:29:06 +000022 Angular 7, (Angular Buildtools Convergence -
Sean Condon5ca00262018-09-06 17:55:25 +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
Carmelo Casconed33d3b42019-06-18 12:12:36 -070040load("//tools/build/bazel:jdk_genrule.bzl", genrule = "jdk_genrule")
41
Sean Condon5ca00262018-09-06 17:55:25 +010042COMPILE_DEPS = CORE_DEPS + JACKSON + KRYO + [
43 "@javax_ws_rs_api//jar",
44 "@servlet_api//jar",
45 "@jetty_websocket//jar",
46 "@jetty_util//jar",
47 "@jersey_media_multipart//jar",
48 "@jersey_server//jar",
49 "//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 ":package.json",
68 ":package-lock.json",
69 ":tsconfig.json",
70 ":tslint.json",
71 ],
72)
73
74filegroup(
75 name = "_e2e_test_files",
76 srcs = [
77 ":e2e/protractor.conf.js",
78 ":e2e/src/app.e2e-spec.ts",
79 ":e2e/src/app.po.ts",
80 ":e2e/tsconfig.e2e.json",
81 ],
82)
83
84"""
85 Make a group file of all the webapp files.
86"""
87
88filegroup(
89 name = "_gui2_fw_lib_src",
90 srcs = glob(
91 [
92 "projects/gui2-fw-lib/**",
Sean Condon4b7818d2019-05-23 07:45:14 +010093 "README.md",
94 "LICENSE",
Sean Condon5ca00262018-09-06 17:55:25 +010095 ],
96 exclude = [
97 "projects/gui2-fw-lib/**/*.spec.*", # Don't track tests here
98 "projects/gui2-fw-lib/karma.conf.js",
99 "projects/gui2-fw-lib/src/test.ts",
100 ],
101 ),
102)
103
104"""
105 Make a group of all the webapp qpp files.
106"""
107
108filegroup(
109 name = "_gui2_app_files",
110 srcs = glob(
111 [
112 "src/**/*",
113 ],
114 ),
115)
116
117"""
118 Make a jar file of all the webapp test (*.spec.ts) files.
119"""
120
121genrule(
122 name = "_gui2_fw_lib_tests",
123 srcs = glob(
124 [
125 "projects/gui2-fw-lib/karma.conf.js",
126 "projects/gui2-fw-lib/src/test.ts",
127 "projects/gui2-fw-lib/tsconfig.spec.json",
128 "projects/gui2-fw-lib/**/*.spec.ts",
129 ],
130 exclude = [
131 "projects/gui2-fw-lib/ng-package.json",
132 "projects/gui2-fw-lib/ng-package.prod.json",
133 "projects/gui2-fw-lib/package.json",
134 "projects/gui2-fw-lib/tsconfig.lib.json",
135 "projects/gui2-fw-lib/tslint.json",
136 "projects/gui2-fw-lib/src/public_api.ts",
137 ],
138 ),
139 outs = ["gui2_fw_lib_tests.jar"],
140 cmd = "cd web/gui2-fw-lib &&" +
141 " jar Mcf ../../$@ .",
142)
143
144"""
145 Make a jar file of all the CSS files we want to reuse in the target.
146"""
147
148genrule(
149 name = "gui2_fw_lib_ext_css",
150 srcs = glob(
151 [
152 "projects/gui2-fw-lib/src/lib/widget/panel.css",
153 "projects/gui2-fw-lib/src/lib/widget/panel-theme.css",
154 "projects/gui2-fw-lib/src/lib/widget/table.css",
155 "projects/gui2-fw-lib/src/lib/widget/table.theme.css",
156 "projects/gui2-fw-lib/src/lib/widget/table.theme.css",
157 "projects/gui2-fw-lib/src/lib/layer/loading.service.css",
158 ],
159 ),
160 outs = ["gui2_fw_lib_css.jar"],
161 cmd = " ROOT=`pwd` &&" +
162 " cd web/gui2-fw-lib/projects/gui2-fw-lib/src/lib &&" +
163 " jar Mcf $$ROOT/$@ .",
164 visibility = ["//visibility:public"],
165)
166
167"""
168 Install npm packages listed in package.json in web/gui2
169 See bazel-genfiles/web/gui2/onos-gui2-npm-install.log for details of the 'npm install'
170"""
171
172genrule(
173 name = "onos-gui2-fw-npm-install",
174 srcs = [
175 "@nodejs//:bin/npm",
176 "@nodejs//:bin/node",
Sean Condon5ca00262018-09-06 17:55:25 +0100177 "@nodejs//:bin/nodejs/bin/node",
178 "@nodejs//:bin/nodejs/bin/npm",
179 ":_root_level_files",
180 ],
181 outs = [
182 "onos-gui2-npm-install.jar",
183 "onos-gui2-npm-install.log",
184 ],
185 cmd = " ROOT=`pwd` &&" +
186 " export HOME=. &&" +
187 " export XDG_CONFIG_HOME=$(@D)/config &&" + # npm config cache to the sandbox
188 " export BABEL_DISABLE_CACHE=1 &&" + # turn off babel cache
189 ' if [[ ! -z $${HTTP_PROXY-} ]]; then NPM_ARGS="--proxy $$HTTP_PROXY --without-ssl --insecure"; else NPM_ARGS=""; fi &&' +
190 " NPM=$(location @nodejs//:bin/npm) &&" +
191 " export PATH=$$ROOT/$$(dirname $${NPM}):$$PATH &&" +
192 " npm -v > $$ROOT/$(location onos-gui2-npm-install.log) 2>&1 &&" +
193 " cd web/gui2-fw-lib && " +
194 " npm $$NPM_ARGS install --no-cache >> $$ROOT/$(location onos-gui2-npm-install.log) 2>&1 &&" +
195 " jar Mcf $$ROOT/$(location onos-gui2-npm-install.jar) node_modules &&" +
196 " touch $$ROOT/$(location onos-gui2-npm-install.log)", # to get the log always as the 2nd file
197 message = "NodeJS npm install",
198 visibility = ["//visibility:public"],
199)
200
201"""
202 Run ng build to create outputs in production mode
203 See bazel-genfiles/web/gui2/onos-gui2-ng-build-prod.log for details of the Angular CLI output
204"""
205
206genrule(
207 name = "onos-gui2-fw-ng-build",
208 srcs = [
209 "@nodejs//:bin/npm",
210 "@nodejs//:bin/node",
Sean Condon5ca00262018-09-06 17:55:25 +0100211 "@nodejs//:bin/nodejs/bin/node",
212 "@nodejs//:bin/nodejs/bin/npm",
213 ":onos-gui2-fw-npm-install",
Sean Condon95fb5742019-04-02 12:16:55 +0100214 "//web/gui:onos-gui-data-for-gui2",
Sean Condon5ca00262018-09-06 17:55:25 +0100215 ":_root_level_files",
216 ":_gui2_fw_lib_src",
217 ],
218 outs = [
219 "gui2-fw-ng-build-prod.log",
220 "gui2-fw-lib-ver.tgz",
221 ],
222 cmd = "ROOT=`pwd` &&" +
223 " export HOME=. &&" +
224 " export XDG_CONFIG_HOME=$(@D)/config &&" +
225 " NODE=$(location @nodejs//:bin/node) &&" +
226 " INSTALL_FILES=($(locations :onos-gui2-fw-npm-install)) &&" + # An array of filenames - sorted by time created
227 " cd web/gui2-fw-lib &&" +
228 " jar xf $$ROOT/$${INSTALL_FILES[0]} &&" +
229 " chmod +x $$ROOT/web/gui2-fw-lib/node_modules/@angular/cli/bin/ng &&" +
230 " export PATH=$$ROOT/$$(dirname $${NODE}):$$ROOT/web/gui2-fw-lib/node_modules/@angular/cli/bin:$$PATH &&" +
231 " node -v > ../../$(location gui2-fw-ng-build-prod.log) &&" +
232 " npm -v >> ../../$(location gui2-fw-ng-build-prod.log) &&" +
Sean Condon7d275162018-11-02 16:29:06 +0000233 " ng version >> ../../$(location gui2-fw-ng-build-prod.log);" +
Sean Condon5ca00262018-09-06 17:55:25 +0100234 " ng build --prod gui2-fw-lib >> $$ROOT/$(location gui2-fw-ng-build-prod.log) 2>&1 ||" +
235 " if [ $$? -eq 0 ]; then echo 'Successfully built GUI FW library';" +
236 " else " +
237 " echo 'Error running \'ng build gui2-fw-lib\' on \'//web/gui2-fw-lib:onos-gui2-fw-ng-build\'. \\\n" +
238 " See bazel-genfiles/web/gui2-fw-lib/gui2-fw-ng-build-prod.log for more details' >&2;" +
239 " exit 1;" +
240 " fi;" +
Sean Condon95fb5742019-04-02 12:16:55 +0100241 # see https://github.com/angular/angular-cli/issues/11071 - Angular CLI does not yet copy across assets
242 " unzip -q $$ROOT/$(location //web/gui:onos-gui-data-for-gui2) web/gui/src/main/webapp/data/img/loading/* &&" +
243 " mkdir -p dist/gui2-fw-lib/assets &&" +
244 " mv web/gui/src/main/webapp/data/img/loading dist/gui2-fw-lib/assets &&" +
Sean Condon4b7818d2019-05-23 07:45:14 +0100245 " cp README.md LICENSE dist/gui2-fw-lib &&" +
246 " npm pack ./dist/gui2-fw-lib >> $$ROOT/$(location gui2-fw-ng-build-prod.log) 2>&1 &&" +
Sean Condon5ca00262018-09-06 17:55:25 +0100247 " mv gui2-fw-lib-*.tgz $$ROOT/$(location gui2-fw-lib-ver.tgz) &&" +
248 " touch $$ROOT/$(location gui2-fw-ng-build-prod.log)", # to get the log always as the 2nd file
249 message = "GUI FW Lib build",
250 visibility = ["//visibility:public"],
251)
252
253"""
254 Run 'ng test' to run Angular test and 'ng lint' for checkstyle
255 See bazel-genfiles/web/gui2/onos-gui2-fw-ng-lint.log or
256 bazel-genfiles/web/gui2/onos-gui2-fw-ng-test.log for details of the Angular CLI output
257"""
258
259genrule(
260 name = "_onos-gui2-fw-ng-test",
261 srcs = [
262 "@nodejs//:bin/npm",
263 "@nodejs//:bin/node",
Sean Condon5ca00262018-09-06 17:55:25 +0100264 "@nodejs//:bin/nodejs/bin/node",
265 "@nodejs//:bin/nodejs/bin/npm",
266 ":onos-gui2-fw-npm-install",
Sean Condonee5d4b92019-03-11 19:57:34 +0000267 "//web/gui:onos-gui-data-for-gui2",
Sean Condon5ca00262018-09-06 17:55:25 +0100268 ":_root_level_files",
269 ":_gui2_fw_lib_src",
270 ":_gui2_fw_lib_tests",
271 ":_e2e_test_files",
272 ],
273 outs = [
274 "onos-gui2-fw-ng-ver.log",
275 "onos-gui2-fw-ng-lint.log",
276 "onos-gui2-fw-ng-test.log",
277 ],
278 cmd = " ROOT=`pwd` &&" +
279 " export HOME=. &&" +
280 " export XDG_CONFIG_HOME=$(@D)/config &&" +
281 " NODE=$(location @nodejs//:bin/node) &&" +
282 " INSTALL_FILES=($(locations :onos-gui2-fw-npm-install)) &&" + # An array of filenames - sorted by time created
283 " mkdir -p web/gui2-fw-lib &&" +
284 " cd web/gui2-fw-lib &&" +
285 " jar xf ../../$(location :_gui2_fw_lib_tests) &&" +
286 " jar xf $$ROOT/$${INSTALL_FILES[0]} &&" +
Sean Condonee5d4b92019-03-11 19:57:34 +0000287 # next 2 lines needed for png file referenced from mast.component.css
288 " unzip -q $$ROOT/$(location //web/gui:onos-gui-data-for-gui2) web/gui/src/main/webapp/data/img/dropdown-icon.png &&" +
289 " mv web/gui/src/main/webapp/data projects/gui2-fw-lib/src/lib/mast/mast/ &&" +
Sean Condon5ca00262018-09-06 17:55:25 +0100290 " chmod +x $$ROOT/web/gui2-fw-lib/node_modules/@angular/cli/bin/ng &&" +
291 " export PATH=$$ROOT/$$(dirname $${NODE}):$$ROOT/web/gui2-fw-lib/node_modules/@angular/cli/bin:$$PATH &&" +
292 " node -v > ../../$(location onos-gui2-fw-ng-ver.log) &&" +
293 " npm -v >> ../../$(location onos-gui2-fw-ng-ver.log) &&" +
Sean Condonb2c483c2019-01-16 20:28:55 +0000294 " ng version >> ../../$(location onos-gui2-fw-ng-ver.log);" +
295 " ng lint gui2-fw-lib > ../../$(location onos-gui2-fw-ng-lint.log) 2>&1 ||" +
296 " if [ $$? -eq 0 ]; then echo 'Successfully ran lint';" +
297 " else " +
298 " echo 'Error running \'ng lint\' on \'//web/gui2-fw-lib:_onos-gui2-fw-ng-test\'. \\\n" +
299 " See bazel-genfiles/web/gui2-fw-lib/onos-gui2-fw-ng-lint.log for more details' >&2;" +
300 " exit 1;" +
301 " fi;" +
Sean Condon5ca00262018-09-06 17:55:25 +0100302 " if [ -f /usr/bin/chromium-browser ]; then " + # Add to this for Mac and Chrome
303 " export CHROME_BIN=/usr/bin/chromium-browser; " +
304 " elif [ -f /opt/google/chrome/chrome ]; then " +
305 " export CHROME_BIN=/opt/google/chrome/chrome; " +
306 " else " +
307 " MSG='Warning: Step _onos-gui2-fw-ng-test skipped because \\n" +
308 " no binary for ChromeHeadless browser was found at /usr/bin/chromium-browser. \\n" +
309 " Install Google Chrome or Chromium Browser to allow this step to run.';" +
310 " echo -e $$MSG >&2;" +
311 " echo -e $$MSG > ../../$(location onos-gui2-fw-ng-test.log);" +
312 " exit 0;" +
313 " fi;" +
Sean Condon7d275162018-11-02 16:29:06 +0000314 " ng test gui2-fw-lib --preserve-symlinks --code-coverage --browsers=ChromeHeadless" +
315 " --watch=false > ../../$(location onos-gui2-fw-ng-test.log) 2>&1 ||" +
Sean Condon5ca00262018-09-06 17:55:25 +0100316 " if [ $$? -eq 0 ]; then echo 'Successfully ran tests';" +
317 " else " +
318 " echo 'Error running \'ng test\' on \'//web/gui2-fw-lib:onos-gui2-fw-ng-test\'. \\\n" +
319 " See bazel-genfiles/web/gui2-fw-lib/onos-gui2-fw-ng-test.log for more details' >&2;" +
320 #" tail -n 100 ../../$(location onos-gui2-fw-ng-test.log) >&2;" +
321 " exit 1;" +
322 " fi;",
323 message = "GUI FW lib lint and test",
324)
325
326"""
327 Wrap the genrule for testing in a test
328"""
329
330sh_test(
331 name = "onos-gui2-ng-tests",
332 size = "small",
333 srcs = [
334 ":ng-test.sh",
335 ],
336 data = [
337 ":_onos-gui2-fw-ng-test",
338 ],
339 deps = [
340 "@bazel_tools//tools/bash/runfiles",
341 ],
342)