Merge remote-tracking branch 'origin/devel'
[tools/build.git] / build-recipe-mock
1 #
2 # mock 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_mock() {
25     recipe_setup_spec "$@"
26 }
27
28 recipe_prepare_mock() {
29     recipe_prepare_spec "$@"
30 }
31
32 recipe_build_mock() {
33     test -d $BUILD_ROOT/.build.binaries || cleanup_and_exit 1
34     if test "$DO_INIT" = true -o ! -d "$BUILD_ROOT/.build.binaries/repodata" ; then
35         echo "creating repository for mock..."
36         chroot $BUILD_ROOT createrepo --no-database --basedir /.build.binaries -o /.build.binaries /.build.binaries
37     fi
38     MOCK_CHROOT_SETUP_CMD="$(queryconfig --dist "$BUILD_DIST" --archpath "$BUILD_ARCH" --configdir "$CONFIG_DIR" substitute mock:chroot_setup_cmd)"
39     test -z "$MOCK_CHROOT_SETUP_CMD" && MOCK_CHROOT_SETUP_CMD="groupinstall buildsys-build"
40     echo "config_opts['root'] = 'build'" > $BUILD_ROOT/etc/mock/build.cfg
41     echo "config_opts['target_arch'] = '${BUILD_ARCH%%:*}'" >> $BUILD_ROOT/etc/mock/build.cfg
42     echo "config_opts['plugin_conf']['ccache_enable'] = False" >> $BUILD_ROOT/etc/mock/build.cfg
43     echo "config_opts['chroot_setup_cmd'] = '$MOCK_CHROOT_SETUP_CMD'" >> $BUILD_ROOT/etc/mock/build.cfg
44     cat >> $BUILD_ROOT/etc/mock/build.cfg <<-'EOF'
45         config_opts['yum.conf'] = """
46         [main]
47         cachedir=/var/cache/yum
48         debuglevel=1
49         reposdir=/dev/null
50         logfile=/var/log/yum.log
51         obsoletes=1
52         gpgcheck=0
53         assumeyes=1
54         syslog_ident=mock
55         syslog_device=
56
57         [build]
58         name=build
59         baseurl=file:///.build.binaries
60         """
61         EOF
62     touch $BUILD_ROOT/etc/resolv.conf
63     BUILD_SUCCEEDED=false
64     echo "building src rpm..."
65     MOCK_INIT_ARG=
66     test "$DO_INIT" = true || MOCK_INIT_ARG=--no-clean
67     if chroot $BUILD_ROOT /usr/bin/mock -r build $MOCK_INIT_ARG --buildsrpm --spec "$TOPDIR/SOURCES/$RECIPEFILE" --sources "$TOPDIR/SOURCES" ; then
68         BUILT_SRPM=
69         for i in "$BUILD_ROOT/var/lib/mock/build/result/"*src.rpm ; do
70             test -s "$i" && BUILT_SRPM="${i##*/}"
71         done
72         if test -n "$BUILT_SRPM" ; then
73             mkdir -p "$BUILD_ROOT/$TOPDIR/SRPMS"
74             mv "$BUILD_ROOT/var/lib/mock/build/result/$BUILT_SRPM" "$BUILD_ROOT/$TOPDIR/SRPMS/$BUILT_SRPM"
75             echo "building binary rpms..."
76             if chroot $BUILD_ROOT /usr/bin/mock -v -r build --rebuild --no-clean "$TOPDIR/SRPMS/$BUILT_SRPM" ; then
77                 BUILD_SUCCEEDED=true
78                 # move result over to TOPDIR
79                 rm -f "$TOPDIR/SRPMS/$BUILT_SRPM"
80                 for i in "$BUILD_ROOT/var/lib/mock/build/result/"*.rpm ; do
81                     a="${i%.rpm}"
82                     a="${a##*/}"
83                     a="${a##*.}"
84                     if test "$a" = src -o "$a" = nosrc ; then
85                         mkdir -p "$BUILD_ROOT/$TOPDIR/SRPMS"
86                         mv $i "$BUILD_ROOT/$TOPDIR/SRPMS/."
87                     else
88                         mkdir -p "$BUILD_ROOT/$TOPDIR/RPMS/$a"
89                         mv $i "$BUILD_ROOT/$TOPDIR/RPMS/$a/."
90                     fi
91                 done
92             fi
93         fi
94     fi
95 }
96
97 recipe_resultdirs_mock() {
98     echo RPMS SRPMS
99 }
100