blob: 57680d93478a339e48d468cf93d69585c3bcb910 [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
Carmelo Casconed33d3b42019-06-18 12:12:36 -070031load("//tools/build/bazel:jdk_genrule.bzl", genrule = "jdk_genrule")
32
Ray Milkey86ad7bb2018-09-27 12:32:28 -070033COMPILE_DEPS = CORE_DEPS + JACKSON + KRYO + CLI + [
Ray Milkey6b3775a2018-06-28 11:18:44 -070034 "@javax_ws_rs_api//jar",
35 "@servlet_api//jar",
36 "@jetty_websocket//jar",
Ray Milkeyd84f89b2018-08-17 14:54:17 -070037 "@jetty_websocket_api//jar",
Ray Milkey6b3775a2018-06-28 11:18:44 -070038 "@jetty_util//jar",
39 "@jersey_media_multipart//jar",
Ray Milkey6b3775a2018-06-28 11:18:44 -070040 "@jersey_server//jar",
Ray Milkey427e9752018-11-15 16:34:48 -080041 "@jersey_hk2//jar",
Ray Milkey6b3775a2018-06-28 11:18:44 -070042 "//utils/rest:onlab-rest",
43 "//core/store/serializers:onos-core-serializers",
44]
45
46TEST_DEPS = TEST + [
47 "//core/api:onos-api-tests",
48 "//drivers/default:onos-drivers-default",
49]
50
Ray Milkeyd7be3622018-07-12 10:29:21 -070051"""
52 Files that get put at the top level of the tar ball
53"""
Ray Milkey6b3775a2018-06-28 11:18:44 -070054
55filegroup(
56 name = "_root_level_files",
57 srcs =
58 [
59 ":src/main/webapp/bower.json",
60 ":src/main/webapp/bs-config.js",
61 ":src/main/webapp/dev_server.js",
62 ":src/main/webapp/package.json",
63 ],
64)
65
Ray Milkeyd7be3622018-07-12 10:29:21 -070066"""
67 Files that get put into the WEB-INF directory of the tar ball
68"""
69
Ray Milkey6b3775a2018-06-28 11:18:44 -070070filegroup(
71 name = "_web_inf_classes_files",
72 srcs =
73 [
74 ":src/main/webapp/error.html",
75 ":src/main/webapp/index.html",
76 ":src/main/webapp/login.html",
77 ":src/main/webapp/nav.html",
78 ":src/main/webapp/not-ready.html",
79 ":src/main/webapp/onos.js",
80 ],
81)
82
Ray Milkeyd7be3622018-07-12 10:29:21 -070083"""
84 webapp raw files
85"""
86
Ray Milkey6b3775a2018-06-28 11:18:44 -070087filegroup(
88 name = "_raw_classes_files",
89 srcs = glob(["src/main/webapp/raw/**"]),
90)
91
Ray Milkeyd7be3622018-07-12 10:29:21 -070092"""
Ray Milkeyd7be3622018-07-12 10:29:21 -070093 Install node.js and npm, and gather files needed from //tools/gui
94"""
95
96genrule(
97 name = "_onos-gui-npm-install",
98 srcs = [
99 "@nodejs//:bin/npm",
Sean Condonf6af2a52018-08-19 10:43:24 +0100100 "@nodejs//:bin/nodejs/bin/node",
Sean Condon0a884ad2019-10-28 17:57:21 +0000101 "@gui1_npm//:node_modules",
Ray Milkeyd7be3622018-07-12 10:29:21 -0700102 "//tools/gui:tools-gui-gulp",
Thomas Vachuska34328622018-08-03 09:21:17 -0700103 ],
Sean Condon0a884ad2019-10-28 17:57:21 +0000104 outs = [
105 "onos-gui-npm-install.jar",
106 "onos-gui1-npm-install.log",
107 ],
Ray Milkeyd7be3622018-07-12 10:29:21 -0700108 cmd = " ROOT=`pwd` &&" +
Thomas Vachuska06206132018-08-06 16:43:43 -0700109 " export HOME=. &&" +
Ray Milkeyd7be3622018-07-12 10:29:21 -0700110 " export XDG_CONFIG_HOME=$(@D)/config &&" + # npm config cache to the sandbos
Ray Milkeycc9620a2018-07-31 14:22:40 -0700111 " export BABEL_DISABLE_CACHE=1 &&" + # turn off babel cache
Thomas Vachuska277ec4e2018-08-29 17:59:47 +0000112 ' if [[ ! -z $${HTTP_PROXY-} ]]; then NPM_ARGS="--proxy $$HTTP_PROXY --without-ssl --insecure"; else NPM_ARGS=""; fi &&' +
Ray Milkeyd7be3622018-07-12 10:29:21 -0700113 " NPM=$$ROOT/$(location @nodejs//:bin/npm) &&" +
114 " mkdir -p tools/gui &&" +
115 " cd tools/gui &&" +
Thomas Vachuska34328622018-08-03 09:21:17 -0700116 " jar xf ../../$(location //tools/gui:tools-gui-gulp) &&" +
Sean Condon0a884ad2019-10-28 17:57:21 +0000117 " $$NPM $$NPM_ARGS install --no-cache --loglevel=error > $$ROOT/$(location onos-gui1-npm-install.log) 2>&1 &&" +
Thomas Vachuska34328622018-08-03 09:21:17 -0700118 " find . -name package.json | while read pjson; do egrep -v '/execroot/' $$pjson > ptmp; mv ptmp $$pjson; done &&" +
119 " find package.json gulpfile.babel.js node_modules gulp-tasks -type f -exec touch -t 201806280000 {} \; &&" +
Sean Condon0a884ad2019-10-28 17:57:21 +0000120 " jar Mcf $$ROOT/$(location onos-gui-npm-install.jar) package.json gulpfile.babel.js node_modules gulp-tasks &&" +
121 " touch $$ROOT/$(location onos-gui1-npm-install.log)", # to get the log always as the 2nd file
Ray Milkeyd7be3622018-07-12 10:29:21 -0700122)
123
124"""
125 Run npm build to create node.js files
126"""
127
128genrule(
129 name = "_onos-gui-npm-build",
130 srcs = [
Sean Condon0a884ad2019-10-28 17:57:21 +0000131 "@nodejs//:npm",
Ray Milkeyd7be3622018-07-12 10:29:21 -0700132 "@nodejs//:bin/npm",
Sean Condonf6af2a52018-08-19 10:43:24 +0100133 "@nodejs//:bin/nodejs/bin/node",
Ray Milkeyd7be3622018-07-12 10:29:21 -0700134 ":_onos-gui-npm-install",
135 ":_web_app_all",
136 ],
Sean Condon0a884ad2019-10-28 17:57:21 +0000137 outs = [
138 "onos-gui-npm-build.jar",
139 "onos-gui1-npm-build.log",
140 ],
141 cmd = "ROOT=`pwd` &&" +
Thomas Vachuska06206132018-08-06 16:43:43 -0700142 " export HOME=. &&" +
Ray Milkeyd7be3622018-07-12 10:29:21 -0700143 " export XDG_CONFIG_HOME=$(@D)/config &&" +
Ray Milkey61289c12018-08-27 17:09:25 -0700144 " export BABEL_DISABLE_CACHE=1 &&" +
Sean Condon0a884ad2019-10-28 17:57:21 +0000145 " INSTALL_FILES=($(locations :_onos-gui-npm-install)) &&" + # An array of filenames - sorted by time created
Ray Milkey61289c12018-08-27 17:09:25 -0700146 ' if [[ ! -z $${HTTP_PROXY-} ]]; then NPM_ARGS="--proxy $$HTTP_PROXY --without-ssl --insecure"; else NPM_ARGS=""; fi &&' +
Ray Milkeyd7be3622018-07-12 10:29:21 -0700147 " NPM=$(location @nodejs//:bin/npm) &&" +
Thomas Vachuska34328622018-08-03 09:21:17 -0700148 " (mkdir -p web/gui && cd web/gui && jar xf ../../$(location :_web_app_all)) &&" +
Ray Milkeyd7be3622018-07-12 10:29:21 -0700149 " mkdir -p tools/gui && cd tools/gui &&" +
Sean Condon0a884ad2019-10-28 17:57:21 +0000150 " jar xf $$ROOT/$${INSTALL_FILES[0]} &&" +
Thomas Vachuska34328622018-08-03 09:21:17 -0700151 " chmod a+x ./node_modules/gulp/bin/gulp.js &&" +
Sean Condon0a884ad2019-10-28 17:57:21 +0000152 " $$ROOT/$$NPM $$NPM_ARGS run build --no-cache --loglevel=error > $$ROOT/$(location onos-gui1-npm-build.log) &&" +
Ray Milkeyd7be3622018-07-12 10:29:21 -0700153 " cd ../../web/gui/src/main/webapp &&" +
Thomas Vachuska34328622018-08-03 09:21:17 -0700154 " find dist vendor data README.md _doc _dev app/fw app/*.css app/*.js app/*.txt -type f -exec touch -t 201806280000 {} \; &&" +
Sean Condon0a884ad2019-10-28 17:57:21 +0000155 " jar Mcf $$ROOT/$(location onos-gui-npm-build.jar) dist vendor data README.md _doc _dev app/fw app/*.css app/*.js app/*.txt &&" +
156 " touch $$ROOT/$(location onos-gui1-npm-build.log)", # to get the log always as the 2nd file
Ray Milkeyd7be3622018-07-12 10:29:21 -0700157)
158
159"""
160 Make a jar file of all the webapp files. Useful for breaking symblic links in the sandbox
161"""
162
163genrule(
164 name = "_web_app_all",
Jian Lid486a732018-08-03 00:32:11 +0900165 srcs = glob(
166 [
167 "src/main/webapp/**",
168 "src/main/webapp/app/**/*.js",
169 ],
170 exclude = [
171 "src/main/webapp/tests/**",
172 "src/main/webapp/node_modules/**",
173 "src/main/webapp/dist/**",
174 "src/main/webapp/vendor/**",
175 "src/main/webapp/npm-debug.log",
176 ],
177 ),
Thomas Vachuska34328622018-08-03 09:21:17 -0700178 outs = ["web_app_all.jar"],
179 cmd = "cd web/gui &&" +
180 " find src/main/webapp -type f -exec touch -t 201806280000 {} \; &&" +
181 " jar Mcf ../../$@ src/main/webapp",
Ray Milkeyd7be3622018-07-12 10:29:21 -0700182)
183
184"""
185 app/view is packaged as a tar file because it has subdirectories that need to be preserved
186"""
187
Ray Milkey6b3775a2018-06-28 11:18:44 -0700188genrule(
189 name = "_app_view_tar",
190 srcs = glob(["src/main/webapp/app/view/**"]),
Thomas Vachuska34328622018-08-03 09:21:17 -0700191 outs = ["app_view_tar.jar"],
Ray Milkey6b3775a2018-06-28 11:18:44 -0700192 cmd = " ROOT=`pwd` &&" +
193 " cd web/gui/src/main/webapp/app/view &&" +
Thomas Vachuska34328622018-08-03 09:21:17 -0700194 " find . -type f -exec touch -t 201806280000 {} \; &&" +
195 " jar Mcf $$ROOT/$@ .",
Ray Milkey6b3775a2018-06-28 11:18:44 -0700196)
197
Ray Milkeyd7be3622018-07-12 10:29:21 -0700198"""
199 Builds the java jar for the java code provided by the GUI
200"""
201
202osgi_jar_with_tests(
Thomas Vachuska2bd1fc82018-10-22 13:09:14 -0700203 name = "onos-gui-jar",
Ray Milkeyd7be3622018-07-12 10:29:21 -0700204 exclude_tests = [
205 "org.onosproject.ui.impl.AbstractUiImplTest",
206 "org.onosproject.ui.impl.topo.model.AbstractTopoModelTest",
207 ],
Ray Milkey8753ede2018-10-12 09:08:35 -0700208 karaf_command_packages = [
209 "org.onosproject.ui.impl.cli",
210 "org.onosproject.ui.impl.topo",
211 ],
Ray Milkeyd7be3622018-07-12 10:29:21 -0700212 test_deps = TEST_DEPS,
213 web_context = "/onos/ui",
214 deps = COMPILE_DEPS,
215)
216
Sean Condon3c8e5582018-08-28 23:22:43 +0100217genrule(
218 name = "onos-gui-java-for-gui2",
219 srcs = glob([
Sean Condonb2c483c2019-01-16 20:28:55 +0000220 "src/main/java/org/onosproject/ui/impl/**/*.java",
Sean Condon3c8e5582018-08-28 23:22:43 +0100221 ]),
222 outs = ["onos-gui-java-for-gui2.srcjar"],
223 cmd = "jar cf $@ $(SRCS)",
224 visibility = ["//visibility:public"],
225)
226
Sean Condonb2c483c2019-01-16 20:28:55 +0000227genrule(
228 name = "onos-gui-lion-for-gui2",
229 srcs = glob([
230 "src/main/resources/org/onosproject/ui/lion/**/*",
231 "src/main/resources/core/**/*",
232 ]),
233 outs = ["onos-gui-lion-for-gui2.srcjar"],
234 cmd = "jar cf $@ $(SRCS)",
235 visibility = ["//visibility:public"],
236)
237
Sean Condon0d064ec2019-02-04 21:53:53 +0000238genrule(
239 name = "onos-gui-data-for-gui2",
240 srcs = glob([
241 "src/main/webapp/data/**/*",
242 ]),
243 outs = ["onos-gui-data-for-gui2.srcjar"],
244 cmd = "jar cf $@ $(SRCS)",
245 visibility = ["//visibility:public"],
246)
247
Ray Milkeyd7be3622018-07-12 10:29:21 -0700248"""
249 Builds the tar ball for the ONOS GUI
250"""
251
Ray Milkey6b3775a2018-06-28 11:18:44 -0700252genrule(
Sean Condonbf7ff4f2019-03-17 16:18:42 +0000253 name = "onos-web-gui",
Ray Milkey6b3775a2018-06-28 11:18:44 -0700254 srcs = [
255 ":_onos-gui-npm-build",
Thomas Vachuska2bd1fc82018-10-22 13:09:14 -0700256 ":onos-gui-jar",
Ray Milkey6b3775a2018-06-28 11:18:44 -0700257 ":_root_level_files",
258 ":_web_inf_classes_files",
259 ":_raw_classes_files",
260 ":_app_view_tar",
261 ],
262 outs = ["onos-gui.jar"],
263 cmd = " ROOT=`pwd` &&" +
Sean Condon0a884ad2019-10-28 17:57:21 +0000264 " BUILD_FILES=($(locations :_onos-gui-npm-build)) &&" + # An array of filenames - sorted by time created
Ray Milkey6b3775a2018-06-28 11:18:44 -0700265 " mkdir -p gui/WEB-INF/classes &&" +
266 " cd gui &&" +
Sean Condon0a884ad2019-10-28 17:57:21 +0000267 " jar xf $$ROOT/$${BUILD_FILES[0]} &&" +
Thomas Vachuska34328622018-08-03 09:21:17 -0700268 " (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 -0700269 " for i in $(locations :_root_level_files); do cp $$ROOT/$$i .; done &&" +
270 " for i in $(locations :_web_inf_classes_files); do cp $$ROOT/$$i ./WEB-INF/classes/; done &&" +
Ray Milkeyd7be3622018-07-12 10:29:21 -0700271 " mkdir ./WEB-INF/classes/raw && " +
272 " for i in $(locations :_raw_classes_files); do cp $$ROOT/$$i ./WEB-INF/classes/raw/; done &&" +
Thomas Vachuska2bd1fc82018-10-22 13:09:14 -0700273 " jar xf $$ROOT/$(location :onos-gui-jar) &&" +
Thomas Vachuska34328622018-08-03 09:21:17 -0700274 " find . -type f -exec touch -t 201806280000 {} \; &&" +
Ray Milkey6b3775a2018-06-28 11:18:44 -0700275 " jar cmf META-INF/MANIFEST.MF $$ROOT/$@ .",
Ray Milkey6b3775a2018-06-28 11:18:44 -0700276 output_to_bindir = 1,
277 visibility = ["//visibility:public"],
278)
Sean Condonbf7ff4f2019-03-17 16:18:42 +0000279
280onos_app(
281 category = "Graphical User Interface",
282 description = "ONOS GUI - the original ONOS GUI based " +
283 "on the latest AngularJS - new development should be on GUI2",
284 title = "ONOS Legacy GUI",
285 url = "http://onosproject.org",
286)