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