| #!/bin/sh -e |
| |
| function usage { |
| cat <<EOF |
| usage: $0 [ -h ] [ -b BUILD_DIR ] [ -w ARGS ] SRC_SDK DST_SDK [ |
| |
| This script looks at build products produced by an Apple internal build to |
| determine which private frameworks WebKit uses. It then copies TBD stubs of |
| those frameworks from an internal SDK, and strips them of symbols not used |
| by the WebKit build. This process is manually run as part of the |
| open-source build bringup when new Xcode SDKs are released. |
| |
| SRC_SDK path to an internal SDK to extract framework stubs from |
| DST_SDK path to copy framework stubs to, typically in WebKitLibraries/SDKs |
| -b BUILD_DIR directory to read WebKit binaries from (defaults to webkit-build-directory) |
| -w ARGS additional arguments to pass to webkit-build-directory (e.g. --ios-simulator) |
| -h print this help message |
| EOF |
| exit 1 |
| } |
| |
| function error { |
| echo "error: $1" &1>2 |
| usage |
| } |
| |
| function run { |
| echo ">" $"\033[1m"$@$"\033[0m" 1>&2 |
| "$@" |
| } |
| |
| while getopts b:w:e:h OPT; do |
| case $OPT in |
| b) build_dir="$OPTARG" ;; |
| w) wbd_args="$OPTARG" ;; |
| h) usage ;; |
| ?) usage ;; |
| esac |
| done |
| shift $((OPTIND-1)) |
| |
| internal_sdk_dir="$1" |
| sparse_sdk_dir="$2" |
| shift 2 |
| |
| [ -n "${internal_sdk_dir}" ] || error "missing source SDK to extract from" |
| [ -n "${sparse_sdk_dir}" ] || error "missing destination SDK to copy to" |
| [ -n "${build_dir}" ] || build_dir="$(webkit-build-directory ${wbd_args} --configuration )" |
| export_list="$(mktemp -t WebKit.exp)" |
| |
| # Binaries known to link against private frameworks in some configurations. |
| interesting_executables=( |
| "$build_dir/WebCore.framework/WebCore" |
| "$build_dir/WebKit.framework/WebKit" |
| "$build_dir/webpushd" |
| "$build_dir/TestWebKitAPI" |
| "$build_dir/WebKitTestRunnerApp.app/WebKitTestRunnerApp" |
| ) |
| webkit_private_frameworks="(WebCore|WebInspectorUI|WebKitLegacy)\.framework" |
| |
| # 1. Using the build products given, find the dylibs in PrivateFrameworks that |
| # we link against. Create an export list from the build products scanned, which |
| # will included the needed symbols from these dylibs. |
| tbds=() |
| for x in "${interesting_executables[@]}"; do |
| for fwk in `run otool -L "$x" | grep PrivateFrameworks | grep -vE "${webkit_private_frameworks}" | awk '{ print $1 }'`; do |
| tbds+=("${fwk%.dylib}.tbd") |
| done |
| run nm -gj "$x" >> "${export_list}" |
| done |
| |
| # 2. Copy TBDs for the identified dylibs to the sparse SDK. |
| for tbd in `echo "${tbds[@]}" | sort | uniq`; do |
| run ditto "${internal_sdk_dir}${tbd}" "${sparse_sdk_dir}${tbd}" |
| done |
| |
| # 3. Strip the symbols WebKit is not using from the TBDs. |
| run strip-tbd -s "${export_list}" "${tbds[@]/#/${sparse_sdk_dir}}" |