Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 403 lines (357 sloc) 14.1 KB
#!/bin/sh
set -e
export PATH=$PATH:/usr/local/bin/
while [ ! -z "$1" ]; do
case "$1" in
"--stage")
HHVM_REPO="git@github.com:hhvm/hhvm-staging.git"
echo "Using staging repo: $HHVM_REPO"
shift
;;
"--dry-run")
DRY_RUN=1
echo "!!!! Doing a dry run !!!!"
shift
;;
"--verbose")
set -x
shift
;;
*)
break
;;
esac
done
if [ -z "$HHVM_REPO" ]; then
HHVM_REPO="https://github.com/facebook/hhvm.git"
echo "Using default repo: $HHVM_REPO"
fi
if [ "$#" -le 2 ]; then
echo "$0 [--stage|--dry-run|--verbose] DISTRO_NAME RELEASE VERSION [SOURCE_DIR] [PACKAGE_DIR] [BUILD_DIR] [DEV_PACKAGE_DIR]"
echo " for example, stable:"
echo " $0 ubuntu precise 3.3.0-1"
echo " or nightly:"
echo " $0 debian jessie 3.4.0-nightly"
exit
fi
DIR=`dirname $0`
DIR=`readlink -m $DIR`
DISTRO_NAME=$1
RELEASE=$2
DISTRO_DIR=$DIR/$RELEASE
VERSION=$3 # Version of deb we are building, including minor revision (if applicable), e.g., 3.3.2-1
HHVM_VERSION=`echo $VERSION | cut -d '-' -f 1` # Version without minor revision, e.g., 3.3.2
STABLE_VERSION=`echo $VERSION | cut -d '.' -f 1-2` # Stable version series, e.g., 3.3
MINOR_VERSION=`echo $VERSION | cut -d '.' -f 2` # Minor version, e.g., for 3.4.5-1 -> 4
SOURCE=$4
SKELETON=$DIR/skeleton
PACKAGE=$5
BUILD=$6
DPACKAGE=$7
NIGHTLY_DATE=`date +%Y.%m.%d`
EXTRA_CMAKE_FLAGS=""
NIGHTLY=false
DEBUG=false
DEVONLY=false
LTS=false
if [ ! -d $DISTRO_DIR ]; then
echo "directory $DISTRO_DIR doesn't exist"
exit
fi
#TODO check that DISTRO_NAME exists on the remote server
if [ -z "$SOURCE" -o ! -d "$SOURCE" ]; then
SOURCE=`mktemp -d`
fi
if [ `echo $VERSION | grep '.*-nightly.*'` ]; then
NIGHTLY=true
echo "Nightly"
fi
if [ "$NIGHTLY" = true ]; then
GIT_TARGET=master
PACKAGE_VERSION=$NIGHTLY_DATE~$RELEASE
else
GIT_TARGET=HHVM-$HHVM_VERSION
PACKAGE_VERSION=`echo $VERSION | sed -E 's/-(dbg|dev)$//'`~$RELEASE
if [ $(expr $MINOR_VERSION % 3) -eq 0 ]; then
echo "You are using the wrong branch of the packaging script."
exit 1
fi
fi
if [ `echo $VERSION | grep '.*-dev$'` ]; then
DEVONLY=true
VERSION=`echo $VERSION | sed s/-dev$//`
echo "Dev only, Debug off"
fi
if [ `echo $VERSION | grep '.*-dbg$'` ]; then
DEBUG=true
VERSION=`echo $VERSION | sed s/-dbg$//`
echo "Debug"
fi
if [ -z "$BUILD" -o ! -d "$BUILD" ]; then
BUILD=`mktemp -d`
fi
cd $SOURCE
if [ ! -d $SOURCE/.git ]; then
git clone $HHVM_REPO $SOURCE
git checkout $GIT_TARGET
if [ "$NIGHTLY" = true ]; then
perl -pi -e 's/([0-9.]*-dev)/\1~nightly.'$NIGHTLY_DATE/ hphp/system/idl/constants.idl.json
fi
# After the checkout since the submodules might be different between versions
git submodule update --init --recursive
HEADERS=`mktemp -d`
mkdir $HEADERS/include
# Ensure that /usr/lib/hhvm exists
sudo mkdir -p /usr/lib/hhvm
if [ "$RELEASE" = "wheezy" ]; then
# These distros don't have a new enough glog
sudo ln -sf /usr/lib/hhvm/libglog.so.0 /usr/lib/hhvm/libglog.so
git clone https://github.com/google/glog.git $HEADERS/google-glog
cd $HEADERS/google-glog
git checkout v0.3.3
./configure --prefix=$HEADERS
make -j 8
make install
cd -
sudo cp -d $HEADERS/lib/libglog.so /usr/lib/hhvm/
sudo cp -d $HEADERS/lib/libglog.so.0 /usr/lib/hhvm/
sudo cp -d $HEADERS/lib/libglog.so.0.0.0 /usr/lib/hhvm/
# They also don't have a new enough jemalloc
sudo ln -sf /usr/lib/hhvm/libjemalloc.so.1 /usr/lib/hhvm/libjemalloc.so
cd $HEADERS
wget http://www.canonware.com/download/jemalloc/jemalloc-3.6.0.tar.bz2
tar xjvf jemalloc-3.6.0.tar.bz2
cd -
cd $HEADERS/jemalloc-3.6.0
./configure --prefix=$HEADERS
make -j 8
make install
cd -
sudo cp -d $HEADERS/lib/libjemalloc.so /usr/lib/hhvm/
sudo cp -d $HEADERS/lib/libjemalloc.so.1 /usr/lib/hhvm/
# Or boost :(
cd $HEADERS
wget http://sourceforge.net/projects/boost/files/boost/1.55.0/boost_1_55_0.tar.bz2/download -O boost_1_55_0.tar.bz2
tar xf boost_1_55_0.tar.bz2
cd -
cd $HEADERS/boost_1_55_0/
./bootstrap.sh --without-libraries=python --prefix=$HEADERS
./b2 variant=release threading=multi link=static --layout=tagged -j4
./b2 variant=release threading=multi link=static --layout=tagged install
cd -
# Extra options:
# - Old version of gcc in the base distros mean we need to manually
# install a new gcc, and so should statically link libstdc++ and
# libgcc so users don't have to have the new gcc-base.
# - Old version of boost in the base distros means we need to locally
# build boost, but don't want to ship the crapload of extra libraries
# and so statically link.
EXTRA_CMAKE_FLAGS="-DSTATIC_CXX_LIB=On -DBoost_USE_STATIC_LIBS=ON"
fi
if [ "$DEBUG" = true ]; then
EXTRA_CMAKE_FLAGS="$EXTRA_CMAKE_FLAGS -DCMAKE_BUILD_TYPE=Debug"
fi
CMAKE_INCLUDE_PATH=$HEADERS/include/ CMAKE_LIBRARY_PATH="/usr/lib/hhvm/" HPHP_HOME=$SOURCE cmake -Wno-dev -DCMAKE_INSTALL_PREFIX="/usr" -DMYSQL_UNIX_SOCK_ADDR=/var/run/mysqld/mysqld.sock $EXTRA_CMAKE_FLAGS .
HPHP_HOME=$SOURCE make version
if [ `echo "$VERSION" | sed s/nightly/dev/` != `$SOURCE/hphp/tools/version/version` ]; then
echo "$VERSION does not match version.h"
exit
fi
fi
if [ ! -f $SOURCE/hphp/hhvm/hhvm ]; then
HPHP_HOME=$SOURCE make -j 4
if [ ! -f $SOURCE/hphp/hhvm/hhvm ]; then
echo "$SOURCE/hphp/hhvm/hhvm doesn't exist"
exit
fi
fi
echo "Installing hhvm into $BUILD"
# build the headers essentially.
if [ ! -f $BUILD/usr/bin/hphpize ]; then
HPHP_HOME=$SOURCE make install DESTDIR=$BUILD
if [ ! -f $BUILD/usr/bin/hphpize ]; then
echo "$BUILD/bin/hhvm doesn't exist"
exit
fi
fi
echo "Checking version"
$SOURCE/hphp/hhvm/hhvm --version | grep -q $HHVM_VERSION
if [ -z "$PACKAGE" -o ! -d "$PACKAGE" ]; then
PACKAGE=`mktemp -d`
fi
FAKEROOT=$PACKAGE/fakeroot.dat
echo "Packaging HHVM in $PACKAGE"
cd $PACKAGE
if [ ! -d $PACKAGE/root ]; then
mkdir $PACKAGE/root
cp -R $SKELETON/* $PACKAGE/root/
cp -R $DISTRO_DIR/* $PACKAGE/root/
if [ -f $PACKAGE/root/deps ]; then
rm $PACKAGE/root/deps
fi
cp $SOURCE/hphp/hhvm/hhvm $PACKAGE/root/usr/bin/
chmod 755 $PACKAGE/root/usr/bin/hhvm
if [ -f $SOURCE/hphp/tools/oss-repo-mode ]; then
cp $SOURCE/hphp/tools/oss-repo-mode $PACKAGE/root/usr/bin/hhvm-repo-mode
chmod 755 $PACKAGE/root/usr/bin/hhvm-repo-mode
fi
if [ -f $SOURCE/hphp/hack/bin/hh_server ]; then
cp $SOURCE/hphp/hack/bin/hh_client $PACKAGE/root/usr/bin/
cp $SOURCE/hphp/hack/bin/hh_server $PACKAGE/root/usr/bin/
chmod 755 $PACKAGE/root/usr/bin/hh_client
chmod 755 $PACKAGE/root/usr/bin/hh_server
fi
if [ -f $SOURCE/hphp/hack/bin/hackfmt ]; then
cp $SOURCE/hphp/hack/bin/hackfmt $PACKAGE/root/usr/bin/
chmod 755 $PACKAGE/root/usr/bin/hackfmt
fi
if [ -f $SOURCE/hphp/hack/bin/hh_format ]; then
cp $SOURCE/hphp/hack/bin/hh_format $PACKAGE/root/usr/bin/
chmod 755 $PACKAGE/root/usr/bin/hh_format
fi
if [ -f $SOURCE/hphp/hack/bin/h2tp ]; then
cp $SOURCE/hphp/hack/bin/h2tp $PACKAGE/root/usr/bin/
chmod 755 $PACKAGE/root/usr/bin/h2tp
mkdir -p $PACKAGE/root/usr/share/hhvm/hack/
cp -r $SOURCE/hphp/hack/src/h2tp/resources $PACKAGE/root/usr/share/hhvm/hack/hacklib
fi
mkdir -p $PACKAGE/root/usr/share/hhvm/hack/
cp -r $SOURCE/hphp/hack/editor-plugins/emacs $PACKAGE/root/usr/share/hhvm/hack/
if [ "$RELEASE" = "wheezy" ]; then
mkdir -p $PACKAGE/root/usr/lib/hhvm/
cp -L /usr/lib/hhvm/libglog.so.0 $PACKAGE/root/usr/lib/hhvm/
cp -L /usr/lib/hhvm/libjemalloc.so.1 $PACKAGE/root/usr/lib/hhvm/
fi
if [ "$NIGHTLY" = true ]; then
perl -pi -e "s/Conflicts: .*\n//" $PACKAGE/root/DEBIAN/control
perl -pi -e "s/Provides: .*\n//" $PACKAGE/root/DEBIAN/control
perl -pi -e "s/Replaces: .*\n//" $PACKAGE/root/DEBIAN/control
perl -pi -e "s/Version:.*/Version: $PACKAGE_VERSION/" $PACKAGE/root/DEBIAN/control
if [ "$DEBUG" = true ]; then
perl -pi -e "s/Package: hhvm/Package: hhvm-nightly-dbg\nConflicts: hhvm, hhvm-nightly, hhvm-dbg\nProvides: hhvm\nReplaces: hhvm, hhvm-nightly, hhvm-dbg/" $PACKAGE/root/DEBIAN/control
else
perl -pi -e "s/Package: hhvm/Package: hhvm-nightly\nConflicts: hhvm, hhvm-dbg\nProvides: hhvm\nReplaces: hhvm, hhvm-dbg/" $PACKAGE/root/DEBIAN/control
fi
else
if [ "$DEBUG" = true ]; then
perl -pi -e "s/Conflicts: .*\n//" $PACKAGE/root/DEBIAN/control
perl -pi -e "s/Provides: .*\n//" $PACKAGE/root/DEBIAN/control
perl -pi -e "s/Replaces: .*\n//" $PACKAGE/root/DEBIAN/control
perl -pi -e "s/Package: hhvm/Package: hhvm-dbg\nConflicts: hhvm\nProvides: hhvm\nReplaces: hhvm/" $PACKAGE/root/DEBIAN/control
fi
perl -pi -e "s/Version:.*/Version: $PACKAGE_VERSION/" $PACKAGE/root/DEBIAN/control
fi
fakeroot -s $FAKEROOT chown -R root:root $PACKAGE/root
fakeroot -s $FAKEROOT -i $FAKEROOT chown -R www-data:www-data $PACKAGE/root/var/log/hhvm/
fakeroot -s $FAKEROOT -i $FAKEROOT chown -R www-data:www-data $PACKAGE/root/var/cache/hhvm/
echo "finished creating hhvm package contents"
fi
fakeroot -i $FAKEROOT dpkg -b $PACKAGE/root/ hhvm_${PACKAGE_VERSION}_amd64.deb
dpkg-sig -k 452A652F --sign builder $PACKAGE/hhvm_${PACKAGE_VERSION}_amd64.deb
if [ -z "$DPACKAGE" -o ! -d "$DPACKAGE" ]; then
DPACKAGE=`mktemp -d`
fi
FAKEROOT=$DPACKAGE/fakeroot.dat
if [ "$DEBUG" = false ]; then
echo "Packaging dev in $DPACKAGE"
cd $DPACKAGE
if [ ! -d $DPACKAGE/root ]; then
mkdir $DPACKAGE/root
cp -r $SKELETON-dev/* $DPACKAGE/root/
cp -r $DISTRO_DIR-dev/* $DPACKAGE/root/
cp -r $BUILD/usr/include/hphp $DPACKAGE/root/usr/include/
# cmake 2.8.7 does not support debian multiarch and lucid is too old
if cmake --version | grep --quiet "2\.8\.7" || test "$RELEASE" = "lucid"; then
echo "cmake is version 2.8.7. building lib files into lib"
mkdir --parents $DPACKAGE/root/usr/lib
cp -r $BUILD/usr/lib/hhvm $DPACKAGE/root/usr/lib/hhvm
else
# this should give us the lib/<architecture> of the machine we are on
ARCH=`dpkg-architecture -qDEB_BUILD_GNU_TYPE`
echo "cmake is not 2.8.7. building lib files into lib/$ARCH"
mkdir --parents $DPACKAGE/root/usr/lib/$ARCH
cp -r $BUILD/usr/lib/$ARCH/hhvm $DPACKAGE/root/usr/lib/$ARCH/hhvm
fi
cp -r $BUILD/usr/bin/hphpize $DPACKAGE/root/usr/bin/
chmod 755 $DPACKAGE/root/usr/bin/hphpize
perl -pi -e "s/Version:.*/Version: $PACKAGE_VERSION/" $DPACKAGE/root/DEBIAN/control
if [ "$NIGHTLY" = true ]; then
perl -pi -e "s/Package: hhvm-dev/Package: hhvm-dev-nightly\nConflicts: hhvm-dev\nProvides: hhvm-dev\nReplaces: hhvm-dev/" $DPACKAGE/root/DEBIAN/control
fi
fakeroot -s $FAKEROOT chown -R root:root $DPACKAGE/root
echo "finished creating dev package contents"
fi
fakeroot -i $FAKEROOT dpkg -b $DPACKAGE/root/ hhvm_dev_${PACKAGE_VERSION}_amd64.deb
dpkg-sig -k 452A652F --sign builder $DPACKAGE/hhvm_dev_${PACKAGE_VERSION}_amd64.deb
fi
SSH_KEY=$HOME/.ssh/id_rsa_phraseless
STAGING=/var/tmp/staging/$DISTRO_NAME/
RSYNC_HOST=ftp-osl.osuosl.org
mkdir -p $STAGING
rsync --delete -av -e "ssh -i $SSH_KEY" hiphop@$RSYNC_HOST:data/$DISTRO_NAME/ $STAGING || true
# Make a lock on the remote machine so we don't collide with other packagers
LOCKFILE=/tmp/build-sync.lock
echo Waiting for lock...
ssh -i $SSH_KEY hiphop@$RSYNC_HOST <<EOF 2>/dev/null
until mkdir $LOCKFILE; do
sleep 1
done
EOF
echo Lock acquired...
trap "{ ssh -i $SSH_KEY hiphop@$RSYNC_HOST 'rmdir $LOCKFILE' || true; }" EXIT
# do it twice since it takes so long something else might have pushed
rsync --delete -av -e "ssh -i $SSH_KEY" hiphop@$RSYNC_HOST:data/$DISTRO_NAME/ $STAGING
REPREPRO="reprepro --keepunreferencedfiles --keepunusednewfiles includedeb"
cd $STAGING
if [ "$DEVONLY" = true ]; then
# these take up too much space
if [ "$NIGHTLY" = true ]; then
rm pool/main/h/hhvm-dev-nightly/*dev*${RELEASE}*.deb || true
fi
echo "repreproing dev package"
$REPREPRO $RELEASE $DPACKAGE/hhvm_dev_${PACKAGE_VERSION}_amd64.deb
if [ "$LTS" = true ]; then
$REPREPRO $RELEASE-lts-$STABLE_VERSION $DPACKAGE/hhvm_dev_${PACKAGE_VERSION}_amd64.deb
fi
else
if [ "$NIGHTLY" = true ]; then
if [ "$DEBUG" = true ]; then
rm pool/main/h/hhvm-nightly-dbg/*${RELEASE}*.deb || true
else
rm pool/main/h/hhvm-nightly/*${RELEASE}*.deb || true
fi
fi
#TODO figure out how the -b options works
$REPREPRO $RELEASE $PACKAGE/hhvm_${PACKAGE_VERSION}_amd64.deb
if [ "$LTS" = true ]; then
$REPREPRO $RELEASE-lts-$STABLE_VERSION $PACKAGE/hhvm_${PACKAGE_VERSION}_amd64.deb
fi
if [ "$DEBUG" = false ]; then
echo "repreproing dev package"
$REPREPRO $RELEASE $DPACKAGE/hhvm_dev_${PACKAGE_VERSION}_amd64.deb
if [ "$LTS" = true ]; then
$REPREPRO $RELEASE-lts-$STABLE_VERSION $DPACKAGE/hhvm_dev_${PACKAGE_VERSION}_amd64.deb
fi
fi
fi
cd -
RSYNC_OPTS=""
if [ "$NIGHTLY" = true ]; then
# if we are nightly, blow away uneeded things, otherwise keep the old packages
RSYNC_OPTS="--delete"
fi
if [ ! -z "$DRY_RUN" ]; then
RSYNC_OPTS="$RSYNC_OPTS --dry-run"
fi
rsync $RSYNC_OPTS -av -e "ssh -i $SSH_KEY" $STAGING hiphop@$RSYNC_HOST:data/$DISTRO_NAME/
if [ -z "$DRY_RUN" ]; then
ssh -i $SSH_KEY hiphop@$RSYNC_HOST "/home/hiphop/trigger-hiphop"
fi
# cleanup
rm -rf $HEADERS $SOURCE
rm -rf $PACKAGE $BUILD $DPACKAGE
if [ -z "$DRY_RUN" -a "$NIGHTLY" = true -a "$DEBUG" = false ]; then
echo "Pinging FB build tracker"
curl "https://our.intern.facebook.com/intern/hhvm/ossbuildping/?distro=$RELEASE"
echo
fi