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