diff options
-rw-r--r-- | scripts/ci/bazel-tests.json | 3 | ||||
-rw-r--r-- | src/test/shell/bazel/BUILD | 9 | ||||
-rw-r--r-- | src/test/shell/bazel/cpp_darwin_integration_test.sh | 52 | ||||
-rwxr-xr-x | tools/cpp/osx_cc_wrapper.sh | 20 | ||||
-rw-r--r-- | tools/cpp/osx_cc_wrapper.sh.tpl | 20 |
5 files changed, 83 insertions, 21 deletions
diff --git a/scripts/ci/bazel-tests.json b/scripts/ci/bazel-tests.json index 535459dec4..d0a81d599e 100644 --- a/scripts/ci/bazel-tests.json +++ b/scripts/ci/bazel-tests.json @@ -86,7 +86,8 @@ "//scripts/...", "filter(\"^(?!//src/test/docker).*$\", //src/test/...)", "//third_party/ijar/...", - "//tools/android/..." + "//tools/android/...", + "//src/test/shell/bazel:cpp_darwin_integration_test" ], "targets": [] } diff --git a/src/test/shell/bazel/BUILD b/src/test/shell/bazel/BUILD index 378655e92d..62f0c55e90 100644 --- a/src/test/shell/bazel/BUILD +++ b/src/test/shell/bazel/BUILD @@ -78,6 +78,15 @@ sh_test( ) sh_test( + name = "cpp_darwin_integration_test", + size = "large", + srcs = ["cpp_darwin_integration_test.sh"], + data = [ + ":test-deps", + ], +) + +sh_test( name = "bazel_tools_test", size = "large", srcs = ["bazel_tools_test.sh"], diff --git a/src/test/shell/bazel/cpp_darwin_integration_test.sh b/src/test/shell/bazel/cpp_darwin_integration_test.sh new file mode 100644 index 0000000000..8b5eabb7c9 --- /dev/null +++ b/src/test/shell/bazel/cpp_darwin_integration_test.sh @@ -0,0 +1,52 @@ +#!/bin/bash +# +# Copyright 2017 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# Tests for Bazel's C++ rules on Darwin + +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${CURRENT_DIR}/../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } + +function test_osx_cc_wrapper_rpaths_handling() { + mkdir -p cpp/rpaths + cat > cpp/rpaths/BUILD <<EOF +cc_library( + name = "foo", + srcs = ["foo.cc"], +) +cc_binary( + name = "libbar.so", + linkshared = 1, +) +cc_test( + name = "test", + srcs = [ "test.cc", ":libbar.so" ], + deps = [":foo"], +) +EOF + cat > cpp/rpaths/foo.cc <<EOF + int foo() { return 42; } +EOF + cat > cpp/rpaths/test.cc <<EOF + int main() {} +EOF + assert_build //cpp/rpaths:test >& $TEST_log || fail "//cpp/rpaths:test didn't build" + ./bazel-bin/cpp/rpaths/test >& $TEST_log || fail "//cpp/rpaths:test execution failed" +} + +run_suite "Tests for Bazel's C++ rules on Darwin" + diff --git a/tools/cpp/osx_cc_wrapper.sh b/tools/cpp/osx_cc_wrapper.sh index 739fca5de6..8aba869443 100755 --- a/tools/cpp/osx_cc_wrapper.sh +++ b/tools/cpp/osx_cc_wrapper.sh @@ -32,21 +32,18 @@ INSTALL_NAME_TOOL="/usr/bin/install_name_tool" LIBS= LIB_DIRS= -RPATH= +RPATHS= OUTPUT= # let parse the option list for i in "$@"; do if [[ "${OUTPUT}" = "1" ]]; then OUTPUT=$i elif [[ "$i" =~ ^-l(.*)$ ]]; then - # lib LIBS="${BASH_REMATCH[1]} $LIBS" elif [[ "$i" =~ ^-L(.*)$ ]]; then - # lib LIB_DIRS="${BASH_REMATCH[1]} $LIB_DIRS" elif [[ "$i" =~ ^-Wl,-rpath,\$ORIGIN/(.*)$ ]]; then - # rpath - RPATH=${BASH_REMATCH[1]} + RPATHS="${BASH_REMATCH[1]} ${RPATHS}" elif [[ "$i" = "-o" ]]; then # output is coming OUTPUT=1 @@ -83,12 +80,15 @@ function get_otool_path() { } # Do replacements in the output -if [ -n "${RPATH}" ]; then +for rpath in ${RPATHS}; do for lib in ${LIBS}; do - libpath=$(get_library_path ${lib}) - if [ -n "${libpath}" ]; then - ${INSTALL_NAME_TOOL} -change $(get_otool_path "${libpath}") "@loader_path/${RPATH}/lib${lib}.so" "${OUTPUT}" + if [ -f "`dirname ${OUTPUT}`/${rpath}/lib${lib}.so" ]; then + libpath=$(get_library_path ${lib}) + if [ -n "${libpath}" ]; then + ${INSTALL_NAME_TOOL} -change $(get_otool_path "${libpath}") \ + "@loader_path/${rpath}/lib${lib}.so" "${OUTPUT}" + fi fi done -fi +done diff --git a/tools/cpp/osx_cc_wrapper.sh.tpl b/tools/cpp/osx_cc_wrapper.sh.tpl index 5ea4b52c1b..fb32e1e6b9 100644 --- a/tools/cpp/osx_cc_wrapper.sh.tpl +++ b/tools/cpp/osx_cc_wrapper.sh.tpl @@ -31,21 +31,18 @@ INSTALL_NAME_TOOL="/usr/bin/install_name_tool" LIBS= LIB_DIRS= -RPATH= +RPATHS= OUTPUT= # let parse the option list for i in "$@"; do if [[ "${OUTPUT}" = "1" ]]; then OUTPUT=$i elif [[ "$i" =~ ^-l(.*)$ ]]; then - # lib LIBS="${BASH_REMATCH[1]} $LIBS" elif [[ "$i" =~ ^-L(.*)$ ]]; then - # lib LIB_DIRS="${BASH_REMATCH[1]} $LIB_DIRS" elif [[ "$i" =~ ^-Wl,-rpath,\$ORIGIN/(.*)$ ]]; then - # rpath - RPATH=${BASH_REMATCH[1]} + RPATHS="${BASH_REMATCH[1]} ${RPATHS}" elif [[ "$i" = "-o" ]]; then # output is coming OUTPUT=1 @@ -85,12 +82,15 @@ function get_otool_path() { } # Do replacements in the output -if [ -n "${RPATH}" ]; then +for rpath in ${RPATHS}; do for lib in ${LIBS}; do - libpath=$(get_library_path ${lib}) - if [ -n "${libpath}" ]; then - ${INSTALL_NAME_TOOL} -change $(get_otool_path "${libpath}") "@loader_path/${RPATH}/lib${lib}.so" "${OUTPUT}" + if [ -f "`dirname ${OUTPUT}`/${rpath}/lib${lib}.so" ]; then + libpath=$(get_library_path ${lib}) + if [ -n "${libpath}" ]; then + ${INSTALL_NAME_TOOL} -change $(get_otool_path "${libpath}") \ + "@loader_path/${rpath}/lib${lib}.so" "${OUTPUT}" + fi fi done -fi +done |