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