blob: 6fe640529f816417d52e9cbd19d75d3877551b1d [file] [log] [blame]
Sean Condonff85fbe2019-03-16 14:28:46 +00001"""
2 Copyright 2019-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 Topology 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 Condonff85fbe2019-03-16 14:28:46 +000025COMPILE_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 Topo GUI 2 library in production mode
69 The output file gui2-topo-lib-ver.tgz is in the form that can be uploaded directly to https://www.npmjs.com/
70 See bazel-genfiles/web/gui2-topo-lib/gui2-topo-lib.log for details of the Angular CLI output
71"""
72
73genrule(
74 name = "gui2-topo-lib-build",
75 srcs = [
76 "@nodejs//:bin/npm",
77 "@nodejs//:bin/node",
78 "@nodejs//:bin/nodejs/bin/node",
79 "@nodejs//:bin/nodejs/bin/npm",
80 "//web/gui2-fw-lib:onos-gui2-fw-npm-install",
81 "//web/gui2-fw-lib:onos-gui2-fw-ng-build",
82 "//web/gui2-fw-lib:gui2_fw_lib_ext_css",
83 ":_root_level_files",
84 ":_gui2_topo_lib_src",
85 ":_gui2_topo_tester_files",
86 ],
87 outs = [
88 "gui2-topo-lib.log",
89 "gui2-topo-lib-ver.tgz",
90 ],
91 cmd = "ROOT=`pwd` &&" +
92 " export HOME=. &&" +
93 " export XDG_CONFIG_HOME=$(@D)/config &&" +
94 " NODE=$(location @nodejs//:bin/node) &&" +
95 " INSTALL_FILES=($(locations //web/gui2-fw-lib:onos-gui2-fw-npm-install)) &&" + # An array of filenames - sorted by time created
96 " TOPOLIB_FILES=($(locations //web/gui2-fw-lib:onos-gui2-fw-ng-build)) &&" + # An array of filenames - sorted by time created
97 " mkdir -p web/gui2-topo-lib &&" +
98 " cd web/gui2-topo-lib &&" +
99 " jar xf $$ROOT/$${INSTALL_FILES[0]} &&" +
100 " tar xf $$ROOT/$${TOPOLIB_FILES[0]} &&" +
101 " mv package/ node_modules/gui2-fw-lib/ &&" +
102 " mkdir -p projects/gui2-topo-lib/fw &&" +
103 " (cd projects/gui2-topo-lib/fw &&" +
104 " jar xf $$ROOT/$(location //web/gui2-fw-lib:gui2_fw_lib_ext_css)) &&" +
105 " chmod +x node_modules/@angular/cli/bin/ng &&" +
106 " export PATH=$$ROOT/$$(dirname $${NODE}):$$ROOT/web/gui2-topo-lib/node_modules/@angular/cli/bin:$$PATH &&" +
107 " ng build gui2-topo-lib >> $$ROOT/$(location gui2-topo-lib.log) 2>&1 ||" +
108 " if [ $$? -eq 0 ]; then echo 'Successfully ran build';" +
109 " else " +
110 " echo 'Error running \'ng build gui2-topo-lib\' on \'//web/gui2-topo-lib:gui2-topo-lib-build\'. \\\n" +
111 " See bazel-genfiles/web/gui2-topo-lib/gui2-topo-lib.log for more details' >&2;" +
112 #" tail -n 100 ../../$(location onos-gui2-ng-test.log) >&2;" +
113 " exit 1;" +
114 " fi;" +
Sean Condon4b7818d2019-05-23 07:45:14 +0100115 " cp README.md LICENSE dist/gui2-topo-lib && " +
116 " npm pack ./dist/gui2-topo-lib >> $$ROOT/$(location gui2-topo-lib.log) 2>&1 &&" +
Sean Condonff85fbe2019-03-16 14:28:46 +0000117 " mv gui2-topo-lib-*.tgz $$ROOT/$(location gui2-topo-lib-ver.tgz) &&" +
118 " touch $$ROOT/$(location gui2-topo-lib.log)", # to get the log always as the 2nd file,
119 message = "Angular Topo GUI2 build",
120 visibility = ["//visibility:public"],
121)
122
123"""
124 Run 'ng test' to run Angular test and 'ng lint' for checkstyle
125 See bazel-genfiles/web/gui2-topo-lib/gui2-topo-lib-lint.log or
126 bazel-genfiles/web/gui2-topo-lib/gui2-topo-lib-test.log for details of the Angular CLI output
127"""
128
129genrule(
130 name = "_gui2-topo-lib-test-genrule",
131 srcs = [
132 "@nodejs//:bin/npm",
133 "@nodejs//:bin/node",
134 "@nodejs//:bin/nodejs/bin/node",
135 "@nodejs//:bin/nodejs/bin/npm",
136 "//web/gui2-fw-lib:onos-gui2-fw-npm-install",
137 "//web/gui2-fw-lib:onos-gui2-fw-ng-build",
138 "//web/gui2-fw-lib:gui2_fw_lib_ext_css",
139 ":_root_level_files",
140 ":_gui2_topo_lib_src",
141 ":_gui2_topo_lib_src_tests",
142 ],
143 outs = [
144 "gui2-topo-lib-ver.log",
145 "gui2-topo-lib-lint.log",
146 "gui2-topo-lib-test.log",
147 ],
148 cmd = " ROOT=`pwd` &&" +
149 " export HOME=. &&" +
150 " export XDG_CONFIG_HOME=$(@D)/config &&" +
151 " NODE=$(location @nodejs//:bin/node) &&" +
152 " INSTALL_FILES=($(locations //web/gui2-fw-lib:onos-gui2-fw-npm-install)) &&" + # An array of filenames - sorted by time created
153 " FWLIB_FILES=($(locations //web/gui2-fw-lib:onos-gui2-fw-ng-build)) &&" + # An array of filenames - sorted by time created
154 " mkdir -p web/gui2-topo-lib &&" +
155 " cd web/gui2-topo-lib &&" +
156 " jar xf ../../$(location :_gui2_topo_lib_src_tests) &&" +
157 " jar xf $$ROOT/$${INSTALL_FILES[0]} &&" +
158 " tar xf $$ROOT/$${FWLIB_FILES[0]} &&" +
159 " mv package/ node_modules/gui2-fw-lib/ &&" +
160 " mkdir -p projects/gui2-topo-lib/fw &&" +
161 " (cd projects/gui2-topo-lib/fw &&" +
162 " jar xf $$ROOT/$(location //web/gui2-fw-lib:gui2_fw_lib_ext_css)) &&" +
163 " chmod +x $$ROOT/web/gui2-topo-lib/node_modules/@angular/cli/bin/ng &&" +
164 " export PATH=$$ROOT/$$(dirname $${NODE}):node_modules/@angular/cli/bin:$$PATH &&" +
165 " node -v > ../../$(location gui2-topo-lib-ver.log) &&" +
166 " npm -v >> ../../$(location gui2-topo-lib-ver.log) &&" +
167 " ng version >> ../../$(location gui2-topo-lib-ver.log) &&" +
168 " ng lint gui2-topo-lib > ../../$(location gui2-topo-lib-lint.log) 2>&1 ||" +
169 " if [ $$? -eq 0 ]; then echo 'Successfully ran lint';" +
170 " else " +
171 " echo 'Error running \'ng lint\' on \'//web/gui2-topo-lib:_gui2-topo-lib-test-genrule\'. \\\n" +
172 " See bazel-genfiles/web/gui2-topo-lib/gui2-topo-lib-lint.log for more details' >&2;" +
173 " exit 1;" +
174 " fi;" +
175 " if [ -f /usr/bin/chromium-browser ]; then " + # Add to this for Mac and Chrome
176 " export CHROME_BIN=/usr/bin/chromium-browser; " +
177 " elif [ -f /opt/google/chrome/chrome ]; then " +
178 " export CHROME_BIN=/opt/google/chrome/chrome; " +
179 " else " +
180 " MSG='Warning: Step gui2-topo-lib-tests skipped because \\n" +
181 " no binary for ChromeHeadless browser was found at /usr/bin/chromium-browser. \\n" +
182 " Install Google Chrome or Chromium Browser to allow this step to run.';" +
183 " echo -e $$MSG >&2;" +
184 " echo -e $$MSG > ../../$(location gui2-topo-lib-test.log);" +
185 " exit 0;" +
186 " fi;" +
187 " ng test gui2-topo-lib --preserve-symlinks --code-coverage --browsers=ChromeHeadless" +
188 " --watch=false > ../../$(location gui2-topo-lib-test.log) 2>&1 ||" +
189 " if [ $$? -eq 0 ]; then echo 'Successfully ran tests';" +
190 " else " +
191 " echo 'Error running \'ng test gui2-topo-lib\' on \'//web/gui2-topo-lib:_gui2-topo-lib-test-genrule\'. \\\n" +
192 " See bazel-genfiles/web/gui2-topo-lib/gui2-topo-lib-test.log for more details' >&2;" +
193 " exit 1;" +
194 " fi;",
195 message = "Angular Topo GUI2 Lib lint and test",
196)
197
198"""
199 Make a group of all the webapp files.
200"""
201
202filegroup(
203 name = "_gui2_topo_lib_src",
204 srcs = glob(
205 [
206 "projects/gui2-topo-lib/**/*",
Sean Condon4b7818d2019-05-23 07:45:14 +0100207 "README.md",
208 "LICENSE",
Sean Condonff85fbe2019-03-16 14:28:46 +0000209 ],
210 exclude = [
211 "projects/gui2-topo-lib/**/*.spec.*", # Don't track tests here
212 "projects/gui2-topo-lib/karma.conf.js",
213 "projects/gui2-topo-lib/src/test.ts",
214 "projects/gui2-topo-lib/fw/**/*",
215 ],
216 ),
217)
218
219"""
220 Make a group of all the webapp qpp files.
221"""
222
223filegroup(
224 name = "_gui2_topo_tester_files",
225 srcs = glob(
226 [
227 "src/**/*",
228 ],
229 ),
230)
231
232"""
233 Make a jar file of all the webapp test (*.spec.ts) files.
234"""
235
236genrule(
237 name = "_gui2_topo_lib_src_tests",
238 srcs = glob(
239 [
240 "projects/gui2-topo-lib/karma.conf.js",
241 "projects/gui2-topo-lib/src/test.ts",
242 "projects/gui2-topo-lib/tsconfig.spec.json",
243 "projects/gui2-topo-lib/**/*.spec.ts",
244 ],
245 exclude = [
246 "projects/gui2-topo-lib/ng-package.json",
247 "projects/gui2-topo-lib/ng-package.prod.json",
248 "projects/gui2-topo-lib/package.json",
249 "projects/gui2-topo-lib/tsconfig.lib.json",
250 "projects/gui2-topo-lib/tslint.json",
251 "projects/gui2-topo-lib/src/public_api.ts",
252 ],
253 ),
254 outs = ["gui2_topo_lib_src_tests.jar"],
255 cmd = "cd web/gui2-topo-lib &&" +
256 " jar Mcf ../../$@ .",
257)
258
259"""
260 Make a jar file of all the webapp test (*.spec.ts) files.
261"""
262
263genrule(
264 name = "_gui2_topo_lib_tests",
265 srcs = glob(
266 [
267 "projects/gui2-topo-lib/**/*.spec.ts",
268 "projects/gui2-topo-lib/**/*.spec.json",
269 ],
270 exclude = [
271 "src/main/webapp/tests/**",
272 "src/main/webapp/node_modules/**",
273 "src/main/webapp/dist/**",
274 "src/main/webapp/doc/**",
275 ],
276 ),
277 outs = ["gui2_topo_lib_tests.jar"],
278 cmd = "cd web/gui2-topo-lib &&" +
279 " find projects/gui2-topo-lib/src/lib -type f -exec touch -t 201808280000 {} \; &&" +
280 " jar Mcf ../../$@ projects/gui2-topo-lib/src/lib",
281)
282
283"""
284 Wrap the genrule for testing in a test
285"""
286
287sh_test(
288 name = "gui2-topo-lib-tests",
289 size = "small",
290 srcs = [
291 ":ng-test.sh",
292 ],
293 data = [
294 ":_gui2-topo-lib-test-genrule",
295 ],
296 deps = [
297 "@bazel_tools//tools/bash/runfiles",
298 ],
299)