Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame^] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # Note: travis currently does not support testing more than one language so the |
| 4 | # .travis.yml cheats and claims to only be cpp. If they add multiple language |
| 5 | # support, this should probably get updated to install steps and/or |
| 6 | # rvm/gemfile/jdk/etc. entries rather than manually doing the work. |
| 7 | |
| 8 | # .travis.yml uses matrix.exclude to block the cases where app-get can't be |
| 9 | # use to install things. |
| 10 | |
| 11 | # For when some other test needs the C++ main build, including protoc and |
| 12 | # libprotobuf. |
| 13 | internal_build_cpp() { |
| 14 | if [ $(uname -s) == "Linux" ]; then |
| 15 | # Install GCC 4.8 to replace the default GCC 4.6. We need 4.8 for more |
| 16 | # decent C++ 11 support in order to compile conformance tests. |
| 17 | sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y |
| 18 | sudo apt-get update -qq |
| 19 | sudo apt-get install -qq g++-4.8 |
| 20 | export CXX="g++-4.8" CC="gcc-4.8" |
| 21 | fi |
| 22 | |
| 23 | ./autogen.sh |
| 24 | ./configure |
| 25 | make -j2 |
| 26 | } |
| 27 | |
| 28 | build_cpp() { |
| 29 | internal_build_cpp |
| 30 | make check -j2 |
| 31 | cd conformance && make test_cpp && cd .. |
| 32 | } |
| 33 | |
| 34 | build_cpp_distcheck() { |
| 35 | ./autogen.sh |
| 36 | ./configure |
| 37 | make distcheck -j2 |
| 38 | } |
| 39 | |
| 40 | build_csharp() { |
| 41 | # Just for the conformance tests. We don't currently |
| 42 | # need to really build protoc, but it's simplest to keep with the |
| 43 | # conventions of the other builds. |
| 44 | internal_build_cpp |
| 45 | |
| 46 | # Install latest version of Mono |
| 47 | sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF |
| 48 | echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list |
| 49 | echo "deb http://download.mono-project.com/repo/debian wheezy-libtiff-compat main" | sudo tee -a /etc/apt/sources.list.d/mono-xamarin.list |
| 50 | sudo apt-get update -qq |
| 51 | sudo apt-get install -qq mono-devel referenceassemblies-pcl nunit |
| 52 | wget www.nuget.org/NuGet.exe -O nuget.exe |
| 53 | |
| 54 | (cd csharp/src; mono ../../nuget.exe restore) |
| 55 | csharp/buildall.sh |
| 56 | cd conformance && make test_csharp && cd .. |
| 57 | } |
| 58 | |
| 59 | build_golang() { |
| 60 | # Go build needs `protoc`. |
| 61 | internal_build_cpp |
| 62 | # Add protoc to the path so that the examples build finds it. |
| 63 | export PATH="`pwd`/src:$PATH" |
| 64 | |
| 65 | # Install Go and the Go protobuf compiler plugin. |
| 66 | sudo apt-get update -qq |
| 67 | sudo apt-get install -qq golang |
| 68 | export GOPATH="$HOME/gocode" |
| 69 | mkdir -p "$GOPATH/src/github.com/google" |
| 70 | ln -s "`pwd`" "$GOPATH/src/github.com/google/protobuf" |
| 71 | export PATH="$GOPATH/bin:$PATH" |
| 72 | go get github.com/golang/protobuf/protoc-gen-go |
| 73 | |
| 74 | cd examples && make gotest && cd .. |
| 75 | } |
| 76 | |
| 77 | use_java() { |
| 78 | version=$1 |
| 79 | case "$version" in |
| 80 | jdk6) |
| 81 | sudo apt-get install openjdk-6-jdk |
| 82 | export PATH=/usr/lib/jvm/java-6-openjdk-amd64/bin:$PATH |
| 83 | ;; |
| 84 | jdk7) |
| 85 | sudo apt-get install openjdk-7-jdk |
| 86 | export PATH=/usr/lib/jvm/java-7-openjdk-amd64/bin:$PATH |
| 87 | ;; |
| 88 | oracle7) |
| 89 | sudo apt-get install python-software-properties # for apt-add-repository |
| 90 | echo "oracle-java7-installer shared/accepted-oracle-license-v1-1 select true" | \ |
| 91 | sudo debconf-set-selections |
| 92 | yes | sudo apt-add-repository ppa:webupd8team/java |
| 93 | yes | sudo apt-get install oracle-java7-installer |
| 94 | export PATH=/usr/lib/jvm/java-7-oracle/bin:$PATH |
| 95 | ;; |
| 96 | esac |
| 97 | |
| 98 | which java |
| 99 | java -version |
| 100 | } |
| 101 | |
| 102 | build_java() { |
| 103 | # Java build needs `protoc`. |
| 104 | internal_build_cpp |
| 105 | cd java && mvn test && mvn install |
| 106 | cd util && mvn test |
| 107 | cd ../.. |
| 108 | } |
| 109 | |
| 110 | build_java_with_conformance_tests() { |
| 111 | # Java build needs `protoc`. |
| 112 | internal_build_cpp |
| 113 | cd java && mvn test && mvn install |
| 114 | cd util && mvn test && mvn assembly:single |
| 115 | cd ../.. |
| 116 | cd conformance && make test_java && cd .. |
| 117 | } |
| 118 | |
| 119 | build_javanano() { |
| 120 | # Java build needs `protoc`. |
| 121 | internal_build_cpp |
| 122 | cd javanano && mvn test && cd .. |
| 123 | } |
| 124 | |
| 125 | build_java_jdk6() { |
| 126 | use_java jdk6 |
| 127 | build_java |
| 128 | } |
| 129 | build_java_jdk7() { |
| 130 | use_java jdk7 |
| 131 | build_java_with_conformance_tests |
| 132 | } |
| 133 | build_java_oracle7() { |
| 134 | use_java oracle7 |
| 135 | build_java |
| 136 | } |
| 137 | |
| 138 | build_javanano_jdk6() { |
| 139 | use_java jdk6 |
| 140 | build_javanano |
| 141 | } |
| 142 | build_javanano_jdk7() { |
| 143 | use_java jdk7 |
| 144 | build_javanano |
| 145 | } |
| 146 | build_javanano_oracle7() { |
| 147 | use_java oracle7 |
| 148 | build_javanano |
| 149 | } |
| 150 | |
| 151 | internal_install_python_deps() { |
| 152 | # Install tox (OS X doesn't have pip). |
| 153 | if [ $(uname -s) == "Darwin" ]; then |
| 154 | sudo easy_install tox |
| 155 | else |
| 156 | sudo pip install tox |
| 157 | fi |
| 158 | # Only install Python2.6/3.x on Linux. |
| 159 | if [ $(uname -s) == "Linux" ]; then |
| 160 | sudo apt-get install -y python-software-properties # for apt-add-repository |
| 161 | sudo apt-add-repository -y ppa:fkrull/deadsnakes |
| 162 | sudo apt-get update -qq |
| 163 | sudo apt-get install -y python2.6 python2.6-dev |
| 164 | sudo apt-get install -y python3.3 python3.3-dev |
| 165 | sudo apt-get install -y python3.4 python3.4-dev |
| 166 | fi |
| 167 | } |
| 168 | |
| 169 | internal_objectivec_common () { |
| 170 | # Make sure xctool is up to date. Adapted from |
| 171 | # http://docs.travis-ci.com/user/osx-ci-environment/ |
| 172 | # We don't use a before_install because we test multiple OSes. |
| 173 | brew update |
| 174 | brew outdated xctool || brew upgrade xctool |
| 175 | # Reused the build script that takes care of configuring and ensuring things |
| 176 | # are up to date. Xcode and conformance tests will be directly invoked. |
| 177 | objectivec/DevTools/full_mac_build.sh \ |
| 178 | --core-only --skip-xcode --skip-objc-conformance |
| 179 | } |
| 180 | |
| 181 | internal_xctool_debug_and_release() { |
| 182 | xctool -configuration Debug "$@" |
| 183 | xctool -configuration Release "$@" |
| 184 | } |
| 185 | |
| 186 | build_objectivec_ios() { |
| 187 | internal_objectivec_common |
| 188 | # https://github.com/facebook/xctool/issues/509 - unlike xcodebuild, xctool |
| 189 | # doesn't support >1 destination, so we have to build first and then run the |
| 190 | # tests one destination at a time. |
| 191 | internal_xctool_debug_and_release \ |
| 192 | -project objectivec/ProtocolBuffers_iOS.xcodeproj \ |
| 193 | -scheme ProtocolBuffers \ |
| 194 | -sdk iphonesimulator \ |
| 195 | build-tests |
| 196 | IOS_DESTINATIONS=( |
| 197 | "platform=iOS Simulator,name=iPhone 4s,OS=8.1" # 32bit |
| 198 | "platform=iOS Simulator,name=iPhone 6,OS=9.1" # 64bit |
| 199 | "platform=iOS Simulator,name=iPad 2,OS=8.1" # 32bit |
| 200 | "platform=iOS Simulator,name=iPad Air,OS=9.1" # 64bit |
| 201 | ) |
| 202 | for i in "${IOS_DESTINATIONS[@]}" ; do |
| 203 | internal_xctool_debug_and_release \ |
| 204 | -project objectivec/ProtocolBuffers_iOS.xcodeproj \ |
| 205 | -scheme ProtocolBuffers \ |
| 206 | -sdk iphonesimulator \ |
| 207 | -destination "${i}" \ |
| 208 | run-tests |
| 209 | done |
| 210 | } |
| 211 | |
| 212 | build_objectivec_osx() { |
| 213 | internal_objectivec_common |
| 214 | internal_xctool_debug_and_release \ |
| 215 | -project objectivec/ProtocolBuffers_OSX.xcodeproj \ |
| 216 | -scheme ProtocolBuffers \ |
| 217 | -destination "platform=OS X,arch=x86_64" \ |
| 218 | test |
| 219 | cd conformance && make test_objc && cd .. |
| 220 | } |
| 221 | |
| 222 | build_python() { |
| 223 | internal_build_cpp |
| 224 | internal_install_python_deps |
| 225 | cd python |
| 226 | # Only test Python 2.6/3.x on Linux |
| 227 | if [ $(uname -s) == "Linux" ]; then |
| 228 | envlist=py\{26,27,33,34\}-python |
| 229 | else |
| 230 | envlist=py27-python |
| 231 | fi |
| 232 | tox -e $envlist |
| 233 | cd .. |
| 234 | } |
| 235 | |
| 236 | build_python_cpp() { |
| 237 | internal_build_cpp |
| 238 | internal_install_python_deps |
| 239 | export LD_LIBRARY_PATH=../src/.libs # for Linux |
| 240 | export DYLD_LIBRARY_PATH=../src/.libs # for OS X |
| 241 | cd python |
| 242 | # Only test Python 2.6/3.x on Linux |
| 243 | if [ $(uname -s) == "Linux" ]; then |
| 244 | # py26 is currently disabled due to json_format |
| 245 | envlist=py\{27,33,34\}-cpp |
| 246 | else |
| 247 | envlist=py27-cpp |
| 248 | fi |
| 249 | tox -e $envlist |
| 250 | cd .. |
| 251 | } |
| 252 | |
| 253 | build_ruby19() { |
| 254 | internal_build_cpp # For conformance tests. |
| 255 | cd ruby && bash travis-test.sh ruby-1.9 && cd .. |
| 256 | } |
| 257 | build_ruby20() { |
| 258 | internal_build_cpp # For conformance tests. |
| 259 | cd ruby && bash travis-test.sh ruby-2.0 && cd .. |
| 260 | } |
| 261 | build_ruby21() { |
| 262 | internal_build_cpp # For conformance tests. |
| 263 | cd ruby && bash travis-test.sh ruby-2.1 && cd .. |
| 264 | } |
| 265 | build_ruby22() { |
| 266 | internal_build_cpp # For conformance tests. |
| 267 | cd ruby && bash travis-test.sh ruby-2.2 && cd .. |
| 268 | } |
| 269 | build_jruby() { |
| 270 | internal_build_cpp # For conformance tests. |
| 271 | cd ruby && bash travis-test.sh jruby && cd .. |
| 272 | } |
| 273 | |
| 274 | build_javascript() { |
| 275 | internal_build_cpp |
| 276 | cd js && npm install && npm test && cd .. |
| 277 | } |
| 278 | |
| 279 | # -------- main -------- |
| 280 | |
| 281 | if [ "$#" -ne 1 ]; then |
| 282 | echo " |
| 283 | Usage: $0 { cpp | |
| 284 | csharp | |
| 285 | java_jdk6 | |
| 286 | java_jdk7 | |
| 287 | java_oracle7 | |
| 288 | javanano_jdk6 | |
| 289 | javanano_jdk7 | |
| 290 | javanano_oracle7 | |
| 291 | objectivec_ios | |
| 292 | objectivec_osx | |
| 293 | python | |
| 294 | python_cpp | |
| 295 | ruby_19 | |
| 296 | ruby_20 | |
| 297 | ruby_21 | |
| 298 | ruby_22 | |
| 299 | jruby } |
| 300 | " |
| 301 | exit 1 |
| 302 | fi |
| 303 | |
| 304 | set -e # exit immediately on error |
| 305 | set -x # display all commands |
| 306 | eval "build_$1" |