blob: 667814fa8144137c2cbbfd1e146d6c8ad0479bd9 [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/**",
91 ],
92 exclude = [
93 "projects/gui2-fw-lib/**/*.spec.*", # Don't track tests here
94 "projects/gui2-fw-lib/karma.conf.js",
95 "projects/gui2-fw-lib/src/test.ts",
96 ],
97 ),
98)
99
100"""
101 Make a group of all the webapp qpp files.
102"""
103
104filegroup(
105 name = "_gui2_app_files",
106 srcs = glob(
107 [
108 "src/**/*",
109 ],
110 ),
111)
112
113"""
114 Make a jar file of all the webapp test (*.spec.ts) files.
115"""
116
117genrule(
118 name = "_gui2_fw_lib_tests",
119 srcs = glob(
120 [
121 "projects/gui2-fw-lib/karma.conf.js",
122 "projects/gui2-fw-lib/src/test.ts",
123 "projects/gui2-fw-lib/tsconfig.spec.json",
124 "projects/gui2-fw-lib/**/*.spec.ts",
125 ],
126 exclude = [
127 "projects/gui2-fw-lib/ng-package.json",
128 "projects/gui2-fw-lib/ng-package.prod.json",
129 "projects/gui2-fw-lib/package.json",
130 "projects/gui2-fw-lib/tsconfig.lib.json",
131 "projects/gui2-fw-lib/tslint.json",
132 "projects/gui2-fw-lib/src/public_api.ts",
133 ],
134 ),
135 outs = ["gui2_fw_lib_tests.jar"],
136 cmd = "cd web/gui2-fw-lib &&" +
137 " jar Mcf ../../$@ .",
138)
139
140"""
141 Make a jar file of all the CSS files we want to reuse in the target.
142"""
143
144genrule(
145 name = "gui2_fw_lib_ext_css",
146 srcs = glob(
147 [
148 "projects/gui2-fw-lib/src/lib/widget/panel.css",
149 "projects/gui2-fw-lib/src/lib/widget/panel-theme.css",
150 "projects/gui2-fw-lib/src/lib/widget/table.css",
151 "projects/gui2-fw-lib/src/lib/widget/table.theme.css",
152 "projects/gui2-fw-lib/src/lib/widget/table.theme.css",
153 "projects/gui2-fw-lib/src/lib/layer/loading.service.css",
154 ],
155 ),
156 outs = ["gui2_fw_lib_css.jar"],
157 cmd = " ROOT=`pwd` &&" +
158 " cd web/gui2-fw-lib/projects/gui2-fw-lib/src/lib &&" +
159 " jar Mcf $$ROOT/$@ .",
160 visibility = ["//visibility:public"],
161)
162
163"""
164 Install npm packages listed in package.json in web/gui2
165 See bazel-genfiles/web/gui2/onos-gui2-npm-install.log for details of the 'npm install'
166"""
167
168genrule(
169 name = "onos-gui2-fw-npm-install",
170 srcs = [
171 "@nodejs//:bin/npm",
172 "@nodejs//:bin/node",
173 "@nodejs//:bin/node.js",
174 "@nodejs//:bin/nodejs/bin/node",
175 "@nodejs//:bin/nodejs/bin/npm",
176 ":_root_level_files",
177 ],
178 outs = [
179 "onos-gui2-npm-install.jar",
180 "onos-gui2-npm-install.log",
181 ],
182 cmd = " ROOT=`pwd` &&" +
183 " export HOME=. &&" +
184 " export XDG_CONFIG_HOME=$(@D)/config &&" + # npm config cache to the sandbox
185 " export BABEL_DISABLE_CACHE=1 &&" + # turn off babel cache
186 ' if [[ ! -z $${HTTP_PROXY-} ]]; then NPM_ARGS="--proxy $$HTTP_PROXY --without-ssl --insecure"; else NPM_ARGS=""; fi &&' +
187 " NPM=$(location @nodejs//:bin/npm) &&" +
188 " export PATH=$$ROOT/$$(dirname $${NPM}):$$PATH &&" +
189 " npm -v > $$ROOT/$(location onos-gui2-npm-install.log) 2>&1 &&" +
190 " cd web/gui2-fw-lib && " +
191 " npm $$NPM_ARGS install --no-cache >> $$ROOT/$(location onos-gui2-npm-install.log) 2>&1 &&" +
192 " jar Mcf $$ROOT/$(location onos-gui2-npm-install.jar) node_modules &&" +
193 " touch $$ROOT/$(location onos-gui2-npm-install.log)", # to get the log always as the 2nd file
194 message = "NodeJS npm install",
195 visibility = ["//visibility:public"],
196)
197
198"""
199 Run ng build to create outputs in production mode
200 See bazel-genfiles/web/gui2/onos-gui2-ng-build-prod.log for details of the Angular CLI output
201"""
202
203genrule(
204 name = "onos-gui2-fw-ng-build",
205 srcs = [
206 "@nodejs//:bin/npm",
207 "@nodejs//:bin/node",
208 "@nodejs//:bin/node.js",
209 "@nodejs//:bin/nodejs/bin/node",
210 "@nodejs//:bin/nodejs/bin/npm",
211 ":onos-gui2-fw-npm-install",
212 ":_root_level_files",
213 ":_gui2_fw_lib_src",
214 ],
215 outs = [
216 "gui2-fw-ng-build-prod.log",
217 "gui2-fw-lib-ver.tgz",
218 ],
219 cmd = "ROOT=`pwd` &&" +
220 " export HOME=. &&" +
221 " export XDG_CONFIG_HOME=$(@D)/config &&" +
222 " NODE=$(location @nodejs//:bin/node) &&" +
223 " INSTALL_FILES=($(locations :onos-gui2-fw-npm-install)) &&" + # An array of filenames - sorted by time created
224 " cd web/gui2-fw-lib &&" +
225 " jar xf $$ROOT/$${INSTALL_FILES[0]} &&" +
226 " chmod +x $$ROOT/web/gui2-fw-lib/node_modules/@angular/cli/bin/ng &&" +
227 " export PATH=$$ROOT/$$(dirname $${NODE}):$$ROOT/web/gui2-fw-lib/node_modules/@angular/cli/bin:$$PATH &&" +
228 " node -v > ../../$(location gui2-fw-ng-build-prod.log) &&" +
229 " npm -v >> ../../$(location gui2-fw-ng-build-prod.log) &&" +
Sean Condon7d275162018-11-02 16:29:06 +0000230 " ng version >> ../../$(location gui2-fw-ng-build-prod.log);" +
Sean Condon5ca00262018-09-06 17:55:25 +0100231 " ng build --prod gui2-fw-lib >> $$ROOT/$(location gui2-fw-ng-build-prod.log) 2>&1 ||" +
232 " if [ $$? -eq 0 ]; then echo 'Successfully built GUI FW library';" +
233 " else " +
234 " echo 'Error running \'ng build gui2-fw-lib\' on \'//web/gui2-fw-lib:onos-gui2-fw-ng-build\'. \\\n" +
235 " See bazel-genfiles/web/gui2-fw-lib/gui2-fw-ng-build-prod.log for more details' >&2;" +
236 " exit 1;" +
237 " fi;" +
238 " cd dist/gui2-fw-lib &&" +
239 " npm pack &&" +
240 " mv gui2-fw-lib-*.tgz $$ROOT/$(location gui2-fw-lib-ver.tgz) &&" +
241 " touch $$ROOT/$(location gui2-fw-ng-build-prod.log)", # to get the log always as the 2nd file
242 message = "GUI FW Lib build",
243 visibility = ["//visibility:public"],
244)
245
246"""
247 Run 'ng test' to run Angular test and 'ng lint' for checkstyle
248 See bazel-genfiles/web/gui2/onos-gui2-fw-ng-lint.log or
249 bazel-genfiles/web/gui2/onos-gui2-fw-ng-test.log for details of the Angular CLI output
250"""
251
252genrule(
253 name = "_onos-gui2-fw-ng-test",
254 srcs = [
255 "@nodejs//:bin/npm",
256 "@nodejs//:bin/node",
257 "@nodejs//:bin/node.js",
258 "@nodejs//:bin/nodejs/bin/node",
259 "@nodejs//:bin/nodejs/bin/npm",
260 ":onos-gui2-fw-npm-install",
261 ":_root_level_files",
262 ":_gui2_fw_lib_src",
263 ":_gui2_fw_lib_tests",
264 ":_e2e_test_files",
265 ],
266 outs = [
267 "onos-gui2-fw-ng-ver.log",
268 "onos-gui2-fw-ng-lint.log",
269 "onos-gui2-fw-ng-test.log",
270 ],
271 cmd = " ROOT=`pwd` &&" +
272 " export HOME=. &&" +
273 " export XDG_CONFIG_HOME=$(@D)/config &&" +
274 " NODE=$(location @nodejs//:bin/node) &&" +
275 " INSTALL_FILES=($(locations :onos-gui2-fw-npm-install)) &&" + # An array of filenames - sorted by time created
276 " mkdir -p web/gui2-fw-lib &&" +
277 " cd web/gui2-fw-lib &&" +
278 " jar xf ../../$(location :_gui2_fw_lib_tests) &&" +
279 " jar xf $$ROOT/$${INSTALL_FILES[0]} &&" +
280 " chmod +x $$ROOT/web/gui2-fw-lib/node_modules/@angular/cli/bin/ng &&" +
281 " export PATH=$$ROOT/$$(dirname $${NODE}):$$ROOT/web/gui2-fw-lib/node_modules/@angular/cli/bin:$$PATH &&" +
282 " node -v > ../../$(location onos-gui2-fw-ng-ver.log) &&" +
283 " npm -v >> ../../$(location onos-gui2-fw-ng-ver.log) &&" +
Sean Condon7d275162018-11-02 16:29:06 +0000284 " ng version >> ../../$(location onos-gui2-fw-ng-ver.log) &&" +
Sean Condon5ca00262018-09-06 17:55:25 +0100285 " ng lint gui2-fw-lib > ../../$(location onos-gui2-fw-ng-lint.log);" +
286 " if [ -f /usr/bin/chromium-browser ]; then " + # Add to this for Mac and Chrome
287 " export CHROME_BIN=/usr/bin/chromium-browser; " +
288 " elif [ -f /opt/google/chrome/chrome ]; then " +
289 " export CHROME_BIN=/opt/google/chrome/chrome; " +
290 " else " +
291 " MSG='Warning: Step _onos-gui2-fw-ng-test skipped because \\n" +
292 " no binary for ChromeHeadless browser was found at /usr/bin/chromium-browser. \\n" +
293 " Install Google Chrome or Chromium Browser to allow this step to run.';" +
294 " echo -e $$MSG >&2;" +
295 " echo -e $$MSG > ../../$(location onos-gui2-fw-ng-test.log);" +
296 " exit 0;" +
297 " fi;" +
Sean Condon7d275162018-11-02 16:29:06 +0000298 " ng test gui2-fw-lib --preserve-symlinks --code-coverage --browsers=ChromeHeadless" +
299 " --watch=false > ../../$(location onos-gui2-fw-ng-test.log) 2>&1 ||" +
Sean Condon5ca00262018-09-06 17:55:25 +0100300 " if [ $$? -eq 0 ]; then echo 'Successfully ran tests';" +
301 " else " +
302 " echo 'Error running \'ng test\' on \'//web/gui2-fw-lib:onos-gui2-fw-ng-test\'. \\\n" +
303 " See bazel-genfiles/web/gui2-fw-lib/onos-gui2-fw-ng-test.log for more details' >&2;" +
304 #" tail -n 100 ../../$(location onos-gui2-fw-ng-test.log) >&2;" +
305 " exit 1;" +
306 " fi;",
307 message = "GUI FW lib lint and test",
308)
309
310"""
311 Wrap the genrule for testing in a test
312"""
313
314sh_test(
315 name = "onos-gui2-ng-tests",
316 size = "small",
317 srcs = [
318 ":ng-test.sh",
319 ],
320 data = [
321 ":_onos-gui2-fw-ng-test",
322 ],
323 deps = [
324 "@bazel_tools//tools/bash/runfiles",
325 ],
326)