package.sh 8.48 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#!/bin/bash

# RUN FROM c:\cygwin64\bin\bash c:\Users\Administrateur\Desktop\BUILD\package.sh

#############################
# CONFIGURATION
#############################

TASK=$1
if [ "$TASK" != "setup"  ] && [ "$TASK" != "build" ] && [ "$TASK" != "test" ]; then
	echo "Unrecognized task ! [ setup | build | test ]"
	exit 1
fi

if [ ! $2 ]; then
    BUILD_TARGET="win-amd64"
else
    BUILD_TARGET=$2
fi

21 22 23 24
if [ -n "${RUN_NIGHTLY_BUILD}" ]
then
    VERSION_NAME="devel"
else
eric pellegrini's avatar
eric pellegrini committed
25 26 27 28 29 30 31
    if [[ ${CI_BUILD_TAG} =~ ^v([0-9]+\.[0-9]+\.[0-9]+)$ ]]
    then
        VERSION_NAME=${BASH_REMATCH[1]}
    else
        echo "Invalid version number ${CI_BUILD_TAG}"
        exit
    fi
32 33
fi

34 35 36 37 38 39 40 41 42 43 44 45 46 47
if [ "$BUILD_TARGET" = "win32" ]; then
	PYTHON_SUFFIX=""
	MSVC_BUILD_TARGET="/x86"
elif [ "$BUILD_TARGET" = "win-amd64" ]; then
	PYTHON_SUFFIX=".amd64"
	MSVC_BUILD_TARGET="/x64"
else
	echo "Unrecognized build target ! [ win32 | win-amd64]"
	exit 1 # signal error
fi

##Which versions of external programs to use
PYTHON_VERSION=2.7.6

48 49
CI_PROJECT_DIR_WIN=$(cygpath -a -w ${CI_PROJECT_DIR})

50 51
# Change working directory to the directory the script is in
# http://stackoverflow.com/a/246128
52 53
#SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SCRIPT_DIR="${CI_PROJECT_DIR}/BuildServer/Windows"
54 55

# This is the directory that will contain the temporary installation
Jamie Hall's avatar
Jamie Hall committed
56
TARGET_DIR="${CI_PROJECT_DIR_WIN}\\BuildServer\\Windows\\Build"
57 58 59 60 61 62 63 64 65 66 67 68 69
TARGET_DIR_CYGWIN=$(cygpath -u $TARGET_DIR)

function extract
{
	echo "Extracting $*"
	echo "7z x -y $*" >> log.txt
	7z x -y $* >> log.txt
}

#############################
# Build the packages
#############################

70
cd "${SCRIPT_DIR}"
71 72 73 74 75 76 77 78

if [ $TASK = "setup" ]; then

	if [ -e "$TARGET_DIR_CYGWIN" ]; then
		echo "Removing previous target dir : $TARGET_DIR_CYGWIN"
		rm -rf ${TARGET_DIR_CYGWIN}
	fi

Jamie Hall's avatar
Jamie Hall committed
79

Jamie Hall's avatar
Jamie Hall committed
80
	DEPENDENCIES_DIR=${CI_WINDOWS_DEPENDENCIES_PATH_UNIX}/${BUILD_TARGET}
Jamie Hall's avatar
Jamie Hall committed
81

82
	PYTHON_MSI=python-${PYTHON_VERSION}${PYTHON_SUFFIX}.msi
Jamie Hall's avatar
Jamie Hall committed
83
	PYTHON_MSI_WIN=${CI_WINDOWS_DEPENDENCIES_PATH}\\${BUILD_TARGET}\\${PYTHON_MSI}
84

85 86
	echo "Extracting python ${PYTHON_MSI_WIN} in ${TARGET_DIR}"
	cmd /c "msiexec  /L* pythonlog.txt /qn /a ${PYTHON_MSI_WIN} TARGETDIR=${TARGET_DIR}"
87

88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
	# Exit now if something goes wrong
	if [ $? -ne 0 ]; then
		status = $?
		echo "Failed to extract python"
		exit status
	fi

	#Clean up python a bit, to keep the package size down
	echo "Cleaning up Python"
	rm -rf ${TARGET_DIR_CYGWIN}/Doc
	rm -rf ${TARGET_DIR_CYGWIN}/Lib/site-packages
	rm -rf ${TARGET_DIR_CYGWIN}/Lib/test
	rm -rf ${TARGET_DIR_CYGWIN}/Tools/Scripts
	rm -rf ${TARGET_DIR_CYGWIN}/tcl
	rm -f ${TARGET_DIR_CYGWIN}/NEWS.txt
	rm -f ${TARGET_DIR_CYGWIN}/${PYTHON_MSI}

	mkdir -p ${TARGET_DIR_CYGWIN}/Lib/site-packages
	mkdir -p ${TARGET_DIR_CYGWIN}/Scripts

	cd ${DEPENDENCIES_DIR}

	echo "Extracting dependencies"
111

