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
20ARCH=$1
21PLATFORM=$2
22# Create an indexed local gem source with gRPC gems to test
23GEM_SOURCE=../../../gem_source
24mkdir -p "${GEM_SOURCE}/gems"
25cp "$EXTERNAL_GIT_ROOT"/input_artifacts/grpc-*"$ARCH-$PLATFORM".gem "${GEM_SOURCE}/gems"
26# TODO: rewrite the following line to be shellcheck-compliant
27# shellcheck disable=SC2010
28if [[ "$(ls "${GEM_SOURCE}/gems" | grep -c grpc)" != 1 ]]; then
29  echo "Sanity check failed. Copied over more than one grpc gem into the gem source directory."
30  exit 1
31fi;
32gem install builder
33gem generate_index --directory "${GEM_SOURCE}"
34
35bundle install
36
37bundle exec ./distribtest.rb
38
39# Attempt to repro https://github.com/google/protobuf/issues/4210.
40# TODO: This sanity check only works for linux-based distrib tests and for
41# binary gRPC packages. It will need to be ran conditionally if this test script is
42# used for other types of distrib tests.
43INSTALLATION_DIR="$(gem env | grep '\- INSTALLATION DIRECTORY' | awk '{ print $4 }')"
44if [[ "$(find "$INSTALLATION_DIR" -name 'grpc_c.so' | wc -l)" == 0 ]]; then
45  echo "Sanity check failed. The gRPC package is not installed in $INSTALLATION_DIR."
46  exit 1
47fi
48LIBRUBY_DEPENDENCY_EXISTS="$(find "$INSTALLATION_DIR" -name 'grpc_c.so' -exec ldd {} \; | grep -c 'libruby')" || true
49if [[ "$LIBRUBY_DEPENDENCY_EXISTS" != 0 ]]; then
50  echo "A grpc_c.so file in this binary gRPC package is dynamically linked to libruby."
51fi
52DEPENDENCY_NOT_FOUND="$(find "$INSTALLATION_DIR" -name 'grpc_c.so' -exec ldd {} \; | grep -c 'not found')" || true
53if [[ "$DEPENDENCY_NOT_FOUND" != 0 ]]; then
54  echo "A grpc_c.so file in this binary gRPC package has an non-portable dependency."
55fi
56if [ "$LIBRUBY_DEPENDENCY_EXISTS" != 0 ] || [ "$DEPENDENCY_NOT_FOUND" != 0 ]; then
57  exit 1
58fi
59