Skip to content

Instantly share code, notes, and snippets.

@flightonary
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flightonary/28aca7f0cfac425764d5 to your computer and use it in GitHub Desktop.
Save flightonary/28aca7f0cfac425764d5 to your computer and use it in GitHub Desktop.
gem pre-compile script
#!/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