Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 1 | """ |
| 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 Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 30 | |
Ray Milkey | 86ad7bb | 2018-09-27 12:32:28 -0700 | [diff] [blame] | 31 | COMPILE_DEPS = CORE_DEPS + JACKSON + KRYO + CLI + [ |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 32 | "@javax_ws_rs_api//jar", |
| 33 | "@servlet_api//jar", |
| 34 | "@jetty_websocket//jar", |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 35 | "@jetty_websocket_api//jar", |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 36 | "@jetty_util//jar", |
| 37 | "@jersey_media_multipart//jar", |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 38 | "@jersey_server//jar", |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 39 | "//utils/rest:onlab-rest", |
| 40 | "//core/store/serializers:onos-core-serializers", |
| 41 | ] |
| 42 | |
| 43 | TEST_DEPS = TEST + [ |
| 44 | "//core/api:onos-api-tests", |
| 45 | "//drivers/default:onos-drivers-default", |
| 46 | ] |
| 47 | |
Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 48 | """ |
| 49 | Files that get put at the top level of the tar ball |
| 50 | """ |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 51 | |
| 52 | filegroup( |
| 53 | name = "_root_level_files", |
| 54 | srcs = |
| 55 | [ |
| 56 | ":src/main/webapp/bower.json", |
| 57 | ":src/main/webapp/bs-config.js", |
| 58 | ":src/main/webapp/dev_server.js", |
| 59 | ":src/main/webapp/package.json", |
| 60 | ], |
| 61 | ) |
| 62 | |
Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 63 | """ |
| 64 | Files that get put into the WEB-INF directory of the tar ball |
| 65 | """ |
| 66 | |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 67 | filegroup( |
| 68 | name = "_web_inf_classes_files", |
| 69 | srcs = |
| 70 | [ |
| 71 | ":src/main/webapp/error.html", |
| 72 | ":src/main/webapp/index.html", |
| 73 | ":src/main/webapp/login.html", |
| 74 | ":src/main/webapp/nav.html", |
| 75 | ":src/main/webapp/not-ready.html", |
| 76 | ":src/main/webapp/onos.js", |
| 77 | ], |
| 78 | ) |
| 79 | |
Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 80 | """ |
| 81 | webapp raw files |
| 82 | """ |
| 83 | |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 84 | filegroup( |
| 85 | name = "_raw_classes_files", |
| 86 | srcs = glob(["src/main/webapp/raw/**"]), |
| 87 | ) |
| 88 | |
Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 89 | """ |
Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 90 | Install node.js and npm, and gather files needed from //tools/gui |
| 91 | """ |
| 92 | |
| 93 | genrule( |
| 94 | name = "_onos-gui-npm-install", |
| 95 | srcs = [ |
| 96 | "@nodejs//:bin/npm", |
Sean Condon | f6af2a5 | 2018-08-19 10:43:24 +0100 | [diff] [blame] | 97 | "@nodejs//:bin/node", |
| 98 | "@nodejs//:bin/node.js", |
| 99 | "@nodejs//:bin/nodejs/bin/node", |
| 100 | "@nodejs//:bin/nodejs/bin/npm", |
Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 101 | "//tools/gui:tools-gui-gulp", |
Thomas Vachuska | 3432862 | 2018-08-03 09:21:17 -0700 | [diff] [blame] | 102 | ], |
| 103 | outs = ["onos-gui-npm-install.jar"], |
Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 104 | cmd = " ROOT=`pwd` &&" + |
Thomas Vachuska | 0620613 | 2018-08-06 16:43:43 -0700 | [diff] [blame] | 105 | " export HOME=. &&" + |
Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 106 | " export XDG_CONFIG_HOME=$(@D)/config &&" + # npm config cache to the sandbos |
Ray Milkey | cc9620a | 2018-07-31 14:22:40 -0700 | [diff] [blame] | 107 | " export BABEL_DISABLE_CACHE=1 &&" + # turn off babel cache |
Thomas Vachuska | 277ec4e | 2018-08-29 17:59:47 +0000 | [diff] [blame] | 108 | ' if [[ ! -z $${HTTP_PROXY-} ]]; then NPM_ARGS="--proxy $$HTTP_PROXY --without-ssl --insecure"; else NPM_ARGS=""; fi &&' + |
Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 109 | " NPM=$$ROOT/$(location @nodejs//:bin/npm) &&" + |
| 110 | " mkdir -p tools/gui &&" + |
| 111 | " cd tools/gui &&" + |
Thomas Vachuska | 3432862 | 2018-08-03 09:21:17 -0700 | [diff] [blame] | 112 | " jar xf ../../$(location //tools/gui:tools-gui-gulp) &&" + |
Ray Milkey | 61289c1 | 2018-08-27 17:09:25 -0700 | [diff] [blame] | 113 | " $$NPM $$NPM_ARGS install --no-cache --loglevel=error >npm-install.out 2>&1 &&" + |
Thomas Vachuska | 3432862 | 2018-08-03 09:21:17 -0700 | [diff] [blame] | 114 | " find . -name package.json | while read pjson; do egrep -v '/execroot/' $$pjson > ptmp; mv ptmp $$pjson; done &&" + |
| 115 | " find package.json gulpfile.babel.js node_modules gulp-tasks -type f -exec touch -t 201806280000 {} \; &&" + |
| 116 | " jar Mcf $$ROOT/$@ package.json gulpfile.babel.js node_modules gulp-tasks", |
Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 117 | ) |
| 118 | |
| 119 | """ |
| 120 | Run npm build to create node.js files |
| 121 | """ |
| 122 | |
| 123 | genrule( |
| 124 | name = "_onos-gui-npm-build", |
| 125 | srcs = [ |
| 126 | "@nodejs//:bin/npm", |
Sean Condon | f6af2a5 | 2018-08-19 10:43:24 +0100 | [diff] [blame] | 127 | "@nodejs//:bin/node", |
| 128 | "@nodejs//:bin/node.js", |
| 129 | "@nodejs//:bin/nodejs/bin/node", |
| 130 | "@nodejs//:bin/nodejs/bin/npm", |
Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 131 | ":_onos-gui-npm-install", |
| 132 | ":_web_app_all", |
| 133 | ], |
Thomas Vachuska | 3432862 | 2018-08-03 09:21:17 -0700 | [diff] [blame] | 134 | outs = ["onos-gui-npm-build.jar"], |
Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 135 | cmd = "(ROOT=`pwd` &&" + |
Thomas Vachuska | 0620613 | 2018-08-06 16:43:43 -0700 | [diff] [blame] | 136 | " export HOME=. &&" + |
Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 137 | " export XDG_CONFIG_HOME=$(@D)/config &&" + |
Ray Milkey | 61289c1 | 2018-08-27 17:09:25 -0700 | [diff] [blame] | 138 | " export BABEL_DISABLE_CACHE=1 &&" + |
| 139 | ' if [[ ! -z $${HTTP_PROXY-} ]]; then NPM_ARGS="--proxy $$HTTP_PROXY --without-ssl --insecure"; else NPM_ARGS=""; fi &&' + |
Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 140 | " NPM=$(location @nodejs//:bin/npm) &&" + |
Thomas Vachuska | 3432862 | 2018-08-03 09:21:17 -0700 | [diff] [blame] | 141 | " (mkdir -p web/gui && cd web/gui && jar xf ../../$(location :_web_app_all)) &&" + |
Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 142 | " mkdir -p tools/gui && cd tools/gui &&" + |
Thomas Vachuska | 3432862 | 2018-08-03 09:21:17 -0700 | [diff] [blame] | 143 | " jar xf $$ROOT/$(location :_onos-gui-npm-install) &&" + |
| 144 | " chmod a+x ./node_modules/gulp/bin/gulp.js &&" + |
Ray Milkey | 61289c1 | 2018-08-27 17:09:25 -0700 | [diff] [blame] | 145 | " $$ROOT/$$NPM $$NPM_ARGS run build --no-cache --loglevel=error >npm-build.out &&" + |
Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 146 | " cd ../../web/gui/src/main/webapp &&" + |
Thomas Vachuska | 3432862 | 2018-08-03 09:21:17 -0700 | [diff] [blame] | 147 | " find dist vendor data README.md _doc _dev app/fw app/*.css app/*.js app/*.txt -type f -exec touch -t 201806280000 {} \; &&" + |
| 148 | " jar Mcf $$ROOT/$@ dist vendor data README.md _doc _dev app/fw app/*.css app/*.js app/*.txt)", |
Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 149 | ) |
| 150 | |
| 151 | """ |
| 152 | Make a jar file of all the webapp files. Useful for breaking symblic links in the sandbox |
| 153 | """ |
| 154 | |
| 155 | genrule( |
| 156 | name = "_web_app_all", |
Jian Li | d486a73 | 2018-08-03 00:32:11 +0900 | [diff] [blame] | 157 | srcs = glob( |
| 158 | [ |
| 159 | "src/main/webapp/**", |
| 160 | "src/main/webapp/app/**/*.js", |
| 161 | ], |
| 162 | exclude = [ |
| 163 | "src/main/webapp/tests/**", |
| 164 | "src/main/webapp/node_modules/**", |
| 165 | "src/main/webapp/dist/**", |
| 166 | "src/main/webapp/vendor/**", |
| 167 | "src/main/webapp/npm-debug.log", |
| 168 | ], |
| 169 | ), |
Thomas Vachuska | 3432862 | 2018-08-03 09:21:17 -0700 | [diff] [blame] | 170 | outs = ["web_app_all.jar"], |
| 171 | cmd = "cd web/gui &&" + |
| 172 | " find src/main/webapp -type f -exec touch -t 201806280000 {} \; &&" + |
| 173 | " jar Mcf ../../$@ src/main/webapp", |
Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 174 | ) |
| 175 | |
| 176 | """ |
| 177 | app/view is packaged as a tar file because it has subdirectories that need to be preserved |
| 178 | """ |
| 179 | |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 180 | genrule( |
| 181 | name = "_app_view_tar", |
| 182 | srcs = glob(["src/main/webapp/app/view/**"]), |
Thomas Vachuska | 3432862 | 2018-08-03 09:21:17 -0700 | [diff] [blame] | 183 | outs = ["app_view_tar.jar"], |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 184 | cmd = " ROOT=`pwd` &&" + |
| 185 | " cd web/gui/src/main/webapp/app/view &&" + |
Thomas Vachuska | 3432862 | 2018-08-03 09:21:17 -0700 | [diff] [blame] | 186 | " find . -type f -exec touch -t 201806280000 {} \; &&" + |
| 187 | " jar Mcf $$ROOT/$@ .", |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 188 | ) |
| 189 | |
Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 190 | """ |
| 191 | Builds the java jar for the java code provided by the GUI |
| 192 | """ |
| 193 | |
| 194 | osgi_jar_with_tests( |
Thomas Vachuska | 2bd1fc8 | 2018-10-22 13:09:14 -0700 | [diff] [blame] | 195 | name = "onos-gui-jar", |
Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 196 | exclude_tests = [ |
| 197 | "org.onosproject.ui.impl.AbstractUiImplTest", |
| 198 | "org.onosproject.ui.impl.topo.model.AbstractTopoModelTest", |
| 199 | ], |
Ray Milkey | 8753ede | 2018-10-12 09:08:35 -0700 | [diff] [blame] | 200 | karaf_command_packages = [ |
| 201 | "org.onosproject.ui.impl.cli", |
| 202 | "org.onosproject.ui.impl.topo", |
| 203 | ], |
Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 204 | test_deps = TEST_DEPS, |
| 205 | web_context = "/onos/ui", |
| 206 | deps = COMPILE_DEPS, |
| 207 | ) |
| 208 | |
Sean Condon | 3c8e558 | 2018-08-28 23:22:43 +0100 | [diff] [blame] | 209 | genrule( |
| 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 Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 220 | """ |
| 221 | Builds the tar ball for the ONOS GUI |
| 222 | """ |
| 223 | |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 224 | genrule( |
| 225 | name = "onos-gui", |
| 226 | srcs = [ |
| 227 | ":_onos-gui-npm-build", |
Thomas Vachuska | 2bd1fc8 | 2018-10-22 13:09:14 -0700 | [diff] [blame] | 228 | ":onos-gui-jar", |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 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 Vachuska | 3432862 | 2018-08-03 09:21:17 -0700 | [diff] [blame] | 238 | " 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 Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 240 | " 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 Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 242 | " mkdir ./WEB-INF/classes/raw && " + |
| 243 | " for i in $(locations :_raw_classes_files); do cp $$ROOT/$$i ./WEB-INF/classes/raw/; done &&" + |
Thomas Vachuska | 2bd1fc8 | 2018-10-22 13:09:14 -0700 | [diff] [blame] | 244 | " jar xf $$ROOT/$(location :onos-gui-jar) &&" + |
Thomas Vachuska | 3432862 | 2018-08-03 09:21:17 -0700 | [diff] [blame] | 245 | " find . -type f -exec touch -t 201806280000 {} \; &&" + |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 246 | " jar cmf META-INF/MANIFEST.MF $$ROOT/$@ .", |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 247 | output_to_bindir = 1, |
| 248 | visibility = ["//visibility:public"], |
| 249 | ) |