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 | """ |
| 93 | dependency to expose all webapp files in the sandbox |
| 94 | """ |
| 95 | |
| 96 | filegroup( |
| 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 | |
| 107 | genrule( |
| 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 |
| 122 | " export BABEL_DISABLE_CACHE=1" + # turn off babel cache |
| 123 | " NPM=$$ROOT/$(location @nodejs//:bin/npm) &&" + |
| 124 | " mkdir -p tools/gui &&" + |
| 125 | " cd tools/gui &&" + |
| 126 | " tar xf ../../$(location //tools/gui:tools-gui-gulp) &&" + |
| 127 | " $$NPM install --no-cache --loglevel=error >npm-install.out 2>&1 &&" + |
| 128 | " tar hcf $$ROOT/$@ package.json gulpfile.babel.js node_modules gulp-tasks", |
| 129 | ) |
| 130 | |
| 131 | """ |
| 132 | Run npm build to create node.js files |
| 133 | """ |
| 134 | |
| 135 | genrule( |
| 136 | name = "_onos-gui-npm-build", |
| 137 | srcs = [ |
| 138 | "@nodejs//:bin/npm", |
| 139 | "@nodejs//:bin/node", |
| 140 | ":_onos-gui-npm-install", |
| 141 | ":_web_app_all", |
| 142 | ], |
| 143 | outs = ["onos-gui-npm-build.tar"], |
| 144 | cmd = "(ROOT=`pwd` &&" + |
| 145 | " export XDG_CONFIG_HOME=$(@D)/config &&" + |
| 146 | " export BABEL_DISABLE_CACHE=1" + |
| 147 | " NPM=$(location @nodejs//:bin/npm) &&" + |
| 148 | " (mkdir -p web/gui && cd web/gui && tar xf ../../$(location :_web_app_all)) &&" + |
| 149 | " mkdir -p tools/gui && cd tools/gui &&" + |
| 150 | " tar xf $$ROOT/$(location :_onos-gui-npm-install) &&" + |
| 151 | " $$ROOT/$$NPM run build --no-cache --loglevel=error >npm-build.out &&" + |
| 152 | " cd ../../web/gui/src/main/webapp &&" + |
| 153 | " jar cf $$ROOT/$@ dist vendor data tests README.md _doc _dev app/fw app/*.css app/*.js app/*.txt)", |
| 154 | ) |
| 155 | |
| 156 | """ |
| 157 | Make a jar file of all the webapp files. Useful for breaking symblic links in the sandbox |
| 158 | """ |
| 159 | |
| 160 | genrule( |
| 161 | name = "_web_app_all", |
| 162 | srcs = [":_src_main_webapp_files"], |
| 163 | outs = ["web_app_all.tar"], |
| 164 | cmd = "cd web/gui && tar hcf ../../$@ src/main/webapp", |
| 165 | ) |
| 166 | |
| 167 | """ |
| 168 | app/view is packaged as a tar file because it has subdirectories that need to be preserved |
| 169 | """ |
| 170 | |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 171 | genrule( |
| 172 | name = "_app_view_tar", |
| 173 | srcs = glob(["src/main/webapp/app/view/**"]), |
| 174 | outs = ["app_view_tar.tar"], |
| 175 | cmd = " ROOT=`pwd` &&" + |
| 176 | " cd web/gui/src/main/webapp/app/view &&" + |
Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 177 | " tar hcf $$ROOT/$@ .", |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 178 | ) |
| 179 | |
Ray Milkey | d7be362 | 2018-07-12 10:29:21 -0700 | [diff] [blame] | 180 | """ |
| 181 | Builds the java jar for the java code provided by the GUI |
| 182 | """ |
| 183 | |
| 184 | osgi_jar_with_tests( |
| 185 | name = "_onos-gui-base-jar", |
| 186 | exclude_tests = [ |
| 187 | "org.onosproject.ui.impl.AbstractUiImplTest", |
| 188 | "org.onosproject.ui.impl.topo.model.AbstractTopoModelTest", |
| 189 | ], |
| 190 | test_deps = TEST_DEPS, |
| 191 | web_context = "/onos/ui", |
| 192 | deps = COMPILE_DEPS, |
| 193 | ) |
| 194 | |
| 195 | """ |
| 196 | Builds the tar ball for the ONOS GUI |
| 197 | """ |
| 198 | |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 199 | genrule( |
| 200 | name = "onos-gui", |
| 201 | srcs = [ |
| 202 | ":_onos-gui-npm-build", |
| 203 | ":_onos-gui-base-jar", |
| 204 | ":_root_level_files", |
| 205 | ":_web_inf_classes_files", |
| 206 | ":_raw_classes_files", |
| 207 | ":_app_view_tar", |
| 208 | ], |
| 209 | outs = ["onos-gui.jar"], |
| 210 | cmd = " ROOT=`pwd` &&" + |
| 211 | " mkdir -p gui/WEB-INF/classes &&" + |
| 212 | " cd gui &&" + |
| 213 | " tar xf $$ROOT/$(location :_onos-gui-npm-build) &&" + |
| 214 | " (cd WEB-INF/classes && mkdir -p app/view && cd app/view && tar xf $$ROOT/$(location :_app_view_tar)) &&" + |
| 215 | " for i in $(locations :_root_level_files); do cp $$ROOT/$$i .; done &&" + |
| 216 | " 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] | 217 | " mkdir ./WEB-INF/classes/raw && " + |
| 218 | " 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] | 219 | " jar xf $$ROOT/$(location :_onos-gui-base-jar) &&" + |
| 220 | " jar cmf META-INF/MANIFEST.MF $$ROOT/$@ .", |
Ray Milkey | 6b3775a | 2018-06-28 11:18:44 -0700 | [diff] [blame] | 221 | output_to_bindir = 1, |
| 222 | visibility = ["//visibility:public"], |
| 223 | ) |