public
Last active

Bash script for local nightly builds of QGIS master branch on Mac OS X Snow Leopard and Lion

  • Download Gist
qgis-nightly-build.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
#!/bin/bash
 
# -*- coding: utf-8 -*-
#
# Create QGIS for Mac OS X nightly build from github.com 'master' branch.
# Keep a number of dmg archives of previous builds as backups.
#
# Tested under Lion 10.7.4 and Snow Leopard 10.6.8, **run via sudo**
 
# Requires same kyngchaos.com framework setup and build environment as per
# https://github.com/qgis/Quantum-GIS/blob/master/INSTALL
 
### start run settings
CPUCORES=`/usr/sbin/sysctl -n hw.ncpu`
 
GITPULL=1
GITSTASH=1
 
BUILDQGIS=1
QGISDEBUG=0
QGISAPIDOCS=TRUE
QGISTESTS=FALSE
 
ADDQSCI=1
 
ARCHIVEAPP=1
KEEPARCHIVES=10
### end run settings
 
# output locations
USERDIR=`echo ~`
QGISDIR="$USERDIR/QGIS"
NIGHTLYDIR="$QGISDIR/github-nightly"
QGISGITDIR="$NIGHTLYDIR/quantum-gis"
BUILDDIR="$QGISGITDIR/build"
APPTARGET="$NIGHTLYDIR/QGIS.app"
NIGHTLYARCHIVES="$NIGHTLYDIR/archives"
 
# config build options
BUILDTYPE="MinSizeRel"
if [ $QGISDEBUG -gt 0 ]; then
BUILDTYPE="RelWithDebInfo"
fi
 
# git setup
GIT=/usr/local/git/bin/git
GITURL="git://github.com/qgis/Quantum-GIS.git"
 
 
###############################################################################
## Start Nightly Build
###############################################################################
 
echo -e "QGIS Nightly Build @ `date`"
 
 
###############################################################################
## Update QGIS Working Tree
###############################################################################
 
cd "$NIGHTLYDIR"
 
if [ $GITPULL -gt 0 ]; then
 
# check for existing repo dir
if [ ! -d "$QGISGITDIR" ]; then
echo -e "\nRepository missing, cloning 'master' branch...\n"
mkdir "$QGISGITDIR" && cd "$QGISGITDIR"
$GIT init
$GIT remote add -f -t master -m master origin "$GITURL"
$GIT merge origin
if [ $? -gt 0 ]; then
echo -e "\nERROR in cloning git repo 'master' branch!"
rm -R "$QGISGITDIR"
exit 1
fi
else
cd "$QGISGITDIR"
if [ $GITSTASH -gt 0 ]; then
echo -e "\nClearing any existing stash...\n"
$GIT stash clear
echo -e "\nStashing any unstaged changes...\n"
$GIT stash
fi
# update master branch
echo -e "\nRepository exists, pulling 'master' branch ...\n"
# this assumes no other branches have been created beyond master
$GIT pull
if [ $? -gt 0 ]; then
echo -e "\nERROR pulling git repo 'master' branch!"
exit 1
fi
if [ $GITSTASH -gt 0 ]; then
echo -e "\nApplying any existing stash...\n"
$GIT stash apply
fi
# if [ $? -gt 0 ]; then
# echo -e "\nERROR in applying stash!"
# exit 1
# fi
fi
chown -R $SUDO_USER "$QGISGITDIR"
 
fi
 
 
###############################################################################
## Build QGIS.app
###############################################################################
if [ $BUILDQGIS -gt 0 ]; then
# remove any previous build dir
if [ -d "$BUILDDIR" ]; then
echo -e "\nRemoving existing build directory ...\n"
rm -R "$BUILDDIR"
fi
# QGIS CMake setup supports out-of-source dir builds
# make build directory and configure
mkdir "$BUILDDIR" && cd "$BUILDDIR"
echo -e "\nConfiguring nightly build ...\n"
cmake -D CMAKE_INSTALL_PREFIX="$NIGHTLYDIR" \
-D CMAKE_BUILD_TYPE="$BUILDTYPE" \
-D ENABLE_TESTS="$QGISTESTS" \
-D WITH_INTERNAL_SPATIALITE=FALSE \
-D WITH_PYSPATIALITE=FALSE \
-D QWT_LIBRARY=/usr/local/qwt-5.2.2/lib/libqwt.dylib \
-D QWT_INCLUDE_DIR=/usr/local/qwt-5.2.2/include \
-D BISON_EXECUTABLE=/usr/local/bin/bison \
-D WITH_APIDOC="$QGISAPIDOCS" \
-D QGIS_MACAPP_BUNDLE=2 \
..
if [ $? -gt 0 ]; then
echo -e "\nERROR configuring nightly QGIS build!"
exit 1
fi
#Build and install target QGIS.app
echo -e "\nMaking nightly build ...\n"
make -j $CPUCORES
if [ $? -gt 0 ]; then
echo -e "\nERROR building QGIS!"
exit 1
fi
chown -R $SUDO_USER "$BUILDDIR"
# remove last app built if current repo built
if [ -d "$APPTARGET" ]; then
echo -e "\nRemoving previously built app ...\n"
rm -R "$APPTARGET"
fi
echo -e "\nInstalling nightly build ...\n"
make install
if [ $? -gt 0 ]; then
echo -e "\nERROR installing QGIS!"
exit 1
fi
 
