Skip to content

Instantly share code, notes, and snippets.

@geoff-nixon
Last active December 29, 2015 07:18
Show Gist options
  • Save geoff-nixon/7634594 to your computer and use it in GitHub Desktop.
Save geoff-nixon/7634594 to your computer and use it in GitHub Desktop.
Download and extract the 'jsc' JavaScriptCore utility from the latest WebKit nightly build. The executable and library are packaged into a self-extracting/self-executing script so that it avoids the system JavaScriptCore framework (and doesn't require installing a conflicting one.)
#!/usr/bin/env LASTBUILD=159732 DATE=20131124 sh # 2013 G. Nixon. Public domain.
# Download and extract the 'jsc' utility from the latest WebKit nightly.
# Since the WebKit project neither uses the date of the build in its URIs nor
# posts a convenience 'latest' link, we record the last known build number and
# the date, then basically brute-force the URI with curl. The executable and
# framework are extracted from the disk image and then packaged into a
# self-extracting/self-executing script so that it avoids the system framework,
# and doesn't require installing a conflicting one. Not ideal, but...
if [ $(uname) != Darwin ]; then
echo 'Sorry, WebKit nightlies are only available for Darwin.'; exit 1; fi
OSV=$(sw_vers -productVersion | cut -c 1-4); OS=$(echo $OSV | sed -e 's/\.//')
if [ $OS -le 107 ]; then echo 'Sorry, only 10.8+ is supported.'; exit 1; fi
if [ $OS -ge 109 ]; then J="J"; else J="j"; fi # 10.9 finally includes libLZMA.
U=/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/JavaScriptCore
REPO='http://builds.nightly.webkit.org/files/trunk/mac/WebKit-SVN';EXT='WebKit/'
EXT+="WebKit.app/Contents/Frameworks/$OSV/JavaScriptCore.framework/Versions/A"
L1='H=$(pwd);jsc(){ TD=$(od -XN4 -An /dev/urandom|sed "s/ //g");mkdir -p \'
L2='$TD;cd $TD;echo $ARCHIVE|base64 -D|tar x;cd $H; $TD/jsc "$@"; rm -rf $TD ;}'
HERE=$(pwd); NEWDATE=$(date "+%Y%m%d"); ELAPSED=$(expr $NEWDATE - $DATE)
GUESS=$(echo "($ELAPSED * 50) + 64"|bc); BUILD=$(echo "$LASTBUILD + $GUESS"|bc)
cd "$(dirname $0)"; THERE="$(pwd)/"; IAM="$THERE/$(basename $0)"; cd $HERE
cd /tmp; echo 'Checking for latest nightly WebKit/JavaScriptCore build...'; echo
for b in $(echo "for (i=$(expr $BUILD + $GUESS);i>=$LASTBUILD;i--)i" | bc); do
/bin/echo -n .; if [ x"$DOT" = x"" ]; then DOT=0; else
DOT=$(expr $DOT + 1); fi; if [ "$DOT" = "57" ]; then echo; unset DOT; fi
curl -Ls -r 0-10000 $REPO-r$b.dmg > .maybe.dmg
if [ $(du .maybe.dmg | cut -f1 | sed -e 's/\.//g') -gt 9 ]; then LATEST=$b
echo; echo; /bin/echo -n "Found latest nigtly build $b. Downloading... "
cd "$(dirname $0)"
sed -i '' "s/$LASTBUILD/$LATEST/" "$IAM"
sed -i '' "s/$DATE/$NEWDATE/" "$IAM"
cd /tmp
curl -Ls $REPO-r$b.dmg > .maybe.dmg
rm -rf webkit-*.dmg; rm -rf webkit-$LATEST.dmg
mv .maybe.dmg WebKit-$LATEST.dmg
break
fi; rm -rf .maybe.dmg
done
if [ ! x"$LATEST" = x"" ]; then echo "Success."
echo; /bin/echo -n 'Extracting jsc... '
hdiutil attach -quiet -nobrowse -mountroot /tmp WebKit-$LATEST.dmg
cp $EXT/JavaScriptCore $EXT/Resources/jsc .
hdiutil detach -quiet WebKit; rm -rf WebKit-$LATEST.dmg
mv JavaScriptCore libjsc.dylib
install_name_tool -id JavaScriptCore libjsc.dylib
install_name_tool -change $U @executable_path/libjsc.dylib jsc
lipo -thin $(uname -m) libjsc.dylib -output libjsc.dylib
lipo -thin $(uname -m) jsc -output jsc
tar cf$J jsc.tar libjsc.dylib jsc
openssl base64 < jsc.tar > jsc.tar.b64
rm -rf jsc.tar jsc libjsc.dylib
echo '#!/bin/sh' > ./head; echo $L1 >> ./head; echo $L2 >> ./head
echo 'ARCHIVE="' >> ./head; echo '"; jsc "$@"' > tail
cat head jsc.tar.b64 tail > $HERE/jsc; rm -rf head jsc.tar.b64 tail .maybe.dmg
cd $HERE; chmod +x jsc
echo 'Complete!'
else
echo "No new WebKit/JavaScriptCore nightly could be obtained."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment