blob: 31c83e14a0116bd4ededceed19f02514f1533de6 [file] [log] [blame]
Ray Milkeyd7be3622018-07-12 10:29:21 -07001"""
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 ONOS GUI
19
20 Bazel and npm are incompatibe in how they deal with files. npm likes to follow links
21 to get back to the original canonical path names, and bazel uses links extensively when
22 populating the sandbox. To get around these problems, the rules that follow use filegroups
23 to specify the files as dependencies and then use a genrule to convert the files into a tar
24 ball. Once the tar ball is unrolled into the sandbox, the links are broken, but the build is
25 still hermetic since those files are referred to as dependencies in the genrule.
26
27 Also note that the onos-gui.tar contains files from //tools/gui and //web/gui, so the files are placed into
28 the sandbox at the proper locations and then returned as a tar ball.
29"""
Ray Milkey6b3775a2018-06-28 11:18:44 -070030
Ray Milkey86ad7bb2018-09-27 12:32:28 -070031COMPILE_DEPS = CORE_DEPS + JACKSON + KRYO + CLI + [
Ray Milkey6b3775a2018-06-28 11:18:44 -070032 "@javax_ws_rs_api//jar",
33 "@servlet_api//jar",
34 "@jetty_websocket//jar",
Ray Milkeyd84f89b2018-08-17 14:54:17 -070035 "@jetty_websocket_api//jar",
Ray Milkey6b3775a2018-06-28 11:18:44 -070036 "@jetty_util//jar",
37 "@jersey_media_multipart//jar",
Ray Milkey6b3775a2018-06-28 11:18:44 -070038 "@jersey_server//jar",
Ray Milkey427e9752018-11-15 16:34:48 -080039 "@jersey_hk2//jar",
Ray Milkey6b3775a2018-06-28 11:18:44 -070040 "//utils/rest:onlab-rest",
41 "//core/store/serializers:onos-core-serializers",
42]
43
44TEST_DEPS = TEST + [
45 "//core/api:onos-api-tests",
46 "//drivers/default:onos-drivers-default",
47]
48
Ray Milkeyd7be3622018-07-12 10:29:21 -070049"""
50 Files that get put at the top level of the tar ball
51"""
Ray Milkey6b3775a2018-06-28 11:18:44 -070052
53filegroup(
54 name = "_root_level_files",
55 srcs =
56 [
57 ":src/main/webapp/bower.json",
58 ":src/main/webapp/bs-config.js",
59 ":src/main/webapp/dev_server.js",
60 ":src/main/webapp/package.json",
61 ],
62)
63
Ray Milkeyd7be3622018-07-12 10:29:21 -070064"""
65 Files that get put into the WEB-INF directory of the tar ball
66"""
67
Ray Milkey6b3775a2018-06-28 11:18:44 -070068filegroup(
69 name = "_web_inf_classes_files",
70 srcs =
71 [
72 ":src/main/webapp/error.html",
73 ":src/main/webapp/index.html",
74 ":src/main/webapp/login.html",
75 ":src/main/webapp/nav.html",
76 ":src/main/webapp/not-ready.html",
77 ":src/main/webapp/onos.js",
78 ],
79)
80
Ray Milkeyd7be3622018-07-12 10:29:21 -070081"""
82 webapp raw files
83"""
84
Ray Milkey6b3775a2018-06-28 11:18:44 -070085filegroup(
86 name = "_raw_classes_files",
87 srcs = glob(["src/main/webapp/raw/**"]),
88)
89
Ray Milkeyd7be3622018-07-12 10:29:21 -070090"""
Ray Milkeyd7be3622018-07-12 10:29:21 -070091 Install node.js and npm, and gather files needed from //tools/gui
92"""
93
94genrule(
95 name = "_onos-gui-npm-install",
96 srcs = [
97 "@nodejs//:bin/npm",
Sean Condonf6af2a52018-08-19 10:43:24 +010098 "@nodejs//:bin/node",
Sean Condonf6af2a52018-08-19 10:43:24 +010099 "@nodejs//:bin/nodejs/bin/node",
100 "@nodejs//:bin/nodejs/bin/npm",
Ray Milkeyd7be3622018-07-12 10:29:21 -0700101 "//tools/gui:tools-gui-gulp",
Thomas Vachuska34328622018-08-03 09:21:17 -0700102 ],
103 outs = ["onos-gui-npm-install.jar"],
Ray Milkeyd7be3622018-07-12 10:29:21 -0700104 cmd = " ROOT=`pwd` &&" +
Thomas Vachuska06206132018-08-06 16:43:43 -0700105 " export HOME=. &&" +
Ray Milkeyd7be3622018-07-12 10:29:21 -0700106 " export XDG_CONFIG_HOME=$(@D)/config &&" + # npm config cache to the sandbos
Ray Milkeycc9620a2018-07-31 14:22:40 -0700107 " export BABEL_DISABLE_CACHE=1 &&" + # turn off babel cache
Thomas Vachuska277ec4e2018-08-29 17:59:47 +0000108 ' if [[ ! -z $${HTTP_PROXY-} ]]; then NPM_ARGS="--proxy $$HTTP_PROXY --without-ssl --insecure"; else NPM_ARGS=""; fi &&' +
Ray Milkeyd7be3622018-07-12 10:29:21 -0700109 " NPM=$$ROOT/$(location @nodejs//:bin/npm) &&" +
110 " mkdir -p tools/gui &&" +
111 " cd tools/gui &&" +
Thomas Vachuska34328622018-08-03 09:21:17 -0700112 " jar xf ../../$(location //tools/gui:tools-gui-gulp) &&" +
Ray Milkey61289c12018-08-27 17:09:25 -0700113 " $$NPM $$NPM_ARGS install --no-cache --loglevel=error >npm-install.out 2>&1 &&" +
Thomas Vachuska34328622018-08-03 09:21:17 -0700114 " find . -name package.json | while read pjson; do egrep -v '/execroot/' $$pjson > ptmp; mv ptmp $$pjson; done &&" +
115 " find package.json gulpfile.babel.js node_modules gulp-tasks -type f -exec touch -t 201806280000 {} \; &&" +
116 " jar Mcf $$ROOT/$@ package.json gulpfile.babel.js node_modules gulp-tasks",
Ray Milkeyd7be3622018-07-12 10:29:21 -0700117)
118
119"""
120 Run npm build to create node.js files
121"""
122
123genrule(
124 name = "_onos-gui-npm-build",
125 srcs = [
126 "@nodejs//:bin/npm",
Sean Condonf6af2a52018-08-19 10:43:24 +0100127 "@nodejs//:bin/node",
Sean Condonf6af2a52018-08-19 10:43:24 +0100128 "@nodejs//:bin/nodejs/bin/node",
129 "@nodejs//:bin/nodejs/bin/npm",
Ray Milkeyd7be3622018-07-12 10:29:21 -0700130 ":_onos-gui-npm-install",
131 ":_web_app_all",
132 ],
Thomas Vachuska34328622018-08-03 09:21:17 -0700133 outs = ["onos-gui-npm-build.jar"],
Ray Milkeyd7be3622018-07-12 10:29:21 -0700134 cmd = "(ROOT=`pwd` &&" +
Thomas Vachuska06206132018-08-06 16:43:43 -0700135 " export HOME=. &&" +
Ray Milkeyd7be3622018-07-12 10:29:21 -0700136 " export XDG_CONFIG_HOME=$(@D)/config &&" +
Ray Milkey61289c12018-08-27 17:09:25 -0700137 " export BABEL_DISABLE_CACHE=1 &&" +
138 ' if [[ ! -z $${HTTP_PROXY-} ]]; then NPM_ARGS="--proxy $$HTTP_PROXY --without-ssl --insecure"; else NPM_ARGS=""; fi &&' +
Ray Milkeyd7be3622018-07-12 10:29:21 -0700139 " NPM=$(location @nodejs//:bin/npm) &&" +
Thomas Vachuska34328622018-08-03 09:21:17 -0700140 " (mkdir -p web/gui && cd web/gui && jar xf ../../$(location :_web_app_all)) &&" +
Ray Milkeyd7be3622018-07-12 10:29:21 -0700141 " mkdir -p tools/gui && cd tools/gui &&" +
Thomas Vachuska34328622018-08-03 09:21:17 -0700142 " jar xf $$ROOT/$(location :_onos-gui-npm-install) &&" +
143 " chmod a+x ./node_modules/gulp/bin/gulp.js &&" +
Ray Milkey61289c12018-08-27 17:09:25 -0700144 " $$ROOT/$$NPM $$NPM_ARGS run build --no-cache --loglevel=error >npm-build.out &&" +
Ray Milkeyd7be3622018-07-12 10:29:21 -0700145 " cd ../../web/gui/src/main/webapp &&" +
Thomas Vachuska34328622018-08-03 09:21:17 -0700146 " find dist vendor data README.md _doc _dev app/fw app/*.css app/*.js app/*.txt -type f -exec touch -t 201806280000 {} \; &&" +
147 " jar Mcf $$ROOT/$@ dist vendor data README.md _doc _dev app/fw app/*.css app/*.js app/*.txt)",
Ray Milkeyd7be3622018-07-12 10:29:21 -0700148)
149
150"""
151 Make a jar file of all the webapp files. Useful for breaking symblic links in the sandbox
152"""
153
154genrule(
155 name = "_web_app_all",
Jian Lid486a732018-08-03 00:32:11 +0900156 srcs = glob(
157 [
158 "src/main/webapp/**",
159 "src/main/webapp/app/**/*.js",
160 ],
161 exclude = [
162 "src/main/webapp/tests/**",
163 "src/main/webapp/node_modules/**",
164 "src/main/webapp/dist/**",
165 "src/main/webapp/vendor/**",
166 "src/main/webapp/npm-debug.log",
167 ],
168 ),
Thomas Vachuska34328622018-08-03 09:21:17 -0700169 outs = ["web_app_all.jar"],
170 cmd = "cd web/gui &&" +
171 " find src/main/webapp -type f -exec touch -t 201806280000 {} \; &&" +
172 " jar Mcf ../../$@ src/main/webapp",
Ray Milkeyd7be3622018-07-12 10:29:21 -0700173)
174
175"""
176 app/view is packaged as a tar file because it has subdirectories that need to be preserved
177"""
178
Ray Milkey6b3775a2018-06-28 11:18:44 -0700179genrule(
180 name = "_app_view_tar",
181 srcs = glob(["src/main/webapp/app/view/**"]),
Thomas Vachuska34328622018-08-03 09:21:17 -0700182 outs = ["app_view_tar.jar"],
Ray Milkey6b3775a2018-06-28 11:18:44 -0700183 cmd = " ROOT=`pwd` &&" +
184 " cd web/gui/src/main/webapp/app/view &&" +
Thomas Vachuska34328622018-08-03 09:21:17 -0700185 " find . -type f -exec touch -t 201806280000 {} \; &&" +
186 " jar Mcf $$ROOT/$@ .",
Ray Milkey6b3775a2018-06-28 11:18:44 -0700187)
188
Ray Milkeyd7be3622018-07-12 10:29:21 -0700189"""
190 Builds the java jar for the java code provided by the GUI
191"""
192
193osgi_jar_with_tests(
Thomas Vachuska2bd1fc82018-10-22 13:09:14 -0700194 name = "onos-gui-jar",
Ray Milkeyd7be3622018-07-12 10:29:21 -0700195 exclude_tests = [
196 "org.onosproject.ui.impl.AbstractUiImplTest",
197 "org.onosproject.ui.impl.topo.model.AbstractTopoModelTest",
198 ],
Ray Milkey8753ede2018-10-12 09:08:35 -0700199 karaf_command_packages = [
200 "org.onosproject.ui.impl.cli",
201 "org.onosproject.ui.impl.topo",
202 ],
Ray Milkeyd7be3622018-07-12 10:29:21 -0700203 test_deps = TEST_DEPS,
204 web_context = "/onos/ui",
205 deps = COMPILE_DEPS,
206)
207
Sean Condon3c8e5582018-08-28 23:22:43 +0100208genrule(
209 name = "onos-gui-java-for-gui2",
210 srcs = glob([
Sean Condonb2c483c2019-01-16 20:28:55 +0000211 "src/main/java/org/onosproject/ui/impl/**/*.java",
Sean Condon3c8e5582018-08-28 23:22:43 +0100212 ]),
213 outs = ["onos-gui-java-for-gui2.srcjar"],
214 cmd = "jar cf $@ $(SRCS)",
215 visibility = ["//visibility:public"],
216)
217
Sean Condonb2c483c2019-01-16 20:28:55 +0000218genrule(
219 name = "onos-gui-lion-for-gui2",
220 srcs = glob([
221 "src/main/resources/org/onosproject/ui/lion/**/*",
222 "src/main/resources/core/**/*",
223 ]),
224 outs = ["onos-gui-lion-for-gui2.srcjar"],
225 cmd = "jar cf $@ $(SRCS)",
226 visibility = ["//visibility:public"],
227)
228
Sean Condon0d064ec2019-02-04 21:53:53 +0000229genrule(
230 name = "onos-gui-data-for-gui2",
231 srcs = glob([
232 "src/main/webapp/data/**/*",
233 ]),
234 outs = ["onos-gui-data-for-gui2.srcjar"],
235 cmd = "jar cf $@ $(SRCS)",
236 visibility = ["//visibility:public"],
237)
238
Ray Milkeyd7be3622018-07-12 10:29:21 -0700239"""
240 Builds the tar ball for the ONOS GUI
241"""
242
Ray Milkey6b3775a2018-06-28 11:18:44 -0700243genrule(
Sean Condonbf7ff4f2019-03-17 16:18:42 +0000244 name = "onos-web-gui",
Ray Milkey6b3775a2018-06-28 11:18:44 -0700245 srcs = [
246 ":_onos-gui-npm-build",
Thomas Vachuska2bd1fc82018-10-22 13:09:14 -0700247 ":onos-gui-jar",
Ray Milkey6b3775a2018-06-28 11:18:44 -0700248 ":_root_level_files",
249 ":_web_inf_classes_files",
250 ":_raw_classes_files",
251 ":_app_view_tar",
252 ],
253 outs = ["onos-gui.jar"],
254 cmd = " ROOT=`pwd` &&" +
255 " mkdir -p gui/WEB-INF/classes &&" +
256 " cd gui &&" +
Thomas Vachuska34328622018-08-03 09:21:17 -0700257 " jar xf $$ROOT/$(location :_onos-gui-npm-build) &&" +
258 " (cd WEB-INF/classes && mkdir -p app/view && cd app/view && jar xf $$ROOT/$(location :_app_view_tar)) &&" +
Ray Milkey6b3775a2018-06-28 11:18:44 -0700259 " for i in $(locations :_root_level_files); do cp $$ROOT/$$i .; done &&" +
260 " for i in $(locations :_web_inf_classes_files); do cp $$ROOT/$$i ./WEB-INF/classes/; done &&" +
Ray Milkeyd7be3622018-07-12 10:29:21 -0700261 " mkdir ./WEB-INF/classes/raw && " +
262 " for i in $(locations :_raw_classes_files); do cp $$ROOT/$$i ./WEB-INF/classes/raw/; done &&" +
Thomas Vachuska2bd1fc82018-10-22 13:09:14 -0700263 " jar xf $$ROOT/$(location :onos-gui-jar) &&" +
Thomas Vachuska34328622018-08-03 09:21:17 -0700264 " find . -type f -exec touch -t 201806280000 {} \; &&" +
Ray Milkey6b3775a2018-06-28 11:18:44 -0700265 " jar cmf META-INF/MANIFEST.MF $$ROOT/$@ .",
Ray Milkey6b3775a2018-06-28 11:18:44 -0700266 output_to_bindir = 1,
267 visibility = ["//visibility:public"],
268)
Sean Condonbf7ff4f2019-03-17 16:18:42 +0000269
270onos_app(
271 category = "Graphical User Interface",
272 description = "ONOS GUI - the original ONOS GUI based " +
273 "on the latest AngularJS - new development should be on GUI2",
274 title = "ONOS Legacy GUI",
275 url = "http://onosproject.org",
276)