blob: 4569b968e76c40558460483ab97cc29571fec952 [file] [log] [blame]
Boyuan Yan6b23b382019-06-04 11:59:35 -07001"""
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 roadm 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
Boyuan Yan6b23b382019-06-04 11:59:35 -070025COMPILE_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 roadm GUI 2 library in production mode
69 The output file roadm-gui-lib-ver.tgz is in the form that can be uploaded directly to https://www.npmjs.com/
70 See bazel-genfiles/apps/roadm/web/roadm-gui/roadm-gui-lib.log for details of the Angular CLI output
71"""
72
73genrule(
74 name = "roadm-gui-lib-build",
75 srcs = [
76 "@nodejs//:bin/npm",
Boyuan Yan6b23b382019-06-04 11:59:35 -070077 "@nodejs//:bin/nodejs/bin/node",
Boyuan Yan6b23b382019-06-04 11:59:35 -070078 "//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 ":_roadm_lib_src",
83 ":_roadm_tester_files",
84 ],
85 outs = [
86 "roadm-gui-lib.log",
87 "roadm-gui-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) &&" +
Boyuan Yan6b23b382019-06-04 11:59:35 -070093 " 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/roadm/web/roadm-gui &&" +
96 " cd apps/roadm/web/roadm-gui &&" +
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/roadm-gui-lib/fw &&" +
101 " (cd projects/roadm-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 &&" +
104 " export PATH=$$ROOT/$$(dirname $${NODE}):$$ROOT/apps/roadm/web/roadm-gui/node_modules/@angular/cli/bin:$$PATH &&" +
105 " ng build roadm-gui-lib >> $$ROOT/$(location roadm-gui-lib.log) 2>&1 ||" +
106 " if [ $$? -eq 0 ]; then echo 'Successfully ran build';" +
107 " else " +
108 " echo 'Error running \'ng build roadm-gui-lib\' on \'//apps/roadm/web/roadm-gui:roadm-gui-lib-build\'. \\\n" +
109 " See bazel-genfiles/apps/roadm/web/roadm-gui/roadm-gui-lib.log for more details' >&2;" +
110 #" tail -n 100 ../../../../$(location onos-gui2-ng-test.log) >&2;" +
111 " exit 1;" +
112 " fi;" +
113 " cp README.md LICENSE dist/roadm-gui-lib && " +
Sean Condon0a884ad2019-10-28 17:57:21 +0000114 " $$ROOT/$(location @nodejs//:bin/npm) pack ./dist/roadm-gui-lib >> $$ROOT/$(location roadm-gui-lib.log) 2>&1 &&" +
Boyuan Yan6b23b382019-06-04 11:59:35 -0700115 " mv roadm-gui-lib-*.tgz $$ROOT/$(location roadm-gui-lib-ver.tgz) &&" +
116 " touch $$ROOT/$(location roadm-gui-lib.log)", # to get the log always as the 2nd file,
117 message = "Angular roadm Lib 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/roadm/web/roadm-gui/roadm-gui-lib-lint.log or
124 bazel-genfiles/apps/roadm/web/roadm-gui/roadm-gui-lib-test.log for details of the Angular CLI output
125"""
126
127genrule(
128 name = "_roadm-gui-lib-test-genrule",
129 srcs = [
130 "@nodejs//:bin/npm",
Boyuan Yan6b23b382019-06-04 11:59:35 -0700131 "@nodejs//:bin/nodejs/bin/node",
Boyuan Yan6b23b382019-06-04 11:59:35 -0700132 "//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 ":_roadm_lib_src",
137 ":_roadm_lib_src_tests",
138 ],
139 outs = [
140 "roadm-gui-lib-ver.log",
141 "roadm-gui-lib-lint.log",
142 "roadm-gui-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) &&" +
Boyuan Yan6b23b382019-06-04 11:59:35 -0700148 " 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/roadm/web/roadm-gui &&" +
151 " cd apps/roadm/web/roadm-gui &&" +
152 " jar xf ../../../../$(location :_roadm_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/roadm-gui-lib/fw &&" +
157 " (cd projects/roadm-gui-lib/fw &&" +
158 " jar xf $$ROOT/$(location //web/gui2-fw-lib:gui2_fw_lib_ext_css)) &&" +
159 " chmod +x $$ROOT/apps/roadm/web/roadm-gui/node_modules/@angular/cli/bin/ng &&" +
160 " export PATH=$$ROOT/$$(dirname $${NODE}):node_modules/@angular/cli/bin:$$PATH &&" +
161 " node -v > ../../../../$(location roadm-gui-lib-ver.log) &&" +
Sean Condon0a884ad2019-10-28 17:57:21 +0000162 " $$ROOT/$(location @nodejs//:bin/npm) -v >> ../../../../$(location roadm-gui-lib-ver.log) &&" +
Boyuan Yan6b23b382019-06-04 11:59:35 -0700163 " ng version >> ../../../../$(location roadm-gui-lib-ver.log) &&" +
164 " ng lint roadm-gui-lib > ../../../../$(location roadm-gui-lib-lint.log) 2>&1 ||" +
165 " if [ $$? -eq 0 ]; then echo 'Successfully ran lint';" +
166 " else " +
167 " echo 'Error running \'ng lint\' on \'//apps/roadm/web/roadm-gui:_roadm-gui-lib-test-genrule\'. \\\n" +
168 " See bazel-genfiles/apps/roadm/web/roadm-gui/roadm-gui-lib-lint.log for more details' >&2;" +
169 " exit 1;" +
170 " fi;" +
171 " echo -e 'Skipping unit tests temporarily for roadm-gui-lib' > ../../../../$(location roadm-gui-lib-test.log);",
172 message = "Angular Roadm Lib lint and test",
173)
174
175"""
176 Make a group of all the webapp files.
177"""
178
179filegroup(
180 name = "_roadm_lib_src",
181 srcs = glob(
182 [
183 "projects/roadm-gui-lib/**/*",
184 "README.md",
185 "LICENSE",
186 ],
187 exclude = [
188 "projects/roadm-gui-lib/**/*.spec.*", # Don't track tests here
189 "projects/roadm-gui-lib/karma.conf.js",
190 "projects/roadm-gui-lib/src/test.ts",
191 "projects/roadm-gui-lib/fw/**/*",
192 ],
193 ),
194)
195
196"""
197 Make a group of all the webapp qpp files.
198"""
199
200filegroup(
201 name = "_roadm_tester_files",
202 srcs = glob(
203 [
204 "src/**/*",
205 ],
206 ),
207)
208
209"""
210 Make a jar file of all the webapp test (*.spec.ts) files.
211"""
212
213genrule(
214 name = "_roadm_lib_src_tests",
215 srcs = glob(
216 [
217 "projects/roadm-gui-lib/karma.conf.js",
218 "projects/roadm-gui-lib/src/test.ts",
219 "projects/roadm-gui-lib/tsconfig.spec.json",
220 "projects/roadm-gui-lib/**/*.spec.ts",
221 ],
222 exclude = [
223 "projects/roadm-gui-lib/ng-package.json",
224 "projects/roadm-gui-lib/ng-package.prod.json",
225 "projects/roadm-gui-lib/package.json",
226 "projects/roadm-gui-lib/tsconfig.lib.json",
227 "projects/roadm-gui-lib/tslint.json",
228 "projects/roadm-gui-lib/src/public_api.ts",
229 ],
230 ),
231 outs = ["roadm_gui_lib_src_tests.jar"],
232 cmd = "cd apps/roadm/web/roadm-gui &&" +
233 " jar Mcf ../../../../$@ .",
234)
235
236"""
237 Make a jar file of all the webapp test (*.spec.ts) files.
238"""
239
240genrule(
241 name = "_roadm_gui_lib_tests",
242 srcs = glob(
243 [
244 "projects/roadm-gui-lib/**/*.spec.ts",
245 "projects/roadm-gui-lib/**/*.spec.json",
246 ],
247 exclude = [
248 "src/main/webapp/tests/**",
249 "src/main/webapp/node_modules/**",
250 "src/main/webapp/dist/**",
251 "src/main/webapp/doc/**",
252 ],
253 ),
254 outs = ["roadm_gui_lib_tests.jar"],
255 cmd = "cd apps/roadm/web/roadm-gui &&" +
256 " find projects/roadm-gui-lib/src/lib -type f -exec touch -t 201808280000 {} \; &&" +
257 " jar Mcf ../../../../$@ projects/roadm-gui-lib/src/lib",
258)
259
260"""
261 Wrap the genrule for testing in a test
262"""
263
264sh_test(
265 name = "roadm-gui-lib-tests",
266 size = "small",
267 srcs = [
268 ":ng-test.sh",
269 ],
270 data = [
271 ":_roadm-gui-lib-test-genrule",
272 ],
273 deps = [
274 "@bazel_tools//tools/bash/runfiles",
275 ],
276)