Repository navigation
Expand file tree
/
Copy pathmake-build.sh
More file actions
executable file
·165 lines (150 loc) · 5.6 KB
/
Copy pathmake-build.sh
File metadata and controls
executable file
·165 lines (150 loc) · 5.6 KB
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
#!/bin/bash
# set -x
CHROOT_BASE=
usage() {
echo "$0 -r <repository> -d <distribution> -b <builddir> [-n] [-a <arch>] [-v <version>] [-u] [-e] [-c] [-m] [-k]"
exit 1
}
DEFAULT_TARGETS="source pkg-chroot"
### CLI args
while getopts r:b:d:v:a:uencmhk option ; do
case "$option" in
r) TARGET_REP="$OPTARG" ;;
b) BUILD_DIR="$OPTARG" ;;
d) DISTRIBUTION="$OPTARG" ;;
v) VERSION="$OPTARG" ;;
n) BINARY_UPLOAD="BINARY_UPLOAD=true" ;;
c) CHECKROOT_UPGRADE="true" ;;
u) RELEASE="release" ;;
a) ARCH="$OPTARG" ;;
e) CHECK_EXISTENCE="check-existence" ;;
m) DEFAULT_TARGETS="kernel-module-chroot" ;;
k) DEFAULT_TARGETS="clean patch kpkg-arch" ;;
h) usage ;;
\?) usage ;;
esac
done
[[ -z "$ARCH" ]] && ARCH=amd64
if [[ $ARCH == amd64 ]] && [[ $DEFAULT_TARGETS == *kpkg-arch* ]] ; then
# also build source, doc, etc
DEFAULT_TARGETS="$DEFAULT_TARGETS kpkg-indep"
fi
MAKE_VARIABLES="DISTRIBUTION=${DISTRIBUTION} REPOSITORY=${TARGET_REP} ${BINARY_UPLOAD} TIMESTAMP=$(date +%Y-%m-%dT%H%M%S_%N)"
if [ -n "$VERSION" ] ; then
MAKE_VARIABLES="$MAKE_VARIABLES VERSION=\"${VERSION}\""
VERSION_TARGET=""
else
VERSION_TARGET="version"
fi
processResult() {
result=$1
action=$2
seconds=$(( $(date +%s) - $3 ))
[ $result = 0 ] && resultString="SUCCESS" || resultString="ERROR"
let results=results+result
[[ "$DEFAULT_TARGETS" != *kpkg-arch* ]] && make -f $PKGTOOLS_HOME/Makefile $MAKE_VARIABLES clean-chroot-files
str="**** %-7s %-40s in %3ds: make in %-40s exited with return code $result"
printf "$str" "${resultString}" "($action)" "$seconds" "$directory"
echo
echo "# ======================="
popd > /dev/null
}
### a few variables
export PATH=/sbin:/usr/sbin:${PATH}
FILE_IN="build-order.txt"
PKGTOOLS_HOME=$(dirname $(readlink -f $0))
results=0
### main
# cd into the main trunk (the buildbot is already in there)
cd "${BUILD_DIR}" 2> /dev/null
# patch, if necessary
[ -f Makefile ] && grep -qE '^patch:' Makefile && echo "Patching sources" && make -f Makefile patch
# grab the content of the build-order.txt file
build_dirs=()
while read package repositories architectures ; do
case $package in
\#*) continue ;; # comment
\$*) #command
# for a command, there's no delimited fields, so use the whole line
[[ "${package} ${repositories} ${architectures}" != *${TARGET_REP}* ]] && continue
build_dirs[${#build_dirs[*]}]="$package ${repositories//,/ }"
;;
"") continue ;; # empty line
*) # valid line
# do we build this package for this arch ?
[[ -n "$architectures" ]] && [[ "$architectures" != *${ARCH}* ]] && continue
# do we build this package for this repository ?
[[ "$repositories" != *${TARGET_REP}* ]] && continue
case $ARCH in
amd64) pattern="(any|all|$ARCH)" ;;
*) pattern="(any|$ARCH)" ;;
esac
if [[ "$DEFAULT_TARGETS" = "kernel-module-chroot" ]] || [[ "$DEFAULT_TARGETS" == *kpkg-arch* ]] || grep -qE "^Architecture:.*$pattern" $package/debian/control 2> /dev/null ; then
build_dirs[${#build_dirs[*]}]="$package"
elif [[ -f $package/source.conf ]] ; then # new-style source
pushd $package
make -f $PKGTOOLS_HOME/Makefile get-upstream-source
popd
dir="$(ls -d ${package}/*/ | grep -v patches)"
# copy patches against upstream code to debian/patches/
mkdir -p $dir/debian/patches
cp $package/upstream-patches/*.patch $dir/debian/patches
cat $package/upstream-patches/series >> $dir/debian/patches/series
# apply patches against Debian packaging directly to debian/
while read p ; do
patch -d $dir -p0 < $package/debian-patches/$p
done < $package/debian-patches/series
build_dirs[${#build_dirs[*]}]=$dir
fi ;;
esac
done < $FILE_IN
if ! [[ -f $FILE_IN ]] ; then # build in the current dir no matter what
build_dirs[${#build_dirs[*]}]="."
fi
# now cd into each dir in build_dirs and make
for directory in "${build_dirs[@]}" ; do
echo
case $directory in
\$*) # command
echo "Running $directory"
eval "${directory/\$}"
continue
;;
esac
echo "# $directory"
# cd into it, and attempt to build
pushd "$directory" > /dev/null
# clean up a bit
find . -type f -name core -exec rm {} \;
# bring resources/ from pkgtools into the source directory we cd'ed in
cp -r $PKGTOOLS_HOME/resources ./
seconds=$(date +%s)
make -f $PKGTOOLS_HOME/Makefile $MAKE_VARIABLES clean-build || true # try anyway
if [[ "$DEFAULT_TARGETS" != *kpkg-arch* ]] ; then
output=$(make -f $PKGTOOLS_HOME/Makefile $MAKE_VARIABLES clean-chroot-files $VERSION_TARGET $CHECK_EXISTENCE)
version=$(cat debian/version)
if [ -n "$CHECK_EXISTENCE" ] ; then
matches=$(echo "$output" | grep "is available in")
if [ -n "$matches" ] ; then
if echo "$matches" | grep -q $DISTRIBUTION ; then
processResult 0 "$version already present in $DISTRIBUTION" $seconds && continue
else
distributionFrom=$(echo $matches | awk '{print $NF}')
make -f $PKGTOOLS_HOME/Makefile $MAKE_VARIABLES DISTRIBUTION_FROM=$distributionFrom copy-src
processResult $? "$version copied from $distributionFrom" $seconds && continue
fi
fi
fi
make -f $PKGTOOLS_HOME/Makefile $MAKE_VARIABLES $DEFAULT_TARGETS $RELEASE
else
make -f ./Makefile $MAKE_VARIABLES $DEFAULT_TARGETS $RELEASE
fi
result=$?
rm -fr ./resources
processResult $result "$version actual build" $seconds
# # if we're building only arch-dependent pkgs, we need to give the IQD time to process uploads
# [ $ARCH = "i386" ] || sleep 31
done
# do this last
make -f $PKGTOOLS_HOME/Makefile $MAKE_VARIABLES remove-existence-chroot remove-chroot
exit $results