112 113
	# extract numpy
	extract numpy-MKL-1.8.0.${BUILD_TARGET}-py2.7.exe PLATLIB
114

115 116 117 118 119 120 121 122 123 124 125 126
	# extract matplotlib and its dependencies
	extract pyparsing-2.0.1.${BUILD_TARGET}-py2.7.exe PURELIB
	extract python-dateutil-2.2.${BUILD_TARGET}-py2.7.exe PURELIB
	extract pytz-2013.9.${BUILD_TARGET}-py2.7.exe PURELIB
	extract six-1.5.2.${BUILD_TARGET}-py2.7.exe PURELIB
	extract matplotlib-1.3.1.${BUILD_TARGET}-py2.7.exe PLATLIB

	#extract Cython
	extract Cython-0.19.2.${BUILD_TARGET}-py2.7.exe PLATLIB
	extract Cython-0.19.2.${BUILD_TARGET}-py2.7.exe SCRIPTS

	# extract Pyro
127
	extract Pyro-3.16.${BUILD_TARGET}.exe PURELIB
128 129

	# extract Sphinx and its dependencies
130 131 132 133 134 135 136 137 138 139
	extract alabaster-0.7.5.${BUILD_TARGET}.exe PURELIB
	extract Pygments-2.0.2.${BUILD_TARGET}.exe PURELIB
	extract Pygments-2.0.2.${BUILD_TARGET}.exe SCRIPTS
	extract Babel-1.3.${BUILD_TARGET}.exe PURELIB
	extract Babel-1.3.${BUILD_TARGET}.exe SCRIPTS
	extract MarkupSafe-0.23.${BUILD_TARGET}-py2.7.exe PLATLIB
	extract Jinja2-2.7.3.${BUILD_TARGET}.exe PURELIB
	extract docutils-0.12.${BUILD_TARGET}.exe PURELIB
	extract docutils-0.12.${BUILD_TARGET}.exe SCRIPTS
	extract Sphinx-1.3.1.${BUILD_TARGET}.exe PURELIB
140
	extract sphinx_rtd_theme-0.1.8.${BUILD_TARGET}.exe PURELIB
141 142 143

	extract nose-1.3.7.${BUILD_TARGET}.exe PURELIB
	extract nose-1.3.7.${BUILD_TARGET}.exe SCRIPTS
144 145 146 147 148

	# extract VTK
	extract VTK-5.10.1.${BUILD_TARGET}-py2.7.exe PURELIB

	# extract wxPython and its dependencies
149
	extract wxPython-common-2.8.12.1.${BUILD_TARGET}-py2.7.exe PURELIB
150
	extract wxPython-2.8.12.1.${BUILD_TARGET}-py2.7.exe PLATLIB
151

152 153 154 155
	# extract ScientificPython
	extract ScientificPython-2.9.2.${BUILD_TARGET}-py2.7.exe DATA
	extract ScientificPython-2.9.2.${BUILD_TARGET}-py2.7.exe PLATLIB
	extract ScientificPython-2.9.2.${BUILD_TARGET}-py2.7.exe SCRIPTS
156

157 158
	# extract MMTK
	extract MMTK-2.7.6.${BUILD_TARGET}-py2.7.exe PLATLIB
159

160 161 162 163 164 165 166 167 168
	# move the packages to the target directory
	echo "Moving dependencies to ${BUILD_TARGET}"
	mv PLATLIB/numpy ${TARGET_DIR_CYGWIN}/Lib/site-packages/numpy

	mv PURELIB/dateutil ${TARGET_DIR_CYGWIN}/Lib/site-packages/dateutil
	mv PURELIB/pyparsing.py ${TARGET_DIR_CYGWIN}/Lib/site-packages/pyparsing.py
	mv PURELIB/pytz ${TARGET_DIR_CYGWIN}/Lib/site-packages/pytz
	mv PURELIB/six.py ${TARGET_DIR_CYGWIN}/Lib/site-packages/six.py
	mv PLATLIB/matplotlib ${TARGET_DIR_CYGWIN}/Lib/site-packages/matplotlib
169

