Merge "Support BuildFlags: nocumulaterpms" into devel
[tools/build.git] / build-recipe
1 #
2 # recipe specific functions for the build script
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
25 KIWI_PARAMETERS=
26
27 for i in spec dsc kiwi arch collax preinstallimage simpleimage mock livebuild snapcraft debootstrap debbuild; do
28     . "$BUILD_DIR/build-recipe-$i"
29 done
30
31 recipe_setup() {
32     recipe_setup_$BUILDTYPE "$@"
33 }
34
35 recipe_prepare() {
36     recipe_prepare_$BUILDTYPE "$@"
37 }
38
39 recipe_build() {
40     recipe_build_$BUILDTYPE "$@"
41 }
42
43 recipe_resultdirs () {
44     recipe_resultdirs_$BUILDTYPE "$@"
45 }
46
47 recipe_parse_options() {
48     case ${PARAM/#--/-} in
49       -stage)
50         needarg
51         BUILD_RPM_BUILD_STAGE="$ARG"
52         shift
53         ;;
54       -kiwi-parameter)
55         test -z "$ARG" && ARG="$1"
56         needarg
57         KIWI_PARAMETERS="$KIWI_PARAMETERS $ARG"
58         shift
59         ;;
60       -*)
61         return 1
62         ;;
63     esac
64     nextargs=("$@")
65     return 0
66 }
67
68 recipe_set_buildtype() {
69     BUILDTYPE=
70     case ${RECIPEFILE##_service:*:} in
71         *.spec|*.src.rpm) BUILDTYPE=spec ;;
72         *.dsc) BUILDTYPE=dsc ;;
73         *.kiwi) BUILDTYPE=kiwi ;;
74         PKGBUILD) BUILDTYPE=arch ;;
75         snapcraft.yaml) BUILDTYPE=snapcraft ;;
76         build.collax) BUILDTYPE=collax ;;
77         _preinstallimage) BUILDTYPE=preinstallimage ;;
78         simpleimage) BUILDTYPE=simpleimage ;;
79         *.livebuild) BUILDTYPE=livebuild ;;
80     esac
81     if test -z "$BUILDTYPE" ; then
82        echo "I don't know how to build $RECIPEFILE"
83        cleanup_and_exit 1
84     fi
85     # we can't query right after vm startup, so we put the BUILDENGINE in the build.data
86     if test -z "$RUNNING_IN_VM" ; then
87         BUILDENGINE=
88         if test -n "$BUILD_DIST" ; then
89             BUILDENGINE=`queryconfig buildengine --dist "$BUILD_DIST" --configdir "$CONFIG_DIR" --archpath "$BUILD_ARCH"`
90             test "$BUILDENGINE" = UNDEFINED && BUILDENGINE=
91         fi
92     fi
93     if test "$BUILDENGINE" = mock -a "$BUILDTYPE" = spec ; then
94         BUILDTYPE=mock
95     fi
96     if test "$BUILDENGINE" = debootstrap -a "$BUILDTYPE" = dsc ; then
97         BUILDTYPE=debootstrap
98     fi
99     if test "$BUILDENGINE" = debbuild -a "$BUILDTYPE" = spec ; then
100         BUILDTYPE=debbuild
101     fi
102 }
103
104 # expands all directories into files
105 expand_recipe_directories() {
106     local f t ff found types
107     if test -z "$RECIPEFILES" ; then
108         set -- "`pwd`"
109     else
110         set -- "${RECIPEFILES[@]}"
111     fi
112     RECIPEFILES=()
113     for f in "$@" ; do
114         if test "$f" = "${f#/}" ; then
115             f="`pwd`/$f"
116         fi
117         if test -d "$f" ; then
118             if test -z "$types" ; then
119                 if test -n "$BUILD_DIST" ; then
120                     case $(queryconfig --dist "$BUILD_DIST" --configdir "$CONFIG_DIR" --archpath "$BUILD_ARCH" type) in
121                         dsc) types=".dsc" ;;
122                         kiwi) types=".kiwi" ;;
123                         arch) types="PKGBUILD" ;;
124                         collax) types="build.collax" ;;
125                         livebuild) types=".livebuild" ;;
126                         snapcraft) types="snapcraft.yaml" ;;
127                     esac
128                 fi
129                 types="$types .spec .dsc PKGBUILD build.collax .kiwi .src.rpm .nosrc.rpm simpleimage snapcraft.yaml"
130             fi
131             for t in $types ; do
132                 found=
133                 for ff in "$f"/*$t ; do
134                     test -f "$ff" || continue
135                     RECIPEFILES=("${RECIPEFILES[@]}" "$ff")
136                     found=true
137                 done
138                 test -n "$found" && break
139             done
140         else
141             RECIPEFILES[${#RECIPEFILES[@]}]="$f"
142         fi
143     done
144     if test -z "$RECIPEFILES" ; then
145         echo "no recipe files found in $@. exit..."
146         cleanup_and_exit 1
147     fi
148 }