blob: 5f607a12fd1d0e54b1f62d8081e556f1a699d7d1 [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",
Sean Condon5ca00262018-09-06 17:55:25 +010068 ":tsconfig.json",
69 ":tslint.json",
Sean Condondfc6dba2019-11-09 11:50:23 +000070 ":yarn.lock",
Sean Condon5ca00262018-09-06 17:55:25 +010071 ],
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
Sean Condonc687ccb2019-10-25 12:27:54 +0100169 See bazel-out/k8-fastbuild/bin/web/gui2/onos-gui2-npm-install.log for details of the 'npm install'
Sean Condon5ca00262018-09-06 17:55:25 +0100170"""
171
172genrule(
173 name = "onos-gui2-fw-npm-install",
174 srcs = [
175 "@nodejs//:bin/npm",
Sean Condon5ca00262018-09-06 17:55:25 +0100176 "@nodejs//:bin/nodejs/bin/node",
Sean Condondfc6dba2019-11-09 11:50:23 +0000177 "@npm//:node_modules/@angular/cli/bin/ng",
178 "@npm//:node_modules",
Sean Condon5ca00262018-09-06 17:55:25 +0100179 ":_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 &&" +
Sean Condon0a884ad2019-10-28 17:57:21 +0000192 " $$NPM version > $$ROOT/$(location onos-gui2-npm-install.log) 2>&1 &&" +
Sean Condondfc6dba2019-11-09 11:50:23 +0000193 " NM=external/npm/node_modules &&" +
Sean Condon0a884ad2019-10-28 17:57:21 +0000194 " echo $$NM > $$ROOT/$(location onos-gui2-npm-install.log) 2>&1 &&" +
195 # " ../../$(location @nodejs//:npm) $$NPM_ARGS install --no-cache >> $$ROOT/$(location onos-gui2-npm-install.log) 2>&1 &&" +
Sean Condondfc6dba2019-11-09 11:50:23 +0000196 " cd external/npm &&" +
Sean Condon5ca00262018-09-06 17:55:25 +0100197 " jar Mcf $$ROOT/$(location onos-gui2-npm-install.jar) node_modules &&" +
198 " touch $$ROOT/$(location onos-gui2-npm-install.log)", # to get the log always as the 2nd file
199 message = "NodeJS npm install",
200 visibility = ["//visibility:public"],
201)
202
203"""
204 Run ng build to create outputs in production mode
Sean Condonc687ccb2019-10-25 12:27:54 +0100205 See bazel-out/k8-fastbuild/bin/web/gui2/onos-gui2-ng-build-prod.log for details of the Angular CLI output
Sean Condon5ca00262018-09-06 17:55:25 +0100206"""
207
208genrule(
209 name = "onos-gui2-fw-ng-build",
210 srcs = [
Sean Condon5ca00262018-09-06 17:55:25 +0100211 "@nodejs//:bin/nodejs/bin/node",
Sean Condon0a884ad2019-10-28 17:57:21 +0000212 "@nodejs//:bin/npm",
Sean Condon5ca00262018-09-06 17:55:25 +0100213 ":onos-gui2-fw-npm-install",
Sean Condondfc6dba2019-11-09 11:50:23 +0000214 "@npm//:node_modules/@angular/cli/bin/ng",
215 "@npm//:node_modules",
Sean Condon95fb5742019-04-02 12:16:55 +0100216 "//web/gui:onos-gui-data-for-gui2",
Sean Condon5ca00262018-09-06 17:55:25 +0100217 ":_root_level_files",
218 ":_gui2_fw_lib_src",
219 ],
220 outs = [
221 "gui2-fw-ng-build-prod.log",
222 "gui2-fw-lib-ver.tgz",
223 ],
224 cmd = "ROOT=`pwd` &&" +
225 " export HOME=. &&" +
226 " export XDG_CONFIG_HOME=$(@D)/config &&" +
Sean Condon0a884ad2019-10-28 17:57:21 +0000227 " NODE=$(location @nodejs//:bin/nodejs/bin/node) &&" +
Sean Condondfc6dba2019-11-09 11:50:23 +0000228 # " NG=$(location @npm//:node_modules/@angular/cli/bin/ng) &&" +
Sean Condon5ca00262018-09-06 17:55:25 +0100229 " INSTALL_FILES=($(locations :onos-gui2-fw-npm-install)) &&" + # An array of filenames - sorted by time created
230 " cd web/gui2-fw-lib &&" +
231 " jar xf $$ROOT/$${INSTALL_FILES[0]} &&" +
232 " chmod +x $$ROOT/web/gui2-fw-lib/node_modules/@angular/cli/bin/ng &&" +
233 " export PATH=$$ROOT/$$(dirname $${NODE}):$$ROOT/web/gui2-fw-lib/node_modules/@angular/cli/bin:$$PATH &&" +
234 " node -v > ../../$(location gui2-fw-ng-build-prod.log) &&" +
Sean Condon0a884ad2019-10-28 17:57:21 +0000235 " $$ROOT/$(location @nodejs//:bin/npm) version >> ../../$(location gui2-fw-ng-build-prod.log) &&" +
Sean Condon7d275162018-11-02 16:29:06 +0000236 " ng version >> ../../$(location gui2-fw-ng-build-prod.log);" +
Sean Condon5ca00262018-09-06 17:55:25 +0100237 " ng build --prod gui2-fw-lib >> $$ROOT/$(location gui2-fw-ng-build-prod.log) 2>&1 ||" +
238 " if [ $$? -eq 0 ]; then echo 'Successfully built GUI FW library';" +
239 " else " +
240 " echo 'Error running \'ng build gui2-fw-lib\' on \'//web/gui2-fw-lib:onos-gui2-fw-ng-build\'. \\\n" +
Sean Condonc687ccb2019-10-25 12:27:54 +0100241 " See bazel-out/k8-fastbuild/bin/web/gui2-fw-lib/gui2-fw-ng-build-prod.log for more details' >&2;" +
Sean Condon5ca00262018-09-06 17:55:25 +0100242 " exit 1;" +
243 " fi;" +
Sean Condon95fb5742019-04-02 12:16:55 +0100244 # see https://github.com/angular/angular-cli/issues/11071 - Angular CLI does not yet copy across assets
245 " unzip -q $$ROOT/$(location //web/gui:onos-gui-data-for-gui2) web/gui/src/main/webapp/data/img/loading/* &&" +
246 " mkdir -p dist/gui2-fw-lib/assets &&" +
247 " mv web/gui/src/main/webapp/data/img/loading dist/gui2-fw-lib/assets &&" +
Sean Condon4b7818d2019-05-23 07:45:14 +0100248 " cp README.md LICENSE dist/gui2-fw-lib &&" +
Sean Condon0a884ad2019-10-28 17:57:21 +0000249 " $$ROOT/$(location @nodejs//:bin/npm) pack ./dist/gui2-fw-lib >> $$ROOT/$(location gui2-fw-ng-build-prod.log) 2>&1 &&" +
Sean Condon5ca00262018-09-06 17:55:25 +0100250 " mv gui2-fw-lib-*.tgz $$ROOT/$(location gui2-fw-lib-ver.tgz) &&" +
251 " touch $$ROOT/$(location gui2-fw-ng-build-prod.log)", # to get the log always as the 2nd file
252 message = "GUI FW Lib build",
253 visibility = ["//visibility:public"],
254)
255
256"""
257 Run 'ng test' to run Angular test and 'ng lint' for checkstyle
Sean Condonc687ccb2019-10-25 12:27:54 +0100258 See bazel-out/k8-fastbuild/bin/web/gui2/onos-gui2-fw-ng-lint.log or
259 bazel-out/k8-fastbuild/bin/web/gui2/onos-gui2-fw-ng-test.log for details of the Angular CLI output
Sean Condon5ca00262018-09-06 17:55:25 +0100260"""
261
262genrule(
263 name = "_onos-gui2-fw-ng-test",
264 srcs = [
265 "@nodejs//:bin/npm",
Sean Condon5ca00262018-09-06 17:55:25 +0100266 "@nodejs//:bin/nodejs/bin/node",
Sean Condon5ca00262018-09-06 17:55:25 +0100267 ":onos-gui2-fw-npm-install",
Sean Condonee5d4b92019-03-11 19:57:34 +0000268 "//web/gui:onos-gui-data-for-gui2",
Sean Condon5ca00262018-09-06 17:55:25 +0100269 ":_root_level_files",
270 ":_gui2_fw_lib_src",
271 ":_gui2_fw_lib_tests",
272 ":_e2e_test_files",
273 ],
274 outs = [
275 "onos-gui2-fw-ng-ver.log",
276 "onos-gui2-fw-ng-lint.log",
277 "onos-gui2-fw-ng-test.log",
278 ],
279 cmd = " ROOT=`pwd` &&" +
280 " export HOME=. &&" +
281 " export XDG_CONFIG_HOME=$(@D)/config &&" +
Sean Condon0a884ad2019-10-28 17:57:21 +0000282 " NODE=$(location @nodejs//:bin/nodejs/bin/node) &&" +
Sean Condon5ca00262018-09-06 17:55:25 +0100283 " INSTALL_FILES=($(locations :onos-gui2-fw-npm-install)) &&" + # An array of filenames - sorted by time created
284 " mkdir -p web/gui2-fw-lib &&" +
285 " cd web/gui2-fw-lib &&" +
286 " jar xf ../../$(location :_gui2_fw_lib_tests) &&" +
287 " jar xf $$ROOT/$${INSTALL_FILES[0]} &&" +
Sean Condonee5d4b92019-03-11 19:57:34 +0000288 # next 2 lines needed for png file referenced from mast.component.css
289 " unzip -q $$ROOT/$(location //web/gui:onos-gui-data-for-gui2) web/gui/src/main/webapp/data/img/dropdown-icon.png &&" +
290 " mv web/gui/src/main/webapp/data projects/gui2-fw-lib/src/lib/mast/mast/ &&" +
Sean Condon5ca00262018-09-06 17:55:25 +0100291 " chmod +x $$ROOT/web/gui2-fw-lib/node_modules/@angular/cli/bin/ng &&" +
292 " export PATH=$$ROOT/$$(dirname $${NODE}):$$ROOT/web/gui2-fw-lib/node_modules/@angular/cli/bin:$$PATH &&" +
293 " node -v > ../../$(location onos-gui2-fw-ng-ver.log) &&" +
Sean Condon0a884ad2019-10-28 17:57:21 +0000294 " $$ROOT/$(location @nodejs//:bin/npm) -v >> ../../$(location onos-gui2-fw-ng-ver.log) &&" +
Sean Condonb2c483c2019-01-16 20:28:55 +0000295 " ng version >> ../../$(location onos-gui2-fw-ng-ver.log);" +
296 " ng lint gui2-fw-lib > ../../$(location onos-gui2-fw-ng-lint.log) 2>&1 ||" +
297 " if [ $$? -eq 0 ]; then echo 'Successfully ran lint';" +
298 " else " +
299 " echo 'Error running \'ng lint\' on \'//web/gui2-fw-lib:_onos-gui2-fw-ng-test\'. \\\n" +
Sean Condonc687ccb2019-10-25 12:27:54 +0100300 " See bazel-out/k8-fastbuild/bin/web/gui2-fw-lib/onos-gui2-fw-ng-lint.log for more details' >&2;" +
301 " cat ../../$(location onos-gui2-fw-ng-lint.log) >&2 ||" +
Sean Condonb2c483c2019-01-16 20:28:55 +0000302 " exit 1;" +
303 " fi;" +
Sean Condon5ca00262018-09-06 17:55:25 +0100304 " if [ -f /usr/bin/chromium-browser ]; then " + # Add to this for Mac and Chrome
305 " export CHROME_BIN=/usr/bin/chromium-browser; " +
306 " elif [ -f /opt/google/chrome/chrome ]; then " +
307 " export CHROME_BIN=/opt/google/chrome/chrome; " +
308 " else " +
309 " MSG='Warning: Step _onos-gui2-fw-ng-test skipped because \\n" +
310 " no binary for ChromeHeadless browser was found at /usr/bin/chromium-browser. \\n" +
311 " Install Google Chrome or Chromium Browser to allow this step to run.';" +
312 " echo -e $$MSG >&2;" +
313 " echo -e $$MSG > ../../$(location onos-gui2-fw-ng-test.log);" +
314 " exit 0;" +
315 " fi;" +
Sean Condon7d275162018-11-02 16:29:06 +0000316 " ng test gui2-fw-lib --preserve-symlinks --code-coverage --browsers=ChromeHeadless" +
317 " --watch=false > ../../$(location onos-gui2-fw-ng-test.log) 2>&1 ||" +
Sean Condon5ca00262018-09-06 17:55:25 +0100318 " if [ $$? -eq 0 ]; then echo 'Successfully ran tests';" +
319 " else " +
Sean Condondfc6dba2019-11-09 11:50:23 +0000320 " echo 'Error running \'ng test\' on \'//web/gui2-fw-lib:_onos-gui2-fw-ng-test\'. \\\n" +
Sean Condonc687ccb2019-10-25 12:27:54 +0100321 " See bazel-out/k8-fastbuild/bin/web/gui2-fw-lib/onos-gui2-fw-ng-test.log for more details' >&2;" +
Sean Condondfc6dba2019-11-09 11:50:23 +0000322 " cat ../../$(location onos-gui2-fw-ng-test.log) >&2;" +
Sean Condon5ca00262018-09-06 17:55:25 +0100323 " exit 1;" +
324 " fi;",
325 message = "GUI FW lib lint and test",
326)
327
328"""
329 Wrap the genrule for testing in a test
330"""
331
332sh_test(
333 name = "onos-gui2-ng-tests",
334 size = "small",
335 srcs = [
336 ":ng-test.sh",
337 ],
338 data = [
339 ":_onos-gui2-fw-ng-test",
340 ],
341 deps = [
342 "@bazel_tools//tools/bash/runfiles",
343 ],
344)
Sean Condondfc6dba2019-11-09 11:50:23 +0000345
346# This export allows targets in other packages to reference files that live
347# in this package.
348exports_files([
349 "tsconfig.json",
350])