blob: 50cada3fb7c7502d5bbca611cd4301c7daafb45a [file] [log] [blame]
Sean Condona36f65c2019-05-20 08:21:41 +01001"""
2 Copyright ${year}-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 ${artifactId} 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 ${artifactId} GUI 2 library in production mode
67 The output file ${artifactId}-gui-lib-ver.tgz is in the form that can be uploaded directly to https://www.npmjs.com/
Sean Condon27f06da2019-05-25 17:02:14 +010068 See bazel-genfiles/apps/${artifactId}/web/${artifactId}-gui/${artifactId}-gui-lib.log for details of the Angular CLI output
Sean Condona36f65c2019-05-20 08:21:41 +010069"""
70
71genrule(
72 name = "${artifactId}-gui-lib-build",
73 srcs = [
74 "@nodejs//:bin/npm",
75 "@nodejs//:bin/node",
76 "@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 ":_${artifactId}_lib_src",
83 ":_${artifactId}_tester_files",
84 ],
85 outs = [
86 "${artifactId}-gui-lib.log",
87 "${artifactId}-gui-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
Sean Condon27f06da2019-05-25 17:02:14 +010094 " FWLIB_FILES=($(locations //web/gui2-fw-lib:onos-gui2-fw-ng-build)) &&" + # An array of filenames - sorted by time created
95 " mkdir -p apps/${artifactId}/web/${artifactId}-gui &&" +
96 " cd apps/${artifactId}/web/${artifactId}-gui &&" +
Sean Condona36f65c2019-05-20 08:21:41 +010097 " jar xf $$ROOT/$${INSTALL_FILES[0]} &&" +
Sean Condon27f06da2019-05-25 17:02:14 +010098 " tar xf $$ROOT/$${FWLIB_FILES[0]} &&" +
Sean Condona36f65c2019-05-20 08:21:41 +010099 " mv package/ node_modules/gui2-fw-lib/ &&" +
100 " mkdir -p projects/${artifactId}-gui-lib/fw &&" +
101 " (cd projects/${artifactId}-gui-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 &&" +
Sean Condon27f06da2019-05-25 17:02:14 +0100104 " export PATH=$$ROOT/$$(dirname $${NODE}):$$ROOT/apps/${artifactId}/web/${artifactId}-gui/node_modules/@angular/cli/bin:$$PATH &&" +
Sean Condona36f65c2019-05-20 08:21:41 +0100105 " ng build ${artifactId}-gui-lib >> $$ROOT/$(location ${artifactId}-gui-lib.log) 2>&1 ||" +
106 " if [ $$? -eq 0 ]; then echo 'Successfully ran build';" +
107 " else " +
Sean Condon27f06da2019-05-25 17:02:14 +0100108 " echo 'Error running \'ng build ${artifactId}-gui-lib\' on \'//apps/${artifactId}/web/${artifactId}-gui:${artifactId}-gui-lib-build\'. \\\n" +
109 " See bazel-genfiles/apps/${artifactId}/web/${artifactId}-gui/${artifactId}-gui-lib.log for more details' >&2;" +
110 #" tail -n 100 ../../../../$(location onos-gui2-ng-test.log) >&2;" +
Sean Condona36f65c2019-05-20 08:21:41 +0100111 " exit 1;" +
112 " fi;" +
Sean Condon4b7818d2019-05-23 07:45:14 +0100113 " cp README.md LICENSE dist/${artifactId}-gui-lib && " +
114 " npm pack ./dist/${artifactId}-gui-lib >> $$ROOT/$(location ${artifactId}-gui-lib.log) 2>&1 &&" +
Sean Condona36f65c2019-05-20 08:21:41 +0100115 " mv ${artifactId}-gui-lib-*.tgz $$ROOT/$(location ${artifactId}-gui-lib-ver.tgz) &&" +
116 " touch $$ROOT/$(location ${artifactId}-gui-lib.log)", # to get the log always as the 2nd file,
Sean Condon27f06da2019-05-25 17:02:14 +0100117 message = "Angular ${artifactId} Lib build",
Sean Condona36f65c2019-05-20 08:21:41 +0100118 visibility = ["//visibility:public"],
119)
120
121"""
122 Run 'ng test' to run Angular test and 'ng lint' for checkstyle
Sean Condon27f06da2019-05-25 17:02:14 +0100123 See bazel-genfiles/apps/${artifactId}/web/${artifactId}-gui/${artifactId}-gui-lib-lint.log or
124 bazel-genfiles/apps/${artifactId}/web/${artifactId}-gui/${artifactId}-gui-lib-test.log for details of the Angular CLI output
Sean Condona36f65c2019-05-20 08:21:41 +0100125"""
126
127genrule(
128 name = "_${artifactId}-gui-lib-test-genrule",
129 srcs = [
130 "@nodejs//:bin/npm",
131 "@nodejs//:bin/node",
132 "@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 ":_${artifactId}_lib_src",
139 ":_${artifactId}_lib_src_tests",
140 ],
141 outs = [
142 "${artifactId}-gui-lib-ver.log",
143 "${artifactId}-gui-lib-lint.log",
144 "${artifactId}-gui-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
Sean Condon27f06da2019-05-25 17:02:14 +0100152 " mkdir -p apps/${artifactId}/web/${artifactId}-gui &&" +
153 " cd apps/${artifactId}/web/${artifactId}-gui &&" +
154 " jar xf ../../../../$(location :_${artifactId}_lib_src_tests) &&" +
Sean Condona36f65c2019-05-20 08:21:41 +0100155 " 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/${artifactId}-gui-lib/fw &&" +
159 " (cd projects/${artifactId}-gui-lib/fw &&" +
160 " jar xf $$ROOT/$(location //web/gui2-fw-lib:gui2_fw_lib_ext_css)) &&" +
Sean Condon27f06da2019-05-25 17:02:14 +0100161 " chmod +x $$ROOT/apps/${artifactId}/web/${artifactId}-gui/node_modules/@angular/cli/bin/ng &&" +
Sean Condona36f65c2019-05-20 08:21:41 +0100162 " export PATH=$$ROOT/$$(dirname $${NODE}):node_modules/@angular/cli/bin:$$PATH &&" +
Sean Condon27f06da2019-05-25 17:02:14 +0100163 " node -v > ../../../../$(location ${artifactId}-gui-lib-ver.log) &&" +
164 " npm -v >> ../../../../$(location ${artifactId}-gui-lib-ver.log) &&" +
165 " ng version >> ../../../../$(location ${artifactId}-gui-lib-ver.log) &&" +
166 " ng lint ${artifactId}-gui-lib > ../../../../$(location ${artifactId}-gui-lib-lint.log) 2>&1 ||" +
Sean Condona36f65c2019-05-20 08:21:41 +0100167 " if [ $$? -eq 0 ]; then echo 'Successfully ran lint';" +
168 " else " +
Sean Condon27f06da2019-05-25 17:02:14 +0100169 " echo 'Error running \'ng lint\' on \'//apps/${artifactId}/web/${artifactId}-gui:_${artifactId}-gui-lib-test-genrule\'. \\\n" +
170 " See bazel-genfiles/apps/${artifactId}/web/${artifactId}-gui/${artifactId}-gui-lib-lint.log for more details' >&2;" +
Sean Condona36f65c2019-05-20 08:21:41 +0100171 " exit 1;" +
172 " fi;" +
173 " if [ -f /usr/bin/chromium-browser ]; then " + # Add to this for Mac and Chrome
174 " export CHROME_BIN=/usr/bin/chromium-browser; " +
175 " elif [ -f /opt/google/chrome/chrome ]; then " +
176 " export CHROME_BIN=/opt/google/chrome/chrome; " +
177 " else " +
178 " MSG='Warning: Step ${artifactId}-gui-lib-tests skipped because \\n" +
179 " no binary for ChromeHeadless browser was found at /usr/bin/chromium-browser. \\n" +
180 " Install Google Chrome or Chromium Browser to allow this step to run.';" +
181 " echo -e $$MSG >&2;" +
Sean Condon27f06da2019-05-25 17:02:14 +0100182 " echo -e $$MSG > ../../../../$(location ${artifactId}-gui-lib-test.log);" +
Sean Condona36f65c2019-05-20 08:21:41 +0100183 " exit 0;" +
184 " fi;" +
185 " ng test ${artifactId}-gui-lib --preserve-symlinks --code-coverage --browsers=ChromeHeadless" +
Sean Condon27f06da2019-05-25 17:02:14 +0100186 " --watch=false > ../../../../$(location ${artifactId}-gui-lib-test.log) 2>&1 ||" +
Sean Condona36f65c2019-05-20 08:21:41 +0100187 " if [ $$? -eq 0 ]; then echo 'Successfully ran tests';" +
188 " else " +
Sean Condon27f06da2019-05-25 17:02:14 +0100189 " echo 'Error running \'ng test ${artifactId}-gui-lib\' on \'//apps/${artifactId}/web/${artifactId}-gui:_${artifactId}-gui-lib-test-genrule\'. \\\n" +
190 " See bazel-genfiles/apps/${artifactId}/web/${artifactId}-gui/${artifactId}-gui-lib-test.log for more details' >&2;" +
Sean Condona36f65c2019-05-20 08:21:41 +0100191 " exit 1;" +
192 " fi;",
Sean Condon13f42b72019-05-31 16:17:52 +0100193 message = "Angular ${appNameTitle} Lib lint and test",
Sean Condona36f65c2019-05-20 08:21:41 +0100194)
195
196"""
197 Make a group of all the webapp files.
198"""
199
200filegroup(
201 name = "_${artifactId}_lib_src",
202 srcs = glob(
203 [
204 "projects/${artifactId}-gui-lib/**/*",
Sean Condon4b7818d2019-05-23 07:45:14 +0100205 "README.md",
206 "LICENSE",
Sean Condona36f65c2019-05-20 08:21:41 +0100207 ],
208 exclude = [
209 "projects/${artifactId}-gui-lib/**/*.spec.*", # Don't track tests here
210 "projects/${artifactId}-gui-lib/karma.conf.js",
211 "projects/${artifactId}-gui-lib/src/test.ts",
212 "projects/${artifactId}-gui-lib/fw/**/*",
213 ],
214 ),
215)
216
217"""
218 Make a group of all the webapp qpp files.
219"""
220
221filegroup(
222 name = "_${artifactId}_tester_files",
223 srcs = glob(
224 [
225 "src/**/*",
226 ],
227 ),
228)
229
230"""
231 Make a jar file of all the webapp test (*.spec.ts) files.
232"""
233
234genrule(
235 name = "_${artifactId}_lib_src_tests",
236 srcs = glob(
237 [
238 "projects/${artifactId}-gui-lib/karma.conf.js",
239 "projects/${artifactId}-gui-lib/src/test.ts",
240 "projects/${artifactId}-gui-lib/tsconfig.spec.json",
241 "projects/${artifactId}-gui-lib/**/*.spec.ts",
242 ],
243 exclude = [
244 "projects/${artifactId}-gui-lib/ng-package.json",
245 "projects/${artifactId}-gui-lib/ng-package.prod.json",
246 "projects/${artifactId}-gui-lib/package.json",
247 "projects/${artifactId}-gui-lib/tsconfig.lib.json",
248 "projects/${artifactId}-gui-lib/tslint.json",
249 "projects/${artifactId}-gui-lib/src/public_api.ts",
250 ],
251 ),
252 outs = ["${artifactId}_gui_lib_src_tests.jar"],
Sean Condon27f06da2019-05-25 17:02:14 +0100253 cmd = "cd apps/${artifactId}/web/${artifactId}-gui &&" +
254 " jar Mcf ../../../../$@ .",
Sean Condona36f65c2019-05-20 08:21:41 +0100255)
256
257"""
258 Make a jar file of all the webapp test (*.spec.ts) files.
259"""
260
261genrule(
262 name = "_${artifactId}_gui_lib_tests",
263 srcs = glob(
264 [
265 "projects/${artifactId}-gui-lib/**/*.spec.ts",
266 "projects/${artifactId}-gui-lib/**/*.spec.json",
267 ],
268 exclude = [
269 "src/main/webapp/tests/**",
270 "src/main/webapp/node_modules/**",
271 "src/main/webapp/dist/**",
272 "src/main/webapp/doc/**",
273 ],
274 ),
275 outs = ["${artifactId}_gui_lib_tests.jar"],
Sean Condon27f06da2019-05-25 17:02:14 +0100276 cmd = "cd apps/${artifactId}/web/${artifactId}-gui &&" +
Sean Condona36f65c2019-05-20 08:21:41 +0100277 " find projects/${artifactId}-gui-lib/src/lib -type f -exec touch -t 201808280000 {} \; &&" +
Sean Condon27f06da2019-05-25 17:02:14 +0100278 " jar Mcf ../../../../$@ projects/${artifactId}-gui-lib/src/lib",
Sean Condona36f65c2019-05-20 08:21:41 +0100279)
280
281"""
282 Wrap the genrule for testing in a test
283"""
284
285sh_test(
286 name = "${artifactId}-gui-lib-tests",
287 size = "small",
288 srcs = [
289 ":ng-test.sh",
290 ],
291 data = [
292 ":_${artifactId}-gui-lib-test-genrule",
293 ],
294 deps = [
295 "@bazel_tools//tools/bash/runfiles",
296 ],
297)