Skip to content

Instantly share code, notes, and snippets.

@niw
Created June 27, 2012 01:05
Show Gist options
  • Select an option

  • Save niw/3000603 to your computer and use it in GitHub Desktop.

Select an option

Save niw/3000603 to your computer and use it in GitHub Desktop.
Freeze WebKit frameworks for the specific application.
#!/bin/sh
if [ "$1" = "-h" -o "$1" = "--help" ]; then
echo "Usage: freeze_webkit_for_app.sh [path]"
echo "ARGUMENTS"
echo " path Path to the application."
echo "OPTIONS"
echo " APPLICATION_PATH Path to the application."
echo " WEBKIT_REVISION Revision of WebKit framework nightly build."
exit 1
fi
if [ -z "$WEBKIT_REVISION" ]; then
# Doesn't have any meanings, This is the latest version of WebKit nightly build which supports 10.6 to 10.8.
WEBKIT_REVISION="129982"
fi
if [ ! -z "$1" ]; then
APPLICATION_PATH=$1
fi
if [ -z "$APPLICATION_PATH" ]; then
echo "Please specify the application."
exit 1
fi
contents_path="$APPLICATION_PATH/Contents"
info_plist_path="$contents_path/Info.plist"
if [ ! -f "$info_plist_path" ]; then
echo "$APPLICATION_PATH doesn't have Info.plist."
exit 1
fi
executable_name=`defaults read "$info_plist_path" CFBundleExecutable`
executable_path="$contents_path/MacOS/$executable_name"
if [ ! -f "$executable_path" ]; then
echo "$APPLICATION_PATH is not valid application path."
exit 1
fi
FRAMEWORKS="WebKit.framework WebCore.framework JavaScriptCore.framework"
frameworks_path="$contents_path/Frameworks"
for framework in $FRAMEWORKS; do
if [ -e "$frameworks_path/$framework" ]; then
echo "$framework is already used in $frameworks_path."
exit 1
fi
done
WORKING_PATH=/tmp/freeze_webkit_for_app
mkdir -p "$WORKING_PATH"
echo "Download WebKit nightly revision $WEBKIT_REVISION..."
webkit_dmg_path="$WORKING_PATH/webkit.dmg"
if [ ! -f "$webkit_dmg_path" ]; then
curl -o "$webkit_dmg_path" "http://builds.nightly.webkit.org/files/trunk/mac/WebKit-SVN-r$WEBKIT_REVISION.dmg"
fi
echo "Mount WebKit.dmg..."
webkit_volume_path=`hdiutil attach "$webkit_dmg_path"|awk '$2 == "Apple_HFS" {print $3}'`
if [ -z "$webkit_volume_path" ]; then
echo "Fail to mount WebKit.dmg."
exit 1
fi
macos_product_version=`sw_vers -productVersion|awk -F '.' '{print $1"."$2}'`
webkit_frameworks_path="$webkit_volume_path/WebKit.app/Contents/Frameworks/$macos_product_version"
if [ ! -e "$webkit_frameworks_path" ]; then
echo "Couldn't find WebKit frameworks $webkit_frameworks_path in WebKit.dmg."
exit 1
fi
echo "Prepare frameworks..."
for framework in $FRAMEWORKS; do
if [ ! -e "$WORKING_PATH/$framework" ]; then
cp -Rp "$webkit_frameworks_path/$framework" "$WORKING_PATH/"
fi
done
hdiutil detach "$webkit_volume_path"
rewrite_library_path() {
$2 install_name_tool -change \
"/System/Library/Frameworks/WebKit.framework/Versions/A/WebKit" \
"@executable_path/../Frameworks/WebKit.framework/Versions/A/WebKit" \
"$1"
$2 install_name_tool -change \
"/System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks/WebCore.framework/Versions/A/WebCore" \
"@executable_path/../Frameworks/WebCore.framework/Versions/A/WebCore" \
"$1"
$2 install_name_tool -change \
"/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/JavaScriptCore" \
"@executable_path/../Frameworks/JavaScriptCore.framework/Versions/A/JavaScriptCore" \
"$1"
}
for framework in $FRAMEWORKS; do
framework_name=`basename $framework .framework`
rewrite_library_path "$WORKING_PATH/$framework/Versions/A/$framework_name"
done
echo "Install frameworks..."
# FIXME this sudo hack is not so good implementation.
if [ ! -w "$contents_path" ]; then
SUDO=sudo
fi
$SUDO mkdir -p "$frameworks_path"
for framework in $FRAMEWORKS; do
if [ ! -e "$frameworks_path/$framework" ]; then
$SUDO cp -Rp "$WORKING_PATH/$framework" "$frameworks_path/"
fi
done
$SUDO cp -Rp "$executable_path" "$executable_path.original"
rewrite_library_path "$executable_path" $SUDO
rm -rf "$WORKING_PATH"
echo "Done."
@niw
Copy link
Author

niw commented Jul 5, 2012

Good point, fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment