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 | |
| 31 | COMPILE_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 | |
| 46 | TEST_DEPS = TEST + [ |
| 47 | "//core/api:onos-api-tests", |
| 48 | "//drivers/default:onos-drivers-default", |
| 49 | ] |
| 50 | |
Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 51 | """ |
| 52 | Files that get put at the top level of the tar ball |
| 53 | """ |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 54 | |
| 55 | filegroup( |
| 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 Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 66 | """ |
| 67 | Files that get put into the WEB-INF directory of the tar ball |
| 68 | """ |
| 69 | |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 70 | filegroup( |
| 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 Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 83 | """ |
| 84 | webapp raw files |
| 85 | """ |
| 86 | |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 87 | filegroup( |
| 88 | name = "_raw_classes_files", |
| 89 | srcs = glob(["src/main/webapp/raw/**"]), |
| 90 | ) |
| 91 | |
Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 92 | """ |
Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 93 | Install node.js and npm, and gather files needed from //tools/gui |
| 94 | """ |
| 95 | |
| 96 | genrule( |
| 97 | name = "_onos-gui-npm-install", |
| 98 | srcs = [ |
| 99 | "@nodejs//:bin/npm", |
Sean Condon | f6af2a5 | 2018-08-19 10:43:24 +0100 | [diff] [blame] | 100 | "@nodejs//:bin/node", |
| 101 | "@nodejs//:bin/node.js", |
| 102 | "@nodejs//:bin/nodejs/bin/node", |
| 103 | "@nodejs//:bin/nodejs/bin/npm", |
Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 104 | "//tools/gui:tools-gui-gulp", |
Thomas Vachuska | 3432862 | 2018-08-03 09:21:17 -0700 | [diff] [blame] | 105 | ], |
| 106 | outs = ["onos-gui-npm-install.jar"], |
Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 107 | cmd = " ROOT=`pwd` &&" + |
Thomas Vachuska | 0620613 | 2018-08-06 16:43:43 -0700 | [diff] [blame] | 108 | " export HOME=. &&" + |
Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 109 | " export XDG_CONFIG_HOME=$(@D)/config &&" + # npm config cache to the sandbos |
Ray Milkey | cc9620a | 2018-07-31 14:22:40 -0700 | [diff] [blame] | 110 | " export BABEL_DISABLE_CACHE=1 &&" + # turn off babel cache |
Sean Condon | 42db831 | 2018-08-28 23:22:43 +0100 | [diff] [blame^] | 111 | " 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] | 112 | " NPM=$$ROOT/$(location @nodejs//:bin/npm) &&" + |
| 113 | " mkdir -p tools/gui &&" + |
| 114 | " cd tools/gui &&" + |
Thomas Vachuska | 3432862 | 2018-08-03 09:21:17 -0700 | [diff] [blame] | 115 | " jar xf ../../$(location //tools/gui:tools-gui-gulp) &&" + |
Ray Milkey | 61289c1 | 2018-08-27 17:09:25 -0700 | [diff] [blame] | 116 | " $$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] | 117 | " find . -name package.json | while read pjson; do egrep -v '/execroot/' $$pjson > ptmp; mv ptmp $$pjson; done &&" + |
| 118 | " find package.json gulpfile.babel.js node_modules gulp-tasks -type f -exec touch -t 201806280000 {} \; &&" + |
| 119 | " jar Mcf $$ROOT/$@ package.json gulpfile.babel.js node_modules gulp-tasks", |
Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 120 | ) |
| 121 | |
| 122 | """ |
| 123 | Run npm build to create node.js files |
| 124 | """ |
| 125 | |
| 126 | genrule( |
| 127 | name = "_onos-gui-npm-build", |
| 128 | srcs = [ |
| 129 | "@nodejs//:bin/npm", |
Sean Condon | f6af2a5 | 2018-08-19 10:43:24 +0100 | [diff] [blame] | 130 | "@nodejs//:bin/node", |
| 131 | "@nodejs//:bin/node.js", |
| 132 | "@nodejs//:bin/nodejs/bin/node", |
| 133 | "@nodejs//:bin/nodejs/bin/npm", |
Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 134 | ":_onos-gui-npm-install", |
| 135 | ":_web_app_all", |
| 136 | ], |
Thomas Vachuska | 3432862 | 2018-08-03 09:21:17 -0700 | [diff] [blame] | 137 | outs = ["onos-gui-npm-build.jar"], |
Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 138 | cmd = "(ROOT=`pwd` &&" + |
Thomas Vachuska | 0620613 | 2018-08-06 16:43:43 -0700 | [diff] [blame] | 139 | " export HOME=. &&" + |
Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 140 | " export XDG_CONFIG_HOME=$(@D)/config &&" + |
Ray Milkey | 61289c1 | 2018-08-27 17:09:25 -0700 | [diff] [blame] | 141 | " export BABEL_DISABLE_CACHE=1 &&" + |
| 142 | ' 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] | 143 | " NPM=$(location @nodejs//:bin/npm) &&" + |
Thomas Vachuska | 3432862 | 2018-08-03 09:21:17 -0700 | [diff] [blame] | 144 | " (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] | 145 | " mkdir -p tools/gui && cd tools/gui &&" + |
Thomas Vachuska | 3432862 | 2018-08-03 09:21:17 -0700 | [diff] [blame] | 146 | " jar xf $$ROOT/$(location :_onos-gui-npm-install) &&" + |
| 147 | " chmod a+x ./node_modules/gulp/bin/gulp.js &&" + |
Ray Milkey | 61289c1 | 2018-08-27 17:09:25 -0700 | [diff] [blame] | 148 | " $$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] | 149 | " cd ../../web/gui/src/main/webapp &&" + |
Thomas Vachuska | 3432862 | 2018-08-03 09:21:17 -0700 | [diff] [blame] | 150 | " find dist vendor data README.md _doc _dev app/fw app/*.css app/*.js app/*.txt -type f -exec touch -t 201806280000 {} \; &&" + |
| 151 | " 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] | 152 | ) |
| 153 | |
| 154 | """ |
| 155 | Make a jar file of all the webapp files. Useful for breaking symblic links in the sandbox |
| 156 | """ |
| 157 | |
| 158 | genrule( |
| 159 | name = "_web_app_all", |
Jian Li | d486a73 | 2018-08-03 00:32:11 +0900 | [diff] [blame] | 160 | srcs = glob( |
| 161 | [ |
| 162 | "src/main/webapp/**", |
| 163 | "src/main/webapp/app/**/*.js", |
| 164 | ], |
| 165 | exclude = [ |
| 166 | "src/main/webapp/tests/**", |
| 167 | "src/main/webapp/node_modules/**", |
| 168 | "src/main/webapp/dist/**", |
| 169 | "src/main/webapp/vendor/**", |
| 170 | "src/main/webapp/npm-debug.log", |
| 171 | ], |
| 172 | ), |
Thomas Vachuska | 3432862 | 2018-08-03 09:21:17 -0700 | [diff] [blame] | 173 | outs = ["web_app_all.jar"], |
| 174 | cmd = "cd web/gui &&" + |
| 175 | " find src/main/webapp -type f -exec touch -t 201806280000 {} \; &&" + |
| 176 | " jar Mcf ../../$@ src/main/webapp", |
Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 177 | ) |
| 178 | |
| 179 | """ |
| 180 | app/view is packaged as a tar file because it has subdirectories that need to be preserved |
| 181 | """ |
| 182 | |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 183 | genrule( |
| 184 | name = "_app_view_tar", |
| 185 | srcs = glob(["src/main/webapp/app/view/**"]), |
Thomas Vachuska | 3432862 | 2018-08-03 09:21:17 -0700 | [diff] [blame] | 186 | outs = ["app_view_tar.jar"], |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 187 | cmd = " ROOT=`pwd` &&" + |
| 188 | " cd web/gui/src/main/webapp/app/view &&" + |
Thomas Vachuska | 3432862 | 2018-08-03 09:21:17 -0700 | [diff] [blame] | 189 | " find . -type f -exec touch -t 201806280000 {} \; &&" + |
| 190 | " jar Mcf $$ROOT/$@ .", |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 191 | ) |
| 192 | |
Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 193 | """ |
| 194 | Builds the java jar for the java code provided by the GUI |
| 195 | """ |
| 196 | |
| 197 | osgi_jar_with_tests( |
| 198 | name = "_onos-gui-base-jar", |
| 199 | exclude_tests = [ |
| 200 | "org.onosproject.ui.impl.AbstractUiImplTest", |
| 201 | "org.onosproject.ui.impl.topo.model.AbstractTopoModelTest", |
| 202 | ], |
| 203 | test_deps = TEST_DEPS, |
| 204 | web_context = "/onos/ui", |
| 205 | deps = COMPILE_DEPS, |
| 206 | ) |
| 207 | |
Sean Condon | 42db831 | 2018-08-28 23:22:43 +0100 | [diff] [blame^] | 208 | filegroup( |
| 209 | name = "onos-gui-java-for-gui2", |
| 210 | srcs = glob([ |
| 211 | "src/main/java/org/onosproject/ui/impl/Main*Resource.java", |
| 212 | "src/main/java/org/onosproject/ui/impl/ApplicationResource.java", |
| 213 | ]), |
| 214 | visibility = ["//visibility:public"], |
| 215 | ) |
| 216 | |
Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 217 | """ |
| 218 | Builds the tar ball for the ONOS GUI |
| 219 | """ |
| 220 | |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 221 | genrule( |
| 222 | name = "onos-gui", |
| 223 | srcs = [ |
| 224 | ":_onos-gui-npm-build", |
| 225 | ":_onos-gui-base-jar", |
| 226 | ":_root_level_files", |
| 227 | ":_web_inf_classes_files", |
| 228 | ":_raw_classes_files", |
| 229 | ":_app_view_tar", |
| 230 | ], |
| 231 | outs = ["onos-gui.jar"], |
| 232 | cmd = " ROOT=`pwd` &&" + |
| 233 | " mkdir -p gui/WEB-INF/classes &&" + |
| 234 | " cd gui &&" + |
Thomas Vachuska | 3432862 | 2018-08-03 09:21:17 -0700 | [diff] [blame] | 235 | " jar xf $$ROOT/$(location :_onos-gui-npm-build) &&" + |
| 236 | " (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] | 237 | " for i in $(locations :_root_level_files); do cp $$ROOT/$$i .; done &&" + |
| 238 | " 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] | 239 | " mkdir ./WEB-INF/classes/raw && " + |
| 240 | " for i in $(locations :_raw_classes_files); do cp $$ROOT/$$i ./WEB-INF/classes/raw/; done &&" + |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 241 | " jar xf $$ROOT/$(location :_onos-gui-base-jar) &&" + |
Thomas Vachuska | 3432862 | 2018-08-03 09:21:17 -0700 | [diff] [blame] | 242 | " find . -type f -exec touch -t 201806280000 {} \; &&" + |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 243 | " jar cmf META-INF/MANIFEST.MF $$ROOT/$@ .", |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 244 | output_to_bindir = 1, |
| 245 | visibility = ["//visibility:public"], |
| 246 | ) |