Whamcloud - gitweb
LU-9907 build: add patchless server for lbuild
[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 prepare_and_build_srpm() {
47
48         pushd $TOPDIR >/dev/null
49         # create the buildid
50         local buildid="_lustre${EXTRA_VERSION##*_lustre}"
51
52         # edit the SPEC with our changes
53         patch_spec
54         popd >/dev/null
55
56         # copy our .config into the RPM build tree
57         (echo "# $(basearch ${TARGET_ARCH})"; cat $CONFIG_FILE) > \
58                 SOURCES/kernel-$lnxmaj-${TARGET_ARCH}.config
59
60         # XXX - hackity hack -- until we get (or generate from the base
61         #                       config) configs for xen and debug
62         local f=""
63         for f in SOURCES/kernel-${lnxmaj}-*.config; do
64                 grep -q "^CONFIG_SD_IOSTATS=y" $f || \
65                 echo "CONFIG_SD_IOSTATS=y" >> $f
66         done
67
68     # do we need any special rpm build options
69     local rpmbuildopt="-bb"
70     if $DO_SRC; then
71         rpmbuildopt="-ba"
72     fi
73
74     # stupid Ubuntu's rpm doesn't do debuginfo properly
75     if [ ! -f /usr/lib/rpm/debugedit ]; then
76         rpmbuildopt="$rpmbuildopt --without debuginfo"
77     fi
78
79     # XXX - need to figure this kabichk crap out -- it fails the build
80     if ! $USE_KABI; then
81         rpmbuildopt="$rpmbuildopt --without kabichk"
82     fi
83
84     # get any release specific build options
85     rpmbuildopt="$rpmbuildopt $(get_rpmbuildopts)"
86
87         # now build it
88         if ! eval rpmbuild $rpmbuildopt --target ${TARGET_ARCH} --with baseonly \
89                 --define \"_topdir $TOPDIR\" \
90                 ${buildid:+--define \"buildid $buildid\"} \
91                 --define \"_tmppath $TMPDIR\" \
92                 $TOPDIR/SPECS/$SPEC_NAME 2>&1; then
93                 return 1
94         fi
95
96     # for informative purposes, display a diff between the .config that
97     # was actually built and what we proposed as a .config
98     echo "Diffs between $(basename $CONFIG_FILE) and the built kernel's .config:"
99     local rpmname="$TOPDIR/RPMS/${TARGET_ARCH}/kernel-${lnxmaj}-${lnxrel}${buildid}.${TARGET_ARCH}.rpm"
100     rpmcfg=$(rpm -qpl $rpmname | grep '/boot/config-')
101     rpm2cpio $rpmname | cpio -id .$rpmcfg
102     diff -u $CONFIG_FILE .$rpmcfg
103     rm -rf .$rpmcfg
104
105     return 0
106
107 }
108
109 devel_kernel_name() {
110     local lustre=${1:-false}
111
112     if $lustre; then
113         echo "kernel-lustre-$DEVEL_KERNEL_TYPE"
114     else
115         echo "kernel-$DEVEL_KERNEL_TYPE"
116     fi
117
118 }
119
120 rpm_BUILD_kernel_dirname() {
121     local rpmsmptype="$1"
122     local lnxmaj="$2"
123     local lnxmin="$3"
124     local arch="$4"
125
126     local lustre=""
127     if $KERNEL_LUSTRE_NAMING; then
128         $lustre="-lustre"
129     fi
130     echo kernel${lustre}${lnxmaj}${lnxmin}/linux-${lnxmaj}.$arch
131 }
132
133 find_linux_devel_paths() {
134     local path="$1"
135     local ARCH=$TARGET_ARCH
136
137     # If DEVEL_PATH_ARCH is set, use it. Added for fc11 as it needs i586 string for i686.
138     if [ $DEVEL_PATH_ARCH ];then
139         ARCH=$DEVEL_PATH_ARCH
140     fi
141
142     LINUX=$path/usr/src/kernels/${lnxmaj}${lnxmin}-${lnxrel}${DEVEL_PATH_ARCH_DELIMETER:-"-"}${ARCH}
143     # RHEL doesn't have the -obj tree
144     LINUXOBJ=""
145
146     return 0
147 }
148
149 unpack_linux_devel_rpm-rhel() {
150     local callers_rpm="$1"
151
152     # now just sanity check that everything needed to build properly versioned
153     # modules is in place
154     if [ ! -f usr/src/kernels/${lnxmaj}${lnxmin}-${lnxrel}${DEVEL_PATH_ARCH_DELIMETER:-"-"}$TARGET_ARCH/Module.symvers ]; then
155         fatal 1 "cannot build kernel modules: the Kernel's Module.symvers is missing."
156     fi
157
158     return 0
159
160 }
161
162 # this of course requires a sudo rule on the builder for real RHEL:
163 # hudson ALL= NOPASSWD: /usr/bin/yumdownloader
164 # also must disable the requiretty attribute in the sudoers file
165 find_linux_rpm-rhel() {
166     local prefix="$1"
167     local wanted_kernel="$2"
168     local pathtorpms=${3:-"$KERNELRPMSBASE/$lnxmaj/$DISTROMAJ/$TARGET_ARCH"}
169
170     local tmpdir=$(mktemp -d $pathtorpms/yumXXXXXX)
171     local sudo=""
172     if [ "$(lsb_release -s -i)" = "RedHatEnterpriseServer" ]; then
173         sudo="sudo"
174     fi
175     if ! $sudo yumdownloader --destdir "$tmpdir" kernel-devel-"$wanted_kernel" > /dev/null; then
176         fatal 1 "failed to fetch kernel-devel-$wanted_kernel with yumdownloader."
177     fi
178     local rpm=$(cd $tmpdir; echo *)
179     mv "$tmpdir/$rpm" "$pathtorpms"
180     rmdir $tmpdir
181     echo "$rpm"
182
183     return 0
184
185 }
186
187 # This function digs out the linux release from the linux source tree
188 find_linux_release() {
189         _find_linux_release $LINUX
190 }