Whamcloud - gitweb
a2b0475790a729d2ee5494027d4182b0fefe255e
[fs/lustre-release.git] / contrib / lbuild / lbuild-rhel
1 # vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4:
2
3 # increment this if you have made a change that should force a new kernel
4 # to build built for all releases of this distribution (only -- if you want
5 # to force a kernel build on all distributions, update the BUILD_GEN variable
6 # in build/lbuild)
7 #BUILD_GEN+=".0"
8 #BUILD_GEN+=".1"        # refactor both rhel5 and rhel6
9 #BUILD_GEN+=".0"        # TT-107: don't cache the BUILD dir (reset major to 5)
10 BUILD_GEN+=".2" # LU-9850
11
12 DEVEL_KERNEL_TYPE="devel"
13 RPM_HELPERS_DIR="/usr/lib/rpm/redhat"
14
15 # a method which can be overriden by the release specific code
16 get_rpmbuildopts() {
17
18     return 0
19
20 }
21
22 # patching common to all releases
23 patch_spec_common() {
24
25     sed -i -e '/Provides: kernel-uname-r =/a\
26 Provides: kernel-lustre = %{KVRA}%{?1:.%{1}}\\' \
27            -e '/Provides: kernel-devel-uname-r =/a\
28 Provides: kernel-devel-lustre = %{KVRA}%{?1:.%{1}}\\' \
29            -e '/find $RPM_BUILD_ROOT\/lib\/modules\/$KernelVer/a\
30     cp -a fs/ext3/* $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/fs/ext3 \
31     cp -a fs/ext4/* $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/fs/ext4' \
32           SPECS/$SPEC_NAME 2>&1 || \
33         fatal 1 "Error while editing SPECS/$SPEC_NAME"
34
35     # XXX - a building-on-Ubuntu hack
36     if grep -q "Ubuntu" /etc/issue; then
37         sed  -i -e 's/^\(BuildPreReq: .*\)$/#NOU \1/g' \
38                -e 's/^\(BuildRequires: .*\)$/#NOU \1/g' \
39                -e 's/sha512hmac/md5sum/g' \
40             SPECS/$SPEC_NAME 2>&1 || \
41                 fatal 1 "Error while editing SPECS/$SPEC_NAME"
42     fi
43
44
45 }
46
47 prepare_and_build_srpm() {
48
49     pushd $TOPDIR >/dev/null
50
51     # create the buildid
52     local buildid="_lustre${EXTRA_VERSION##*_lustre}"
53
54     # edit the SPEC with our changes
55     patch_spec
56
57     popd >/dev/null
58
59     # this concept of being able to build a list of targets with a single
60     # lbuild is a fine idea, but in reality I think it's (very) broken.  I
61     # don't even think the lustre.spec can handle being called with "--target
62     # <multiple arches>".  It certainly can't handle the issue where each
63     # arch has it's own kernel location.
64     # but we will do the best we can and put the plumbing in place so that
65     # this could work when the other broken bits are fixed.
66     # in reality, our current use of lbuild only ever has a single arch in
67     # $BUILD_ARCHS
68     local arch
69     local targets=""
70     for arch in $BUILD_ARCHS; do
71         # XXX - ok.  so here's a hack that needs to be fixed properly
72         #       ppc64 was merged to ppc some time ago pre 2.6.18
73         if [ $arch = ppc64 ]; then
74             arch=ppc
75         fi
76         targets="--target $arch $targets"
77         # copy our .config into the RPM build tree
78         (echo "# $(basearch $arch)"; cat $CONFIG_FILE) > \
79             SOURCES/kernel-$lnxmaj-$arch.config
80
81         # XXX - hackity hack -- until we get (or generate from the base
82         #                       config) configs for xen and debug
83         local f=""
84         for f in SOURCES/kernel-${lnxmaj}-*.config; do
85             grep -q "^CONFIG_SD_IOSTATS=y" $f || \
86                 echo "CONFIG_SD_IOSTATS=y" >> $f
87         done
88     done
89
90     # do we need any special rpm build options
91     local rpmbuildopt="-bb"
92     if $DO_SRC; then
93         rpmbuildopt="-ba"
94     fi
95
96     # stupid Ubuntu's rpm doesn't do debuginfo properly
97     if [ ! -f /usr/lib/rpm/debugedit ]; then
98         rpmbuildopt="$rpmbuildopt --without debuginfo"
99     fi
100
101     # XXX - need to figure this kabichk crap out -- it fails the build
102     if ! $USE_KABI; then
103         rpmbuildopt="$rpmbuildopt --without kabichk"
104     fi
105
106     # get any release specific build options
107     rpmbuildopt="$rpmbuildopt $(get_rpmbuildopts)"
108
109     # now build it
110     if ! eval rpmbuild $rpmbuildopt $targets --with baseonly \
111                    --define \"_topdir $TOPDIR\" \
112                    --define \"buildid $buildid\" \
113                    --define \"_tmppath $TMPDIR\" \
114                    $TOPDIR/SPECS/$SPEC_NAME 2>&1; then
115         return 1
116     fi
117
118     # for informative purposes, display a diff between the .config that
119     # was actually built and what we proposed as a .config
120     echo "Diffs between $(basename $CONFIG_FILE) and the built kernel's .config:"
121     local rpmname="$TOPDIR/RPMS/${BUILD_ARCHS# }/kernel-${lnxmaj}-${lnxrel}${buildid}.${BUILD_ARCHS# }.rpm"
122     rpmcfg=$(rpm -qpl $rpmname | grep '/boot/config-')
123     rpm2cpio $rpmname | cpio -id .$rpmcfg
124     diff -u $CONFIG_FILE .$rpmcfg
125     rm -rf .$rpmcfg
126
127     return 0
128
129 }
130
131 devel_kernel_name() {
132     local lustre=${1:-false}
133
134     if $lustre; then
135         echo "kernel-lustre-$DEVEL_KERNEL_TYPE"
136     else
137         echo "kernel-$DEVEL_KERNEL_TYPE"
138     fi
139
140 }
141
142 rpm_BUILD_kernel_dirname() {
143     local rpmsmptype="$1"
144     local lnxmaj="$2"
145     local lnxmin="$3"
146     local arch="$4"
147
148     local lustre=""
149     if $KERNEL_LUSTRE_NAMING; then
150         $lustre="-lustre"
151     fi
152     echo kernel${lustre}${lnxmaj}${lnxmin}/linux-${lnxmaj}.$arch
153 }
154
155 find_linux_devel_paths() {
156     local path="$1"
157     local ARCH=$TARGET_ARCH
158
159     # If DEVEL_PATH_ARCH is set, use it. Added for fc11 as it needs i586 string for i686.
160     if [ $DEVEL_PATH_ARCH ];then
161         ARCH=$DEVEL_PATH_ARCH
162     fi
163
164     LINUX=$path/usr/src/kernels/${lnxmaj}${lnxmin}-${lnxrel}${DEVEL_PATH_ARCH_DELIMETER:-"-"}${ARCH}
165     # RHEL doesn't have the -obj tree
166     LINUXOBJ=""
167
168     return 0
169 }
170
171 unpack_linux_devel_rpm-rhel() {
172     local callers_rpm="$1"
173
174     # now just sanity check that everything needed to build properly versioned
175     # modules is in place
176     if [ ! -f usr/src/kernels/${lnxmaj}${lnxmin}-${lnxrel}${DEVEL_PATH_ARCH_DELIMETER:-"-"}$TARGET_ARCH/Module.symvers ]; then
177         fatal 1 "cannot build kernel modules: the Kernel's Module.symvers is missing."
178     fi
179
180     return 0
181
182 }
183
184 # this of course requires a sudo rule on the builder for real RHEL:
185 # hudson ALL= NOPASSWD: /usr/bin/yumdownloader
186 # also must disable the requiretty attribute in the sudoers file
187 find_linux_rpm-rhel() {
188     local prefix="$1"
189     local wanted_kernel="$2"
190     local pathtorpms=${3:-"$KERNELRPMSBASE/$lnxmaj/$DISTROMAJ/$TARGET_ARCH"}
191
192     local tmpdir=$(mktemp -d $pathtorpms/yumXXXXXX)
193     local sudo=""
194     if [ "$(lsb_release -s -i)" = "RedHatEnterpriseServer" ]; then
195         sudo="sudo"
196     fi
197     if ! $sudo yumdownloader --destdir "$tmpdir" kernel-devel-"$wanted_kernel" > /dev/null; then
198         fatal 1 "failed to fetch kernel-devel-$wanted_kernel with yumdownloader."
199     fi
200     local rpm=$(cd $tmpdir; echo *)
201     mv "$tmpdir/$rpm" "$pathtorpms"
202     rmdir $tmpdir
203     echo "$rpm"
204
205     return 0
206
207 }
208
209 # This function digs out the linux release from the linux source tree
210 find_linux_release() {
211         _find_linux_release $LINUX
212 }