Whamcloud - gitweb
LU-3117 build: zfs-0.6.1 kmod+dkms compatibility
[fs/lustre-release.git] / contrib / lbuild / lbuild
index bf424ee..b4a0a8d 100755 (executable)
@@ -33,7 +33,8 @@ push_exit_trap "kill -INT -$$ || true" kill_children
 #BUILD_GEN=2   # bz19952: remove -lustre tag from kernel RPM names
 #BUILD_GEN=3   # bz19975: enable the building of src.rpms by default
 #BUILD_GEN=4   # bz22281: use the git hash in the kernel extra version
-BUILD_GEN=5    # TT-107: don't cache the BUILD dir
+#BUILD_GEN=5   # TT-107: don't cache the BUILD dir
+BUILD_GEN=6    # TT-1092: don't cache the BUILD dir, to rebuild external OFED
 
 TOPDIR=$PWD
 
@@ -237,7 +238,7 @@ Usage: ${0##*/} [OPTION]... [-- <lustre configure options>]
     Builds a Xen domX kernel.
 
   --set-value
-    Set's a variable to a given value.
+    Sets a variable to a given value.
 
 EOF
 
@@ -992,36 +993,60 @@ build_lustre() {
 #
 # Fetch spl/zfs from the git repo and prepare for lustre build
 #
+# Overrides:
+#   SPLZFSGITREPO - URI of directory where spl.git and zfs.git are located
+#   SPLZFSTAG     - Tag to checkout of clone repositories
+#   SPLZFSVER     - Version to checkout of both (format zfs/spl-$SPLZFSVER)
+#
 # return 0 if successful, else 255
 build_spl_zfs() {
     # make sure the RPM build environment is set up
+    pushd $TOPDIR
     create_rpmbuild_dirs
+    popd
 
     # The spl/zfs spec files expect RPM_BUILD_ROOT to point to the root of the
     # destination for the rpms
     export RPM_BUILD_ROOT=$TOPDIR
+    SPLZFSVER=${SPLZFSVER:-0.6.1}
+    SPLZFSTAG=${SPLZFSTAG:-lustre-zfs}
 
     # The files expect a kver to be set to the kernel version .
-    kver=$(cat ${LINUX}/include/config/kernel.release)
+    local kver=$(find_linux_release ${LINUX})
 
     # build and install the spl and zfs (and -devel) RPMs for lustre to use
     local pkg
     for pkg in spl zfs; do
 
-        local rpmmod spldir
+        local rpmpkg
 
-        [ "$pkg" == "zfs" ] && spldir="$(ls -d $TOPDIR/usr/src/spl-*/*)"
-        rpmmod=$pkg-modules
+        [ "$pkg" == "zfs" ] && spldir="$(ls -d $TOPDIR/usr/src/spl-*/|tail -1)"
 
         # need to fetch the repo in order to build it.
         # default to github but allow override
         git clone ${SPLZFSGITREPO:-"https://github.com/zfsonlinux"}/$pkg.git $pkg 2>&1
 
         pushd $pkg || return 255
-
-        # XXX - _having_ to give a package a kernel just to have it configure
-        #       enough to do a "make dist" is truely bogus!
-        if  ! ./configure --with-linux=${LINUX} \
+       if [ -n "$SPLZFSTAG" ]; then
+           git checkout $SPLZFSTAG
+       else
+           git checkout -b lbuild $pkg-$SPLZFSVER
+       fi
+
+       # This differentiates between older zfs versions
+       if [ -f $pkg-modules.spec.in ]; then
+           rpmpkg=$pkg-modules
+           specdir=.
+           speclist="$pkg.spec $rpmpkg.spec"
+       else
+            rpmpkg=kmod-$pkg-devel
+           specdir=rpm/generic
+           speclist="$pkg.spec $pkg-kmod.spec $pkg-dkms.spec"
+       fi
+
+       sh autogen.sh || return 255
+
+        if  ! ./configure --with-linux=${LINUX} --with-linux-obj=${LINUX} \
                           ${spldir:+--with-spl="${spldir}"} 2>&1 ||
             ! make dist 2>&1; then
             popd
@@ -1029,71 +1054,57 @@ build_spl_zfs() {
         fi
         popd
 
-        # XXX - dirty hack time.  ~sigh~
-        #       because the spl tarball contains two .spec files, we cannot
-        #       simply rebuild the tarball
-        ln $pkg/$pkg-*.tar.gz $TOPDIR/SOURCES ||
-            error "failed to link $pkg/$pkg-*.tar.gz into $TOPDIR/SOURCES"
-
-        # First build the userspace tools RPMs
-        if ! $RPMBUILD $targets -bb $pkg/$pkg.spec \
-            --nodeps -v \
-            --define "configure_args ${CONFIGURE_FLAGS}" \
-            --define "_tmppath /var/tmp" \
-            --define "_topdir $TOPDIR" 2>&1; then
-            return 255
-        fi
-
-        if $DO_SRC; then
-            if ! $RPMBUILD -bs $pkg/$pkg.spec \
-                --nodeps -v \
-                --define "configure_args ${CONFIGURE_FLAGS}" \
-                --define "_tmppath /var/tmp" \
-                --define "_topdir $TOPDIR" 2>&1; then
-                return 255
+        ln -f $pkg/$pkg-*.tar.gz $TOPDIR/SOURCES ||
+           error "failed to link $pkg/$pkg-*.tar.gz into $TOPDIR/SOURCES"
+       if [ -f $pkg/scripts/kmodtool ]; then
+           ln -f $pkg/scripts/kmodtool $TOPDIR/SOURCES/
+       fi
+
+       local rpmb
+       if $DO_SRC; then
+           rpmb=-ba
+       else
+           rpmb=-bb
+       fi
+
+       # set search dir for our own kmodtool to find correct
+       # directories
+       export KERNELSOURCE=$(dirname ${LINUX})
+       # Manually build rpms
+       for spec in $speclist; do
+           echo "Building RPMs from $pkg/$specdir/$spec"
+            if ! $RPMBUILD $rpmb $pkg/$specdir/$spec \
+               --nodeps -v \
+               --define "require_kdir ${LINUX}" \
+               ${LINUXOBJ:+--define "require_kobj ${LINUXOBJ}"} \
+               ${spldir:+--define "require_spldir ${spldir}"} \
+               --define "kver $kver" \
+               --define "kernels $kver" \
+               --define "_tmppath /var/tmp" \
+               --define "kernelbuildroot $(find_linux_builddir $LINUX)" \
+               --define "_topdir $TOPDIR" 2>&1; then
+               return 255
             fi
-        fi
+       done
 
-        # Now the kernel module RPMs
-        # Need to provide pointers to the lustre kernel source, objects, usr/src
-        if ! $RPMBUILD $targets -bb $pkg/$rpmmod.spec \
-            --nodeps -v \
-            --define "require_kdir ${linux}" \
-            ${linuxobj:+--define "require_kobj ${linuxobj}"} \
-            ${spldir:+--define "require_spldir ${spldir}"} \
-            --define "configure_args ${CONFIGURE_FLAGS}" \
-            --define "_usrsrc $TOPDIR/usr/src" \
-            --define "kver $kver" \
-            --define "_tmppath /var/tmp" \
-            --define "_topdir $TOPDIR" 2>&1; then
-            return 255
-        fi
-
-        if $DO_SRC; then
-            if ! $RPMBUILD -bs $pkg/$rpmmod.spec \
-                --nodeps -v \
-                --define "require_kdir ${linux}" \
-                ${linuxobj:+--define "require_kobj ${linuxobj}"} \
-                ${spldir:+--define "require_spldir ${spldir}"} \
-                --define "configure_args ${CONFIGURE_FLAGS}" \
-                --define "_usrsrc $TOPDIR/usr/src" \
-                --define "kver $kver" \
-                --define "_tmppath /var/tmp" \
-                --define "_topdir $TOPDIR" 2>&1; then
-                return 255
-            fi
-        fi
+#      $DO_SRC && mv $pkg*.src.rpm $TOPDIR/SRPMS/
+#      mv $pkg*.noarch.rpm $TOPDIR/RPMS/noarch/
+#      mv *$pkg*.$TARGET_ARCH.rpm $TOPDIR/RPMS/$(basearch $TARGET_ARCH)/
 
-        # We have built the rpms for the package. No we need to extract the
+        # We have built the rpms for the package. Now we need to extract the
         # contained files so we can build further things against them
-        local rpm=$(ls $TOPDIR/RPMS/*/$rpmmod-devel-*.rpm)
+        local rpms=$(ls -1 $TOPDIR/RPMS/*/$rpmpkg-*.rpm)
 
         # cpio only extract to pwd so we need to go there.
         pushd $TOPDIR
-        rpm2cpio < $rpm | cpio -id
+       local rpm
+       for rpm in $rpms; do
+            rpm2cpio $rpm | cpio -id
+       done
         popd
 
-        CONFIGURE_FLAGS="--with-$pkg=$(ls -d $TOPDIR/usr/src/$pkg-*/*) ${CONFIGURE_FLAGS}"
+        CONFIGURE_FLAGS="--with-$pkg=$(ls -d $TOPDIR/usr/src/$pkg-*/|tail -1) ${CONFIGURE_FLAGS}"
+        CONFIGURE_FLAGS="--with-$pkg-obj=$(ls -d $TOPDIR/usr/src/$pkg-*/$kver*|tail -1) ${CONFIGURE_FLAGS}"
     done
 
     OSDZFSRPM=true
@@ -1176,7 +1187,15 @@ find_linux_release() {
     fi
 
     sed -ne 's/#define UTS_RELEASE "\(.*\)"$/\1/p' $LINUXRELEASEHEADER
+}
+
+# This funcition finds the buildroot directory for a given linux
+# kernel directory
+find_linux_builddir() {
+    local linux=${1:-${LINUX}}
+    local rel=$(find_linux_release $linux)
 
+    echo ${linux%/usr/src/kernels/${rel}*}
 }
 
 # unpack kernel(/source/devel) RPM
@@ -1268,9 +1287,19 @@ Patch$n: ${file%%*/}"
             let n=$n+1
         done
         for file in $(ls ${TOPDIR}/lustre/build/patches/ofed/*.ed); do
-            ed_fragment3="$ed_fragment3
+            # Only apply the ed-scripts that should be used for the canonical target
+            # ed-files in ${TOPDIR}/lustre/build/patches/ofed/ have to follow the naming
+            # convention
+            # <two-digits>-<descriptive-name>:<canonical_target_1>: ...:<canonical_target_N>.ed
+            # To apply the same change to multiple canonical target simply specify
+            # a list of colon separated canoncial target names in the file name.
+            echo "$file" | grep -q -e ":${CANONICAL_TARGET}:" \
+                                   -e ":${CANONICAL_TARGET}.ed$"
+            if [ $? -eq 0 ] ; then
+                ed_fragment3="$ed_fragment3
 $(cat $file)"
-            let n=$n+1
+                let n=$n+1
+            fi
         done
 
         if [ $n -gt 1 ]; then
@@ -1451,7 +1480,8 @@ build_kernel_with_srpm() {
     if $USE_BUILD_CACHE && [ -n "$REUSEBUILD" ]; then
         local REUSE_SIGNATURE=$({ echo -en $release_str;
                                   echo $BUILD_GEN;
-                                  cat $CONFIG_FILE $TARGET_FILE $FULL_PATCH; } |
+                                  cat $CONFIG_FILE $TARGET_FILE $FULL_PATCH;
+                                  cat ${0%/lbuild}/lbuild ${0%/lbuild}/lbuild-${DISTRO}; } |
                                 md5sum | cut -d" " -f1)
         # see if we can link to the reuse pool
         # XXX - hrm.  i'm not convinced this doesn't belong in the reuse
@@ -1565,8 +1595,11 @@ build_ofed() {
     # build kernel-ib/compat-rdma
     if $USE_BUILD_CACHE && [ -n "$REUSEBUILD" ]; then
         local REUSE_SIGNATURE=$({ echo "$ofed_version";
-                                  echo "$(find_linux_release ${linux})";
-                                  cat "${linux}/include/linux/autoconf.h"; } |
+                                  echo "$(find_linux_release ${linux};
+                                  echo "$BUILD_GEN")";
+                                  cat "${linux}/include/linux/autoconf.h";
+                                  cat "${0%/lbuild}/lbuild" ;
+                                  cat "${0%/lbuild}/lbuild-${DISTRO}"; } |
                                 md5sum | cut -d" " -f1)
         # see if we can link to the reuse pool
         # XXX - hrm.  i'm not convinced this doesn't belong in the reuse
@@ -1750,6 +1783,7 @@ create_rpmbuild_dirs() {
         fi
         [ -d RPMS/$arch ] || mkdir RPMS/$arch
     done
+    [ -d RPMS/noarch ] || mkdir RPMS/noarch
     [ -d BUILD ] || mkdir BUILD
     [ -d SOURCES ] || mkdir SOURCES
     [ -d SPECS ] || mkdir SPECS
@@ -1850,10 +1884,7 @@ else
   seen_list=$(add_list "$seen_list" "${BASH_SOURCE[0]}:${BASH_LINENO[0]}")
 fi
 backtrace
-echo
-echo "Environment:"
-set
-) | mail -s "Untrapped error at ${BASH_SOURCE[0]##*/}:$((LINENO-15)) on $HOSTNAME" brian@whamcloud.com >&2; set $xtrace' ERR
+) ; set $xtrace' ERR
 set -E
 
 [ -r ~/.lbuildrc ] && . ~/.lbuildrc