change the date
[tools/build.git] / build-recipe-dsc
1 #
2 # dsc specific functions.
3 #
4 ################################################################
5 #
6 # Copyright (c) 1995-2014 SUSE Linux Products GmbH
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License version 2 or 3 as
10 # published by the Free Software Foundation.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program (see the file COPYING); if not, write to the
19 # Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21 #
22 ################################################################
23
24 recipe_setup_dsc() {
25     TOPDIR=/usr/src/packages
26     test "$DO_INIT_TOPDIR" = false || rm -rf "$BUILD_ROOT$TOPDIR"
27     mkdir -p "$BUILD_ROOT$TOPDIR"
28     mkdir -p "$BUILD_ROOT$TOPDIR/OTHER"
29     mkdir -p "$BUILD_ROOT$TOPDIR/SOURCES"
30     mkdir -p "$BUILD_ROOT/$TOPDIR/DEBS"
31     chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"
32     cp -p "$MYSRCDIR"/* $BUILD_ROOT$TOPDIR/SOURCES/
33     # FIX to work with baselibs_$PROJ etc
34     if test -e "$MYSRCDIR/baselibs-deb.conf" ; then
35         echo "dsc build and baselibs-deb.conf present: forcing --baselibs to true"
36         CREATE_BASELIBS=true
37     fi
38 }
39
40 recipe_prepare_dsc() {
41     rm -rf "$BUILD_ROOT$TOPDIR/BUILD"
42     mkdir -p "$BUILD_ROOT$TOPDIR/SOURCES.DEB"
43     chown -R "$ABUILD_UID:$ABUILD_GID" "$BUILD_ROOT$TOPDIR"
44     DEB_TRANSFORM=
45     DEB_SOURCEDIR="$TOPDIR/SOURCES"
46     DEB_DSCFILE="$RECIPEFILE"
47     for f in $BUILD_ROOT$TOPDIR/SOURCES/debian.* ; do 
48         test -f $f && DEB_TRANSFORM=true
49     done
50     # remove rpm macros (everything after "%")
51     # they are not evaluated by the Debian build process
52     DEB_RELEASE=`sed 's/%.*$//' <<< $RELEASE`
53     OBS_DCH_RELEASE=""
54
55     if test -n "$DEB_TRANSFORM" ; then 
56         CHANGELOGARGS=
57         test -n "$CHANGELOG" -a -f "$BUILD_ROOT/.build-changelog" && CHANGELOGARGS="--changelog $BUILD_ROOT/.build-changelog"
58         echo "Found files matching debian.*, running debian transformer..."
59         if [ "$RELEASE" ]; then
60           echo "release: ($RELEASE), release (DEB) ($DEB_RELEASE)"
61                  RELEASEARGS="--release $DEB_RELEASE"
62         fi
63         if ! debtransform $CHANGELOGARGS $RELEASEARGS $BUILD_ROOT$TOPDIR/SOURCES $BUILD_ROOT$TOPDIR/SOURCES/$RECIPEFILE $BUILD_ROOT$TOPDIR/SOURCES.DEB ; then
64             echo "debian transforming failed."
65             cleanup_and_exit 1
66         fi
67         DEB_SOURCEDIR=$TOPDIR/SOURCES.DEB
68         for DEB_DSCFILE in $BUILD_ROOT/$DEB_SOURCEDIR/*.dsc ; do : ; done 
69         DEB_DSCFILE="${DEB_DSCFILE##*/}"
70     fi
71     chroot $BUILD_ROOT su -c "dpkg-source -x $DEB_SOURCEDIR/$DEB_DSCFILE $TOPDIR/BUILD" - $BUILD_USER
72
73     # Alternative to debtransform: apply OBS release number if tag OBS-DCH-RELEASE is set.
74     if test -z "$DEB_TRANSFORM" && grep -Eq '^OBS-DCH-RELEASE: 1' $BUILD_ROOT$TOPDIR/SOURCES/$RECIPEFILE; then
75         OBS_DCH_RELEASE="+$DEB_RELEASE"
76         chroot $BUILD_ROOT su -c /bin/sh <<EOF
77 cd $TOPDIR/BUILD
78 [ ! -f debian/changelog ] && exit 0
79 # avoid devscripts dependency and mimic dch
80 PACKAGE=\$(dpkg-parsechangelog 2> /dev/null | grep -E '^Source:'  | awk '{ print \$NF }')
81 VERSION=\$(dpkg-parsechangelog 2> /dev/null | grep -E '^Version:' | awk '{ print \$NF }')
82 sed -i "s/\${PACKAGE} (\${VERSION})/\${PACKAGE} (\${VERSION}$OBS_DCH_RELEASE)/" debian/changelog
83 EOF
84     fi
85
86 }
87
88 dsc_build() {
89     local buildroot=$1
90
91     DSC_BUILD_OPTIONS=
92     if test -n "$BUILD_JOBS" ; then
93         DSC_BUILD_OPTIONS="parallel=${BUILD_JOBS}"
94     fi
95     # Checks to see if a build script should be used
96     # this allows the build environment to be manipulated
97     # and alternate build commands can be used
98     DSC_BUILD_CMD="$(queryconfig --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir "$CONFIG_DIR" substitute dsc:build_cmd)"
99     test -z "$DSC_BUILD_CMD" && DSC_BUILD_CMD="dpkg-buildpackage -us -uc"
100     if test -e $buildroot/$TOPDIR/SOURCES/build.script ; then
101         echo "Sourcing build.script to build - it should normally run 'dpkg-buildpackage -us -uc'"
102         DSC_BUILD_CMD="source $TOPDIR/SOURCES/build.script"
103         chmod +x $buildroot/$TOPDIR/SOURCES/build.script
104     fi
105
106     if test -n "$RUN_SHELL"; then
107         chroot $buildroot su -
108     else
109         chroot $buildroot su -c "export DEB_BUILD_OPTIONS=${DSC_BUILD_OPTIONS} ; cd $TOPDIR/BUILD && $DSC_BUILD_CMD" - $BUILD_USER < /dev/null && BUILD_SUCCEEDED=true
110         if test "$BUILD_SUCCEEDED" = true -a "$DO_CHECKS" != "false" && ( chroot $buildroot su -c "which lintian > /dev/null" - $BUILD_USER < /dev/null ); then
111            DEB_CHANGESFILE=${DEB_DSCFILE%.dsc}$OBS_DCH_RELEASE"_"$(chroot $buildroot su -c 'dpkg-architecture -qDEB_BUILD_ARCH')".changes"
112            chroot $buildroot su -c "cd $TOPDIR && echo Running lintian && (set -x && lintian -i $TOPDIR/$DEB_CHANGESFILE)" - $BUILD_USER < /dev/null || BUILD_SUCCEEDED=false
113         fi
114     fi
115 }
116
117 dsc_move_build_result() {
118     for DEB in $BUILD_ROOT/$TOPDIR/*.{deb,changes} ; do
119         test -e "$DEB" && mv "$DEB" "$BUILD_ROOT/$TOPDIR/DEBS"
120     done
121
122     # link used sources over to DEB directory
123     ln $BUILD_ROOT/$DEB_SOURCEDIR/$DEB_DSCFILE $BUILD_ROOT/$TOPDIR/DEBS/
124     while read f ; do
125         ln $BUILD_ROOT/$DEB_SOURCEDIR/$f $BUILD_ROOT/$TOPDIR/DEBS/
126     done < <(sed -ne '/^Files:/,$s/^ ................................ [0-9][0-9]* //p' < $BUILD_ROOT/$DEB_SOURCEDIR/$DEB_DSCFILE)
127 }
128
129
130 recipe_build_dsc() {
131     dsc_build "$BUILD_ROOT"
132     dsc_move_build_result
133 }
134
135 recipe_resultdirs_dsc() {
136     echo DEBS
137 }