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 | ab5d41e | 2019-03-06 18:02:34 -0800 | [diff] [blame] | 22 | BMV2_COMMIT="5d25d0d94681492d155d3e5b72b16a56121f8dfe" |
Carmelo Cascone | a4dc3c1 | 2019-02-12 17:30:00 -0800 | [diff] [blame] | 23 | PI_COMMIT="81b7e84bf8c27ce87571f66e5ccc76ce228caa8c" |
| 24 | P4C_COMMIT="5ae390430bd025b301854cd04c78b1ff9902180f" |
| 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 | |
Charles Chan | 87dc82e | 2018-08-05 16:27:10 -0700 | [diff] [blame] | 96 | sudo -H pip install setuptools cffi ipaddr ipaddress pypcap |
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" |
| 235 | if [[ "${FAST_BUILD}" = true ]] ; then |
| 236 | confOpts="${confOpts} --disable-dependency-tracking" |
Carmelo Cascone | f02872d | 2018-06-20 08:49:02 +0200 | [diff] [blame] | 237 | fi |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 238 | if [[ "${DEBUG_FLAGS}" = false ]] ; then |
| 239 | confOpts="${confOpts} --disable-logging-macros" |
| 240 | fi |
| 241 | if [[ "${USE_STRATUM}" = true ]] ; then |
| 242 | confOpts="CPPFLAGS=\"-isystem${BMV2_INSTALL}/include\" --prefix=${BMV2_INSTALL} --without-thrift ${confOpts}" |
| 243 | fi |
| 244 | confCmd="./configure ${confOpts}" |
| 245 | eval ${confCmd} |
| 246 | |
| 247 | make -j${NUM_CORES} |
| 248 | sudo make install |
| 249 | cd targets/simple_switch |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 250 | make -j${NUM_CORES} |
| 251 | sudo make install |
| 252 | sudo ldconfig |
| 253 | |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 254 | if [[ "${USE_STRATUM}" = false ]] ; then |
| 255 | # Simple_switch_grpc target (not using Stratum) |
Carmelo Cascone | a4dc3c1 | 2019-02-12 17:30:00 -0800 | [diff] [blame] | 256 | cd ../simple_switch_grpc |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 257 | ./autogen.sh |
| 258 | ./configure --with-thrift |
| 259 | make -j${NUM_CORES} |
| 260 | sudo make install |
| 261 | sudo ldconfig |
| 262 | fi |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | function do_p4c { |
| 266 | cd ${BUILD_DIR} |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 267 | if [[ ! -d p4c ]]; then |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 268 | git clone https://github.com/p4lang/p4c.git |
| 269 | fi |
| 270 | cd p4c |
| 271 | git fetch |
| 272 | git checkout ${P4C_COMMIT} |
| 273 | git submodule update --init --recursive |
| 274 | |
| 275 | mkdir -p build |
| 276 | cd build |
Carmelo Cascone | 03ae0ac | 2018-10-11 08:31:59 -0700 | [diff] [blame] | 277 | cmake .. -DENABLE_EBPF=OFF |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 278 | make -j${NUM_CORES} |
| 279 | sudo make install |
| 280 | sudo ldconfig |
| 281 | } |
| 282 | |
Carmelo Cascone | 95e5afd | 2018-07-17 14:45:23 +0200 | [diff] [blame] | 283 | function do_scapy-vxlan { |
Carmelo Cascone | 76b3ee6 | 2018-01-30 15:45:27 -0800 | [diff] [blame] | 284 | cd ${BUILD_DIR} |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 285 | if [[ ! -d scapy-vxlan ]]; then |
Carmelo Cascone | 95e5afd | 2018-07-17 14:45:23 +0200 | [diff] [blame] | 286 | git clone https://github.com/p4lang/scapy-vxlan.git |
Carmelo Cascone | 76b3ee6 | 2018-01-30 15:45:27 -0800 | [diff] [blame] | 287 | fi |
Carmelo Cascone | 95e5afd | 2018-07-17 14:45:23 +0200 | [diff] [blame] | 288 | cd scapy-vxlan |
| 289 | |
Carmelo Cascone | 76b3ee6 | 2018-01-30 15:45:27 -0800 | [diff] [blame] | 290 | git pull origin master |
| 291 | |
Carmelo Cascone | 95e5afd | 2018-07-17 14:45:23 +0200 | [diff] [blame] | 292 | sudo python setup.py install |
| 293 | } |
| 294 | |
| 295 | function do_ptf { |
| 296 | cd ${BUILD_DIR} |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 297 | if [[ ! -d ptf ]]; then |
Carmelo Cascone | 95e5afd | 2018-07-17 14:45:23 +0200 | [diff] [blame] | 298 | git clone https://github.com/p4lang/ptf.git |
| 299 | fi |
| 300 | cd ptf |
| 301 | git pull origin master |
| 302 | |
| 303 | sudo python setup.py install |
Carmelo Cascone | 76b3ee6 | 2018-01-30 15:45:27 -0800 | [diff] [blame] | 304 | } |
| 305 | |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 306 | function check_commit { |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 307 | if [[ ! -e $2 ]]; then |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 308 | return 0 # true |
| 309 | fi |
| 310 | if [[ $(< $2) != "$1" ]]; then |
| 311 | return 0 # true |
| 312 | fi |
| 313 | return 1 # false |
| 314 | } |
| 315 | |
| 316 | # The following is borrowed from Mininet's util/install.sh |
| 317 | function version_ge { |
| 318 | # sort -V sorts by *version number* |
| 319 | latest=`printf "$1\n$2" | sort -V | tail -1` |
| 320 | # If $1 is latest version, then $1 >= $2 |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 321 | [[ "$1" == "$latest" ]] |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 322 | } |
| 323 | |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 324 | function missing_lib { |
Carmelo Cascone | e45902b | 2018-12-18 13:30:45 -0800 | [diff] [blame] | 325 | ldconfig -p | grep $1 &> /dev/null |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 326 | if [[ $? == 0 ]]; then |
Carmelo Cascone | e45902b | 2018-12-18 13:30:45 -0800 | [diff] [blame] | 327 | echo "$1 found!" |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 328 | return 1 # false |
Carmelo Cascone | e45902b | 2018-12-18 13:30:45 -0800 | [diff] [blame] | 329 | fi |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 330 | return 0 # true |
| 331 | } |
| 332 | |
Carmelo Cascone | a4dc3c1 | 2019-02-12 17:30:00 -0800 | [diff] [blame] | 333 | function missing_protoc { |
| 334 | command -v protoc >/dev/null 2>&1 |
| 335 | if [[ $? == 0 ]]; then |
| 336 | protoc --version | grep $1 &> /dev/null |
| 337 | if [[ $? == 0 ]]; then |
| 338 | echo "protoc ${1} found!" |
| 339 | else |
| 340 | echo "A version of protoc was found, but not $1 (you may experience issues)" |
| 341 | fi |
| 342 | return 1 # false |
| 343 | fi |
| 344 | return 0 # true |
| 345 | } |
| 346 | |
| 347 | function missing_grpc { |
| 348 | # Is there a better way to check if a specific version of grpc is installed? |
| 349 | if [[ -f /usr/local/lib/libgrpc++.so ]]; then |
| 350 | ls -l /usr/local/lib/libgrpc++.so | grep libgrpc++.so.${1} &> /dev/null |
| 351 | if [[ $? == 0 ]]; then |
| 352 | echo "grpc ${1} found!" |
| 353 | else |
| 354 | echo "A version of grpc was found, but not $1 (you may experience issues)" |
| 355 | fi |
| 356 | return 1 # false |
| 357 | else |
| 358 | return 0 # true |
| 359 | fi |
| 360 | } |
| 361 | |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 362 | function all_done { |
| 363 | if [[ "${CLEAN_UP}" = true ]] ; then |
| 364 | echo "Cleaning up build dir... ${BUILD_DIR})" |
| 365 | sudo rm -rf ${BUILD_DIR} |
| 366 | fi |
| 367 | echo "Done!" |
| 368 | exit 0 |
Carmelo Cascone | e45902b | 2018-12-18 13:30:45 -0800 | [diff] [blame] | 369 | } |
| 370 | |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 371 | MUST_DO_ALL=false |
| 372 | DID_REQUIREMENTS=false |
| 373 | function check_and_do { |
| 374 | # Check if the latest built commit is the same we are trying to build now, |
| 375 | # or if all projects must be built. If true builds this project. |
| 376 | commit_id="$1" |
| 377 | proj_dir="$2" |
| 378 | func_name="$3" |
Carmelo Cascone | 95e5afd | 2018-07-17 14:45:23 +0200 | [diff] [blame] | 379 | step_name="$4" |
| 380 | commit_file=${BUILD_DIR}/${proj_dir}/.last_built_commit_${step_name} |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 381 | if [[ ${MUST_DO_ALL} = true ]] \ |
Carmelo Cascone | 95e5afd | 2018-07-17 14:45:23 +0200 | [diff] [blame] | 382 | || check_commit ${commit_id} ${commit_file}; then |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 383 | echo "#" |
Carmelo Cascone | 95e5afd | 2018-07-17 14:45:23 +0200 | [diff] [blame] | 384 | echo "# Building ${step_name} (${commit_id})" |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 385 | echo "#" |
| 386 | # Print commands used to install to aid debugging |
| 387 | set -x |
| 388 | if ! ${DID_REQUIREMENTS} = true; then |
| 389 | do_requirements |
| 390 | # TODO consider other Linux distros; presently this script assumes |
| 391 | # that it is running on Ubuntu. |
| 392 | RELEASE=`lsb_release -rs` |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 393 | if version_ge ${RELEASE} 18.04; then |
Jonghwan Hyun | bfb3a21 | 2018-11-16 11:42:18 +0900 | [diff] [blame] | 394 | do_requirements_1804 |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 395 | elif version_ge ${RELEASE} 16.04; then |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 396 | do_requirements_1604 |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 397 | else |
| 398 | echo "Ubuntu version $RELEASE is not supported" |
| 399 | exit 1 |
| 400 | fi |
| 401 | DID_REQUIREMENTS=true |
| 402 | fi |
| 403 | eval ${func_name} |
Carmelo Cascone | e45902b | 2018-12-18 13:30:45 -0800 | [diff] [blame] | 404 | if [[ -d ${BUILD_DIR}/${proj_dir} ]]; then |
| 405 | # If project was built, we expect its dir. Otherwise, we assume |
| 406 | # build was skipped. |
| 407 | echo ${commit_id} > ${commit_file} |
| 408 | # Build all next projects as they might depend on this one. |
| 409 | MUST_DO_ALL=true |
| 410 | fi |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 411 | # Disable printing to reduce output |
| 412 | set +x |
| 413 | else |
Carmelo Cascone | 95e5afd | 2018-07-17 14:45:23 +0200 | [diff] [blame] | 414 | echo "${step_name} is up to date (commit ${commit_id})" |
| 415 | fi |
| 416 | # Exit if last step. |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 417 | if [[ ${step_name} = ${LAST_STEP} ]]; then |
| 418 | all_done |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 419 | fi |
| 420 | } |
| 421 | |
| 422 | mkdir -p ${BUILD_DIR} |
| 423 | cd ${BUILD_DIR} |
| 424 | # In dependency order. |
Carmelo Cascone | a4dc3c1 | 2019-02-12 17:30:00 -0800 | [diff] [blame] | 425 | if missing_protoc ${PROTOBUF_VER}; then |
| 426 | check_and_do ${PROTOBUF_VER} protobuf-${PROTOBUF_VER} do_protobuf protobuf |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 427 | fi |
Carmelo Cascone | a4dc3c1 | 2019-02-12 17:30:00 -0800 | [diff] [blame] | 428 | if missing_grpc ${GRPC_VER}; then |
| 429 | check_and_do ${GRPC_VER} grpc-${GRPC_VER} do_grpc grpc |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 430 | fi |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 431 | check_and_do ${BMV2_COMMIT} bmv2 do_pi_bmv2_deps bmv2-deps |
Carmelo Cascone | 95e5afd | 2018-07-17 14:45:23 +0200 | [diff] [blame] | 432 | check_and_do ${PI_COMMIT} PI do_PI PI |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 433 | check_and_do ${BMV2_COMMIT} bmv2 do_bmv2 bmv2 |
| 434 | check_and_do ${P4C_COMMIT} p4c do_p4c p4c |
Carmelo Cascone | 95e5afd | 2018-07-17 14:45:23 +0200 | [diff] [blame] | 435 | check_and_do master scapy-vxlan do_scapy-vxlan scapy-vxlan |
| 436 | check_and_do master ptf do_ptf ptf |
Carmelo Cascone | b7e618d | 2018-01-12 18:31:33 -0800 | [diff] [blame] | 437 | |
Carmelo Cascone | 7c82bcf | 2019-02-08 22:57:18 -0800 | [diff] [blame] | 438 | all_done |