travis.sh 8.66 KB
Newer Older
Tamir Duberstein's avatar
Tamir Duberstein committed
1
#!/usr/bin/env bash
2

3 4 5 6 7 8 9 10
# Note: travis currently does not support testing more than one language so the
# .travis.yml cheats and claims to only be cpp.  If they add multiple language
# support, this should probably get updated to install steps and/or
# rvm/gemfile/jdk/etc. entries rather than manually doing the work.

# .travis.yml uses matrix.exclude to block the cases where app-get can't be
# use to install things.

11 12 13
# For when some other test needs the C++ main build, including protoc and
# libprotobuf.
internal_build_cpp() {
14 15 16 17 18 19 20 21
  if [ $(uname -s) == "Linux" ]; then
    # Install GCC 4.8 to replace the default GCC 4.6. We need 4.8 for more
    # decent C++ 11 support in order to compile conformance tests.
    sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
    sudo apt-get update -qq
    sudo apt-get install -qq g++-4.8
    export CXX="g++-4.8" CC="gcc-4.8"
  fi
22

23 24 25
  ./autogen.sh
  ./configure
  make -j2
26 27 28 29
}

build_cpp() {
  internal_build_cpp
30 31 32 33 34 35 36 37 38 39
  make check -j2
  cd conformance && make test_cpp && cd ..
}

build_cpp_distcheck() {
  ./autogen.sh
  ./configure
  make distcheck -j2
}

40
build_csharp() {
41 42 43 44 45
  # Just for the conformance tests. We don't currently
  # need to really build protoc, but it's simplest to keep with the
  # conventions of the other builds.
  internal_build_cpp

46 47 48 49 50 51 52 53 54 55
  # Install latest version of Mono
  sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
  echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
  echo "deb http://download.mono-project.com/repo/debian wheezy-libtiff-compat main" | sudo tee -a /etc/apt/sources.list.d/mono-xamarin.list
  sudo apt-get update -qq
  sudo apt-get install -qq mono-devel referenceassemblies-pcl nunit
  wget www.nuget.org/NuGet.exe -O nuget.exe

  (cd csharp/src; mono ../../nuget.exe restore)
  csharp/buildall.sh
56
  cd conformance && make test_csharp && cd ..
57 58
}

Tim Swast's avatar
Tim Swast committed
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
build_golang() {
  # Go build needs `protoc`.
  internal_build_cpp
  # Add protoc to the path so that the examples build finds it.
  export PATH="`pwd`/src:$PATH"

  # Install Go and the Go protobuf compiler plugin.
  sudo apt-get update -qq
  sudo apt-get install -qq golang
  export GOPATH="$HOME/gocode"
  mkdir -p "$GOPATH/src/github.com/google"
  ln -s "`pwd`" "$GOPATH/src/github.com/google/protobuf"
  export PATH="$GOPATH/bin:$PATH"
  go get github.com/golang/protobuf/protoc-gen-go

  cd examples && make gotest && cd ..
}

77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
use_java() {
  version=$1
  case "$version" in
    jdk6)
      sudo apt-get install openjdk-6-jdk
      export PATH=/usr/lib/jvm/java-6-openjdk-amd64/bin:$PATH
      ;;
    jdk7)
      sudo apt-get install openjdk-7-jdk
      export PATH=/usr/lib/jvm/java-7-openjdk-amd64/bin:$PATH
      ;;
    oracle7)
      sudo apt-get install python-software-properties # for apt-add-repository
      echo "oracle-java7-installer shared/accepted-oracle-license-v1-1 select true" | \
        sudo debconf-set-selections
      yes | sudo apt-add-repository ppa:webupd8team/java
      yes | sudo apt-get install oracle-java7-installer
      export PATH=/usr/lib/jvm/java-7-oracle/bin:$PATH
      ;;
  esac

  which java
  java -version
}

build_java() {
103 104 105 106 107 108 109 110
  # Java build needs `protoc`.
  internal_build_cpp
  cd java && mvn test && mvn install
  cd util && mvn test
  cd ../..
}

build_java_with_conformance_tests() {
111
  # Java build needs `protoc`.
112
  internal_build_cpp
Feng Xiao's avatar
Feng Xiao committed
113 114 115
  cd java && mvn test && mvn install
  cd util && mvn test && mvn assembly:single
  cd ../..
116 117 118 119 120
  cd conformance && make test_java && cd ..
}

build_javanano() {
  # Java build needs `protoc`.
121
  internal_build_cpp
122 123 124 125 126 127 128 129 130
  cd javanano && mvn test && cd ..
}

build_java_jdk6() {
  use_java jdk6
  build_java
}
build_java_jdk7() {
  use_java jdk7
131
  build_java_with_conformance_tests
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
}
build_java_oracle7() {
  use_java oracle7
  build_java
}

build_javanano_jdk6() {
  use_java jdk6
  build_javanano
}
build_javanano_jdk7() {
  use_java jdk7
  build_javanano
}
build_javanano_oracle7() {
  use_java oracle7
  build_javanano
}

151
internal_install_python_deps() {
152 153 154 155 156 157
  # Install tox (OS X doesn't have pip).
  if [ $(uname -s) == "Darwin" ]; then
    sudo easy_install tox
  else
    sudo pip install tox
  fi
158
  # Only install Python2.6/3.x on Linux.
159 160 161 162 163
  if [ $(uname -s) == "Linux" ]; then
    sudo apt-get install -y python-software-properties # for apt-add-repository
    sudo apt-add-repository -y ppa:fkrull/deadsnakes
    sudo apt-get update -qq
    sudo apt-get install -y python2.6 python2.6-dev
164 165
    sudo apt-get install -y python3.3 python3.3-dev
    sudo apt-get install -y python3.4 python3.4-dev
166
  fi
167 168
}