fi
 
 
###############################################################################
## Add QScintilla Python modules to QGIS.app
###############################################################################
 
if [ $ADDQSCI -gt 0 ]; then
echo -e "\nAdding Qsci.so module to nightly build..."
# cd $QSCIPATH
# QSCIPATH="$QGISDIR/Qsci_Lion/4.8.0"
# /bin/cp -a Qsci.so "$APPTARGET/Contents/Resources/python/PyQt4/";
# /bin/cp -a libqscintilla2.* "$APPTARGET/Contents/MacOS/lib/";
# /usr/bin/install_name_tool -add_rpath @executable_path/lib/libqscintilla2.8.dylib "$APPTARGET/Contents/MacOS/QGIS"
QSCI=''
if [ -e /Library/Python/2.7/site-packages/PyQt4/Qsci.so ]; then
QSCI=/Library/Python/2.7/site-packages/PyQt4/Qsci.so
elif [ -e /Library/Python/2.6/site-packages/PyQt4/Qsci.so ]; then
QSCI=/Library/Python/2.6/site-packages/PyQt4/Qsci.so
fi
if [ -n $QSCI ]; then
cd "$APPTARGET/Contents/Resources/python/PyQt4"
cp -a $QSCI .
install_name_tool -change /Library/Frameworks/libqscintilla2.8.dylib \
@loader_path/../../../MacOS/lib/libqscintilla2.8.dylib Qsci.so
install_name_tool -change QtCore.framework/Versions/4/QtCore \
@loader_path/../../../MacOS/../Frameworks/QtCore.framework/QtCore Qsci.so
install_name_tool -change QtGui.framework/Versions/4/QtGui \
@loader_path/../../../MacOS/../Frameworks/QtGui.framework/QtGui Qsci.so
cd "$APPTARGET/Contents/MacOS/lib"
cp -a /Library/Frameworks/libqscintilla*.dylib .
install_name_tool -change QtCore.framework/Versions/4/QtCore \
@loader_path/../../Frameworks/QtCore.framework/QtCore libqscintilla2.8.dylib
install_name_tool -change QtGui.framework/Versions/4/QtGui \
@loader_path/../../Frameworks/QtGui.framework/QtGui libqscintilla2.8.dylib
install_name_tool -add_rpath @executable_path/lib/libqscintilla2.8.dylib \
"$APPTARGET/Contents/MacOS/QGIS"
else
echo -e "\nQsci.so module not found..."
fi
fi
 
 
# set permissions on app
chown -R $SUDO_USER "$APPTARGET"
 
 
###############################################################################
## Archive QGIS.app to DMG Archives
###############################################################################
if [ $ARCHIVEAPP -gt 0 ]; then
 
sleep 5
# make sure dir structure exists
if [ ! -d "$NIGHTLYARCHIVES" ]; then
mkdir -p "$NIGHTLYARCHIVES"
fi
# congifure archive file
cd "$QGISGITDIR"
REVHASH=`$GIT log --no-color --pretty=format:%H origin/master^..origin/master`
REVSHORTHASH=`echo ${REVHASH:0:7}`
REVMAJOR=`grep 'SET(CPACK_PACKAGE_VERSION_MAJOR' CMakeLists.txt | egrep -o '[0-9]+'`
REVMINOR=`grep 'SET(CPACK_PACKAGE_VERSION_MINOR' CMakeLists.txt | egrep -o '[0-9]+'`
REVPATCH=`grep 'SET(CPACK_PACKAGE_VERSION_PATCH' CMakeLists.txt | egrep -o '[0-9]+'`
VERNUM="${REVMAJOR}-${REVMINOR}-${REVPATCH}"
TODAY=`date -u +"%Y-%m-%d"`
APPNAME="qgis-nightly_${VERNUM}_${TODAY}_${REVSHORTHASH}"
APPARCHIVE="$APPNAME.dmg"
OLDARCHIVE="$APPNAME_old.dmg"
# archive built app to compressed dmg
echo -e "\nArchiving nightly build ...\n"
cd "$NIGHTLYDIR"
# keep at least 1 archive with same hash, in case build fails
if [ -e "$NIGHTLYARCHIVES/$APPARCHIVE" ]; then
if [ -e "$NIGHTLYARCHIVES/$OLDARCHIVE" ]; then
rm "$NIGHTLYARCHIVES/$OLDARCHIVE"
fi
mv "$NIGHTLYARCHIVES/$APPARCHIVE" "$NIGHTLYARCHIVES/$OLDARCHIVE"
fi
# create dmg archive
hdiutil create -nospotlight -skipunreadable -noanyowners \
-copyuid $SUDO_USER -srcfolder "$APPTARGET" "$NIGHTLYARCHIVES/$APPARCHIVE"
if [ $? -gt 0 ]; then
echo -e "\nERROR archiving QGIS to dmg!"
exit 1
fi
chown -R $SUDO_USER "$NIGHTLYARCHIVES"
# prune dmg archives
CURFILE=1
for f in $( ls -1t "$NIGHTLYARCHIVES" ); do
if [ $CURFILE -gt $KEEPARCHIVES ]; then
rm "$NIGHTLYARCHIVES/$f"
fi
let CURFILE=CURFILE+1
done
 
fi
 
 
exit 0

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.