blob: 8cca7b9150e8cb51e384bbd453439e604576e080 [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/**",
100 ]),
101)
102
103"""
104 Install node.js and npm, and gather files needed from //tools/gui
105"""
106
107genrule(
108 name = "_onos-gui-npm-install",
109 srcs = [
110 "@nodejs//:bin/npm",
111 "//tools/gui:tools-gui-gulp",
112 ] + glob(
113 [
114 "src/main/webapp/*.js",
115 "src/main/webapp/app/**/*.js",
116 ],
117 exclude = ["src/main/webapp/dist/*.js"],
118 ),
119 outs = ["onos-gui-npm-install.tar"],
120 cmd = " ROOT=`pwd` &&" +
121 " export XDG_CONFIG_HOME=$(@D)/config &&" + # npm config cache to the sandbos
Ray Milkeycc9620a2018-07-31 14:22:40 -0700122 " export BABEL_DISABLE_CACHE=1 &&" + # turn off babel cache
123 " export bower_storage__packages=.bower &&" +
124 " export bower_storage__registry=.bower &&" +
Ray Milkeyd7be3622018-07-12 10:29:21 -0700125 " NPM=$$ROOT/$(location @nodejs//:bin/npm) &&" +
126 " mkdir -p tools/gui &&" +
127 " cd tools/gui &&" +
128 " tar xf ../../$(location //tools/gui:tools-gui-gulp) &&" +
129 " $$NPM install --no-cache --loglevel=error >npm-install.out 2>&1 &&" +
130 " tar hcf $$ROOT/$@ package.json gulpfile.babel.js node_modules gulp-tasks",
131)
132
133"""
134 Run npm build to create node.js files
135"""
136
137genrule(
138 name = "_onos-gui-npm-build",
139 srcs = [
140 "@nodejs//:bin/npm",
141 "@nodejs//:bin/node",
142 ":_onos-gui-npm-install",
143 ":_web_app_all",
144 ],
145 outs = ["onos-gui-npm-build.tar"],
146 cmd = "(ROOT=`pwd` &&" +
147 " export XDG_CONFIG_HOME=$(@D)/config &&" +
148 " export BABEL_DISABLE_CACHE=1" +
Ray Milkeycc9620a2018-07-31 14:22:40 -0700149 " export bower_storage__packages=.bower &&" +
150 " export bower_storage__registry=.bower &&" +
Ray Milkeyd7be3622018-07-12 10:29:21 -0700151 " NPM=$(location @nodejs//:bin/npm) &&" +
152 " (mkdir -p web/gui && cd web/gui && tar xf ../../$(location :_web_app_all)) &&" +
153 " mkdir -p tools/gui && cd tools/gui &&" +
154 " tar xf $$ROOT/$(location :_onos-gui-npm-install) &&" +
155 " $$ROOT/$$NPM run build --no-cache --loglevel=error >npm-build.out &&" +
156 " cd ../../web/gui/src/main/webapp &&" +
157 " jar cf $$ROOT/$@ dist vendor data tests README.md _doc _dev app/fw app/*.css app/*.js app/*.txt)",
158)
159
160"""
161 Make a jar file of all the webapp files. Useful for breaking symblic links in the sandbox
162"""
163
164genrule(
165 name = "_web_app_all",
166 srcs = [":_src_main_webapp_files"],
167 outs = ["web_app_all.tar"],
168 cmd = "cd web/gui && tar hcf ../../$@ src/main/webapp",
169)
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/**"]),
178 outs = ["app_view_tar.tar"],
179 cmd = " ROOT=`pwd` &&" +
180 " cd web/gui/src/main/webapp/app/view &&" +
Ray Milkeyd7be3622018-07-12 10:29:21 -0700181 " tar hcf $$ROOT/$@ .",
Ray Milkey6b3775a2018-06-28 11:18:44 -0700182)
183
Ray Milkeyd7be3622018-07-12 10:29:21 -0700184"""
185 Builds the java jar for the java code provided by the GUI
186"""
187
188osgi_jar_with_tests(
189 name = "_onos-gui-base-jar",
190 exclude_tests = [
191 "org.onosproject.ui.impl.AbstractUiImplTest",
192 "org.onosproject.ui.impl.topo.model.AbstractTopoModelTest",
193 ],
194 test_deps = TEST_DEPS,
195 web_context = "/onos/ui",
196 deps = COMPILE_DEPS,
197)
198
199"""
200 Builds the tar ball for the ONOS GUI
201"""
202
Ray Milkey6b3775a2018-06-28 11:18:44 -0700203genrule(
204 name = "onos-gui",
205 srcs = [
206 ":_onos-gui-npm-build",
207 ":_onos-gui-base-jar",
208 ":_root_level_files",
209 ":_web_inf_classes_files",
210 ":_raw_classes_files",
211 ":_app_view_tar",
212 ],
213 outs = ["onos-gui.jar"],
214 cmd = " ROOT=`pwd` &&" +
215 " mkdir -p gui/WEB-INF/classes &&" +
216 " cd gui &&" +
217 " tar xf $$ROOT/$(location :_onos-gui-npm-build) &&" +
218 " (cd WEB-INF/classes && mkdir -p app/view && cd app/view && tar xf $$ROOT/$(location :_app_view_tar)) &&" +
219 " for i in $(locations :_root_level_files); do cp $$ROOT/$$i .; done &&" +
220 " for i in $(locations :_web_inf_classes_files); do cp $$ROOT/$$i ./WEB-INF/classes/; done &&" +
Ray Milkeyd7be3622018-07-12 10:29:21 -0700221 " mkdir ./WEB-INF/classes/raw && " +
222 " for i in $(locations :_raw_classes_files); do cp $$ROOT/$$i ./WEB-INF/classes/raw/; done &&" +
Ray Milkey6b3775a2018-06-28 11:18:44 -0700223 " jar xf $$ROOT/$(location :_onos-gui-base-jar) &&" +
224 " jar cmf META-INF/MANIFEST.MF $$ROOT/$@ .",
Ray Milkey6b3775a2018-06-28 11:18:44 -0700225 output_to_bindir = 1,
226 visibility = ["//visibility:public"],
227)