blob: 6b8ba33d67bc312f7b0e0ae8d79c6f753172c367 [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"""
93 dependency to expose all webapp files in the sandbox
94"""
95
96filegroup(
97 name = "_src_main_webapp_files",
98 srcs = glob([
99 "src/main/webapp/**",
Thomas Vachuskaf34554f2018-07-31 17:09:36 -0700100 ], exclude = [
101 "src/main/webapp/tests/**",
102 "src/main/webapp/node_modules/**",
103 "src/main/webapp/dist/**",
104 "src/main/webapp/vendor/**",
105 "src/main/webapp/npm-debug.log",
Ray Milkeyd7be3622018-07-12 10:29:21 -0700106 ]),
107)
108
109"""
110 Install node.js and npm, and gather files needed from //tools/gui
111"""
112
113genrule(
114 name = "_onos-gui-npm-install",
115 srcs = [
116 "@nodejs//:bin/npm",
117 "//tools/gui:tools-gui-gulp",
118 ] + glob(
119 [
120 "src/main/webapp/*.js",
121 "src/main/webapp/app/**/*.js",
122 ],
123 exclude = ["src/main/webapp/dist/*.js"],
124 ),
125 outs = ["onos-gui-npm-install.tar"],
126 cmd = " ROOT=`pwd` &&" +
127 " export XDG_CONFIG_HOME=$(@D)/config &&" + # npm config cache to the sandbos
Ray Milkeycc9620a2018-07-31 14:22:40 -0700128 " export BABEL_DISABLE_CACHE=1 &&" + # turn off babel cache
129 " export bower_storage__packages=.bower &&" +
130 " export bower_storage__registry=.bower &&" +
Ray Milkeyd7be3622018-07-12 10:29:21 -0700131 " NPM=$$ROOT/$(location @nodejs//:bin/npm) &&" +
132 " mkdir -p tools/gui &&" +
133 " cd tools/gui &&" +
134 " tar xf ../../$(location //tools/gui:tools-gui-gulp) &&" +
135 " $$NPM install --no-cache --loglevel=error >npm-install.out 2>&1 &&" +
136 " tar hcf $$ROOT/$@ package.json gulpfile.babel.js node_modules gulp-tasks",
137)
138
139"""
140 Run npm build to create node.js files
141"""
142
143genrule(
144 name = "_onos-gui-npm-build",
145 srcs = [
146 "@nodejs//:bin/npm",
147 "@nodejs//:bin/node",
148 ":_onos-gui-npm-install",
149 ":_web_app_all",
150 ],
151 outs = ["onos-gui-npm-build.tar"],
152 cmd = "(ROOT=`pwd` &&" +
153 " export XDG_CONFIG_HOME=$(@D)/config &&" +
154 " export BABEL_DISABLE_CACHE=1" +
Ray Milkeycc9620a2018-07-31 14:22:40 -0700155 " export bower_storage__packages=.bower &&" +
156 " export bower_storage__registry=.bower &&" +
Ray Milkeyd7be3622018-07-12 10:29:21 -0700157 " NPM=$(location @nodejs//:bin/npm) &&" +
158 " (mkdir -p web/gui && cd web/gui && tar xf ../../$(location :_web_app_all)) &&" +
159 " mkdir -p tools/gui && cd tools/gui &&" +
160 " tar xf $$ROOT/$(location :_onos-gui-npm-install) &&" +
161 " $$ROOT/$$NPM run build --no-cache --loglevel=error >npm-build.out &&" +
162 " cd ../../web/gui/src/main/webapp &&" +
Thomas Vachuska1506abb2018-07-31 16:28:37 -0700163 " jar cf $$ROOT/$@ dist vendor data README.md _doc _dev app/fw app/*.css app/*.js app/*.txt)",
Ray Milkeyd7be3622018-07-12 10:29:21 -0700164)
165
166"""
167 Make a jar file of all the webapp files. Useful for breaking symblic links in the sandbox
168"""
169
170genrule(
171 name = "_web_app_all",
172 srcs = [":_src_main_webapp_files"],
173 outs = ["web_app_all.tar"],
Thomas Vachuskaf34554f2018-07-31 17:09:36 -0700174 cmd = "cd web/gui && du -hHs src/main/webapp && tar hcf ../../$@ src/main/webapp",
Ray Milkeyd7be3622018-07-12 10:29:21 -0700175)
176
177"""
178 app/view is packaged as a tar file because it has subdirectories that need to be preserved
179"""
180
Ray Milkey6b3775a2018-06-28 11:18:44 -0700181genrule(
182 name = "_app_view_tar",
183 srcs = glob(["src/main/webapp/app/view/**"]),
184 outs = ["app_view_tar.tar"],
185 cmd = " ROOT=`pwd` &&" +
186 " cd web/gui/src/main/webapp/app/view &&" +
Ray Milkeyd7be3622018-07-12 10:29:21 -0700187 " tar hcf $$ROOT/$@ .",
Ray Milkey6b3775a2018-06-28 11:18:44 -0700188)
189
Ray Milkeyd7be3622018-07-12 10:29:21 -0700190"""
191 Builds the java jar for the java code provided by the GUI
192"""
193
194osgi_jar_with_tests(
195 name = "_onos-gui-base-jar",
196 exclude_tests = [
197 "org.onosproject.ui.impl.AbstractUiImplTest",
198 "org.onosproject.ui.impl.topo.model.AbstractTopoModelTest",
199 ],
200 test_deps = TEST_DEPS,
201 web_context = "/onos/ui",
202 deps = COMPILE_DEPS,
203)
204
205"""
206 Builds the tar ball for the ONOS GUI
207"""
208
Ray Milkey6b3775a2018-06-28 11:18:44 -0700209genrule(
210 name = "onos-gui",
211 srcs = [
212 ":_onos-gui-npm-build",
213 ":_onos-gui-base-jar",
214 ":_root_level_files",
215 ":_web_inf_classes_files",
216 ":_raw_classes_files",
217 ":_app_view_tar",
218 ],
219 outs = ["onos-gui.jar"],
220 cmd = " ROOT=`pwd` &&" +
221 " mkdir -p gui/WEB-INF/classes &&" +
222 " cd gui &&" +
223 " tar xf $$ROOT/$(location :_onos-gui-npm-build) &&" +
224 " (cd WEB-INF/classes && mkdir -p app/view && cd app/view && tar xf $$ROOT/$(location :_app_view_tar)) &&" +
225 " for i in $(locations :_root_level_files); do cp $$ROOT/$$i .; done &&" +
226 " for i in $(locations :_web_inf_classes_files); do cp $$ROOT/$$i ./WEB-INF/classes/; done &&" +
Ray Milkeyd7be3622018-07-12 10:29:21 -0700227 " mkdir ./WEB-INF/classes/raw && " +
228 " for i in $(locations :_raw_classes_files); do cp $$ROOT/$$i ./WEB-INF/classes/raw/; done &&" +
Ray Milkey6b3775a2018-06-28 11:18:44 -0700229 " jar xf $$ROOT/$(location :_onos-gui-base-jar) &&" +
230 " jar cmf META-INF/MANIFEST.MF $$ROOT/$@ .",
Ray Milkey6b3775a2018-06-28 11:18:44 -0700231 output_to_bindir = 1,
232 visibility = ["//visibility:public"],
233)