aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/tools/xcode
diff options
context:
space:
mode:
authorGravatar Chris Parsons <cparsons@google.com>2016-05-05 20:24:13 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2016-05-06 09:30:03 +0000
commit87846c72372447ac9a3eb88bcd18a1d00bdcc595 (patch)
treeaaf73eb15ec33c6167c14ea17c541946edd97f90 /src/tools/xcode
parent76c58128251f39c7d1fe4cae412e7ca9a8447e3b (diff)
Attempt 3 at deduping libtool inputs with the same basename. Libtool wrapper overrides old previous symlinks it created.
-- MOS_MIGRATED_REVID=121609372
Diffstat (limited to 'src/tools/xcode')
-rwxr-xr-xsrc/tools/xcode/xcrunwrapper/xcrunwrapper.sh77
1 files changed, 72 insertions, 5 deletions
diff --git a/src/tools/xcode/xcrunwrapper/xcrunwrapper.sh b/src/tools/xcode/xcrunwrapper/xcrunwrapper.sh
index dfb36aa4ef..ecd2ef60c6 100755
--- a/src/tools/xcode/xcrunwrapper/xcrunwrapper.sh
+++ b/src/tools/xcode/xcrunwrapper/xcrunwrapper.sh
@@ -14,14 +14,29 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-# xcrunwrapper runs the command passed to it using xcrun.
-# It replaces __BAZEL_XCODE_DEVELOPER_DIR__ with $DEVELOPER_DIR (or reasonable
-# default) and __BAZEL_XCODE_SDKROOT__ with a valid path based on SDKROOT (or
-# reasonable default).
+# xcrunwrapper runs the command passed to it using xcrun. The first arg
+# passed is the name of the tool to be invoked via xcrun. (For example, libtool
+# or clang).
+# xcrunwrapper replaces __BAZEL_XCODE_DEVELOPER_DIR__ with $DEVELOPER_DIR (or
+# reasonable default) and __BAZEL_XCODE_SDKROOT__ with a valid path based on
+# SDKROOT (or reasonable default).
# These values (__BAZEL_XCODE_*) are a shared secret withIosSdkCommands.java.
set -eu
+TOOLNAME=$1
+shift
+
+# Creates a symbolic link to the input argument file and returns the symlink
+# file path.
+function hash_objfile() {
+ ORIGINAL_NAME="$1"
+ ORIGINAL_HASH="$(/sbin/md5 -q "${ORIGINAL_NAME}")"
+ SYMLINK_NAME="${ORIGINAL_NAME%.o}_${ORIGINAL_HASH}.o"
+ ln -sf "$(basename "$ORIGINAL_NAME")" "$SYMLINK_NAME"
+ echo "$SYMLINK_NAME"
+}
+
# Pick values for DEVELOPER_DIR and SDKROOT as appropriate (if they weren't set)
WRAPPER_DEVDIR="${DEVELOPER_DIR:-}"
@@ -47,8 +62,60 @@ if [[ -z "${WRAPPER_SDKROOT:-}" ]] ; then
WRAPPER_SDKROOT="$(/usr/bin/xcrun --show-sdk-path --sdk ${WRAPPER_SDK})"
fi
+ARGS=("$TOOLNAME")
+while [[ $# -gt 0 ]]; do
+ ARG="$1"
+ shift
+
+ # Libtool artifact symlinking. Apple's libtool has a bug when there are two
+ # input files with the same basename. We thus create symlinks that are named
+ # with a hash suffix for each input, and pass them to libtool.
+ # See b/28186497.
+ # TODO(b/28347228): Handle this in a separate wrapper.
+ if [ "$TOOLNAME" = "libtool" ] ; then
+ case "${ARG}" in
+ # Filelist flag, need to symlink each input in the contents of file and
+ # pass a new filelist which contains the symlinks.
+ -filelist)
+ ARGS+=("${ARG}")
+ ARG="$1"
+ shift
+ HASHED_FILELIST="${ARG%.objlist}_hashes.objlist"
+ rm -f "${HASHED_FILELIST}"
+ while read INPUT_FILE || [ -n "$INPUT_FILE" ]; do
+ echo "$(hash_objfile "${INPUT_FILE}")" >> "$HASHED_FILELIST"
+ done < "${ARG}"
+ ARGS+=("${HASHED_FILELIST}")
+ ;;
+ # Flags with no args
+ -static|-s|-a|-c|-L|-T|-no_warning_for_no_symbols)
+ ARGS+=("${ARG}")
+ ;;
+ # Single-arg flags
+ -o|-arch_only|-syslibroot)
+ ARGS+=("${ARG}")
+ ARG="$1"
+ shift
+ ARGS+=("${ARG}")
+ ;;
+ # Any remaining flags are unexpected and may ruin flag parsing.
+ -*)
+ echo "Unrecognized libtool flag ${ARG}"
+ exit 1
+ ;;
+ # Remaining args are input objects
+ *)
+ ARGS+=("$(echo "$(hash_objfile "${ARG}")")")
+ ;;
+ esac
+ else
+ ARGS+=("${ARG}")
+ fi
+done
+
+# Subsitute toolkit path placeholders.
UPDATEDARGS=()
-for ARG in "$@" ; do
+for ARG in "${ARGS[@]}" ; do
ARG="${ARG//__BAZEL_XCODE_DEVELOPER_DIR__/${WRAPPER_DEVDIR}}"
ARG="${ARG//__BAZEL_XCODE_SDKROOT__/${WRAPPER_SDKROOT}}"
UPDATEDARGS+=("${ARG}")