169 170 171 172 173
internal_objectivec_common () {
  # Make sure xctool is up to date. Adapted from
  #  http://docs.travis-ci.com/user/osx-ci-environment/
  # We don't use a before_install because we test multiple OSes.
  brew update
174 175 176 177 178 179 180
  # xctool 0.2.8 seems to have a bug where it randomly kills tests saying
  # they failed. Disabling the updates, but letting it report about being
  # updates as a hint that this needs to eventually get re-enabled.
  #   https://github.com/facebook/xctool/issues/619
  #   https://github.com/google/protobuf/issues/1232
  brew outdated xctool || true
  #brew outdated xctool || brew upgrade xctool
181
  # Reused the build script that takes care of configuring and ensuring things
182 183 184
  # are up to date. Xcode and conformance tests will be directly invoked.
  objectivec/DevTools/full_mac_build.sh \
      --core-only --skip-xcode --skip-objc-conformance
185 186 187
}

internal_xctool_debug_and_release() {
188 189 190 191
  # Always use -reporter plain to avoid escape codes in output (makes travis
  # logs easier to read).
  xctool -reporter plain -configuration Debug "$@"
  xctool -reporter plain -configuration Release "$@"
192 193 194
}

build_objectivec_ios() {
195 196 197 198 199 200 201 202 203 204 205
  internal_objectivec_common
  # https://github.com/facebook/xctool/issues/509 - unlike xcodebuild, xctool
  # doesn't support >1 destination, so we have to build first and then run the
  # tests one destination at a time.
  internal_xctool_debug_and_release \
    -project objectivec/ProtocolBuffers_iOS.xcodeproj \
    -scheme ProtocolBuffers \
    -sdk iphonesimulator \
    build-tests
  IOS_DESTINATIONS=(
    "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit
206
    "platform=iOS Simulator,name=iPhone 6,OS=9.2" # 64bit
207
    "platform=iOS Simulator,name=iPad 2,OS=8.1" # 32bit
208
    "platform=iOS Simulator,name=iPad Air,OS=9.2" # 64bit
209 210 211 212 213 214 215
  )
  for i in "${IOS_DESTINATIONS[@]}" ; do
    internal_xctool_debug_and_release \
      -project objectivec/ProtocolBuffers_iOS.xcodeproj \
      -scheme ProtocolBuffers \
      -sdk iphonesimulator \
      -destination "${i}" \
216
      run-tests
217
  done
218 219 220
}

build_objectivec_osx() {
221 222 223 224 225 226
  internal_objectivec_common
  internal_xctool_debug_and_release \
    -project objectivec/ProtocolBuffers_OSX.xcodeproj \
    -scheme ProtocolBuffers \
    -destination "platform=OS X,arch=x86_64" \
    test
227
  cd conformance && make test_objc && cd ..
228
}
229

230
build_python() {
231
  internal_build_cpp
232
  internal_install_python_deps
233
  cd python
234
  # Only test Python 2.6/3.x on Linux
235
  if [ $(uname -s) == "Linux" ]; then
236
    envlist=py\{26,27,33,34\}-python
237 238 239 240
  else
    envlist=py27-python
  fi
  tox -e $envlist
241 242 243 244
  cd ..
}

build_python_cpp() {
245
  internal_build_cpp
246 247
  internal_install_python_deps
  export LD_LIBRARY_PATH=../src/.libs # for Linux
248
  export DYLD_LIBRARY_PATH=../src/.libs # for OS X
249
  cd python
250
  # Only test Python 2.6/3.x on Linux
251
  if [ $(uname -s) == "Linux" ]; then
252 253
    # py26 is currently disabled due to json_format
    envlist=py\{27,33,34\}-cpp
254 255 256 257
  else
    envlist=py27-cpp
  fi
  tox -e $envlist
258 259 260 261
  cd ..
}

build_ruby19() {
262
  internal_build_cpp  # For conformance tests.
263 264 265
  cd ruby && bash travis-test.sh ruby-1.9 && cd ..
}
build_ruby20() {
266
  internal_build_cpp  # For conformance tests.
267 268 269
  cd ruby && bash travis-test.sh ruby-2.0 && cd ..
}
build_ruby21() {
270
  internal_build_cpp  # For conformance tests.
271 272 273
  cd ruby && bash travis-test.sh ruby-2.1 && cd ..
}
build_ruby22() {
274
  internal_build_cpp  # For conformance tests.
275 276 277
  cd ruby && bash travis-test.sh ruby-2.2 && cd ..
}
build_jruby() {
278
  internal_build_cpp  # For conformance tests.
279 280 281
  cd ruby && bash travis-test.sh jruby && cd ..
}

282 283
build_javascript() {
  internal_build_cpp
284
  cd js && npm install && npm test && cd ..
285 286
}

287 288 289 290 291
# -------- main --------

if [ "$#" -ne 1 ]; then
  echo "
Usage: $0 { cpp |
292
            csharp |
293 294 295 296 297 298
            java_jdk6 |
            java_jdk7 |
            java_oracle7 |
            javanano_jdk6 |
            javanano_jdk7 |
            javanano_oracle7 |
299 300
            objectivec_ios |
            objectivec_osx |
301 302 303 304 305 306 307 308 309 310 311 312 313 314
            python |
            python_cpp |
            ruby_19 |
            ruby_20 |
            ruby_21 |
            ruby_22 |
            jruby }
"
  exit 1
fi

set -e  # exit immediately on error
set -x  # display all commands
eval "build_$1"