Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | # ----------------------------------------------------------------------------- |
| 3 | # Builds and installs all tools needed for developing and testing P4 support in |
| 4 | # ONOS. |
| 5 | # |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 6 | # Tested on 16.04 and 18.04. |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 7 | # |
| 8 | # Recommended minimum system requirements: |
| 9 | # 4 GB of RAM |
| 10 | # 2 cores |
| 11 | # 8 GB free hard drive space (~4 GB to build everything) |
Carmelo Cascone | 95e5afd | 2018-07-17 14:45:23 +0200 | [diff] [blame] | 12 | # |
| 13 | # To execute up to a given step, pass the step name as the first argument. For |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 14 | # example, to install PI, but not bmv2, p4c, etc: |
Carmelo Cascone | 95e5afd | 2018-07-17 14:45:23 +0200 | [diff] [blame] | 15 | # ./install-p4-tools.sh PI |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 16 | # ----------------------------------------------------------------------------- |
| 17 | |
| 18 | # Exit on errors. |
| 19 | set -e |
Carmelo Cascone | a4dc3c1 | 2019-02-12 17:30:00 -0800 | [diff] [blame] | 20 | set -x |
| 21 | |
Carmelo Cascone | 1537e8e | 2019-06-28 14:30:05 -0700 | [diff] [blame] | 22 | BMV2_COMMIT="10c2d3434a7212631f11d5d1e3bc802ba6365f6a" |
| 23 | PI_COMMIT="0bcaeda2269a4f2f0539cf8eac49868e389a8c18" |
Carmelo Cascone | ada7b5b | 2019-04-23 13:50:03 -0700 | [diff] [blame] | 24 | P4C_COMMIT="e2934ab32ace8a877bf2b34704950a4da69b6202" |
Carmelo Cascone | a4dc3c1 | 2019-02-12 17:30:00 -0800 | [diff] [blame] | 25 | |
| 26 | # p4c seems to break when using protobuf versions newer than 3.2.0 |
| 27 | PROTOBUF_VER=${PROTOBUF_VER:-3.2.0} |
| 28 | GRPC_VER=${GRPC_VER:-1.3.2} |
| 29 | |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 30 | |
| 31 | BUILD_DIR=~/p4tools |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 32 | NUM_CORES=`grep -c ^processor /proc/cpuinfo` |
Carmelo Cascone | f02872d | 2018-06-20 08:49:02 +0200 | [diff] [blame] | 33 | # If false, build tools without debug features to improve throughput of BMv2 and |
Carmelo Cascone | 03ae0ac | 2018-10-11 08:31:59 -0700 | [diff] [blame] | 34 | # reduce CPU/memory footprint. Default is true. |
Carmelo Cascone | f02872d | 2018-06-20 08:49:02 +0200 | [diff] [blame] | 35 | DEBUG_FLAGS=${DEBUG_FLAGS:-true} |
Carmelo Cascone | 95e5afd | 2018-07-17 14:45:23 +0200 | [diff] [blame] | 36 | # Execute up to the given step (first argument), or all if not defined. |
| 37 | LAST_STEP=${1:-all} |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 38 | # PI and BMv2 must be configured differently if we want to use Stratum |
| 39 | USE_STRATUM=${USE_STRATUM:-false} |
| 40 | # Improve time for one-time builds |
| 41 | FAST_BUILD=${FAST_BUILD:-false} |
| 42 | # Remove build artifacts |
| 43 | CLEAN_UP=${CLEAN_UP:-false} |
| 44 | BMV2_INSTALL=/usr/local |
Carmelo Cascone | fb99267 | 2019-07-09 10:26:01 -0700 | [diff] [blame] | 45 | PI_INSTALL=/usr/local |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 46 | set +x |
Carmelo Cascone | 95e5afd | 2018-07-17 14:45:23 +0200 | [diff] [blame] | 47 | |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 48 | function do_requirements { |
| 49 | sudo apt update |
| 50 | sudo apt-get install -y --no-install-recommends \ |
| 51 | autoconf \ |
| 52 | automake \ |
| 53 | bison \ |
| 54 | build-essential \ |
| 55 | cmake \ |
| 56 | cpp \ |
| 57 | curl \ |
| 58 | flex \ |
| 59 | git \ |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 60 | graphviz \ |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 61 | libavl-dev \ |
| 62 | libboost-dev \ |
Carmelo Cascone | b5324e7 | 2018-11-25 02:26:32 -0800 | [diff] [blame] | 63 | libboost-graph-dev \ |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 64 | libboost-program-options-dev \ |
| 65 | libboost-system-dev \ |
| 66 | libboost-filesystem-dev \ |
| 67 | libboost-thread-dev \ |
| 68 | libboost-filesystem-dev \ |
| 69 | libboost-program-options-dev \ |
| 70 | libboost-system-dev \ |
| 71 | libboost-test-dev \ |
| 72 | libboost-thread-dev \ |
| 73 | libc6-dev \ |
| 74 | libev-dev \ |
| 75 | libevent-dev \ |
| 76 | libffi-dev \ |
| 77 | libfl-dev \ |
| 78 | libgc-dev \ |
| 79 | libgc1c2 \ |
| 80 | libgflags-dev \ |
| 81 | libgmp-dev \ |
| 82 | libgmp10 \ |
| 83 | libgmpxx4ldbl \ |
| 84 | libjudy-dev \ |
| 85 | libpcap-dev \ |
| 86 | libpcre3-dev \ |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 87 | libssl-dev \ |
| 88 | libtool \ |
| 89 | make \ |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 90 | pkg-config \ |
Carmelo Cascone | 57defd3 | 2018-05-11 14:34:01 -0700 | [diff] [blame] | 91 | python2.7 \ |
| 92 | python2.7-dev \ |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 93 | tcpdump \ |
| 94 | wget \ |
| 95 | unzip |
| 96 | |
Carmelo Cascone | ada7b5b | 2019-04-23 13:50:03 -0700 | [diff] [blame] | 97 | sudo -H pip2.7 install setuptools cffi ipaddr ipaddress pypcap \ |
| 98 | git+https://github.com/p4lang/scapy-vxlan \ |
| 99 | git+https://github.com/p4lang/ptf.git |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 100 | } |
| 101 | |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 102 | function do_requirements_1604 { |
| 103 | sudo apt-get update |
| 104 | sudo apt-get install -y --no-install-recommends \ |
| 105 | ca-certificates \ |
| 106 | g++ \ |
Kevin Chuang | 53a9d5b | 2018-01-17 15:55:32 +0800 | [diff] [blame] | 107 | libboost-iostreams1.58-dev \ |
Jonghwan Hyun | bfb3a21 | 2018-11-16 11:42:18 +0900 | [diff] [blame] | 108 | libreadline6 \ |
| 109 | libreadline6-dev \ |
| 110 | mktemp |
| 111 | } |
| 112 | |
| 113 | function do_requirements_1804 { |
| 114 | sudo apt-get update |
| 115 | sudo apt-get install -y --no-install-recommends \ |
| 116 | ca-certificates \ |
| 117 | g++ \ |
| 118 | libboost1.65-dev \ |
| 119 | libboost-regex1.65-dev \ |
| 120 | libboost-iostreams1.65-dev \ |
| 121 | libreadline-dev \ |
Carmelo Cascone | a4dc3c1 | 2019-02-12 17:30:00 -0800 | [diff] [blame] | 122 | libssl1.0-dev |
Kevin Chuang | 53a9d5b | 2018-01-17 15:55:32 +0800 | [diff] [blame] | 123 | } |
| 124 | |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 125 | function do_protobuf { |
| 126 | cd ${BUILD_DIR} |
Carmelo Cascone | a4dc3c1 | 2019-02-12 17:30:00 -0800 | [diff] [blame] | 127 | if [[ ! -d protobuf-${PROTOBUF_VER} ]]; then |
| 128 | # Get python package which also includes cpp. |
| 129 | wget https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOBUF_VER}/protobuf-python-${PROTOBUF_VER}.tar.gz |
| 130 | tar -xzf protobuf-python-${PROTOBUF_VER}.tar.gz |
| 131 | rm -r protobuf-python-${PROTOBUF_VER}.tar.gz |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 132 | fi |
Carmelo Cascone | a4dc3c1 | 2019-02-12 17:30:00 -0800 | [diff] [blame] | 133 | cd protobuf-${PROTOBUF_VER} |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 134 | |
| 135 | export CFLAGS="-Os" |
| 136 | export CXXFLAGS="-Os" |
| 137 | export LDFLAGS="-Wl,-s" |
| 138 | ./autogen.sh |
Carmelo Cascone | a4dc3c1 | 2019-02-12 17:30:00 -0800 | [diff] [blame] | 139 | confOpts="--prefix=/usr" |
| 140 | if [[ "${FAST_BUILD}" = true ]] ; then |
| 141 | confOpts="${confOpts} --disable-dependency-tracking" |
| 142 | fi |
| 143 | ./configure ${confOpts} |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 144 | make -j${NUM_CORES} |
| 145 | sudo make install |
| 146 | sudo ldconfig |
| 147 | unset CFLAGS CXXFLAGS LDFLAGS |
Carmelo Cascone | f645e84 | 2018-07-16 18:31:52 +0200 | [diff] [blame] | 148 | |
| 149 | cd python |
Carmelo Cascone | a4dc3c1 | 2019-02-12 17:30:00 -0800 | [diff] [blame] | 150 | # Hack to get the -std=c++11 flag when building 3.6.1 |
| 151 | # https://github.com/protocolbuffers/protobuf/blob/v3.6.1/python/setup.py#L208 |
| 152 | export KOKORO_BUILD_NUMBER="hack" |
Carmelo Cascone | ada7b5b | 2019-04-23 13:50:03 -0700 | [diff] [blame] | 153 | sudo -E python2.7 setup.py build --cpp_implementation |
| 154 | sudo -E pip2.7 install . |
Carmelo Cascone | a4dc3c1 | 2019-02-12 17:30:00 -0800 | [diff] [blame] | 155 | unset KOKORO_BUILD_NUMBER |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | function do_grpc { |
| 159 | cd ${BUILD_DIR} |
Carmelo Cascone | a4dc3c1 | 2019-02-12 17:30:00 -0800 | [diff] [blame] | 160 | if [[ ! -d grpc-${GRPC_VER} ]]; then |
| 161 | git clone --depth 1 --single-branch --branch v${GRPC_VER} https://github.com/grpc/grpc.git grpc-${GRPC_VER} |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 162 | fi |
Carmelo Cascone | a4dc3c1 | 2019-02-12 17:30:00 -0800 | [diff] [blame] | 163 | |
| 164 | cd grpc-${GRPC_VER} |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 165 | git submodule update --init |
| 166 | |
| 167 | export LDFLAGS="-Wl,-s" |
Jonghwan Hyun | bfb3a21 | 2018-11-16 11:42:18 +0900 | [diff] [blame] | 168 | RELEASE=`lsb_release -rs` |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 169 | if version_ge ${RELEASE} 18.04; then |
Jonghwan Hyun | bfb3a21 | 2018-11-16 11:42:18 +0900 | [diff] [blame] | 170 | # Ubuntu 18.04 ships OpenSSL 1.1 by default, which has breaking changes in the API. |
| 171 | # Here, we will build grpc with OpenSSL 1.0. |
| 172 | # (Reference: https://github.com/grpc/grpc/issues/10589) |
| 173 | # Also, set CFLAGS to avoid compilcation error caused by gcc7. |
| 174 | # (Reference: https://github.com/grpc/grpc/issues/13854) |
| 175 | PKG_CONFIG_PATH=/usr/lib/openssl-1.0/pkgconfig make -j${NUM_CORES} CFLAGS='-Wno-error' |
| 176 | else |
| 177 | make -j${NUM_CORES} |
| 178 | fi |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 179 | sudo make install |
| 180 | sudo ldconfig |
| 181 | unset LDFLAGS |
Carmelo Cascone | f645e84 | 2018-07-16 18:31:52 +0200 | [diff] [blame] | 182 | |
Carmelo Cascone | ada7b5b | 2019-04-23 13:50:03 -0700 | [diff] [blame] | 183 | sudo pip2.7 install -r requirements.txt |
| 184 | sudo pip2.7 install . |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 185 | } |
| 186 | |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 187 | function checkout_bmv2 { |
| 188 | cd ${BUILD_DIR} |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 189 | if [[ ! -d bmv2 ]]; then |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 190 | git clone https://github.com/p4lang/behavioral-model.git bmv2 |
| 191 | fi |
| 192 | cd bmv2 |
| 193 | git fetch |
| 194 | git checkout ${BMV2_COMMIT} |
| 195 | } |
| 196 | |
| 197 | function do_pi_bmv2_deps { |
| 198 | checkout_bmv2 |
| 199 | # From bmv2's install_deps.sh. |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 200 | tmpdir=`mktemp -d -p .` |
| 201 | cd ${tmpdir} |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 202 | if [[ "${USE_STRATUM}" = false ]] ; then |
| 203 | bash ../travis/install-thrift.sh |
| 204 | fi |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 205 | sudo ldconfig |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 206 | cd .. |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 207 | sudo rm -rf ${tmpdir} |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 208 | } |
| 209 | |
Carmelo Cascone | 95e5afd | 2018-07-17 14:45:23 +0200 | [diff] [blame] | 210 | function do_PI { |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 211 | cd ${BUILD_DIR} |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 212 | if [[ ! -d PI ]]; then |
Carmelo Cascone | 95e5afd | 2018-07-17 14:45:23 +0200 | [diff] [blame] | 213 | git clone https://github.com/p4lang/PI.git |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 214 | fi |
Carmelo Cascone | 95e5afd | 2018-07-17 14:45:23 +0200 | [diff] [blame] | 215 | cd PI |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 216 | git fetch |
| 217 | git checkout ${PI_COMMIT} |
| 218 | git submodule update --init --recursive |
| 219 | |
| 220 | ./autogen.sh |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 221 | if [[ "${USE_STRATUM}" = false ]] ; then |
Carmelo Cascone | fb99267 | 2019-07-09 10:26:01 -0700 | [diff] [blame] | 222 | ./configure --with-proto --without-internal-rpc --without-cli --prefix=${PI_INSTALL} |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 223 | else |
| 224 | # Configure for Stratum |
Carmelo Cascone | fb99267 | 2019-07-09 10:26:01 -0700 | [diff] [blame] | 225 | ./configure --without-bmv2 --with-proto --with-fe-cpp --without-cli --without-internal-rpc --prefix=${PI_INSTALL} |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 226 | fi |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 227 | make -j${NUM_CORES} |
| 228 | sudo make install |
| 229 | sudo ldconfig |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | function do_bmv2 { |
| 233 | checkout_bmv2 |
| 234 | |
| 235 | ./autogen.sh |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 236 | |
| 237 | confOpts="--with-pi --disable-elogger --without-nanomsg --without-targets" |
Carmelo Cascone | 4b2ff04 | 2019-04-16 13:25:10 -0700 | [diff] [blame] | 238 | # We are building --without-targets but we know for sure we need those |
| 239 | # parts of the BMv2 PI library for simple_switch. |
| 240 | cppFlags="-I${PWD}/targets/simple_switch -DWITH_SIMPLE_SWITCH" |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 241 | if [[ "${FAST_BUILD}" = true ]] ; then |
| 242 | confOpts="${confOpts} --disable-dependency-tracking" |
Carmelo Cascone | f02872d | 2018-06-20 08:49:02 +0200 | [diff] [blame] | 243 | fi |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 244 | if [[ "${DEBUG_FLAGS}" = false ]] ; then |
| 245 | confOpts="${confOpts} --disable-logging-macros" |
| 246 | fi |
| 247 | if [[ "${USE_STRATUM}" = true ]] ; then |
Carmelo Cascone | 4b2ff04 | 2019-04-16 13:25:10 -0700 | [diff] [blame] | 248 | confOpts="--prefix=${BMV2_INSTALL} --without-thrift ${confOpts}" |
Carmelo Cascone | fb99267 | 2019-07-09 10:26:01 -0700 | [diff] [blame] | 249 | cppFlags="${cppFlags} -isystem${BMV2_INSTALL}/include -isystem${PI_INSTALL}/include -L${PI_INSTALL}/lib" |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 250 | fi |
Carmelo Cascone | 4b2ff04 | 2019-04-16 13:25:10 -0700 | [diff] [blame] | 251 | confCmd="./configure CPPFLAGS=\"${cppFlags}\" ${confOpts}" |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 252 | eval ${confCmd} |
| 253 | |
| 254 | make -j${NUM_CORES} |
| 255 | sudo make install |
| 256 | cd targets/simple_switch |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 257 | make -j${NUM_CORES} |
| 258 | sudo make install |
| 259 | sudo ldconfig |
| 260 | |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 261 | if [[ "${USE_STRATUM}" = false ]] ; then |
| 262 | # Simple_switch_grpc target (not using Stratum) |
Carmelo Cascone | a4dc3c1 | 2019-02-12 17:30:00 -0800 | [diff] [blame] | 263 | cd ../simple_switch_grpc |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 264 | ./autogen.sh |
| 265 | ./configure --with-thrift |
| 266 | make -j${NUM_CORES} |
| 267 | sudo make install |
| 268 | sudo ldconfig |
| 269 | fi |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | function do_p4c { |
| 273 | cd ${BUILD_DIR} |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 274 | if [[ ! -d p4c ]]; then |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 275 | git clone https://github.com/p4lang/p4c.git |
| 276 | fi |
| 277 | cd p4c |
| 278 | git fetch |
| 279 | git checkout ${P4C_COMMIT} |
| 280 | git submodule update --init --recursive |
| 281 | |
| 282 | mkdir -p build |
| 283 | cd build |
Carmelo Cascone | 03ae0ac | 2018-10-11 08:31:59 -0700 | [diff] [blame] | 284 | cmake .. -DENABLE_EBPF=OFF |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 285 | make -j${NUM_CORES} |
| 286 | sudo make install |
| 287 | sudo ldconfig |
| 288 | } |
| 289 | |
| 290 | function check_commit { |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 291 | if [[ ! -e $2 ]]; then |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 292 | return 0 # true |
| 293 | fi |
| 294 | if [[ $(< $2) != "$1" ]]; then |
| 295 | return 0 # true |
| 296 | fi |
| 297 | return 1 # false |
| 298 | } |
| 299 | |
| 300 | # The following is borrowed from Mininet's util/install.sh |
| 301 | function version_ge { |
| 302 | # sort -V sorts by *version number* |
| 303 | latest=`printf "$1\n$2" | sort -V | tail -1` |
| 304 | # If $1 is latest version, then $1 >= $2 |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 305 | [[ "$1" == "$latest" ]] |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 306 | } |
| 307 | |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 308 | function missing_lib { |
Carmelo Cascone | e45902b | 2018-12-18 13:30:45 -0800 | [diff] [blame] | 309 | ldconfig -p | grep $1 &> /dev/null |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 310 | if [[ $? == 0 ]]; then |
Carmelo Cascone | e45902b | 2018-12-18 13:30:45 -0800 | [diff] [blame] | 311 | echo "$1 found!" |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 312 | return 1 # false |
Carmelo Cascone | e45902b | 2018-12-18 13:30:45 -0800 | [diff] [blame] | 313 | fi |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 314 | return 0 # true |
| 315 | } |
| 316 | |
Carmelo Cascone | a4dc3c1 | 2019-02-12 17:30:00 -0800 | [diff] [blame] | 317 | function missing_protoc { |
| 318 | command -v protoc >/dev/null 2>&1 |
| 319 | if [[ $? == 0 ]]; then |
| 320 | protoc --version | grep $1 &> /dev/null |
| 321 | if [[ $? == 0 ]]; then |
| 322 | echo "protoc ${1} found!" |
| 323 | else |
| 324 | echo "A version of protoc was found, but not $1 (you may experience issues)" |
| 325 | fi |
| 326 | return 1 # false |
| 327 | fi |
| 328 | return 0 # true |
| 329 | } |
| 330 | |
| 331 | function missing_grpc { |
| 332 | # Is there a better way to check if a specific version of grpc is installed? |
| 333 | if [[ -f /usr/local/lib/libgrpc++.so ]]; then |
| 334 | ls -l /usr/local/lib/libgrpc++.so | grep libgrpc++.so.${1} &> /dev/null |
| 335 | if [[ $? == 0 ]]; then |
| 336 | echo "grpc ${1} found!" |
| 337 | else |
| 338 | echo "A version of grpc was found, but not $1 (you may experience issues)" |
| 339 | fi |
| 340 | return 1 # false |
| 341 | else |
| 342 | return 0 # true |
| 343 | fi |
| 344 | } |
| 345 | |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 346 | function all_done { |
| 347 | if [[ "${CLEAN_UP}" = true ]] ; then |
| 348 | echo "Cleaning up build dir... ${BUILD_DIR})" |
| 349 | sudo rm -rf ${BUILD_DIR} |
| 350 | fi |
| 351 | echo "Done!" |
| 352 | exit 0 |
Carmelo Cascone | e45902b | 2018-12-18 13:30:45 -0800 | [diff] [blame] | 353 | } |
| 354 | |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 355 | MUST_DO_ALL=false |
| 356 | DID_REQUIREMENTS=false |
| 357 | function check_and_do { |
| 358 | # Check if the latest built commit is the same we are trying to build now, |
| 359 | # or if all projects must be built. If true builds this project. |
| 360 | commit_id="$1" |
| 361 | proj_dir="$2" |
| 362 | func_name="$3" |
Carmelo Cascone | 95e5afd | 2018-07-17 14:45:23 +0200 | [diff] [blame] | 363 | step_name="$4" |
| 364 | commit_file=${BUILD_DIR}/${proj_dir}/.last_built_commit_${step_name} |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 365 | if [[ ${MUST_DO_ALL} = true ]] \ |
Carmelo Cascone | 95e5afd | 2018-07-17 14:45:23 +0200 | [diff] [blame] | 366 | || check_commit ${commit_id} ${commit_file}; then |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 367 | echo "#" |
Carmelo Cascone | 95e5afd | 2018-07-17 14:45:23 +0200 | [diff] [blame] | 368 | echo "# Building ${step_name} (${commit_id})" |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 369 | echo "#" |
| 370 | # Print commands used to install to aid debugging |
| 371 | set -x |
| 372 | if ! ${DID_REQUIREMENTS} = true; then |
| 373 | do_requirements |
| 374 | # TODO consider other Linux distros; presently this script assumes |
| 375 | # that it is running on Ubuntu. |
| 376 | RELEASE=`lsb_release -rs` |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 377 | if version_ge ${RELEASE} 18.04; then |
Jonghwan Hyun | bfb3a21 | 2018-11-16 11:42:18 +0900 | [diff] [blame] | 378 | do_requirements_1804 |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 379 | elif version_ge ${RELEASE} 16.04; then |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 380 | do_requirements_1604 |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 381 | else |
| 382 | echo "Ubuntu version $RELEASE is not supported" |
| 383 | exit 1 |
| 384 | fi |
| 385 | DID_REQUIREMENTS=true |
| 386 | fi |
| 387 | eval ${func_name} |
Carmelo Cascone | e45902b | 2018-12-18 13:30:45 -0800 | [diff] [blame] | 388 | if [[ -d ${BUILD_DIR}/${proj_dir} ]]; then |
| 389 | # If project was built, we expect its dir. Otherwise, we assume |
| 390 | # build was skipped. |
| 391 | echo ${commit_id} > ${commit_file} |
| 392 | # Build all next projects as they might depend on this one. |
| 393 | MUST_DO_ALL=true |
| 394 | fi |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 395 | # Disable printing to reduce output |
| 396 | set +x |
| 397 | else |
Carmelo Cascone | 95e5afd | 2018-07-17 14:45:23 +0200 | [diff] [blame] | 398 | echo "${step_name} is up to date (commit ${commit_id})" |
| 399 | fi |
| 400 | # Exit if last step. |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 401 | if [[ ${step_name} = ${LAST_STEP} ]]; then |
| 402 | all_done |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 403 | fi |
| 404 | } |
| 405 | |
| 406 | mkdir -p ${BUILD_DIR} |
| 407 | cd ${BUILD_DIR} |
| 408 | # In dependency order. |
Carmelo Cascone | a4dc3c1 | 2019-02-12 17:30:00 -0800 | [diff] [blame] | 409 | if missing_protoc ${PROTOBUF_VER}; then |
| 410 | check_and_do ${PROTOBUF_VER} protobuf-${PROTOBUF_VER} do_protobuf protobuf |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 411 | fi |
Carmelo Cascone | a4dc3c1 | 2019-02-12 17:30:00 -0800 | [diff] [blame] | 412 | if missing_grpc ${GRPC_VER}; then |
| 413 | check_and_do ${GRPC_VER} grpc-${GRPC_VER} do_grpc grpc |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 414 | fi |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 415 | check_and_do ${BMV2_COMMIT} bmv2 do_pi_bmv2_deps bmv2-deps |
Carmelo Cascone | 95e5afd | 2018-07-17 14:45:23 +0200 | [diff] [blame] | 416 | check_and_do ${PI_COMMIT} PI do_PI PI |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 417 | check_and_do ${BMV2_COMMIT} bmv2 do_bmv2 bmv2 |
| 418 | check_and_do ${P4C_COMMIT} p4c do_p4c p4c |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 419 | |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 420 | all_done |