1#!/bin/bash 2# Copyright 2015 gRPC authors. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16set -ex 17 18cd "$(dirname "$0")" 19 20function die { 21 echo "$1" 22 exit 1 23} 24 25ARCH="$1" 26PLATFORM="$2" 27PACKAGE_TYPE="$3" 28PROTOBUF_VERSION="$4" 29 30echo "$EXTERNAL_GIT_ROOT" 31GRPC_VERSION="$(ruby -e 'require ENV["EXTERNAL_GIT_ROOT"] + "/src/ruby/lib/grpc/version.rb"; puts GRPC::VERSION')" 32if [[ "$PACKAGE_TYPE" == "source" ]]; then 33 GEM_NAME="grpc-${GRPC_VERSION}.gem" 34else 35 [[ "$PACKAGE_TYPE" == "binary" ]] || die "unexpeced package type: $PACKAGE_TYPE" 36 GEM_NAME="grpc-${GRPC_VERSION}-${ARCH}-${PLATFORM}.gem" 37fi 38# Create an indexed local gem source with gRPC gems to test 39GEM_SOURCE=../../../gem_source 40mkdir -p "${GEM_SOURCE}/gems" 41cp "${EXTERNAL_GIT_ROOT}/input_artifacts/${GEM_NAME}" "${GEM_SOURCE}/gems" 42# TODO: rewrite the following line to be shellcheck-compliant 43# shellcheck disable=SC2010 44if [[ "$(ls "${GEM_SOURCE}/gems" | grep -c grpc)" != 1 ]]; then 45 echo "Sanity check failed. Copied over more than one grpc gem into the gem source directory." 46 exit 1 47fi; 48gem install builder 49gem generate_index --directory "${GEM_SOURCE}" 50 51if [[ -n "$PROTOBUF_VERSION" ]]; then 52 bundle add google-protobuf --version "~> $PROTOBUF_VERSION" 53fi; 54 55bundle install 56 57bundle exec ./distribtest.rb 58 59[[ "$PACKAGE_TYPE" == "source" ]] && exit 0 60# Attempt to repro https://github.com/protocolbuffers/protobuf/issues/4210. 61# This sanity check only works for linux-based distrib tests and for 62# binary gRPC packages. 63INSTALLATION_DIR="$(gem env | grep '\- INSTALLATION DIRECTORY' | awk '{ print $4 }')" 64if [[ "$(find "$INSTALLATION_DIR" -name 'grpc_c.so' | wc -l)" == 0 ]]; then 65 echo "Sanity check failed. The gRPC package is not installed in $INSTALLATION_DIR." 66 exit 1 67fi 68LIBRUBY_DEPENDENCY_EXISTS="$(find "$INSTALLATION_DIR" -name 'grpc_c.so' -exec ldd {} \; | grep -c 'libruby')" || true 69if [[ "$LIBRUBY_DEPENDENCY_EXISTS" != 0 ]]; then 70 echo "A grpc_c.so file in this binary gRPC package is dynamically linked to libruby." 71fi 72DEPENDENCY_NOT_FOUND="$(find "$INSTALLATION_DIR" -name 'grpc_c.so' -exec ldd {} \; | grep -c 'not found')" || true 73if [[ "$DEPENDENCY_NOT_FOUND" != 0 ]]; then 74 echo "A grpc_c.so file in this binary gRPC package has an non-portable dependency." 75fi 76if [ "$LIBRUBY_DEPENDENCY_EXISTS" != 0 ] || [ "$DEPENDENCY_NOT_FOUND" != 0 ]; then 77 exit 1 78fi 79