2019-05-23 21:13:50 +02:00
|
|
|
#!/usr/bin/env bash
|
2015-05-21 16:31:43 +00:00
|
|
|
|
|
|
|
inc_buildrun=true
|
|
|
|
[ -z "$inc_makerules" ] && . "$basedir/build/makerules.sh"
|
2015-05-28 14:55:27 +00:00
|
|
|
[ -z "$inc_logging" ] && . "$basedir/build/logging.sh"
|
2015-05-31 21:09:48 +00:00
|
|
|
[ -z "$inc_misc" ] && . "$basedir/build/misc.sh"
|
2015-05-24 23:18:52 +00:00
|
|
|
|
2020-04-24 08:52:01 +02:00
|
|
|
match(){
|
|
|
|
printf %s "$1" | egrep -q "$2"
|
|
|
|
}
|
|
|
|
|
|
|
|
dir_maker(){
|
|
|
|
# set up directory tree for output
|
|
|
|
# optimise by only issuing mkdir commands
|
|
|
|
# for leaf directories
|
|
|
|
input="${1%/}"
|
|
|
|
output="${2%/}"
|
|
|
|
|
|
|
|
curpath="$output"
|
|
|
|
find "$input" -depth -type d \
|
|
|
|
\! -path '*/.svn' \! -path '*/.svn/*' \
|
|
|
|
\! -path '*/.git' \! -path '*/.git/*' \
|
|
|
|
-printf '%P\n' \
|
|
|
|
| while read filepath; do
|
|
|
|
oldpath="$curpath"
|
|
|
|
curpath="$output/$filepath/"
|
|
|
|
srcdir="$output/source/$filepath/"
|
|
|
|
match "$oldpath" "^$curpath" || mkdir -p "$curpath" "$srcdir"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2020-04-23 17:14:47 +02:00
|
|
|
# The actual build
|
|
|
|
buildrun(){
|
2019-03-11 20:53:35 +01:00
|
|
|
set -o pipefail
|
|
|
|
|
|
|
|
printf %s "$start_time" > "$(logname start_time)"
|
|
|
|
|
2015-05-28 14:55:27 +00:00
|
|
|
ncpu="$(grep -c ^processor /proc/cpuinfo)"
|
2015-05-21 16:31:43 +00:00
|
|
|
|
2015-09-14 14:15:53 +00:00
|
|
|
[ -n "$statusdir" ] && cp "$basedir/build/status.html.sh" "$statusdir/index.cgi"
|
2019-03-11 20:53:35 +01:00
|
|
|
|
2019-03-11 02:35:51 +01:00
|
|
|
[ -f "$(logname lasterror)" ] && rm "$(logname lasterror)"
|
|
|
|
[ -f "$(logname debug)" ] && rm "$(logname debug)"
|
2015-09-14 14:15:53 +00:00
|
|
|
|
2019-03-11 20:53:35 +01:00
|
|
|
{
|
|
|
|
echo "Starting phase 1" \
|
2019-06-27 20:56:40 +02:00
|
|
|
&& make --silent --directory="$basedir" build_env="${build_env:-development}" 2>&1 \
|
2019-03-11 20:53:35 +01:00
|
|
|
&& echo "Finishing phase 1" \
|
|
|
|
|| die "Error during phase 1"
|
|
|
|
} | t_logstatus phase_1 || exit 1
|
2015-05-21 16:31:43 +00:00
|
|
|
|
2019-03-11 18:34:11 +01:00
|
|
|
dir_maker "$basedir" "$stagedir" || exit 1
|
2015-05-24 23:18:52 +00:00
|
|
|
|
2019-03-11 21:13:10 +01:00
|
|
|
forcelog Makefile
|
|
|
|
|
2019-03-11 20:53:35 +01:00
|
|
|
{
|
|
|
|
tree_maker "$basedir" "$stagedir" 2>&1 \
|
|
|
|
|| die "Error during phase 2 Makefile generation"
|
|
|
|
} > "$(logname Makefile)" || exit 1
|
2019-02-16 12:35:53 +01:00
|
|
|
|
2019-03-11 20:53:35 +01:00
|
|
|
{
|
|
|
|
echo "Starting phase 2" \
|
2019-03-12 19:34:57 +01:00
|
|
|
&& make --silent --jobs=$ncpu --file="$(logname Makefile)" 2>&1 \
|
2019-03-11 20:53:35 +01:00
|
|
|
&& echo "Finishing phase 2" \
|
|
|
|
|| die "Error during phase 2"
|
|
|
|
} | t_logstatus phase_2 || exit 1
|
2015-06-04 17:21:37 +00:00
|
|
|
|
2016-11-03 19:12:12 +00:00
|
|
|
if [ "$stagedir" != "$target" ]; then
|
2020-03-23 16:39:20 +01:00
|
|
|
# rsync issues a "copying unsafe symlink" message for each of the "unsafe"
|
|
|
|
# symlinks which we copy while rsyncing. These messages are issued even if
|
|
|
|
# the files have not changed and clutter up the output, so we filter them
|
|
|
|
# out.
|
2021-10-12 16:52:42 +02:00
|
|
|
{
|
|
|
|
for destination in ${target//,/ }; do
|
|
|
|
echo "Syncing files to $(echo "$destination" | grep -Po "(?<=@)[^:]+")"
|
|
|
|
rsync -av --copy-unsafe-links --del "$stagedir/" "$destination/" | grep -v "copying unsafe symlink"
|
|
|
|
done
|
|
|
|
} | t_logstatus stagesync
|
2016-11-03 19:12:12 +00:00
|
|
|
fi
|
|
|
|
|
2019-03-11 20:53:35 +01:00
|
|
|
date +%s > "$(logname end_time)"
|
|
|
|
|
2015-10-05 14:25:09 +00:00
|
|
|
if [ -n "$statusdir" ]; then
|
2019-03-11 20:53:35 +01:00
|
|
|
( cd "$statusdir"; ./index.cgi | tail -n+3 > status_$(date +%s).html )
|
2015-10-05 14:25:09 +00:00
|
|
|
fi
|
2015-05-21 16:31:43 +00:00
|
|
|
}
|
2015-05-31 21:09:48 +00:00
|
|
|
|
2020-07-28 15:59:05 +02:00
|
|
|
# Update git (try 3x) and then do an actual build
|
2017-08-18 11:30:02 +00:00
|
|
|
git_build_into(){
|
|
|
|
forcelog GITchanges; GITchanges="$(logname GITchanges)"
|
|
|
|
forcelog GITerrors; GITerrors="$(logname GITerrors)"
|
|
|
|
|
2020-07-28 15:59:05 +02:00
|
|
|
gitterm=1
|
|
|
|
i=0
|
|
|
|
while [[ ( $gitterm -ne 0 ) && ( $i -lt 3) ]]; do
|
|
|
|
((i++))
|
|
|
|
|
|
|
|
git -C "$basedir" pull >"$GITchanges" 2>"$GITerrors"
|
|
|
|
gitterm="$?"
|
|
|
|
|
|
|
|
if [ $gitterm -ne 0 ]; then
|
|
|
|
debug "Git pull unsuccessful. Trying again in a few seconds."
|
|
|
|
sleep $(shuf -i 10-30 -n1)
|
|
|
|
fi
|
|
|
|
done
|
2017-08-18 11:30:02 +00:00
|
|
|
|
|
|
|
if [ "$gitterm" -ne 0 ]; then
|
2019-03-11 18:34:11 +01:00
|
|
|
die "GIT reported the following problem:\n$(cat "$GITerrors")"
|
2017-08-18 11:30:02 +00:00
|
|
|
fi
|
|
|
|
|
2020-03-24 17:15:05 +01:00
|
|
|
if egrep '^Already up[ -]to[ -]date' "$GITchanges"; then
|
2019-03-11 18:34:11 +01:00
|
|
|
debug "No changes to GIT:\n$(cat "$GITchanges")"
|
2019-02-16 15:25:05 +01:00
|
|
|
# Exit status should only be 0 if there was a successful build.
|
|
|
|
# So set it to 1 here.
|
|
|
|
exit 1
|
2015-05-31 21:09:48 +00:00
|
|
|
fi
|
2019-03-11 18:34:11 +01:00
|
|
|
|
|
|
|
logstatus GITlatest < "$GITchanges"
|
2020-04-23 17:14:47 +02:00
|
|
|
buildrun
|
|
|
|
}
|
|
|
|
|
|
|
|
# Clean up everything and then do an actual (full) build
|
|
|
|
build_into(){
|
|
|
|
|
|
|
|
# Clean up source directory.
|
|
|
|
git -C "${basedir}" clean -dxf
|
|
|
|
|
|
|
|
# Remove old stage directory.
|
|
|
|
rm -rf "${stagedir}"
|
|
|
|
|
|
|
|
buildrun
|
2015-05-31 21:09:48 +00:00
|
|
|
}
|