blob: dd471f7366ca6bc4c5da90fddcafae1e8c414b5b [file] [log] [blame]
Sean Condon87b78502018-09-17 20:53: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 Fault Management (FM) GUI app for GUI 2
19
20
21"""
22
Carmelo Casconed33d3b42019-06-18 12:12:36 -070023load("//tools/build/bazel:jdk_genrule.bzl", genrule = "jdk_genrule")
24
Sean Condon87b78502018-09-17 20:53:24 +010025COMPILE_DEPS = CORE_DEPS + JACKSON + KRYO + [
26 "@javax_ws_rs_api//jar",
27 "@servlet_api//jar",
28 "@jetty_websocket//jar",
29 "@jetty_util//jar",
30 "@jersey_media_multipart//jar",
31 "@jersey_server//jar",
32 "//utils/rest:onlab-rest",
33 "//core/store/serializers:onos-core-serializers",
34]
35
36TEST_DEPS = TEST + [
37 "//core/api:onos-api-tests",
38 "//drivers/default:onos-drivers-default",
39]
40
41"""
42 Files that get put at the top level of the tar ball
43"""
44
45filegroup(
46 name = "_root_level_files",
47 srcs =
48 [
49 ":angular.json",
50 ":package.json",
51 ":package-lock.json",
52 ":tsconfig.json",
53 ":tslint.json",
54 ],
55)
56
57filegroup(
58 name = "_e2e_test_files",
59 srcs = [
60 ":e2e/protractor.conf.js",
61 ":e2e/src/app.e2e-spec.ts",
62 ":e2e/src/app.po.ts",
63 ":e2e/tsconfig.e2e.json",
64 ],
65)
66
67"""
68 Run ng build to create FM GUI 2 library in production mode
69 The output file fm-gui2-lib-ver.tgz is in the form that can be uploaded directly to https://www.npmjs.com/
70 See bazel-genfiles/apps/faultmanagement/fm-gui2-lib/fm-gui2-lib.log for details of the Angular CLI output
71"""
72
73genrule(
74 name = "fm-gui2-lib-build",
75 srcs = [
76 "@nodejs//:bin/npm",
Sean Condon87b78502018-09-17 20:53:24 +010077 "@nodejs//:bin/nodejs/bin/node",
Sean Condon87b78502018-09-17 20:53:24 +010078 "//web/gui2-fw-lib:onos-gui2-fw-npm-install",
79 "//web/gui2-fw-lib:onos-gui2-fw-ng-build",
80 "//web/gui2-fw-lib:gui2_fw_lib_ext_css",
81 ":_root_level_files",
82 ":_fm_gui2_lib_src",
83 ":_fm-gui2_app_files",
84 ],
85 outs = [
86 "fm-gui2-lib.log",
87 "fm-gui2-lib-ver.tgz",
88 ],
89 cmd = "ROOT=`pwd` &&" +
90 " export HOME=. &&" +
91 " export XDG_CONFIG_HOME=$(@D)/config &&" +
Sean Condon0a884ad2019-10-28 17:57:21 +000092 " NODE=$(location @nodejs//:bin/nodejs/bin/node) &&" +
Sean Condon87b78502018-09-17 20:53:24 +010093 " INSTALL_FILES=($(locations //web/gui2-fw-lib:onos-gui2-fw-npm-install)) &&" + # An array of filenames - sorted by time created
94 " FWLIB_FILES=($(locations //web/gui2-fw-lib:onos-gui2-fw-ng-build)) &&" + # An array of filenames - sorted by time created
95 " mkdir -p apps/faultmanagement/fm-gui2-lib &&" +
96 " cd apps/faultmanagement/fm-gui2-lib &&" +
97 " jar xf $$ROOT/$${INSTALL_FILES[0]} &&" +
98 " tar xf $$ROOT/$${FWLIB_FILES[0]} &&" +
99 " mv package/ node_modules/gui2-fw-lib/ &&" +
100 " mkdir -p projects/fm-gui2-lib/fw &&" +
101 " (cd projects/fm-gui2-lib/fw &&" +
102 " jar xf $$ROOT/$(location //web/gui2-fw-lib:gui2_fw_lib_ext_css)) &&" +
103 " chmod +x node_modules/@angular/cli/bin/ng &&" +
104 " export PATH=$$ROOT/$$(dirname $${NODE}):$$ROOT/apps/faultmanagement/fm-gui2-lib/node_modules/@angular/cli/bin:$$PATH &&" +
105 " ng build --prod fm-gui2-lib >> $$ROOT/$(location fm-gui2-lib.log) 2>&1 ||" +
106 " if [ $$? -eq 0 ]; then echo 'Successfully ran build';" +
107 " else " +
108 " echo 'Error running \'ng build fm-gui2-lib\' on \'//apps/faultmanagement/fm-gui2-lib:fm-gui2-lib-build\'. \\\n" +
109 " See bazel-genfiles/apps/faultmanagement/fm-gui2-lib/fm-gui2-lib.log for more details' >&2;" +
110 #" tail -n 100 ../../$(location onos-gui2-ng-test.log) >&2;" +
111 " exit 1;" +
112 " fi;" +
113 " cd dist/fm-gui2-lib && " +
Sean Condon0a884ad2019-10-28 17:57:21 +0000114 " $$ROOT/$(location @nodejs//:bin/npm) pack >> $$ROOT/$(location fm-gui2-lib.log) 2>&1 &&" +
Sean Condon87b78502018-09-17 20:53:24 +0100115 " mv fm-gui2-lib-*.tgz $$ROOT/$(location fm-gui2-lib-ver.tgz) &&" +
116 " touch $$ROOT/$(location fm-gui2-lib.log)", # to get the log always as the 2nd file,
117 message = "Angular FM GUI2 build",
118 visibility = ["//visibility:public"],
119)
120
121"""
122 Run 'ng test' to run Angular test and 'ng lint' for checkstyle
123 See bazel-genfiles/apps/faultmanagement/fm-gui2-lib/fm-gui2-lib-lint.log or
124 bazel-genfiles/apps/faultmanagement/fm-gui2-lib/fm-gui2-lib-test.log for details of the Angular CLI output
125"""
126
127genrule(
128 name = "_fm-gui2-lib-test-genrule",
129 srcs = [
130 "@nodejs//:bin/npm",
Sean Condon87b78502018-09-17 20:53:24 +0100131 "@nodejs//:bin/nodejs/bin/node",
Sean Condon87b78502018-09-17 20:53:24 +0100132 "//web/gui2-fw-lib:onos-gui2-fw-npm-install",
133 "//web/gui2-fw-lib:onos-gui2-fw-ng-build",
134 "//web/gui2-fw-lib:gui2_fw_lib_ext_css",
135 ":_root_level_files",
136 ":_fm_gui2_lib_src",
137 ":_fm_gui2_lib_src_tests",
138 ],
139 outs = [
140 "fm-gui2-lib-ver.log",
141 "fm-gui2-lib-lint.log",
142 "fm-gui2-lib-test.log",
143 ],
144 cmd = " ROOT=`pwd` &&" +
145 " export HOME=. &&" +
146 " export XDG_CONFIG_HOME=$(@D)/config &&" +
Sean Condon0a884ad2019-10-28 17:57:21 +0000147 " NODE=$(location @nodejs//:bin/nodejs/bin/node) &&" +
Sean Condon87b78502018-09-17 20:53:24 +0100148 " INSTALL_FILES=($(locations //web/gui2-fw-lib:onos-gui2-fw-npm-install)) &&" + # An array of filenames - sorted by time created
149 " FWLIB_FILES=($(locations //web/gui2-fw-lib:onos-gui2-fw-ng-build)) &&" + # An array of filenames - sorted by time created
150 " mkdir -p apps/faultmanagement/fm-gui2-lib &&" +
151 " cd apps/faultmanagement/fm-gui2-lib &&" +
152 " jar xf ../../../$(location :_fm_gui2_lib_src_tests) &&" +
153 " jar xf $$ROOT/$${INSTALL_FILES[0]} &&" +
154 " tar xf $$ROOT/$${FWLIB_FILES[0]} &&" +
155 " mv package/ node_modules/gui2-fw-lib/ &&" +
156 " mkdir -p projects/fm-gui2-lib/fw &&" +
157 " (cd projects/fm-gui2-lib/fw &&" +
158 " jar xf $$ROOT/$(location //web/gui2-fw-lib:gui2_fw_lib_ext_css)) &&" +
159 " chmod +x $$ROOT/apps/faultmanagement/fm-gui2-lib/node_modules/@angular/cli/bin/ng &&" +
160 " export PATH=$$ROOT/$$(dirname $${NODE}):node_modules/@angular/cli/bin:$$PATH &&" +
161 " node -v > ../../../$(location fm-gui2-lib-ver.log) &&" +
Sean Condon0a884ad2019-10-28 17:57:21 +0000162 " $$ROOT/$(location @nodejs//:bin/npm) -v >> ../../../$(location fm-gui2-lib-ver.log) &&" +
Sean Condon87b78502018-09-17 20:53:24 +0100163 " ng -v >> ../../../$(location fm-gui2-lib-ver.log) &&" +
164 " ng lint fm-gui2-lib > ../../../$(location fm-gui2-lib-lint.log);" +
165 " if [ -f /usr/bin/chromium-browser ]; then " + # Add to this for Mac and Chrome
166 " export CHROME_BIN=/usr/bin/chromium-browser; " +
167 " elif [ -f /opt/google/chrome/chrome ]; then " +
168 " export CHROME_BIN=/opt/google/chrome/chrome; " +
169 " else " +
170 " MSG='Warning: Step fm-gui2-lib-tests skipped because \\n" +
171 " no binary for ChromeHeadless browser was found at /usr/bin/chromium-browser. \\n" +
172 " Install Google Chrome or Chromium Browser to allow this step to run.';" +
173 " echo -e $$MSG >&2;" +
174 " echo -e $$MSG > ../../../$(location fm-gui2-lib-test.log);" +
175 " exit 0;" +
176 " fi;" +
Sean Condon7d275162018-11-02 16:29:06 +0000177 " ng test fm-gui2-lib --preserve-symlinks --code-coverage --browsers=ChromeHeadless" +
178 " --watch=false > ../../../$(location fm-gui2-lib-test.log) 2>&1 ||" +
Sean Condon87b78502018-09-17 20:53:24 +0100179 " if [ $$? -eq 0 ]; then echo 'Successfully ran tests';" +
180 " else " +
181 " echo 'Error running \'ng test fm-gui2-lib\' on \'//apps/faultmanagement/fm-gui2-lib:_fm-gui2-lib-test-genrule\'. \\\n" +
182 " See bazel-genfiles/apps/faultmanagement/fm-gui2-lib/fm-gui2-lib-test.log for more details' >&2;" +
183 " exit 1;" +
184 " fi;",
185 message = "Angular FM GUI2 Lib lint and test",
186)
187
188"""
189 Make a group of all the webapp files.
190"""
191
192filegroup(
193 name = "_fm_gui2_lib_src",
194 srcs = glob(
195 [
196 "projects/fm-gui2-lib/**/*",
197 ],
198 exclude = [
199 "projects/fm-gui2-lib/**/*.spec.*", # Don't track tests here
200 "projects/fm-gui2-lib/karma.conf.js",
201 "projects/fm-gui2-lib/src/test.ts",
202 "projects/fm-gui2-lib/fw/**/*",
203 ],
204 ),
205)
206
207"""
208 Make a group of all the webapp qpp files.
209"""
210
211filegroup(
212 name = "_fm-gui2_app_files",
213 srcs = glob(
214 [
215 "src/**/*",
216 ],
217 ),
218)
219
220"""
221 Make a jar file of all the webapp test (*.spec.ts) files.
222"""
223
224genrule(
225 name = "_fm_gui2_lib_src_tests",
226 srcs = glob(
227 [
228 "projects/fm-gui2-lib/karma.conf.js",
229 "projects/fm-gui2-lib/src/test.ts",
230 "projects/fm-gui2-lib/tsconfig.spec.json",
231 "projects/fm-gui2-lib/**/*.spec.ts",
232 ],
233 exclude = [
234 "projects/fm-gui2-lib/ng-package.json",
235 "projects/fm-gui2-lib/ng-package.prod.json",
236 "projects/fm-gui2-lib/package.json",
237 "projects/fm-gui2-lib/tsconfig.lib.json",
238 "projects/fm-gui2-lib/tslint.json",
239 "projects/fm-gui2-lib/src/public_api.ts",
240 ],
241 ),
242 outs = ["fm_gui2_lib_src_tests.jar"],
243 cmd = "cd apps/faultmanagement/fm-gui2-lib &&" +
244 " jar Mcf ../../../$@ .",
245)
246
247"""
248 Make a jar file of all the webapp test (*.spec.ts) files.
249"""
250
251genrule(
252 name = "_fm_gui2_lib_tests",
253 srcs = glob(
254 [
255 "projects/fm-gui2-lib/**/*.spec.ts",
256 "projects/fm-gui2-lib/**/*.spec.json",
257 ],
258 exclude = [
259 "src/main/webapp/tests/**",
260 "src/main/webapp/node_modules/**",
261 "src/main/webapp/dist/**",
262 "src/main/webapp/doc/**",
263 ],
264 ),
265 outs = ["fm_gui2_lib_tests.jar"],
266 cmd = "cd apps/faultmanagement/fm-gui2-lib &&" +
267 " find projects/fm-gui2-lib/src/lib -type f -exec touch -t 201808280000 {} \; &&" +
268 " jar Mcf ../../../$@ projects/fm-gui2-lib/src/lib",
269)
270
271"""
272 Wrap the genrule for testing in a test
273"""
274
275sh_test(
276 name = "fm-gui2-lib-tests",
277 size = "small",
278 srcs = [
279 ":ng-test.sh",
280 ],
281 data = [
282 ":_fm-gui2-lib-test-genrule",
283 ],
284 deps = [
285 "@bazel_tools//tools/bash/runfiles",
286 ],
287)