Last active
August 29, 2015 14:12
-
-
Save flightonary/28aca7f0cfac425764d5 to your computer and use it in GitHub Desktop.
gem pre-compile script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# commands | |
GEM=/usr/bin/gem | |
RAKE=/usr/bin/rake | |
# const params | |
TMP_DIR=/tmp/gem-native | |
usage() | |
{ | |
echo "$0 <bundle_package_dir>" | |
exit 0 | |
} | |
tmpdir() | |
{ | |
if [ -d "$TMP_DIR" ]; then | |
rm -rf $TMP_DIR | |
fi | |
mkdir $TMP_DIR | |
} | |
# initialize | |
if [ -z "$1" ] || [ ! -d "$1" ]; then | |
usage | |
fi | |
tmpdir | |
pkg_dir=`readlink -f $1` | |
gems=`find $pkg_dir -type f -name "*.gem"` | |
cd $TMP_DIR | |
# make native gem | |
for gem in $gems | |
do | |
bname=`basename $gem .gem` | |
echo "checking for $bname" | |
# unpackaging gem | |
$GEM unpack $gem | |
pushd $bname | |
# native compile | |
$RAKE native gem || true | |
native_gem=`test -d "./pkg" && find ./pkg -name "${bname}-*.gem"` | |
# replace gem with native gem if native compiled | |
if [ -n "$native_gem" ] && [ -f "$native_gem" ]; then | |
rm -f $gem | |
cp $native_gem ${gem%/*} | |
fi | |
popd | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment