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