blob: 5e7c10cb48b4bc6c951173bf038fdba5a9fbbfce [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",
35 "@jetty_util//jar",
36 "@jersey_media_multipart//jar",
37 "@org_apache_karaf_shell_console//jar",
38 "@jersey_server//jar",
39 "//cli:onos-cli",
40 "//incubator/api:onos-incubator-api",
41 "//incubator/net:onos-incubator-net",
42 "//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",
100 "//tools/gui:tools-gui-gulp",
Thomas Vachuska34328622018-08-03 09:21:17 -0700101 ],
102 outs = ["onos-gui-npm-install.jar"],
Ray Milkeyd7be3622018-07-12 10:29:21 -0700103 cmd = " ROOT=`pwd` &&" +
Thomas Vachuska06206132018-08-06 16:43:43 -0700104 " export HOME=. &&" +
Ray Milkeyd7be3622018-07-12 10:29:21 -0700105 " export XDG_CONFIG_HOME=$(@D)/config &&" + # npm config cache to the sandbos
Ray Milkeycc9620a2018-07-31 14:22:40 -0700106 " export BABEL_DISABLE_CACHE=1 &&" + # turn off babel cache
Ray Milkeya8e5c262018-08-27 17:09:25 -0700107 ' if [[ ! -z $${HTTP_PROXY-} ]]; then NPM_ARGS="--proxy $$HTTP_PROXY --without-ssl --insecure"; else NPM_ARGS=""; fi &&' +
Ray Milkeyd7be3622018-07-12 10:29:21 -0700108 " NPM=$$ROOT/$(location @nodejs//:bin/npm) &&" +
109 " mkdir -p tools/gui &&" +
110 " cd tools/gui &&" +
Thomas Vachuska34328622018-08-03 09:21:17 -0700111 " jar xf ../../$(location //tools/gui:tools-gui-gulp) &&" +
Ray Milkeya8e5c262018-08-27 17:09:25 -0700112 " $$NPM $$NPM_ARGS install --no-cache --loglevel=error >npm-install.out 2>&1 &&" +
Thomas Vachuska34328622018-08-03 09:21:17 -0700113 " find . -name package.json | while read pjson; do egrep -v '/execroot/' $$pjson > ptmp; mv ptmp $$pjson; done &&" +
114 " find package.json gulpfile.babel.js node_modules gulp-tasks -type f -exec touch -t 201806280000 {} \; &&" +
115 " jar Mcf $$ROOT/$@ package.json gulpfile.babel.js node_modules gulp-tasks",
Ray Milkeyd7be3622018-07-12 10:29:21 -0700116)
117
118"""
119 Run npm build to create node.js files
120"""
121
122genrule(
123 name = "_onos-gui-npm-build",
124 srcs = [
125 "@nodejs//:bin/npm",
Ray Milkeyd7be3622018-07-12 10:29:21 -0700126 ":_onos-gui-npm-install",
127 ":_web_app_all",
128 ],
Thomas Vachuska34328622018-08-03 09:21:17 -0700129 outs = ["onos-gui-npm-build.jar"],
Ray Milkeyd7be3622018-07-12 10:29:21 -0700130 cmd = "(ROOT=`pwd` &&" +
Thomas Vachuska06206132018-08-06 16:43:43 -0700131 " export HOME=. &&" +
Ray Milkeyd7be3622018-07-12 10:29:21 -0700132 " export XDG_CONFIG_HOME=$(@D)/config &&" +
Ray Milkeya8e5c262018-08-27 17:09:25 -0700133 " export BABEL_DISABLE_CACHE=1 &&" +
134 ' if [[ ! -z $${HTTP_PROXY-} ]]; then NPM_ARGS="--proxy $$HTTP_PROXY --without-ssl --insecure"; else NPM_ARGS=""; fi &&' +
Ray Milkeyd7be3622018-07-12 10:29:21 -0700135 " NPM=$(location @nodejs//:bin/npm) &&" +
Thomas Vachuska34328622018-08-03 09:21:17 -0700136 " (mkdir -p web/gui && cd web/gui && jar xf ../../$(location :_web_app_all)) &&" +
Ray Milkeyd7be3622018-07-12 10:29:21 -0700137 " mkdir -p tools/gui && cd tools/gui &&" +
Thomas Vachuska34328622018-08-03 09:21:17 -0700138 " jar xf $$ROOT/$(location :_onos-gui-npm-install) &&" +
139 " chmod a+x ./node_modules/gulp/bin/gulp.js &&" +
Ray Milkeya8e5c262018-08-27 17:09:25 -0700140 " $$ROOT/$$NPM $$NPM_ARGS run build --no-cache --loglevel=error >npm-build.out &&" +
Ray Milkeyd7be3622018-07-12 10:29:21 -0700141 " cd ../../web/gui/src/main/webapp &&" +
Thomas Vachuska34328622018-08-03 09:21:17 -0700142 " find dist vendor data README.md _doc _dev app/fw app/*.css app/*.js app/*.txt -type f -exec touch -t 201806280000 {} \; &&" +
143 " 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 -0700144)
145
146"""
147 Make a jar file of all the webapp files. Useful for breaking symblic links in the sandbox
148"""
149
150genrule(
151 name = "_web_app_all",
Jian Lid486a732018-08-03 00:32:11 +0900152 srcs = glob(
153 [
154 "src/main/webapp/**",
155 "src/main/webapp/app/**/*.js",
156 ],
157 exclude = [
158 "src/main/webapp/tests/**",
159 "src/main/webapp/node_modules/**",
160 "src/main/webapp/dist/**",
161 "src/main/webapp/vendor/**",
162 "src/main/webapp/npm-debug.log",
163 ],
164 ),
Thomas Vachuska34328622018-08-03 09:21:17 -0700165 outs = ["web_app_all.jar"],
166 cmd = "cd web/gui &&" +
167 " find src/main/webapp -type f -exec touch -t 201806280000 {} \; &&" +
168 " jar Mcf ../../$@ src/main/webapp",
Ray Milkeyd7be3622018-07-12 10:29:21 -0700169)
170
171"""
172 app/view is packaged as a tar file because it has subdirectories that need to be preserved
173"""
174
Ray Milkey6b3775a2018-06-28 11:18:44 -0700175genrule(
176 name = "_app_view_tar",
177 srcs = glob(["src/main/webapp/app/view/**"]),
Thomas Vachuska34328622018-08-03 09:21:17 -0700178 outs = ["app_view_tar.jar"],
Ray Milkey6b3775a2018-06-28 11:18:44 -0700179 cmd = " ROOT=`pwd` &&" +
180 " cd web/gui/src/main/webapp/app/view &&" +
Thomas Vachuska34328622018-08-03 09:21:17 -0700181 " find . -type f -exec touch -t 201806280000 {} \; &&" +
182 " jar Mcf $$ROOT/$@ .",
Ray Milkey6b3775a2018-06-28 11:18:44 -0700183)
184
Ray Milkeyd7be3622018-07-12 10:29:21 -0700185"""
186 Builds the java jar for the java code provided by the GUI
187"""
188
189osgi_jar_with_tests(
190 name = "_onos-gui-base-jar",
191 exclude_tests = [
192 "org.onosproject.ui.impl.AbstractUiImplTest",
193 "org.onosproject.ui.impl.topo.model.AbstractTopoModelTest",
194 ],
195 test_deps = TEST_DEPS,
196 web_context = "/onos/ui",
197 deps = COMPILE_DEPS,
198)
199
200"""
201 Builds the tar ball for the ONOS GUI
202"""
203
Ray Milkey6b3775a2018-06-28 11:18:44 -0700204genrule(
205 name = "onos-gui",
206 srcs = [
207 ":_onos-gui-npm-build",
208 ":_onos-gui-base-jar",
209 ":_root_level_files",
210 ":_web_inf_classes_files",
211 ":_raw_classes_files",
212 ":_app_view_tar",
213 ],
214 outs = ["onos-gui.jar"],
215 cmd = " ROOT=`pwd` &&" +
216 " mkdir -p gui/WEB-INF/classes &&" +
217 " cd gui &&" +
Thomas Vachuska34328622018-08-03 09:21:17 -0700218 " jar xf $$ROOT/$(location :_onos-gui-npm-build) &&" +
219 " (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 -0700220 " for i in $(locations :_root_level_files); do cp $$ROOT/$$i .; done &&" +
221 " for i in $(locations :_web_inf_classes_files); do cp $$ROOT/$$i ./WEB-INF/classes/; done &&" +
Ray Milkeyd7be3622018-07-12 10:29:21 -0700222 " mkdir ./WEB-INF/classes/raw && " +
223 " for i in $(locations :_raw_classes_files); do cp $$ROOT/$$i ./WEB-INF/classes/raw/; done &&" +
Ray Milkey6b3775a2018-06-28 11:18:44 -0700224 " jar xf $$ROOT/$(location :_onos-gui-base-jar) &&" +
Thomas Vachuska34328622018-08-03 09:21:17 -0700225 " find . -type f -exec touch -t 201806280000 {} \; &&" +
Ray Milkey6b3775a2018-06-28 11:18:44 -0700226 " jar cmf META-INF/MANIFEST.MF $$ROOT/$@ .",
Ray Milkey6b3775a2018-06-28 11:18:44 -0700227 output_to_bindir = 1,
228 visibility = ["//visibility:public"],
229)