-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_build.sh
executable file
·132 lines (109 loc) · 3.84 KB
/
setup_build.sh
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
#!/bin/bash
# Script to get a git branch and make a .tar.gz on a shared disk, for use by
# autobuild scripts on our build machines.
#
# Should be run on from a crontab on a machine that has access to a git
# clone, e.g.
#
# 10 1 * * * /home/ben/imp_nightly_builds/setup_build.sh develop
if [ $# -ne 1 ]; then
echo "Usage: $0 branch"
exit 1
fi
# Get config
. $(dirname $0)/build_config.sh
BRANCH=$1
TMPDIR=/var/tmp/imp-build-$$
IMPTOP=${IMP_INSTALL_TOP}/$BRANCH
mkdir -p ${IMPTOP}
cd ${GIT_TOP}/imp.git
# Get top-most revision of branch we're interested in
rev=$(git rev-parse ${BRANCH})
shortrev=$(git rev-parse --short ${BRANCH})
# Get old revision
oldrev_file=${IMPTOP}/.new/build/imp-gitrev
if [ -f "${oldrev_file}" ]; then
oldrev=$(cat ${oldrev_file})
fi
# For non-develop builds, skip if the revision hasn't changed
if [ "${BRANCH}" != "develop" ] && [ "${oldrev}" = "${rev}" ]; then
exit 0
fi
rm -rf ${TMPDIR}
mkdir ${TMPDIR}
cd ${TMPDIR}
# Get IMP code from git
git clone -b ${BRANCH} -q ${GIT_TOP}/imp.git
# Update any submodules, etc. if necessary
(cd imp && git submodule --quiet update --init --recursive) > /dev/null
if [ -d imp/modules/rmf/dependency/RMF_source ]; then
# Get submodule revision
RMF_rev=`(cd imp/modules/rmf/dependency/RMF_source && git rev-parse HEAD)`
else
# Harder to do for subtree; parse the specially-formatted log message
RMF_rev=`(cd imp && git log --grep='git\-subtree\-dir: modules\/rmf\/dependency\/RMF' -n 1|grep git-subtree-split|cut -d: -f 2|cut -b2-)`
fi
# Get date and revision-specific install directories
SORTDATE=$(date -u "+%Y%m%d")
DATE=$(date -u +'%Y/%m/%d')
IMPSUBDIR=${SORTDATE}-${shortrev}
IMPINSTALL=${IMPTOP}/${IMPSUBDIR}
if [ -e imp/VERSION ]; then
# If VERSION file is present, use it
IMPVERSION="$(sed -e 's/[ /-]/./g' imp/VERSION)"
else
# Make sure VERSION file is reasonable
(cd imp && python3 tools/build/make_version.py --source=.)
if [ ${BRANCH} = "develop" ]; then
# For nightly builds, prepend the date so the packages are upgradeable
IMPVERSION="${SORTDATE}.develop.${shortrev}"
else
IMPVERSION="$(sed -e 's/[ /-]/./g' imp/VERSION)"
# For stable releases, assign submodules the same version as IMP itself
rm -f imp/modules/*/VERSION
fi
fi
# Make sure VERSION file matches the package version
echo $IMPVERSION > imp/VERSION
IMPSRCTGZ=${IMPINSTALL}/build/sources/imp-${IMPVERSION}.tar.gz
rm -rf ${IMPINSTALL}
mkdir -p ${IMPINSTALL}/build/sources ${IMPINSTALL}/build/logs
# Make link so build system can find the install location
rm -f ${IMPTOP}/.new
ln -s ${IMPSUBDIR} ${IMPTOP}/.new
# Add build date to nightly docs
if [ ${BRANCH} = "develop" ]; then
IMPVER="develop.${shortrev}"
(cd imp/tools/build/doxygen_templates && sed -e "s#^PROJECT_NUMBER.*#PROJECT_NUMBER = ${IMPVER}, ${DATE}#" < Doxyfile.in > .dox && mv .dox Doxyfile.in)
fi
# Write out version files
verfile="${IMPINSTALL}/build/imp-version"
revfile="${IMPINSTALL}/build/imp-gitrev"
RMF_revfile="${IMPINSTALL}/build/rmf-gitrev"
mkdir -p "${IMPINSTALL}/build"
echo "${IMPVERSION}" > $verfile
echo "${rev}" > $revfile
echo "${RMF_rev}" > $RMF_revfile
# Write out log from previous build to this one
logfile="${IMPINSTALL}/build/imp-gitlog"
if [ -n "${oldrev}" ]; then
(cd imp && git log ${oldrev}..${rev} --format="%H%x00%an%x00%ae%x00%s") > ${logfile}
fi
# Write out list of all components
compfile="${IMPINSTALL}/build/imp-components"
python3 <<END
import sys
sys.path.insert(0, 'imp/tools/build')
import tools
mf = tools.ModulesFinder(source_dir='imp')
with open('$compfile', 'w') as fh:
fh.write('\n'.join('module\t' + m.name for m in mf.get_ordered()))
END
# Write out a tarball:
mv imp imp-${IMPVERSION} && tar --exclude .git -czf ${IMPSRCTGZ} imp-${IMPVERSION}
# Add build scripts
cd $(dirname $0)
cp build.sh build_config.sh build_vagrant.sh build_functions.sh "${IMPINSTALL}/build/"
# Cleanup
cd /
rm -rf ${TMPDIR}