170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
	mv PLATLIB/Cython ${TARGET_DIR_CYGWIN}/Lib/site-packages/Cython
	mv SCRIPTS/cython.py ${TARGET_DIR_CYGWIN}/Scripts/cython.py
	cp ${TARGET_DIR}/Scripts/cython.py ${TARGET_DIR_CYGWIN}/Lib/site-packages/
	mv PURELIB/Pyro ${TARGET_DIR_CYGWIN}/Lib/site-packages/Pyro

	mv PURELIB/alabaster ${TARGET_DIR_CYGWIN}/Lib/site-packages/alabaster
	mv PURELIB/pygments ${TARGET_DIR_CYGWIN}/Lib/site-packages/pygments
	mv SCRIPTS/pygment* ${TARGET_DIR_CYGWIN}/Scripts/
	mv PURELIB/babel ${TARGET_DIR_CYGWIN}/Lib/site-packages/babel
	mv SCRIPTS/pybabel* ${TARGET_DIR_CYGWIN}/Scripts/
	mv PLATLIB/markupsafe ${TARGET_DIR_CYGWIN}/Lib/site-packages/markupsafe
	mv PURELIB/jinja2 ${TARGET_DIR_CYGWIN}/Lib/site-packages/jinja2
	mv PURELIB/docutils ${TARGET_DIR_CYGWIN}/Lib/site-packages/docutils
	mv SCRIPTS/rst* ${TARGET_DIR_CYGWIN}/Scripts/
	mv PURELIB/sphinx ${TARGET_DIR_CYGWIN}/Lib/site-packages/sphinx
	mv PURELIB/sphinx_rtd_theme ${TARGET_DIR_CYGWIN}/Lib/site-packages/sphinx_rtd_theme

	mv PURELIB/nose ${TARGET_DIR_CYGWIN}/Lib/site-packages/nose
	mv SCRIPTS/nosetests ${TARGET_DIR_CYGWIN}/Scripts/
189

190 191 192 193 194
	mv PURELIB/vtk ${TARGET_DIR_CYGWIN}/Lib/site-packages/vtk

	mv PURELIB/wx.pth ${TARGET_DIR_CYGWIN}/Lib/site-packages/
	mv PURELIB/wxversion.py ${TARGET_DIR_CYGWIN}/Lib/site-packages/
	mv PLATLIB/wx-2.8-msw-unicode ${TARGET_DIR_CYGWIN}/Lib/site-packages/wx-2.8-msw-unicode
195

196 197
	echo "package='NumPy'" >> PLATLIB/Scientific/N.py
	mv PLATLIB/Scientific ${TARGET_DIR_CYGWIN}/Lib/site-packages/Scientific
198
	# this is a hack due to a bug introduced by Konrad in version 2.9.2 of Scientific: the N.package is not defined anymore
199 200 201
	# which triggers erros for modules that used N.package (e.g. MMTK.Random)
	mv DATA/Lib/site-packages/Scientific/netcdf3.dll ${TARGET_DIR_CYGWIN}/Lib/site-packages/Scientific
	mv SCRIPTS/task_manager ${TARGET_DIR_CYGWIN}/Scripts/task_manager
202

203
	mv PLATLIB/MMTK ${TARGET_DIR_CYGWIN}/Lib/site-packages/MMTK
204

205 206 207 208 209 210
	rm -rf DATA
	rm -rf PLATLIB
	rm -rf PURELIB
 	rm -rf SCRIPTS

	cd ${SCRIPT_DIR}
211

212 213 214
	rm pythonlog.txt

elif [ $TASK = "build" ]; then
215

216
	cd ${CI_PROJECT_DIR}
217

218 219 220 221 222
	# Get revision number from GIT
	REV_NUMBER=$(git rev-list --count HEAD)
	echo "Revision number is $REV_NUMBER"

	# Add current revision number to python source code (will appear in "About..." dialog)
223
    sed -i '' 's/.*__version__.*/__version__ = \"${VERSION_NAME}\"/' MDANSE/__pkginfo__.py
Jamie Hall's avatar
Jamie Hall committed
224
    sed -i '' 's/.*__revision__.*/__revision__ = \"${REV_NUMBER}\"/' MDANSE/__pkginfo__.py
225 226 227

	# setup the environment for a visual studio build of MDANSE using microsoft SDK 7.0 and build MDANSE
	echo "MDANSE setup and build"
228

229 230
	# go back to the installation base directory
	cd ${SCRIPT_DIR}
231

232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
	cmd /V:ON /E:ON /C "setup_and_build.bat" "${CI_PROJECT_DIR_WIN}" "${TARGET_DIR}" ${MSVC_BUILD_TARGET}

	# Exit now if unable to build
	if [ $? -ne 0 ]; then
		status = $?
		echo "Failed to build MDANSE"
		exit status
	fi

	echo "Running tests"
	cmd /V:ON /E:ON /C "run_tests.bat" "${TARGET_DIR}" "${CI_PROJECT_DIR_WIN}"

	# Exit now if unable to build
	if [ $? -ne 0 ]; then
		status = $?
		echo "One or several unit tests failed"
		exit status
	fi
250

251
	cd ${CI_PROJECT_DIR}
252 253

	# Other way to fetch the current version without python
254
	#MDANSE_VERSION=$(grep -Po '(?<=__version__ = \")\d.\d.\d' MDANSE/__pkginfo__.py)
255 256 257 258

	cd ${SCRIPT_DIR}

	echo "Packaging"
259

260 261
	# create the MDANSE installer
	echo "Creating nsis installer for target ${BUILD_TARGET}..."
262

263
	makensis /V4 /ONSISlog.txt /DVERSION=${VERSION_NAME} /DARCH=${BUILD_TARGET} /DTARGET_DIR="${TARGET_DIR}" MDANSE_installer.nsi
264
fi