-
Notifications
You must be signed in to change notification settings - Fork 187
/
build-recipe-dsc
221 lines (198 loc) · 9.12 KB
/
build-recipe-dsc
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
#
# dsc specific functions.
#
################################################################
#
# Copyright (c) 1995-2014 SUSE Linux Products GmbH
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program (see the file COPYING); if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
#
################################################################
recipe_setup_dsc() {
TOPDIR=/usr/src/packages
test "$DO_INIT_TOPDIR" = false || rm -rf "$BUILD_ROOT$TOPDIR"
mkdir -p "$BUILD_ROOT$TOPDIR"
mkdir -p "$BUILD_ROOT$TOPDIR/OTHER"
mkdir -p "$BUILD_ROOT$TOPDIR/SOURCES"
mkdir -p "$BUILD_ROOT/$TOPDIR/DEBS"
copy_sources "$MYSRCDIR" "$BUILD_ROOT$TOPDIR/SOURCES/"
chown -hR "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"
# FIX to work with baselibs_$PROJ etc
if test -e "$MYSRCDIR/baselibs-deb.conf" ; then
echo "dsc build and baselibs-deb.conf present: forcing --baselibs to true"
CREATE_BASELIBS=true
fi
}
dsc_export_origtar() {
test -d "$BUILD_ROOT$TOPDIR/SOURCES/build.origtar" || return
local origtar delta
for origtar in "$BUILD_ROOT$TOPDIR/SOURCES/build.origtar"/*.tar ; do
for delta in "$origtar"*.delta "" ; do
test -n "$delta" -a -f "$delta" && break
done
delta="${delta##*/}"
delta="${delta%.delta}"
if test -n "$delta" ; then
echo "recreating upstream $delta with pristine-tar"
mkdir "$BUILD_ROOT$TOPDIR/pristine_tar_tmp"
chroot $BUILD_ROOT bash -c "cd $TOPDIR/pristine_tar_tmp && tar xf - && cd * && pristine-tar gentar $TOPDIR/SOURCES/build.origtar/$delta.delta $TOPDIR/$delta" < "$origtar" || cleanup_and_exit 1 "pristine tar generation failed"
rm -rf "$BUILD_ROOT$TOPDIR/pristine_tar_tmp"
else
echo "creating upstream ${origtar##*/}.gz"
gzip < "$origtar" > "$BUILD_ROOT$TOPDIR/${origtar##*/}.gz" || cleanup_and_exit 1 "tarball compression failed"
fi
done
rm -rf "$BUILD_ROOT$TOPDIR/SOURCES/build.origtar"
}
recipe_prepare_dsc() {
rm -rf "$BUILD_ROOT$TOPDIR/BUILD"
mkdir -p "$BUILD_ROOT$TOPDIR/SOURCES.DEB"
chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"
DEB_TRANSFORM=
DEB_SOURCEDIR="$TOPDIR/SOURCES"
DEB_DSCFILE="$RECIPEFILE"
for f in $BUILD_ROOT$TOPDIR/SOURCES/debian.* ; do
test -f $f && DEB_TRANSFORM=true
done
# remove rpm macros (everything after "%")
# they are not evaluated by the Debian build process
DEB_RELEASE=`sed 's/%.*$//' <<< $RELEASE`
OBS_DCH_RELEASE=""
if test "$RECIPEFILE" = debian/control -o "$RECIPEFILE" = debian.control ; then
dsc_export_origtar
mv $BUILD_ROOT$DEB_SOURCEDIR $BUILD_ROOT$TOPDIR/BUILD
if test -d $BUILD_ROOT$TOPDIR/BUILD/debian ; then
for f in debian.control debian.changelog ; do
test -f $BUILD_ROOT$TOPDIR/BUILD/$f || continue
mv $BUILD_ROOT$TOPDIR/BUILD/$f $BUILD_ROOT$TOPDIR/BUILD/debian/${f#debian.}
done
fi
return
fi
if test -n "$DEB_TRANSFORM" ; then
CHANGELOGARGS=
test -n "$CHANGELOG" -a -f "$BUILD_ROOT/.build-changelog" && CHANGELOGARGS="--changelog $BUILD_ROOT/.build-changelog"
echo "Found files matching debian.*, running debian transformer..."
if [ "$RELEASE" ]; then
echo "release: ($RELEASE), release (DEB) ($DEB_RELEASE)"
RELEASEARGS="--release $DEB_RELEASE"
if grep -Eq '^OBS-DCH-RELEASE: 1' $BUILD_ROOT$TOPDIR/SOURCES/$RECIPEFILE \
&& grep -Eq '^Version:' $BUILD_ROOT$TOPDIR/SOURCES/$RECIPEFILE
then
WSCHAR="`printf '\t '`"
# https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-version
VERSION="`grep -E '^Version:' $BUILD_ROOT$TOPDIR/SOURCES/$RECIPEFILE | sed -e 's,^Version:'"[$WSCHAR][$WSCHAR]"'*,,' -e 's,'"[$WSCHAR]"'*$,,'`"
echo "OBS-DCH-RELEASE: DSC file originally spelled package version as ${VERSION}"
case "$VERSION" in
*-*) # Got a debver or more already, add a plus-suffix to debver
OBS_DCH_RELEASE="+$DEB_RELEASE" ;;
*) # No debver, add the first such token
OBS_DCH_RELEASE="-$DEB_RELEASE" ;;
esac
fi
fi
if ! debtransform $CHANGELOGARGS $RELEASEARGS $BUILD_ROOT$TOPDIR/SOURCES $BUILD_ROOT$TOPDIR/SOURCES/$RECIPEFILE $BUILD_ROOT$TOPDIR/SOURCES.DEB ; then
cleanup_and_exit 1 "debian transforming failed."
fi
DEB_SOURCEDIR=$TOPDIR/SOURCES.DEB
for DEB_DSCFILE in $BUILD_ROOT$DEB_SOURCEDIR/*.dsc ; do : ; done
DEB_DSCFILE="${DEB_DSCFILE##*/}"
fi
# run/copy sources
chroot $BUILD_ROOT su -c "dpkg-source -x $DEB_SOURCEDIR/$DEB_DSCFILE $TOPDIR/BUILD" - $BUILD_USER
# Alternative to debtransform: apply OBS release number if tag OBS-DCH-RELEASE is set.
if test -z "$DEB_TRANSFORM" && grep -Eq '^OBS-DCH-RELEASE: 1' $BUILD_ROOT$TOPDIR/SOURCES/$RECIPEFILE; then
OBS_DCH_RELEASE="+$DEB_RELEASE"
chroot $BUILD_ROOT su -c /bin/sh <<EOF
cd $TOPDIR/BUILD
[ ! -f debian/changelog ] && exit 0
# avoid devscripts dependency and mimic dch
PACKAGE=\$(dpkg-parsechangelog 2> /dev/null | grep -E '^Source:' | awk '{ print \$NF }')
VERSION=\$(dpkg-parsechangelog 2> /dev/null | grep -E '^Version:' | awk '{ print \$NF }')
sed -i "s/\${PACKAGE} (\${VERSION})/\${PACKAGE} (\${VERSION}$OBS_DCH_RELEASE)/" debian/changelog
EOF
fi
}
dsc_build() {
local buildroot=$1
DSC_BUILD_OPTIONS=
if test -n "$BUILD_JOBS" ; then
DSC_BUILD_OPTIONS="parallel=${BUILD_JOBS}"
fi
# Checks to see if a build script should be used
# this allows the build environment to be manipulated
# and alternate build commands can be used
DSC_BUILD_CMD="$(queryconfig --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir "$CONFIG_DIR" substitute dsc:build_cmd)"
test -z "$DSC_BUILD_CMD" && DSC_BUILD_CMD="dpkg-buildpackage -us -uc"
if grep -Eq '^Format: 3\.0 \(quilt\)$' $BUILD_ROOT$TOPDIR/SOURCES/$RECIPEFILE ; then
printf "Recipe file '$RECIPEFILE' is being checked for 'DEBTRANSFORM-FILES'... "
if grep -Eq '^DEBTRANSFORM-FILES:' $BUILD_ROOT$TOPDIR/SOURCES/$RECIPEFILE ; then
echo "found"
echo "$(sed -n '/DEBTRANSFORM-FILES:/,/!(^\s)/p' $BUILD_ROOT$TOPDIR/SOURCES/$RECIPEFILE)"
echo "'--include-binaries' will use with dpkg-source"
DSC_BUILD_CMD="$DSC_BUILD_CMD --source-option=--include-binaries"
else
echo "not found"
fi
fi
if test -e $buildroot/$TOPDIR/SOURCES/build.script ; then
echo "Sourcing build.script to build - it should normally run 'dpkg-buildpackage -us -uc'"
DSC_BUILD_CMD="source $TOPDIR/SOURCES/build.script"
chmod +x $buildroot/$TOPDIR/SOURCES/build.script
fi
if test -z "$ABUILD_TARGET" ; then
ABUILD_TARGET=$(queryconfig target --dist "$BUILD_DIST" --configdir "$CONFIG_DIR" --archpath "$BUILD_ARCH" )
test -z "$ABUILD_TARGET" || echo "build target is $ABUILD_TARGET"
fi
if test -n "$ABUILD_TARGET" ; then
DSC_BUILD_CMD="$DSC_BUILD_CMD --host-type $ABUILD_TARGET"
fi
if test -n "$ABUILD_TARGET" -a -d "$BUILD_ROOT/.build.sysroot" ; then
DSC_BUILD_CMD="$DSC_BUILD_CMD -Pcross,nocheck"
DSC_BUILD_OPTIONS="$DSC_BUILD_OPTIONS nocheck"
DSC_BUILD_OPTIONS="${DSC_BUILD_OPTIONS# }"
fi
chroot $buildroot su -c "export DEB_BUILD_OPTIONS='${DSC_BUILD_OPTIONS}' ; cd $TOPDIR/BUILD && $DSC_BUILD_CMD" - $BUILD_USER < /dev/null && BUILD_SUCCEEDED=true
if test "$BUILD_SUCCEEDED" = true -a "$DO_CHECKS" != "false" && ( chroot $buildroot su -c "which lintian > /dev/null" - $BUILD_USER < /dev/null ); then
DEB_CHANGESFILE=${DEB_DSCFILE%.dsc}$OBS_DCH_RELEASE"_"$(chroot $buildroot su -c 'dpkg-architecture -qDEB_BUILD_ARCH')".changes"
chroot $buildroot su -c "cd $TOPDIR && echo Running lintian && (set -x && lintian -i $TOPDIR/$DEB_CHANGESFILE)" - $BUILD_USER < /dev/null || BUILD_SUCCEEDED=false
fi
}
dsc_move_build_result() {
local changes
for changes in $BUILD_ROOT/$TOPDIR/*.changes ; do
while read f ; do
mv "$BUILD_ROOT/$TOPDIR/$f" "$BUILD_ROOT/$TOPDIR/DEBS/"
done < <(sed -ne '/Files:/,$s/^ ................................ [0-9][0-9]* [^ ]* [^ ]* //p' "$changes")
mv "$changes" "$BUILD_ROOT/$TOPDIR/DEBS"
done
if test "$RECIPEFILE" != "debian/control" -a "$RECIPEFILE" != "debian.control" -a -z "$OBS_DCH_RELEASE" ; then
# link used sources over to DEB directory
ln $BUILD_ROOT/$DEB_SOURCEDIR/$DEB_DSCFILE $BUILD_ROOT/$TOPDIR/DEBS/
while read f ; do
ln $BUILD_ROOT/$DEB_SOURCEDIR/$f $BUILD_ROOT/$TOPDIR/DEBS/
done < <(sed -ne '/^Files:/,$s/^ ................................ [0-9][0-9]* //p' < $BUILD_ROOT/$DEB_SOURCEDIR/$DEB_DSCFILE)
fi
}
recipe_build_dsc() {
dsc_build "$BUILD_ROOT"
dsc_move_build_result
}
recipe_resultdirs_dsc() {
echo DEBS
}
recipe_cleanup_dsc() {
:
}