1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/webrtc/trunk/build/mac/copy_framework_unversioned.sh Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,118 @@ 1.4 +#!/bin/bash 1.5 + 1.6 +# Copyright (c) 2012 The Chromium Authors. All rights reserved. 1.7 +# Use of this source code is governed by a BSD-style license that can be 1.8 +# found in the LICENSE file. 1.9 + 1.10 +# Copies a framework to its new home, "unversioning" it. 1.11 +# 1.12 +# Normally, frameworks are versioned bundles. The contents of a framework are 1.13 +# stored in a versioned directory within the bundle, and symbolic links 1.14 +# provide access to the actual code and resources. See 1.15 +# http://developer.apple.com/mac/library/documentation/MacOSX/Conceptual/BPFrameworks/Concepts/FrameworkAnatomy.html 1.16 +# 1.17 +# The symbolic links usually found in frameworks create problems. Symbolic 1.18 +# links are excluded from code signatures. That means that it's possible to 1.19 +# remove or retarget a symbolic link within a framework without affecting the 1.20 +# seal. In Chrome's case, the outer .app bundle contains a framework where 1.21 +# all application code and resources live. In order for the signature on the 1.22 +# .app to be meaningful, it encompasses the framework. Because framework 1.23 +# resources are accessed through the framework's symbolic links, this 1.24 +# arrangement results in a case where the resources can be altered without 1.25 +# affecting the .app signature's validity. 1.26 +# 1.27 +# Indirection through symbolic links also carries a runtime performance 1.28 +# penalty on open() operations, although open() typically completes so quickly 1.29 +# that this is not considered a major performance problem. 1.30 +# 1.31 +# To resolve these problems, the frameworks that ship within Chrome's .app 1.32 +# bundle are unversioned. Unversioning is simple: instead of using the 1.33 +# original outer .framework directory as the framework that ships within the 1.34 +# .app, the inner versioned directory is used. Instead of accessing bundled 1.35 +# resources through symbolic links, they are accessed directly. In normal 1.36 +# situations, the only hard-coded use of the versioned directory is by dyld, 1.37 +# when loading the framework's code, but this is handled through a normal 1.38 +# Mach-O load command, and it is easy to adjust the load command to point to 1.39 +# the unversioned framework code rather than the versioned counterpart. 1.40 +# 1.41 +# The resulting framework bundles aren't strictly conforming, but they work 1.42 +# as well as normal versioned framework bundles. 1.43 +# 1.44 +# An option to skip running install_name_tool is available. By passing -I as 1.45 +# the first argument to this script, install_name_tool will be skipped. This 1.46 +# is only suitable for copied frameworks that will not be linked against, or 1.47 +# when install_name_tool will be run on any linker output when something is 1.48 +# linked against the copied framework. This option exists to allow signed 1.49 +# frameworks to pass through without subjecting them to any modifications that 1.50 +# would break their signatures. 1.51 + 1.52 +set -e 1.53 + 1.54 +RUN_INSTALL_NAME_TOOL=1 1.55 +if [ $# -eq 3 ] && [ "${1}" = "-I" ] ; then 1.56 + shift 1.57 + RUN_INSTALL_NAME_TOOL= 1.58 +fi 1.59 + 1.60 +if [ $# -ne 2 ] ; then 1.61 + echo "usage: ${0} [-I] FRAMEWORK DESTINATION_DIR" >& 2 1.62 + exit 1 1.63 +fi 1.64 + 1.65 +# FRAMEWORK should be a path to a versioned framework bundle, ending in 1.66 +# .framework. DESTINATION_DIR is the directory that the unversioned framework 1.67 +# bundle will be copied to. 1.68 + 1.69 +FRAMEWORK="${1}" 1.70 +DESTINATION_DIR="${2}" 1.71 + 1.72 +FRAMEWORK_NAME="$(basename "${FRAMEWORK}")" 1.73 +if [ "${FRAMEWORK_NAME: -10}" != ".framework" ] ; then 1.74 + echo "${0}: ${FRAMEWORK_NAME} does not end in .framework" >& 2 1.75 + exit 1 1.76 +fi 1.77 +FRAMEWORK_NAME_NOEXT="${FRAMEWORK_NAME:0:$((${#FRAMEWORK_NAME} - 10))}" 1.78 + 1.79 +# Find the current version. 1.80 +VERSIONS="${FRAMEWORK}/Versions" 1.81 +CURRENT_VERSION_LINK="${VERSIONS}/Current" 1.82 +CURRENT_VERSION_ID="$(readlink "${VERSIONS}/Current")" 1.83 +CURRENT_VERSION="${VERSIONS}/${CURRENT_VERSION_ID}" 1.84 + 1.85 +# Make sure that the framework's structure makes sense as a versioned bundle. 1.86 +if [ ! -e "${CURRENT_VERSION}/${FRAMEWORK_NAME_NOEXT}" ] ; then 1.87 + echo "${0}: ${FRAMEWORK_NAME} does not contain a dylib" >& 2 1.88 + exit 1 1.89 +fi 1.90 + 1.91 +DESTINATION="${DESTINATION_DIR}/${FRAMEWORK_NAME}" 1.92 + 1.93 +# Copy the versioned directory within the versioned framework to its 1.94 +# destination location. 1.95 +mkdir -p "${DESTINATION_DIR}" 1.96 +rsync -acC --delete --exclude Headers --exclude PrivateHeaders \ 1.97 + --include '*.so' "${CURRENT_VERSION}/" "${DESTINATION}" 1.98 + 1.99 +if [[ -n "${RUN_INSTALL_NAME_TOOL}" ]]; then 1.100 + # Adjust the Mach-O LC_ID_DYLIB load command in the framework. This does not 1.101 + # change the LC_LOAD_DYLIB load commands in anything that may have already 1.102 + # linked against the framework. Not all frameworks will actually need this 1.103 + # to be changed. Some frameworks may already be built with the proper 1.104 + # LC_ID_DYLIB for use as an unversioned framework. Xcode users can do this 1.105 + # by setting LD_DYLIB_INSTALL_NAME to 1.106 + # $(DYLIB_INSTALL_NAME_BASE:standardizepath)/$(WRAPPER_NAME)/$(PRODUCT_NAME) 1.107 + # If invoking ld via gcc or g++, pass the desired path to -Wl,-install_name 1.108 + # at link time. 1.109 + FRAMEWORK_DYLIB="${DESTINATION}/${FRAMEWORK_NAME_NOEXT}" 1.110 + LC_ID_DYLIB_OLD="$(otool -l "${FRAMEWORK_DYLIB}" | 1.111 + grep -A10 "^ *cmd LC_ID_DYLIB$" | 1.112 + grep -m1 "^ *name" | 1.113 + sed -Ee 's/^ *name (.*) \(offset [0-9]+\)$/\1/')" 1.114 + VERSION_PATH="/Versions/${CURRENT_VERSION_ID}/${FRAMEWORK_NAME_NOEXT}" 1.115 + LC_ID_DYLIB_NEW="$(echo "${LC_ID_DYLIB_OLD}" | 1.116 + sed -Ee "s%${VERSION_PATH}$%/${FRAMEWORK_NAME_NOEXT}%")" 1.117 + 1.118 + if [ "${LC_ID_DYLIB_NEW}" != "${LC_ID_DYLIB_OLD}" ] ; then 1.119 + install_name_tool -id "${LC_ID_DYLIB_NEW}" "${FRAMEWORK_DYLIB}" 1.120 + fi 1.121 +fi