blob: 87316296a266efb658608f988f350e2af15e0aa4 [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
31COMPILE_DEPS = CORE_DEPS + JACKSON + KRYO + [
32 "@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 Milkeyd84f89b2018-08-17 14:54:17 -070038 "@org_apache_karaf_shell_core//jar",
Ray Milkey6b3775a2018-06-28 11:18:44 -070039 "@jersey_server//jar",
40 "//cli:onos-cli",
41 "//incubator/api:onos-incubator-api",
42 "//incubator/net:onos-incubator-net",
43 "//utils/rest:onlab-rest",
44 "//core/store/serializers:onos-core-serializers",
45]
46
47TEST_DEPS = TEST + [
48 "//core/api:onos-api-tests",
49 "//drivers/default:onos-drivers-default",
50]
51
Ray Milkeyd7be3622018-07-12 10:29:21 -070052"""
53 Files that get put at the top level of the tar ball
54"""
Ray Milkey6b3775a2018-06-28 11:18:44 -070055
56filegroup(
57 name = "_root_level_files",
58 srcs =
59 [
60 ":src/main/webapp/bower.json",
61 ":src/main/webapp/bs-config.js",
62 ":src/main/webapp/dev_server.js",
63 ":src/main/webapp/package.json",
64 ],
65)
66
Ray Milkeyd7be3622018-07-12 10:29:21 -070067"""
68 Files that get put into the WEB-INF directory of the tar ball
69"""
70
Ray Milkey6b3775a2018-06-28 11:18:44 -070071filegroup(
72 name = "_web_inf_classes_files",
73 srcs =
74 [
75 ":src/main/webapp/error.html",
76 ":src/main/webapp/index.html",
77 ":src/main/webapp/login.html",
78 ":src/main/webapp/nav.html",
79 ":src/main/webapp/not-ready.html",
80 ":src/main/webapp/onos.js",
81 ],
82)
83
Ray Milkeyd7be3622018-07-12 10:29:21 -070084"""
85 webapp raw files
86"""
87
Ray Milkey6b3775a2018-06-28 11:18:44 -070088filegroup(
89 name = "_raw_classes_files",
90 srcs = glob(["src/main/webapp/raw/**"]),
91)
92
Ray Milkeyd7be3622018-07-12 10:29:21 -070093"""
Ray Milkeyd7be3622018-07-12 10:29:21 -070094 Install node.js and npm, and gather files needed from //tools/gui
95"""
96
97genrule(
98 name = "_onos-gui-npm-install",
99 srcs = [
100 "@nodejs//:bin/npm",
Sean Condonf6af2a52018-08-19 10:43:24 +0100101 "@nodejs//:bin/node",
102 "@nodejs//:bin/node.js",
103 "@nodejs//:bin/nodejs/bin/node",
104 "@nodejs//:bin/nodejs/bin/npm",
Ray Milkeyd7be3622018-07-12 10:29:21 -0700105 "//tools/gui:tools-gui-gulp",
Thomas Vachuska34328622018-08-03 09:21:17 -0700106 ],
107 outs = ["onos-gui-npm-install.jar"],
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) &&" +
Ray Milkey61289c12018-08-27 17:09:25 -0700117 " $$NPM $$NPM_ARGS install --no-cache --loglevel=error >npm-install.out 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 {} \; &&" +
120 " jar Mcf $$ROOT/$@ package.json gulpfile.babel.js node_modules gulp-tasks",
Ray Milkeyd7be3622018-07-12 10:29:21 -0700121)
122
123"""
124 Run npm build to create node.js files
125"""
126
127genrule(
128 name = "_onos-gui-npm-build",
129 srcs = [
130 "@nodejs//:bin/npm",
Sean Condonf6af2a52018-08-19 10:43:24 +0100131 "@nodejs//:bin/node",
132 "@nodejs//:bin/node.js",
133 "@nodejs//:bin/nodejs/bin/node",
134 "@nodejs//:bin/nodejs/bin/npm",
Ray Milkeyd7be3622018-07-12 10:29:21 -0700135 ":_onos-gui-npm-install",
136 ":_web_app_all",
137 ],
Thomas Vachuska34328622018-08-03 09:21:17 -0700138 outs = ["onos-gui-npm-build.jar"],
Ray Milkeyd7be3622018-07-12 10:29:21 -0700139 cmd = "(ROOT=`pwd` &&" +
Thomas Vachuska06206132018-08-06 16:43:43 -0700140 " export HOME=. &&" +
Ray Milkeyd7be3622018-07-12 10:29:21 -0700141 " export XDG_CONFIG_HOME=$(@D)/config &&" +
Ray Milkey61289c12018-08-27 17:09:25 -0700142 " export BABEL_DISABLE_CACHE=1 &&" +
143 ' if [[ ! -z $${HTTP_PROXY-} ]]; then NPM_ARGS="--proxy $$HTTP_PROXY --without-ssl --insecure"; else NPM_ARGS=""; fi &&' +
Ray Milkeyd7be3622018-07-12 10:29:21 -0700144 " NPM=$(location @nodejs//:bin/npm) &&" +
Thomas Vachuska34328622018-08-03 09:21:17 -0700145 " (mkdir -p web/gui && cd web/gui && jar xf ../../$(location :_web_app_all)) &&" +
Ray Milkeyd7be3622018-07-12 10:29:21 -0700146 " mkdir -p tools/gui && cd tools/gui &&" +
Thomas Vachuska34328622018-08-03 09:21:17 -0700147 " jar xf $$ROOT/$(location :_onos-gui-npm-install) &&" +
148 " chmod a+x ./node_modules/gulp/bin/gulp.js &&" +
Ray Milkey61289c12018-08-27 17:09:25 -0700149 " $$ROOT/$$NPM $$NPM_ARGS run build --no-cache --loglevel=error >npm-build.out &&" +
Ray Milkeyd7be3622018-07-12 10:29:21 -0700150 " cd ../../web/gui/src/main/webapp &&" +
Thomas Vachuska34328622018-08-03 09:21:17 -0700151 " find dist vendor data README.md _doc _dev app/fw app/*.css app/*.js app/*.txt -type f -exec touch -t 201806280000 {} \; &&" +
152 " 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 -0700153)
154
155"""
156 Make a jar file of all the webapp files. Useful for breaking symblic links in the sandbox
157"""
158
159genrule(
160 name = "_web_app_all",
Jian Lid486a732018-08-03 00:32:11 +0900161 srcs = glob(
162 [
163 "src/main/webapp/**",
164 "src/main/webapp/app/**/*.js",
165 ],
166 exclude = [
167 "src/main/webapp/tests/**",
168 "src/main/webapp/node_modules/**",
169 "src/main/webapp/dist/**",
170 "src/main/webapp/vendor/**",
171 "src/main/webapp/npm-debug.log",
172 ],
173 ),
Thomas Vachuska34328622018-08-03 09:21:17 -0700174 outs = ["web_app_all.jar"],
175 cmd = "cd web/gui &&" +
176 " find src/main/webapp -type f -exec touch -t 201806280000 {} \; &&" +
177 " jar Mcf ../../$@ src/main/webapp",
Ray Milkeyd7be3622018-07-12 10:29:21 -0700178)
179
180"""
181 app/view is packaged as a tar file because it has subdirectories that need to be preserved
182"""
183
Ray Milkey6b3775a2018-06-28 11:18:44 -0700184genrule(
185 name = "_app_view_tar",
186 srcs = glob(["src/main/webapp/app/view/**"]),
Thomas Vachuska34328622018-08-03 09:21:17 -0700187 outs = ["app_view_tar.jar"],
Ray Milkey6b3775a2018-06-28 11:18:44 -0700188 cmd = " ROOT=`pwd` &&" +
189 " cd web/gui/src/main/webapp/app/view &&" +
Thomas Vachuska34328622018-08-03 09:21:17 -0700190 " find . -type f -exec touch -t 201806280000 {} \; &&" +
191 " jar Mcf $$ROOT/$@ .",
Ray Milkey6b3775a2018-06-28 11:18:44 -0700192)
193
Ray Milkeyd7be3622018-07-12 10:29:21 -0700194"""
195 Builds the java jar for the java code provided by the GUI
196"""
197
198osgi_jar_with_tests(
199 name = "_onos-gui-base-jar",
200 exclude_tests = [
201 "org.onosproject.ui.impl.AbstractUiImplTest",
202 "org.onosproject.ui.impl.topo.model.AbstractTopoModelTest",
203 ],
204 test_deps = TEST_DEPS,
205 web_context = "/onos/ui",
206 deps = COMPILE_DEPS,
207)
208
Sean Condon3c8e5582018-08-28 23:22:43 +0100209genrule(
210 name = "onos-gui-java-for-gui2",
211 srcs = glob([
212 "src/main/java/org/onosproject/ui/impl/Main*Resource.java",
213 "src/main/java/org/onosproject/ui/impl/ApplicationResource.java",
214 ]),
215 outs = ["onos-gui-java-for-gui2.srcjar"],
216 cmd = "jar cf $@ $(SRCS)",
217 visibility = ["//visibility:public"],
218)
219
Ray Milkeyd7be3622018-07-12 10:29:21 -0700220"""
221 Builds the tar ball for the ONOS GUI
222"""
223
Ray Milkey6b3775a2018-06-28 11:18:44 -0700224genrule(
225 name = "onos-gui",
226 srcs = [
227 ":_onos-gui-npm-build",
228 ":_onos-gui-base-jar",
229 ":_root_level_files",
230 ":_web_inf_classes_files",
231 ":_raw_classes_files",
232 ":_app_view_tar",
233 ],
234 outs = ["onos-gui.jar"],
235 cmd = " ROOT=`pwd` &&" +
236 " mkdir -p gui/WEB-INF/classes &&" +
237 " cd gui &&" +
Thomas Vachuska34328622018-08-03 09:21:17 -0700238 " jar xf $$ROOT/$(location :_onos-gui-npm-build) &&" +
239 " (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 -0700240 " for i in $(locations :_root_level_files); do cp $$ROOT/$$i .; done &&" +
241 " for i in $(locations :_web_inf_classes_files); do cp $$ROOT/$$i ./WEB-INF/classes/; done &&" +
Ray Milkeyd7be3622018-07-12 10:29:21 -0700242 " mkdir ./WEB-INF/classes/raw && " +
243 " for i in $(locations :_raw_classes_files); do cp $$ROOT/$$i ./WEB-INF/classes/raw/; done &&" +
Ray Milkey6b3775a2018-06-28 11:18:44 -0700244 " jar xf $$ROOT/$(location :_onos-gui-base-jar) &&" +
Thomas Vachuska34328622018-08-03 09:21:17 -0700245 " find . -type f -exec touch -t 201806280000 {} \; &&" +
Ray Milkey6b3775a2018-06-28 11:18:44 -0700246 " jar cmf META-INF/MANIFEST.MF $$ROOT/$@ .",
Ray Milkey6b3775a2018-06-28 11:18:44 -0700247 output_to_bindir = 1,
248 visibility = ["//visibility:public"],
249)