blob: de0c531f1ddcd2cd4a5b2f71ef606b0aef342dc9 [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/
Sean Condon53d4e832019-10-25 12:27:54 +010070 See bazel-out/k8-fastbuild/bin/web/gui2-topo-lib/gui2-topo-lib.log for details of the Angular CLI output
Sean Condonff85fbe2019-03-16 14:28:46 +000071"""
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" +
Sean Condon53d4e832019-10-25 12:27:54 +0100111 " See bazel-out/k8-fastbuild/bin/web/gui2-topo-lib/gui2-topo-lib.log for more details' >&2;" +
Sean Condonff85fbe2019-03-16 14:28:46 +0000112 #" 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
Sean Condon53d4e832019-10-25 12:27:54 +0100125 See bazel-out/k8-fastbuild/bin/web/gui2-topo-lib/gui2-topo-lib-lint.log or
126 bazel-out/k8-fastbuild/bin/web/gui2-topo-lib/gui2-topo-lib-test.log for details of the Angular CLI output
Sean Condonff85fbe2019-03-16 14:28:46 +0000127"""
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" +
Sean Condon53d4e832019-10-25 12:27:54 +0100172 " See bazel-out/k8-fastbuild/bin/web/gui2-topo-lib/gui2-topo-lib-lint.log for more details' >&2;" +
173 " cat ../../$(location gui2-topo-lib-lint.log) >&2 ||" +
Sean Condonff85fbe2019-03-16 14:28:46 +0000174 " exit 1;" +
175 " fi;" +
176 " if [ -f /usr/bin/chromium-browser ]; then " + # Add to this for Mac and Chrome
177 " export CHROME_BIN=/usr/bin/chromium-browser; " +
178 " elif [ -f /opt/google/chrome/chrome ]; then " +
179 " export CHROME_BIN=/opt/google/chrome/chrome; " +
180 " else " +
181 " MSG='Warning: Step gui2-topo-lib-tests skipped because \\n" +
182 " no binary for ChromeHeadless browser was found at /usr/bin/chromium-browser. \\n" +
183 " Install Google Chrome or Chromium Browser to allow this step to run.';" +
184 " echo -e $$MSG >&2;" +
185 " echo -e $$MSG > ../../$(location gui2-topo-lib-test.log);" +
186 " exit 0;" +
187 " fi;" +
188 " ng test gui2-topo-lib --preserve-symlinks --code-coverage --browsers=ChromeHeadless" +
189 " --watch=false > ../../$(location gui2-topo-lib-test.log) 2>&1 ||" +
190 " if [ $$? -eq 0 ]; then echo 'Successfully ran tests';" +
191 " else " +
192 " echo 'Error running \'ng test gui2-topo-lib\' on \'//web/gui2-topo-lib:_gui2-topo-lib-test-genrule\'. \\\n" +
Sean Condon53d4e832019-10-25 12:27:54 +0100193 " See bazel-out/k8-fastbuild/bin/web/gui2-topo-lib/gui2-topo-lib-test.log for more details' >&2;" +
Sean Condonff85fbe2019-03-16 14:28:46 +0000194 " exit 1;" +
195 " fi;",
196 message = "Angular Topo GUI2 Lib lint and test",
197)
198
199"""
200 Make a group of all the webapp files.
201"""
202
203filegroup(
204 name = "_gui2_topo_lib_src",
205 srcs = glob(
206 [
207 "projects/gui2-topo-lib/**/*",
Sean Condon4b7818d2019-05-23 07:45:14 +0100208 "README.md",
209 "LICENSE",
Sean Condonff85fbe2019-03-16 14:28:46 +0000210 ],
211 exclude = [
212 "projects/gui2-topo-lib/**/*.spec.*", # Don't track tests here
213 "projects/gui2-topo-lib/karma.conf.js",
214 "projects/gui2-topo-lib/src/test.ts",
215 "projects/gui2-topo-lib/fw/**/*",
216 ],
217 ),
218)
219
220"""
221 Make a group of all the webapp qpp files.
222"""
223
224filegroup(
225 name = "_gui2_topo_tester_files",
226 srcs = glob(
227 [
228 "src/**/*",
229 ],
230 ),
231)
232
233"""
234 Make a jar file of all the webapp test (*.spec.ts) files.
235"""
236
237genrule(
238 name = "_gui2_topo_lib_src_tests",
239 srcs = glob(
240 [
241 "projects/gui2-topo-lib/karma.conf.js",
242 "projects/gui2-topo-lib/src/test.ts",
243 "projects/gui2-topo-lib/tsconfig.spec.json",
244 "projects/gui2-topo-lib/**/*.spec.ts",
245 ],
246 exclude = [
247 "projects/gui2-topo-lib/ng-package.json",
248 "projects/gui2-topo-lib/ng-package.prod.json",
249 "projects/gui2-topo-lib/package.json",
250 "projects/gui2-topo-lib/tsconfig.lib.json",
251 "projects/gui2-topo-lib/tslint.json",
252 "projects/gui2-topo-lib/src/public_api.ts",
253 ],
254 ),
255 outs = ["gui2_topo_lib_src_tests.jar"],
256 cmd = "cd web/gui2-topo-lib &&" +
257 " jar Mcf ../../$@ .",
258)
259
260"""
261 Make a jar file of all the webapp test (*.spec.ts) files.
262"""
263
264genrule(
265 name = "_gui2_topo_lib_tests",
266 srcs = glob(
267 [
268 "projects/gui2-topo-lib/**/*.spec.ts",
269 "projects/gui2-topo-lib/**/*.spec.json",
270 ],
271 exclude = [
272 "src/main/webapp/tests/**",
273 "src/main/webapp/node_modules/**",
274 "src/main/webapp/dist/**",
275 "src/main/webapp/doc/**",
276 ],
277 ),
278 outs = ["gui2_topo_lib_tests.jar"],
279 cmd = "cd web/gui2-topo-lib &&" +
280 " find projects/gui2-topo-lib/src/lib -type f -exec touch -t 201808280000 {} \; &&" +
281 " jar Mcf ../../$@ projects/gui2-topo-lib/src/lib",
282)
283
284"""
285 Wrap the genrule for testing in a test
286"""
287
288sh_test(
289 name = "gui2-topo-lib-tests",
290 size = "small",
291 srcs = [
292 ":ng-test.sh",
293 ],
294 data = [
295 ":_gui2-topo-lib-test-genrule",
296 ],
297 deps = [
298 "@bazel_tools//tools/bash/runfiles",
299 ],
300)