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