From fd0bd149e66cbc06a17c372e159f9bfba024cc97 Mon Sep 17 00:00:00 2001 From: "Brian J. Murrell" Date: Wed, 3 Nov 2010 04:14:44 +0800 Subject: [PATCH 1/1] b=22281 refactor packaging and versioning Configure "--with-dist" switch to optimize configure to do just enough to enable "make dist" to work. There is likely more optimizations that could be done Provide reasonable defaults for the --with-linux and --with-linux-obj configure arguments. The LB_BUILDID macro determines the BUILDID to be used in the resulting packages. The LB_DOWNSTREAM_RELEASE macro implements the --with-downstream-release configure option for downstream packages to provide their own versioning details Many changes to support allowing packagers to define a value in the release string. - allow callers to tell rpm where to find the kernel source/headers and objects. - default to /lib/modules/$(uname -r)/build if not specified - XXX: this should probably be handled completely in configure - allow callers to tell rpm what the release string should be set to - the spec will default to the value that configure uses currently if not specified - this allows both the release string used in Lustre and the Release: string used in the RPM to be in sync - in the make rpms target, strip the configure arguments for --with-linux and --with-linux-obj and give them to rpmbuild via it's new switches - also, pass the release defined by the main configure to the RPM spec for further consistency - XXX: it is questionable whether this in fact has any value - put the "downstream release" right into the release as it is defined by by configure - bring the ldiskfs spec more into sync with the lustre spec file version_tag.pl/make_META.pl needed better support for git. It also needed better support for transporting the information available in a source code system into the tarball so that when unpacked, where no sourcecode system was in place, the origins of the code could still be determined. Example output: git: v1_8_3_RC1-g751b802-CHANGED-2.6.18-128.1.1.el5_lustre.1.8.0.50.20090302160821smp cvs: b1_8-20100429144101-CHANGED-2.6.18-128.1.1.el5_lustre.1.8.0.50.20090302160821smp When run in a tree from a tarball, the output will be composed of the same tag and build id (hash or datestamp) as the source the tarball came from, but will refelect whatever kernel the unpacked source was configured with. Rename the tree_status file to META. There are times when the kernel should be rebuilt for all distros, but other times only for certain distros. Make the "all distros" case easier than having to increment the version in all of the build/lbuild-$distro files. i=wangyb i=mjmac When the lustre-fix is .0, when a tag is made, it includes the .0 so just drop it. Only append the .$BUILDID to the $EXTRA_VERSION when $BUILDID is actually not empty. Otherwise we get a trailing ".". It seems that the regex(7) used in bash's [[ ]] is not terribly portable across bash versions. SLES10 expects (, ), and | (at least) escaped with \. RHEL5 will accept them either escaped or not. Ubuntu fails to match if they are escaped. We need a more consistent test for being a subdir of Lustre. Differences in how automake passes dirnames made the existing code unpredictable. When the tag format is vW_X_Y_Z and lustre-fix (Z) is _0 when a tag is made, it includes the _0 so just drop it. i=yangsheng i=wangyb The return code from git status seems to be not as one would expect and it can return both 1 or 0 in a git repository. So change up and use git branch instead. Simplify the logic around this determination as well. Due to some unknown issue with using rpmbuild with the ldiskfs tarball causing symbol mismatches, do the right thing instead and build ldiskfs first and then build lustre with the external ldiskfs. Right now the method for doing this is a bit hacky since we point lustre at the ldiskfs rpm BUILD product. The right fix is to make an ldiskfs-devel RPM, which is a future enhancement of this work. This also fixes two bugs with ldiskfs' external module support building. One is that the external ldiskfs tree check was using a file that only exists in ext3 and not ext4. The second is that ldiskfs' configure was not properly initializing ldiskfs_is_ext4 and instead depending on the rpmbuild/configure caller to pass flags to tell it to build with ext4. i=wangyb i=minh --- autoMakefile.am | 11 +- build/autoMakefile.am.toplevel | 12 +- build/autoconf/lustre-build-linux.m4 | 39 ++++- build/autoconf/lustre-build.m4 | 119 +++++++++++++- build/lbuild | 201 ++++++++++++------------ build/lbuild-oel5 | 8 +- build/lbuild-rhel5 | 7 +- build/lbuild-sles10 | 7 +- build/lbuild-sles11 | 7 +- ldiskfs/autoMakefile.am | 10 ++ ldiskfs/configure.ac | 17 ++ ldiskfs/lustre-ldiskfs.spec.in | 42 ++++- lustre.spec.in | 41 ++++- lustre/scripts/Makefile.am | 9 +- lustre/scripts/version_tag-cvs.pl | 147 ++++++++++++++++++ lustre/scripts/version_tag-git.pl | 39 +++++ lustre/scripts/version_tag-none.pl | 41 +++++ lustre/scripts/version_tag.pl | 292 +++++++++++------------------------ 18 files changed, 707 insertions(+), 342 deletions(-) create mode 100644 lustre/scripts/version_tag-cvs.pl create mode 100644 lustre/scripts/version_tag-git.pl create mode 100644 lustre/scripts/version_tag-none.pl diff --git a/autoMakefile.am b/autoMakefile.am index 3cffd9c..251ab1e 100644 --- a/autoMakefile.am +++ b/autoMakefile.am @@ -42,9 +42,12 @@ checkstack-clean: module-dist-hook: if [ -d CVS -o -d .git ]; then \ - perl lustre/scripts/tree_status.pl > $(distdir)/tree_status; \ - elif [ -f tree_status ]; then \ - cp tree_status $(distdir)/tree_status; \ + perl lustre/scripts/make_META.pl > $(distdir)/META; \ + cp $(distdir)/META $(distdir)/ldiskfs/META; \ + elif [ -f META ]; then \ + cp META $(distdir)/META; \ + cp $(distdir)/META $(distdir)/ldiskfs/META; \ else \ - echo -e "I have no idea how to create a tree_status file in $(distdir).\nPlease file a bug at http://bugzilla.lustre.org/"; \ + echo -e "I have no idea how to create a META file in $(distdir).\nPlease file a bug at http://bugzilla.lustre.org/"; \ + exit 1; \ fi diff --git a/build/autoMakefile.am.toplevel b/build/autoMakefile.am.toplevel index 9806d8d..185b06f 100644 --- a/build/autoMakefile.am.toplevel +++ b/build/autoMakefile.am.toplevel @@ -104,10 +104,20 @@ EXTRA_DIST = @PACKAGE_TARNAME@.spec \ rpms-real: @PACKAGE_TARNAME@.spec dist Makefile CONFIGURE_ARGS=$$(echo $$(eval echo $(ac_configure_args)) | sed -re 's/--(en|dis)able-tests//'); \ - RPMARGS="--define \"configure_args $$CONFIGURE_ARGS\""; \ + if [ -n "@LINUX@" ]; then \ + CONFIGURE_ARGS=$$(echo $$(eval echo $$CONFIGURE_ARGS) | sed -re 's/--with-linux=[^ ][^ ]*//'); \ + RPMARGS="--define \"kdir @LINUX@\""; \ + CONFIGURE_ARGS=$$(echo $$(eval echo $$CONFIGURE_ARGS) | sed -re 's/--with-linux-obj=[^ ][^ ]*//'); \ + if [ -n "@LINUX_OBJ@" -a "@LINUX_OBJ@" != "@LINUX@" ]; then \ + RPMARGS="$$RPMARGS --define \"kobjdir @LINUX_OBJ@\""; \ + fi; \ + fi; \ + CONFIGURE_ARGS=$$(echo $$(eval echo $$CONFIGURE_ARGS) | sed -re 's/--with-release=[^ ][^ ]*//'); \ + RPMARGS="$$RPMARGS --define \"configure_args $$CONFIGURE_ARGS\""; \ if ! $(BUILD_TESTS); then \ RPMARGS="$$RPMARGS --define \"build_lustre_tests 0\""; \ fi; \ + echo "Building Lustre RPM with $$RPMARGS"; \ eval rpmbuild $$RPMARGS -ta $(distdir).tar.gz srpm-real: @PACKAGE_TARNAME@.spec dist Makefile diff --git a/build/autoconf/lustre-build-linux.m4 b/build/autoconf/lustre-build-linux.m4 index 1c47255..c71b9ac 100644 --- a/build/autoconf/lustre-build-linux.m4 +++ b/build/autoconf/lustre-build-linux.m4 @@ -95,7 +95,15 @@ AC_SUBST(modulenetdir) # ------------ RELEASE -------------------------------- AC_MSG_CHECKING([for Lustre release]) -RELEASE="`echo ${LINUXRELEASE} | tr '-' '_'`_`date +%Y%m%d%H%M`" +AC_ARG_WITH([release], + AC_HELP_STRING([--with-release=string], + [set the release string (default=$kvers_YYYYMMDDhhmm)]), + [RELEASE=$withval], + RELEASE="" + if test -n "$DOWNSTREAM_RELEASE"; then + RELEASE="${DOWNSTREAM_RELEASE}_" + fi + RELEASE="$RELEASE`echo ${LINUXRELEASE} | tr '-' '_'`_$BUILDID") AC_MSG_RESULT($RELEASE) AC_SUBST(RELEASE) @@ -159,12 +167,28 @@ AC_DEFUN([LB_ARG_CANON_PATH], [ # Find paths for linux, handling kernel-source rpms # AC_DEFUN([LB_LINUX_PATH], -[AC_MSG_CHECKING([for Linux sources]) +[# prep some default values +for DEFAULT_LINUX in /lib/modules/$(uname -r)/{source,build} /usr/src/linux; do + if readlink -q -e $DEFAULT_LINUX; then + break + fi +done +if test "$DEFAULT_LINUX" = "/lib/modules/$(uname -r)/source"; then + PATHS="/lib/modules/$(uname -r)/build" +fi +PATHS+="$DEFAULT_LINUX" +for DEFAULT_LINUX_OBJ in $PATHS; do + if readlink -q -e $DEFAULT_LINUX_OBJ; then + break + fi +done +AC_MSG_CHECKING([for Linux sources]) AC_ARG_WITH([linux], AC_HELP_STRING([--with-linux=path], - [set path to Linux source (default=/usr/src/linux)]), - [LB_ARG_CANON_PATH([linux], [LINUX])], - [LINUX=/usr/src/linux]) + [set path to Linux source (default=/lib/modules/$(uname -r)/{source,build},/usr/src/linux)]), + [LB_ARG_CANON_PATH([linux], [LINUX]) + DEFAULT_LINUX_OBJ=$LINUX], + [LINUX=$DEFAULT_LINUX]) AC_MSG_RESULT([$LINUX]) AC_SUBST(LINUX) @@ -176,9 +200,10 @@ LB_CHECK_FILE([$LINUX],[], AC_MSG_CHECKING([for Linux objects dir]) AC_ARG_WITH([linux-obj], AC_HELP_STRING([--with-linux-obj=path], - [set path to Linux objects dir (default=$LINUX)]), + [set path to Linux objects dir (default=/lib/modules/$(uname -r)/build,/usr/src/linux)]), [LB_ARG_CANON_PATH([linux-obj], [LINUX_OBJ])], - [LINUX_OBJ=$LINUX]) + [LINUX_OBJ=$DEFAULT_LINUX_OBJ]) + AC_MSG_RESULT([$LINUX_OBJ]) AC_SUBST(LINUX_OBJ) diff --git a/build/autoconf/lustre-build.m4 b/build/autoconf/lustre-build.m4 index c70afbf..0d9d029 100644 --- a/build/autoconf/lustre-build.m4 +++ b/build/autoconf/lustre-build.m4 @@ -29,6 +29,86 @@ AC_SUBST(lb_target_os) ]) # +# LB_DOWNSTREAM_RELEASE +# +AC_DEFUN([LB_DOWNSTREAM_RELEASE], +[AC_ARG_WITH([downstream-release], + AC_HELP_STRING([--with-downstream-release=string], + [set a string in the BUILD_VERSION and RPM Release: (default is nothing)]), + [DOWNSTREAM_RELEASE=$with_downstream_release], + [ + # if not specified, see if it's in the META file + if test -f META; then + DOWNSTREAM_RELEASE=$(sed -ne '/^LOCAL_VERSION =/s/.*= *//p' META) + fi + ]) +AC_SUBST(DOWNSTREAM_RELEASE) +]) + +# +# LB_BUILDID +# +# Check if the source is a GA release and if not, set a "BUILDID" +# +# Currently there are at least two ways/modes of/for doing this. One +# is if we are in a valid git repository, the other is if we are in a +# non-git source tree of some form. Building the latter from the former +# will be handled here. +AC_DEFUN([LB_BUILDID], +[ +AC_MSG_CHECKING([for buildid]) +BUILDID="" +if git branch >/dev/null 2>&1; then + ffw=0 + hash="" + ver=$(git describe --match [[0-9v]]\* --tags) + if [[[ $ver = *-*-* ]]]; then + hash=${ver##*-} + ffw=${ver#*-} + ffw=${ffw%-*} + ver=${ver%%-*} + fi + # it's tempting to use [[ $ver =~ ^v([0-9]+_)+([0-9]+|RC[0-9]+)$ ]] + # here but the portability of the regex on the right is dismal + # (thanx suse) + if echo "$ver" | egrep -q "^v([0-9]+_)+([0-9]+|RC[0-9]+)$"; then + ver=$(echo $ver | sed -e 's/^v\(.*\)/\1/' \ + -e 's/_RC[[0-9]].*$//' -e 's/_/./g') + fi + + # a "lustre fix" value of .0 should be truncated + if [[[ $ver = *.*.*.0 ]]]; then + ver=${ver%.0} + fi + # ditto for a "lustre fix" value of _0 + if [[[ $ver = v*_*_*_0 ]]]; then + ver=${ver%_0} + fi + + + # only do this test for lustre (not ldiskfs) + if test "$PACKAGE" = "lustre" -a "$ver" != "$VERSION"; then + AC_MSG_ERROR([most recent tag found: $ver does not match current version $VERSION.]) + fi + + if test "$ffw" != "0"; then + BUILDID="$hash" + msg="$BUILDID (ahead by $ffw commits)" + AC_MSG_RESULT([$msg]) + else + AC_MSG_RESULT([none... congratulations, you must be on a tag]) + fi +elif test -f META; then + BUILDID=$(sed -ne '/^BUILDID =/s/.*= *//p' META) + msg="$BUILDID (from META file)" + AC_MSG_RESULT([$msg]) +else + AC_MSG_WARN([FIXME: I don't know how to deal with source trees outside of git that don't have a META file. Not setting a buildid.]) +fi +AC_SUBST(BUILDID) +]) + +# # LB_CHECK_FILE # # Check for file existance even when cross compiling @@ -221,13 +301,13 @@ case x$with_ldiskfs in ;; xinkernel) AC_MSG_RESULT([inkernel]) - LB_CHECK_FILE([$LINUX/include/linux/ldiskfs_fs.h],[],[ - AC_MSG_ERROR([ldiskfs was not found in $LINUX/include/linux/ldiskfs_fs.h]) + LB_CHECK_FILE([$LINUX/fs/ldiskfs/inode.c],[],[ + AC_MSG_ERROR([ldiskfs was not found in $LINUX/fs/ldiskfs/inode.c]) ]) ;; *) AC_MSG_RESULT([$with_ldiskfs]) - LB_CHECK_FILE([$with_ldiskfs/ldiskfs/linux/ldiskfs_fs.h],[],[ + LB_CHECK_FILE([$with_ldiskfs/ldiskfs/inode.c],[],[ AC_MSG_ERROR([A complete (built) external ldiskfs was not found.]) ]) LDISKFS_DIR=$with_ldiskfs @@ -599,6 +679,30 @@ AC_MSG_RESULT([$enable_tests]) ]) # +# LB_CONFIG_DIST +# +# Just enough configure so that "make dist" is useful +# +# this simply re-adjusts some defaults, which of course can be overridden +# on the configure line after the --for-dist option +# +AC_DEFUN([LB_CONFIG_DIST], +[AC_MSG_CHECKING([whether to configure just enough for make dist]) +AC_ARG_ENABLE([dist], + AC_HELP_STRING([--enable-dist], + [only configure enough for make dist]), + [enable_dist='yes'],[enable_dist='no']) +AC_MSG_RESULT([$enable_dist]) +if test x$enable_dist != xno; then + enable_modules='no' + enable_utils='no' + enable_liblustre='no' + enable_doc='no' + enable_tests='no' +fi +]) + +# # LB_CONFIG_DOCS # # Build docs? @@ -610,7 +714,7 @@ AC_ARG_ENABLE(doc, [skip creation of pdf documentation]), [ if test x$enable_doc = xyes ; then - ENABLE_DOC=1 + ENABLE_DOC=1 else ENABLE_DOC=0 fi @@ -810,6 +914,11 @@ AC_PACKAGE_TARNAME[.spec] AC_DEFUN([LB_CONFIGURE], [LB_CANONICAL_SYSTEM +LB_CONFIG_DIST + +LB_DOWNSTREAM_RELEASE +LB_BUILDID + LB_LIBCFS_DIR LB_INCLUDE_RULES @@ -828,7 +937,7 @@ LB_CONFIG_UTILS LB_CONFIG_TESTS LC_CONFIG_CLIENT_SERVER -# two macros for cmd3 +# two macros for cmd3 m4_ifdef([LC_CONFIG_SPLIT], [LC_CONFIG_SPLIT]) LN_CONFIG_CDEBUG LC_QUOTA diff --git a/build/lbuild b/build/lbuild index dfc6f1c..fd97a12 100755 --- a/build/lbuild +++ b/build/lbuild @@ -21,6 +21,13 @@ shopt -s extdebug # our children should die when we do push_exit_trap "kill -INT -$$ || true" kill_children +# increment this if you have made a change that should force a new kernel +# to build built +#BUILD_GEN=1 +#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 + TOPDIR=$PWD # CVSROOT is inherited from the environment @@ -44,7 +51,6 @@ TARGET_ARCHS_ALL=$TARGET_ARCH CONFIGURE_FLAGS= EXTERNAL_PATCHES= EXTRA_VERSION= -LUSTRE_EXTRA_VERSION= STAGEDIR= TMPDIR=${TMPDIR:-"/var/tmp"} TIMESTAMP= @@ -247,7 +253,22 @@ EOF fatal "$1" "$2" } -# canonicalize a relative path +# canonicalize a relative path to a file +canon_filepath() { + local PATH="$1" + + if [ ! -f "$PATH" ]; then + return 1 + fi + + local FILE=${PATH##*/} + local DIR=${PATH%/*} + + echo $(canon_path "$DIR")/$FILE + return 0 +} + +# canonicalize a relative path to a dir canon_path() { local PATH="$1" @@ -615,7 +636,9 @@ load_target() { if $PATCHLESS || [ -n "$SERIES" ]; then EXTRA_VERSION=$(echo $EXTRA_VERSION | sed -e "s/\(.*_lustre\)\..*/\1/") # EXTRA_VERSION="${EXTRA_VERSION}-${TAG}.${TIMESTAMP}" - EXTRA_VERSION="${EXTRA_VERSION}.${TIMESTAMP}" + if ! $PATCHLESS && [ -n "$BUILDID" ]; then + EXTRA_VERSION="${EXTRA_VERSION}.${BUILDID}" + fi fi fi # EXTRA_VERSION=${EXTRA_VERSION//-/_} @@ -693,7 +716,7 @@ unpack_lustre() { fatal 1 "There was an error checking out Lustre/Portals/Build from CVS." echo "Creating lustre tarball..." sh autogen.sh || fatal 1 "There was an error running autogen.sh." - ./configure --disable-{modules,utils,liblustre,tests,doc} || \ + ./configure --enable-dist || \ fatal 1 "There was an error running ./configure to create makefiles." make dist || fatal 1 "There was an error running 'make dist'." LUSTRE=$PWD/lustre-*.tar.gz @@ -756,46 +779,70 @@ build_lustre() { targets="--target $arch $targets" done - local confoptions="--with-linux=${linux}" + local confoptions="" + if $PATCHLESS; then - confoptions="--with-linux=${linux} --disable-server" - fi - if [ "$linuxobj" != "" ]; then - confoptions="$confoptions --with-linux-obj=${linuxobj}" + confoptions="$confoptions --disable-server" fi - ./configure $confoptions ${CONFIGURE_FLAGS} 2>&1 - if [ "$?" != "0" ]; then - local saved_config="../config.log.$(date +%s)" - cp config.log $saved_config - chmod a+r $saved_config - echo "Saved config.log is at $saved_config" - cat /proc/mounts - ls -l /proc/$$ - pwd - echo "config.log contents:" - cat config.log - popd - return 255 + local rpmbuildopt='-tb' + if $NORPM; then + rpmbuildopt='-tc' + echo NORPM mode. Only compiling. fi - gen_lustre_version + ( $(skeep_ldiskfs_rpm $TAG) ) || { - # hack. Somebody move build/lustre.spec to lustre.spec for b1_6 - local lustre_spec - [ -f lustre.spec ] && lustre_spec=lustre.spec - [ -f build/lustre.spec ] && lustre_spec=build/lustre.spec + pushd ldiskfs > /dev/null || return 255 - [ -f "$lustre_spec" ] && sed \ - -e "s^Release: .*$^Release: $LUSTRE_EXTRA_VERSION^" \ - < $lustre_spec \ - > ../lustre.spec + if ! ./configure --enable-dist; then + echo "failed to configure in ldiskfs" + popd >/dev/null # pushd ldiskfs + popd >/dev/null # pushd lustre + return 255 + fi - local rpmbuildopt='-bb' - if $NORPM; then - rpmbuildopt='-bc' - echo NORPM mode. Only compiling. - fi + if ! make dist 2>&1; then + popd >/dev/null # pushd ldiskfs + popd >/dev/null # pushd lustre + return 255 + fi + + #cp lustre-ldiskfs*.tar.gz $TOPDIR/SOURCES || \ + # fatal 1 "Could not copy lustre-ldiskfs*.tar.gz to $TOPDIR/SOURCES" + + if ! $RPMBUILD $targets $rpmbuildopt lustre-ldiskfs*.tar.gz \ + --define "configure_args $confoptions ${CONFIGURE_FLAGS}" \ + --define "kdir $linux" \ + ${linuxobj:+--define "kobjdir $linuxobj"} \ + --define "_tmppath /var/tmp" \ + --define "_topdir $TOPDIR" 2>&1; then + popd >/dev/null # pushd ldiskfs + popd >/dev/null # pushd lustre + return 255 + fi + + if $DO_SRC; then + if ! $RPMBUILD -ts lustre-ldiskfs*.tar.gz \ + --define "configure_args $confoptions ${CONFIGURE_FLAGS}" \ + --define "kdir $linux" \ + ${linuxobj:+--define "kobjdir $linuxobj"} \ + --define "_tmppath /var/tmp" \ + --define "_topdir $TOPDIR" 2>&1; then + popd >/dev/null # pushd ldiskfs + popd >/dev/null # pushd lustre + return 255 + fi + fi + popd >/dev/null # pushd ldiskfs + + # tell lustre where ldiskfs is + # XXX - pointing to the RPM BUILD dir is a hack. we need to flesh + # out the ldiskfs RPM build so that it builds a + # lustre-ldiskfs-devel RPM and install that and point lustre + # to that instead + confoptions="$confoptions --with-ldiskfs=$(ls -d $TOPDIR/BUILD/lustre-ldiskfs-*)" + } # convert the $PATCHLESS boolean to an empty/not-empty boolean # as silly as this seems, it makes the syntax of the rpmbuild command @@ -811,50 +858,18 @@ build_lustre() { lustre_tests="no" fi - $RPMBUILD $targets $rpmbuildopt ../lustre.spec \ + $RPMBUILD $targets $rpmbuildopt "$LUSTRE" \ ${is_patchless:+--define "lustre_name lustre-client"} \ ${lustre_tests:+--define "build_lustre_tests 0"} \ ${FIND_REQUIRES:+--define "__find_requires $FIND_REQUIRES"} \ --define "configure_args $confoptions ${CONFIGURE_FLAGS}" \ + --define "kdir $linux" \ + ${linuxobj:+--define "kobjdir $linuxobj"} \ --define "_tmppath $TMPDIR" \ --define "_topdir $TOPDIR" 2>&1 || \ fatal 1 "Error building rpms for $BUILD_ARCHS." popd >/dev/null - ( $(skeep_ldiskfs_rpm $TAG) ) && return - - pushd lustre/ldiskfs || return 255 - make dist 2>&1 - if [ "$?" != "0" ]; then - popd - return 255 - fi - cp lustre-ldiskfs*.tar.gz $TOPDIR/SOURCES - - gen_lustre_version - - local ldiskfs_spec=lustre-ldiskfs.spec - [ -f "$ldiskfs_spec" ] && sed \ - -e "s^Release: .*$^Release: $LUSTRE_EXTRA_VERSION^" \ - < $ldiskfs_spec \ - > ../lustre-ldiskfs.spec - - if ! $RPMBUILD $targets $rpmbuildopt ../lustre-ldiskfs.spec \ - --define "_tmppath /var/tmp" \ - --define "_topdir $TOPDIR" 2>&1; then - popd - return 255 - fi - - if $DO_SRC; then - if ! $RPMBUILD -bs ../lustre-ldiskfs.spec \ - --define "_tmppath /var/tmp" \ - --define "_topdir $TOPDIR" 2>&1; then - popd - return 255 - fi - fi - popd } @@ -878,33 +893,21 @@ stage() { #check if we need to build separate ldiskfs RPM skeep_ldiskfs_rpm() { - local tag="$1" - - local skip=false - - if ! $LDISKFSRPM; then - skip=true - elif $PATCHLESS; then - skip=true - else - for skiptag in $SKIPLDISKFSRPM; do - [[ $tag == $skiptag ]] && skip=true && break - done - fi + local tag="$1" - pushd $TOPDIR/BUILD/lustre-[1-9]* >/dev/null - grep -q '^SERVER_TRUE[ \t]=[ \t]#$' autoMakefile && skip=true - popd >/dev/null + local skip=false - echo $skip - -} - -#generate LUSTRE_EXTRA_VERSION from EXTRA_VERSION -gen_lustre_version() { + if ! $LDISKFSRPM; then + skip=true + elif $PATCHLESS; then + skip=true + else + for skiptag in $SKIPLDISKFSRPM; do + [[ $tag == $skiptag ]] && skip=true && break + done + fi - LUSTRE_EXTRA_VERSION="${lnxmaj}-${EXTRA_VERSION}${FLAVOR_DELIMITER}${RPMSMPTYPE}" - LUSTRE_EXTRA_VERSION=${LUSTRE_EXTRA_VERSION//-/_} + echo $skip } @@ -1740,7 +1743,9 @@ while [ "$1" ]; do shift 2 ;; --lustre) - LUSTRE=$2 + if ! LUSTRE=$(canon_filepath "$2"); then + fatal 1 "Could not determine the canonical location of $2" + fi shift 2 ;; --nodownload) @@ -1815,6 +1820,10 @@ check_options unpack_lustre +# XXX - should we _always_ get the buildid from the META file? what are the +# other (i.e. non-lustre-tarball use cases of lbuild)? +BUILDID=$(sed -ne '/^BUILDID =/s/.*= *//p' lustre/META) + load_target if [ -n "$OFED_VERSION" -a "$OFED_VERSION" != "inkernel" ]; then diff --git a/build/lbuild-oel5 b/build/lbuild-oel5 index d1aaa94..6b5c38b 100644 --- a/build/lbuild-oel5 +++ b/build/lbuild-oel5 @@ -3,8 +3,6 @@ source ${0%/*}/lbuild-rhel5 # increment this if you have made a change that should force a new kernel -# to build built -#BUILD_GEN=1 -#BUILD_GEN=2 # bz19952: remove -lustre tag from kernel RPM names -BUILD_GEN=3 # bz19975 enable the building of src.rpms by default - +# to build built for this distribution (only -- if you want to force a kernel +# build on all distributions, update the BUILD_GEN variable in build/lbuild) +BUILD_GEN+=".0" diff --git a/build/lbuild-rhel5 b/build/lbuild-rhel5 index 11d9545..f106639 100644 --- a/build/lbuild-rhel5 +++ b/build/lbuild-rhel5 @@ -1,10 +1,9 @@ # vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4: # increment this if you have made a change that should force a new kernel -# to build built -#BUILD_GEN=1 -#BUILD_GEN=2 # bz19952: remove -lustre tag from kernel RPM names -BUILD_GEN=3 # bz19975 enable the building of src.rpms by default +# to build built for this distribution (only -- if you want to force a kernel +# build on all distributions, update the BUILD_GEN variable in build/lbuild) +BUILD_GEN+=".0" DEVEL_KERNEL_TYPE="devel" RPM_HELPERS_DIR="/usr/lib/rpm/redhat" diff --git a/build/lbuild-sles10 b/build/lbuild-sles10 index aece52b..9ca55fe 100644 --- a/build/lbuild-sles10 +++ b/build/lbuild-sles10 @@ -1,10 +1,9 @@ # vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4: # increment this if you have made a change that should force a new kernel -# to build built -#BUILD_GEN=1 -#BUILD_GEN=2 # bz19952: remove -lustre tag from kernel RPM names -BUILD_GEN=3 # bz19975 enable the building of src.rpms by default +# to build built for this distribution (only -- if you want to force a kernel +# build on all distributions, update the BUILD_GEN variable in build/lbuild) +BUILD_GEN+=".0" source ${0%/*}/lbuild-sles diff --git a/build/lbuild-sles11 b/build/lbuild-sles11 index 32f79b5..cdbe33e 100644 --- a/build/lbuild-sles11 +++ b/build/lbuild-sles11 @@ -1,10 +1,9 @@ # vim:expandtab:shiftwidth=4:softtabstop=4:tabstop=4: # increment this if you have made a change that should force a new kernel -# to build built -# BUILD_GEN=1 -#BUILD_GEN=2 # bz19952: remove -lustre tag from kernel RPM names -BUILD_GEN=3 # bz19975 enable the building of src.rpms by default +# to build built for this distribution (only -- if you want to force a kernel +# build on all distributions, update the BUILD_GEN variable in build/lbuild) +BUILD_GEN+=".0" source ${0%/*}/lbuild-sles diff --git a/ldiskfs/autoMakefile.am b/ldiskfs/autoMakefile.am index 163032b..e8b2d0e 100644 --- a/ldiskfs/autoMakefile.am +++ b/ldiskfs/autoMakefile.am @@ -10,4 +10,14 @@ include build/autoMakefile.am.toplevel EXTRA_DIST += kernel_patches +# this only needs to be done if disting stand-alone (i.e. not as a +# subdir of lustre module-dist-hook: + if ! grep "AC_INIT(\[Lustre\], \[LUSTRE_VERSION\], \[https:\/\/bugzilla\.lustre\.org\/], \[lustre\])" ../configure.ac; then \ + if [ -f META ]; then \ + cp META $(distdir)/META; \ + else \ + echo -e "I have no idea how to create a META file in $(distdir).\nPlease file a bug at http://bugzilla.lustre.org/"; \ + exit 1; \ + fi; \ + fi diff --git a/ldiskfs/configure.ac b/ldiskfs/configure.ac index e20d087..010bf6fb 100644 --- a/ldiskfs/configure.ac +++ b/ldiskfs/configure.ac @@ -2,6 +2,7 @@ AC_INIT([Lustre ldiskfs], 3.3.0, [https://bugzilla.lustre.org/]) AC_CONFIG_SRCDIR([lustre-ldiskfs.spec.in]) +ldiskfs_is_ext4=yes # Don't look for install-sh, etc. in .. AC_CONFIG_AUX_DIR([.]) @@ -13,9 +14,22 @@ AM_INIT_AUTOMAKE AC_PROG_CC LB_CANONICAL_SYSTEM + +LB_DOWNSTREAM_RELEASE + +LB_BUILDID + LB_INCLUDE_RULES LB_PROG_CC +AC_ARG_ENABLE([dist], + AC_HELP_STRING([--enable-dist], + [only configure enough for make dist]), + [enable_dist='yes'],[enable_dist='no']) +AC_MSG_RESULT([$enable_dist]) +if test x$enable_dist != xno; then + enable_modules='no' +fi # # LC_TARGET_SUPPORTED @@ -98,6 +112,8 @@ AC_SUBST(BACKFSU) # We need a Upper string AM_CONDITIONAL(USE_EXT4, test x$enable_ext4 = xyes) +if test x$enable_dist != xyes; then + # don't need to do this if only configuring for make dist AC_MSG_CHECKING([which ldiskfs series to use]) case $LINUXRELEASE in 2.6.5*) LDISKFS_SERIES="2.6-suse.series" ;; @@ -123,6 +139,7 @@ case $LINUXRELEASE in *) AC_MSG_WARN([Unknown kernel version $LINUXRELEASE, fix ldiskfs/configure.ac]) esac AC_MSG_RESULT([$LDISKFS_SERIES]) +fi AC_SUBST(LDISKFS_SERIES) AC_SUBST(ac_configure_args) diff --git a/ldiskfs/lustre-ldiskfs.spec.in b/ldiskfs/lustre-ldiskfs.spec.in index fe0e7fa..047f623 100644 --- a/ldiskfs/lustre-ldiskfs.spec.in +++ b/ldiskfs/lustre-ldiskfs.spec.in @@ -1,10 +1,25 @@ -%define version @VERSION@ -%define kversion @LINUXRELEASE@ +# lustre-ldiskfs.spec +%{!?version: %define version @VERSION@} +%{!?kdir: %define kdir %(dir=$(echo "%configure_args" | sed -ne 's/.*--with-linux=\\([^ ][^ ]*\\).*$/\\1/p'); if [ -n "$dir" ]; then echo "$dir"; else echo "/lib/modules/$(uname -r)/build"; fi)} + +%{!?kobjdir: %define kobjdir %(dir=$(echo "%configure_args" | sed -ne 's/.*--with-linux-obj=\\([^ ][^ ]*\\).*$/\\1/p'); if [ -n "$dir" ]; then echo "$dir"; else echo "%kdir"; fi)} + +# as an alternative to this implementation we could simply "make -C $kdir kernelversion" +%{!?kversion: %define kversion %(if test -s %kobjdir/include/linux/utsrelease.h ; then LINUXRELEASEHEADER=utsrelease.h; else LINUXRELEASEHEADER=version.h; fi; sed -ne '/^#define UTS_RELEASE/s/.*"\\(.*\\)"$/\\1/p' %kobjdir/include/linux/$LINUXRELEASEHEADER)} + +%{!?downstream_release: %define downstream_release "@DOWNSTREAM_RELEASE@"} + +%define buildid %(if [ -n "@BUILDID@" ]; then echo "_@BUILDID@"; fi) + +%{!?release: %define release %(if [ -n "%downstream_release" ]; then echo -n "%{downstream_release}_"; fi; release=$(echo %kversion | tr '-' '_'); echo ${release})} + +# always append the buildid, even when the caller defines %release +%define fullrelease %{release}%{buildid} Summary: ldiskfs backend file system Name: lustre-ldiskfs Version: %{version} -Release: @RELEASE@ +Release: %{fullrelease} License: GPL Group: Development/Kernel Source: lustre-ldiskfs-%{version}.tar.gz @@ -38,10 +53,27 @@ rm -rf $RPM_BUILD_ROOT # Set an explicit path to our Linux tree, if we can. cd $RPM_BUILD_DIR/lustre-ldiskfs-%{version} -./configure @ac_configure_args@ %{?configure_flags:configure_flags} \ +CONFIGURE_ARGS="%{?configure_args} --with-release=%release" + +# if %%kdir was given, make sure it's not in the configure arguments +if [ -n "%kdir" ]; then + CONFIGURE_ARGS=$(echo $CONFIGURE_ARGS | sed -e 's/"\?--with-linux=[^ ][^ ]* \?//') +fi +# ditto for %%kobjdir +if [ -n "%kobjdir" ]; then + CONFIGURE_ARGS=$(echo $CONFIGURE_ARGS | sed -e 's/"\?--with-linux-obj=[^ ][^ ]* \?//') +fi + +# we need to eval "configure" because $CONFIGURE_ARGS could have a quoted +# string in it which we don't want word splitted by the shell +%define eval_configure %(echo '%configure' | sed -e 's#\./configure#eval ./configure#') + +eval ./configure %{?configure_args} \ + %{?kdir: --with-linux=%kdir} %{?kobjdir: --with-linux-obj=%kobjdir} \ --sysconfdir=%{_sysconfdir} \ --mandir=%{_mandir} \ - --libdir=%{_libdir} + --libdir=%{_libdir} \ + $CONFIGURE_ARGS make -j $RPM_BUILD_NCPUS -s %install diff --git a/lustre.spec.in b/lustre.spec.in index b0c9adf..1cd6613 100644 --- a/lustre.spec.in +++ b/lustre.spec.in @@ -1,7 +1,21 @@ # lustre.spec %{!?version: %define version @VERSION@} -%{!?kversion: %define kversion @LINUXRELEASE@} -%{!?release: %define release @RELEASE@} +%{!?kdir: %define kdir %(dir=$(echo "%configure_args" | sed -ne 's/.*--with-linux=\\([^ ][^ ]*\\).*$/\\1/p'); if [ -n "$dir" ]; then echo "$dir"; else echo "/lib/modules/$(uname -r)/build"; fi)} + +%{!?kobjdir: %define kobjdir %(dir=$(echo "%configure_args" | sed -ne 's/.*--with-linux-obj=\\([^ ][^ ]*\\).*$/\\1/p'); if [ -n "$dir" ]; then echo "$dir"; else echo "%kdir"; fi)} + +# as an alternative to this implementation we could simply "make -C $kdir kernelversion" +%{!?kversion: %define kversion %(if test -s %kobjdir/include/linux/utsrelease.h ; then LINUXRELEASEHEADER=utsrelease.h; else LINUXRELEASEHEADER=version.h; fi; sed -ne '/^#define UTS_RELEASE/s/.*"\\(.*\\)"$/\\1/p' %kobjdir/include/linux/$LINUXRELEASEHEADER)} + +%{!?downstream_release: %define downstream_release "@DOWNSTREAM_RELEASE@"} + +%define buildid %(if [ -n "@BUILDID@" ]; then echo "_@BUILDID@"; fi) + +%{!?myrelease: %define myrelease %(if [ -n "%downstream_release" ]; then echo -n "%{downstream_release}_"; fi; echo %kversion | tr '-' '_')} + +# always append the buildid, even when the caller defines %release +%define fullrelease %{myrelease}%{buildid} + %{!?lustre_name: %define lustre_name lustre} %{!?build_lustre_tests: %define build_lustre_tests 1} @@ -38,7 +52,7 @@ Summary: Lustre File System Name: %{lustre_name} Version: %{version} -Release: %{release} +Release: %{fullrelease} License: GPL Group: Utilities/System Source: lustre-%{version}.tar.gz @@ -143,13 +157,29 @@ cd $RPM_BUILD_DIR/lustre-%{version} # override %optflags so that the vendor's overzealous flags don't create # build failures %define optflags -g -O2 -Werror -CONFIGURE_ARGS="" +CONFIGURE_ARGS="%{?configure_args} --with-release=%release" %if %{build_lustre_tests} CONFIGURE_ARGS="$CONFIGURE_ARGS --enable-tests --enable-liblustre-tests" %else CONFIGURE_ARGS="$CONFIGURE_ARGS --disable-tests --disable-liblustre-tests" %endif -%configure %{?configure_args:%configure_args} $CONFIGURE_ARGS + +# if %%kdir was given, make sure it's not in the configure arguments +if [ -n "%kdir" ]; then + CONFIGURE_ARGS=$(echo $CONFIGURE_ARGS | sed -e 's/"\?--with-linux=[^ ][^ ]* \?//') +fi +# ditto for %%kobjdir +if [ -n "%kobjdir" ]; then + CONFIGURE_ARGS=$(echo $CONFIGURE_ARGS | sed -e 's/"\?--with-linux-obj=[^ ][^ ]* \?//') +fi + +# we need to eval "configure" because $CONFIGURE_ARGS could have a quoted +# string in it which we don't want word splitted by the shell +%define eval_configure %(echo '%configure' | sed -e 's#\./configure#eval ./configure#') + +%eval_configure \ + %{?kdir: --with-linux=%kdir} %{?kobjdir: --with-linux-obj=%kobjdir} \ + $CONFIGURE_ARGS make -j $RPM_BUILD_NCPUS -s %install @@ -232,6 +262,7 @@ fi %endif pushd $RPM_BUILD_ROOT >/dev/null +> $RPM_BUILD_DIR/lustre-%{version}/lustre-modules.files find lib/modules/%{kversion}/updates -type f | awk "!/(ZZZZZZZZZZ$modules_excludes)/ {print \"%attr(-, root, root) /\"\$0}" >>$RPM_BUILD_DIR/lustre-%{version}/lustre-modules.files popd >/dev/null diff --git a/lustre/scripts/Makefile.am b/lustre/scripts/Makefile.am index 2d53c56..9b00685 100644 --- a/lustre/scripts/Makefile.am +++ b/lustre/scripts/Makefile.am @@ -43,9 +43,10 @@ genscripts = lustre_config lc_modprobe lc_net lc_hb lc_cluman lustre_createcsv \ sbin_SCRIPTS = $(genscripts) $(sbinscripts) bin_SCRIPTS = lustre_req_history lfs_migrate -EXTRA_DIST = license-status maketags.sh version_tag.pl lc_common \ +EXTRA_DIST = license-status maketags.sh version_tag.pl version_tag-git.pl \ + version_tag-cvs.pl version_tag-none.pl lc_common \ $(addsuffix .in,$(genscripts)) lc_mon $(sbinscripts) \ - $(bin_SCRIPTS) tree_status.pl + $(bin_SCRIPTS) make_META.pl scriptlibdir = @libexecdir@/@PACKAGE@ scriptlib_DATA = lc_common @@ -56,5 +57,5 @@ $(genscripts): %: %.in sed -e 's#@scriptlibdir@#$(scriptlibdir)#' < $< > $@ chmod +x $@ -tree_status.pl: version_tag.pl - ln -f version_tag.pl tree_status.pl +make_META.pl: version_tag.pl + ln -f $< $@ diff --git a/lustre/scripts/version_tag-cvs.pl b/lustre/scripts/version_tag-cvs.pl new file mode 100644 index 0000000..59d0e07 --- /dev/null +++ b/lustre/scripts/version_tag-cvs.pl @@ -0,0 +1,147 @@ +use Time::Local; + +my ($last_mtime, $pristine); + +# for CVS, the buildid is that old "latest mtime" process +sub get_buildid() +{ + + return mtime2date($last_mtime); + +} + +# Use the CVS tag first otherwise use the portals version +sub get_tag() +{ + + my $tag; + my $line; + + my $tagfile = new IO::File; + if (!$tagfile->open("lustre/CVS/Tag")) { + my $verfile = new IO::File; + if (!$verfile->open("config.h")) { + return "UNKNOWN"; + } + while(defined($line = <$verfile>)) { + $line =~ /\#define VERSION "(.*)"/; + if ($1) { + $tag = $1; + last; + } + } + $verfile->close(); + return $tag + } else { + my $tmp = <$tagfile>; + $tagfile->close(); + + $tmp =~ m/[TN](.*)/; + return $1; + } + +} + +sub get_latest_mtime() +{ + + my %months=("Jan" => 0, "Feb" => 1, "Mar" => 2, "Apr" => 3, "May" => 4, + "Jun" => 5, "Jul" => 6, "Aug" => 7, "Sep" => 8, "Oct" => 9, + "Nov" => 10, "Dec" => 11); + + my $last_mtime = 0; + my $pristine = 1; + + # if we got here, we are operating in a CVS checkout + my @entries = `find . -name Entries`; + my $entry_file; + foreach $entry_file (@entries) { + chomp($entry_file); + my $entry = new IO::File; + if (!$entry->open($entry_file)) { + die "unable to open $entry_file: $!\n"; + } + my $line; + while (defined($line = <$entry>)) { + chomp($line); + #print "line: $line\n"; + my ($junk, $file, $version, $date) = split(/\//, $line); + + #print "junk: $junk\nfile: $file\nver: $version\ndate: $date\n"; + #print "last_mtime: " . localtime($last_mtime) . "\n"; + + if ($junk eq "D" || + $file eq "lustre.spec.in") { + # also used to skip: "$file !~ m/\.(c|h|am|in)$/" but I see + # no good reason why only the above file patterns should + # count towards pristine/changed. it should be any file, + # surely. + next; + } + + my $cur_dir = $entry_file; + $cur_dir =~ s/\/CVS\/Entries$//; + my @statbuf = stat("$cur_dir/$file"); + my $mtime = $statbuf[9]; + if (!defined($mtime)) { + die "unable to get mtime of $cur_dir/$file: $!\n"; + } + my $local_date = gmtime($mtime); + if ($local_date ne $date && + $file ne "lustre.spec.in") { + #print "$file : " . localtime($mtime) . "\n"; + $pristine = 0; + } + + if ($mtime > $last_mtime) { + $last_mtime = $mtime; + } + + if ($date) { + my @t = split(/ +/, $date); + if (int(@t) != 5) { + #print "skipping: $date\n"; + next; + } + my ($hours, $min, $sec) = split(/:/, $t[3]); + my ($mon, $mday, $year) = ($t[1], $t[2], $t[4]); + my $secs = 0; + $mon = $months{$mon}; + $secs = timelocal($sec, $min, $hours, $mday, $mon, $year); + if ($secs > $last_mtime) { + $last_mtime = $secs; + } + } + } + $entry->close(); + } + return $last_mtime, $pristine; + +} + +sub mtime2date($) +{ + + my $mtime = shift; + + my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = + localtime($mtime); + $year += 1900; + $mon++; + my $show_last = sprintf("%04d%02d%02d%02d%02d%02d", $year, $mon, $mday, + $hour, $min, $sec); + + return $show_last; + +} + +sub is_pristine() +{ + + return $pristine; + +} + +($last_mtime, $pristine) = get_latest_mtime(); + +1; diff --git a/lustre/scripts/version_tag-git.pl b/lustre/scripts/version_tag-git.pl new file mode 100644 index 0000000..4912de8 --- /dev/null +++ b/lustre/scripts/version_tag-git.pl @@ -0,0 +1,39 @@ +my ($tag, $fcoms, $hash); + +sub get_buildid() +{ + + return $main::am_buildid; + +} + +sub is_pristine() +{ + + if ($fcoms > 0) { + return 0; + } + + my $diffcount=`git diff | wc -l`; + if ($diffcount > 0) { + return 0; + } + + return 1; + +} + +sub get_tag() +{ + + return $tag; + +} + +my $desc=`git describe --tags`; +$desc =~ /([^-]+)(?:-(.+)-(.+))?\n/; +$tag = $1; +$fcoms = $2; +$hash = $3; + +1; diff --git a/lustre/scripts/version_tag-none.pl b/lustre/scripts/version_tag-none.pl new file mode 100644 index 0000000..bbbb0fa --- /dev/null +++ b/lustre/scripts/version_tag-none.pl @@ -0,0 +1,41 @@ +my ($tag, $version, $buildid, $pristine); + +sub get_tag() +{ + + return $tag; + +} + +sub get_buildid() +{ + + return $buildid; + +} + +sub is_pristine() +{ + + return $pristine; + +} + +my $META = new IO::File; +if (!$META->open("META")) { + die "unable to open the META file: $!\n"; +} +my $line; +while (defined($line = <$META>)) { + if ($line =~ /^TAG\s*=\s*(.+)/) { + $tag = $1; + } elsif ($line =~ /^VERSION\s*=\s*([\d\.])/) { + $version = $1; + } elsif ($line =~ /^BUILDID\s*=\s*([a-g\d]+)/) { + $buildid = $1; + } elsif ($line =~ /^PRISTINE\s*=\s*([01])/) { + $pristine = $1; + } +} + +1; diff --git a/lustre/scripts/version_tag.pl b/lustre/scripts/version_tag.pl index 92655e1..6ba2494 100644 --- a/lustre/scripts/version_tag.pl +++ b/lustre/scripts/version_tag.pl @@ -1,173 +1,54 @@ #!/usr/bin/perl # -*- Mode: perl; indent-tabs-mode: nil; cperl-indent-level: 4 -*- -use strict; -use diagnostics; use IO::File; -use Time::Local; -my $pristine = 1; -my $kernver = ""; +# get all of the values we want out of the autoMakefile +sub read_autoMakefile() { -# Use the CVS tag first otherwise use the portals version -sub get_tag() -{ - my $tag; - my $line; - - my $tagfile = new IO::File; - if (!$tagfile->open("lustre/CVS/Tag")) { - # is there a good way to do this with git or should the git case just - # fall through to use config.h? it is always nice to know if we are - # working on a tag or branch. - my $verfile = new IO::File; - if (!$verfile->open("config.h")) { - return "UNKNOWN"; - } - while(defined($line = <$verfile>)) { - $line =~ /\#define VERSION "(.*)"/; - if ($1) { - $tag = $1; - last; - } - } - $verfile->close(); - return $tag - } else { - my $tmp = <$tagfile>; - $tagfile->close(); - - $tmp =~ m/[TN](.*)/; - return $1; - } -} - -sub get_latest_mtime() -{ - my %months=("Jan" => 0, "Feb" => 1, "Mar" => 2, "Apr" => 3, "May" => 4, - "Jun" => 5, "Jul" => 6, "Aug" => 7, "Sep" => 8, "Oct" => 9, - "Nov" => 10, "Dec" => 11); - - my $last_mtime = 0; - - # a CVS checkout - if (-d "CVS") { - # if we got here, we are operating in a CVS checkout - my @entries = `find . -name Entries`; - my $entry_file; - foreach $entry_file (@entries) { - chomp($entry_file); - my $entry = new IO::File; - if (!$entry->open($entry_file)) { - die "unable to open $entry_file: $!\n"; - } - my $line; - while (defined($line = <$entry>)) { - chomp($line); - #print "line: $line\n"; - my ($junk, $file, $version, $date) = split(/\//, $line); - - #print "junk: $junk\nfile: $file\nver: $version\ndate: $date\n"; - #print "last_mtime: " . localtime($last_mtime) . "\n"; - - if ($junk eq "D" || - $file eq "lustre.spec.in") { - # also used to skip: "$file !~ m/\.(c|h|am|in)$/" but I see - # no good reason why only the above file patterns should - # count towards pristine/changed. it should be any file, - # surely. - next; - } - - my $cur_dir = $entry_file; - $cur_dir =~ s/\/CVS\/Entries$//; - my @statbuf = stat("$cur_dir/$file"); - my $mtime = $statbuf[9]; - if (!defined($mtime)) { - next; - } - my $local_date = gmtime($mtime); - if ($local_date ne $date && - $file ne "lustre.spec.in") { - #print "$file : " . localtime($mtime) . "\n"; - $pristine = 0; - } - - if ($mtime > $last_mtime) { - $last_mtime = $mtime; - } - - if ($date) { - my @t = split(/ +/, $date); - if (int(@t) != 5) { - #print "skipping: $date\n"; - next; - } - my ($hours, $min, $sec) = split(/:/, $t[3]); - my ($mon, $mday, $year) = ($t[1], $t[2], $t[4]); - my $secs = 0; - $mon = $months{$mon}; - $secs = timelocal($sec, $min, $hours, $mday, $mon, $year); - if ($secs > $last_mtime) { - $last_mtime = $secs; - } - } - } - $entry->close(); - } - } elsif (-d ".git") { - # a git checkout - # TODO: figure out how to determine the most recently modified file - # in a git working copy. - # NOTE: this is not simply the newest file in the whole tree, - # but the newest file in the tree that is from the - # repository. - $last_mtime = time(); - } else { - my $tree_status = new IO::File; - if (!$tree_status->open("tree_status")) { - die "unable to open the tree_status file: $!\n"; - } - my $line; - while (defined($line = <$tree_status>)) { - if ($line =~ /^PRISTINE\s*=\s*(\d)/) { - $pristine = $1; - } elsif ($line =~ /^MTIME\s*=\s*(\d+)/) { - $last_mtime = $1; - } - } - } - return $last_mtime; - -} - -sub get_linuxdir() -{ - my $config = new IO::File; - my ($line, $dir, $objdir); - if (!$config->open("autoMakefile")) { + my $file = new IO::File; + my ($line, $dir, $objdir, $modules, $version, $local_version, $buildid); + if (!$file->open("autoMakefile")) { die "Run ./configure first\n"; } - while (defined($line = <$config>)) { + $modules = 1; + while (defined($line = <$file>)) { chomp($line); - if ($line =~ /LINUX :?= (.*)/) { + if ($line =~ /^LINUX :?= (.*)/) { $dir = $1; - } elsif ($line =~ /LINUX_OBJ :?= (.*)/) { + } elsif ($line =~ /^LINUX_OBJ :?= (.*)/) { $objdir = $1; - } elsif ($line =~ /MODULES_TRUE = #/ || - $line =~ /MODULE_TARGET = $/) { - # nothing to do if modules are not being built - return "" + } elsif ($line =~ /^MODULES_TRUE = #/ || + $line =~ /^MODULE_TARGET = $/) { + # modules are not being built + $modules = 1; + } elsif ($line =~ /^VERSION = (.*)/) { + $version = "$1"; + } elsif ($line =~ /^DOWNSTREAM_RELEASE = (.*)/ && $1 ne "") { + $local_version = "$1"; + } elsif ($line =~ /^BUILDID = (.*)/ && $1 ne "") { + $buildid = "$1"; } } - $config->close(); + $file->close(); + + return ($dir, $objdir, $modules, $version, $local_version, $buildid); + +} + +sub get_kernver($$) +{ + + my $dir = shift; + my $objdir = shift; + my $ver = new IO::File; if (!$ver->open("$objdir/include/linux/utsrelease.h") && !$ver->open("$objdir/include/linux/version.h") && !$ver->open("$dir/include/linux/utsrelease.h") && !$ver->open("$dir/include/linux/version.h")) { die "Run make dep on '$dir'\n"; - } + } while(defined($line = <$ver>)) { $line =~ /\#define UTS_RELEASE "(.*)"/; @@ -178,88 +59,103 @@ sub get_linuxdir() } $ver->close(); chomp($kernver); - $dir =~ s/\//\./g; - return $dir; -} - -sub mtime2date($) -{ - my $mtime = shift; + return $kernver; - my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = - localtime($mtime); - $year += 1900; - $mon++; - my $show_last = sprintf("%04d%02d%02d%02d%02d%02d", $year, $mon, $mday, - $hour, $min, $sec); - - return $show_last; } -sub generate_ver($$$) +sub generate_ver($$$$$$$) { + my $tag = shift; - my $mtime = shift; + my $local_version = shift; + my $buildid = shift; my $linuxdir = shift; + my $pristine = shift; + my $kernver = shift; + my $env_vers = shift; - # assume building without modules - my $postfix = ""; - - if ($linuxdir ne "") { - $postfix = "-$kernver"; - } - - #print "localtime: " . localtime($mtime) . "\n"; - - my $lustre_vers = $ENV{LUSTRE_VERS}; - - print "#define BUILD_VERSION \""; + print "#define BUILD_VERSION \"$tag"; - if ($lustre_vers) { - print "$tag-$lustre_vers\"\n"; + if ($env_vers) { + print "-$env_vers\"\n"; return 0; } - my $show_last = mtime2date($mtime); + if ($local_version ne "") { + print "-$local_version"; + } + print "-$buildid"; # if we want to get rid of the PRISTINE/CHANGED thing, get rid of these # lines. maybe we only want to print -CHANGED when something is changed # and print nothing when it's pristine if ($pristine) { - print "$tag-$show_last-PRISTINE$postfix\"\n"; + print "-PRISTINE"; } else { - print "$tag-$show_last-CHANGED$postfix\"\n"; + print "-CHANGED"; + } + + if ($kernver ne "") { + print "-$kernver"; } + + print "\"\n"; + } my $progname = $0; $progname =~ s/.*\///; -if ($progname eq "tree_status.pl" && !-d "CVS" && !-d ".git") { - die("a tree status can only be determined in an source code control system checkout\n"); -} - chomp(my $cwd = `pwd`); +my $path = $0; +$path =~ s/(.+)\/.*/\1/; +push(@INC, $cwd . "/" . $path); + +my $is_git = 0; +my $is_cvs = 0; + # ARGV[0] = srcdir # ARGV[1] = builddir -# for get_latest_mtime and get_tag you need to be in srcdir - +# need to be in srcdir if ($ARGV[0]) { chdir($ARGV[0]); } + +if (-d ".git") { + $is_git = 1; + require "version_tag-git.pl"; +} elsif (-d "CVS") { + $is_cvs = 1; + require "version_tag-cvs.pl"; +} else { + die("a tree status can only be determined in an source code control system checkout\n") + if ($progname eq "make_META.pl"); + require "version_tag-none.pl"; +} + +($am_linuxdir, $am_linuxobjdir, $am_modules, $am_version, $local_version, + $am_buildid) = read_autoMakefile(); + my $tag = get_tag(); -my $mtime = get_latest_mtime() - if (!defined($ENV{LUSTRE_VERS})); +my $pristine = is_pristine(); +my $buildid = get_buildid(); if ($progname eq "version_tag.pl") { - my $linuxdir = get_linuxdir(); - $linuxdir =~ s/\//\./g; - generate_ver($tag, $mtime, $linuxdir); -} elsif ($progname eq "tree_status.pl") { + die("you have to configure with a linux kernel source/headers tree (i.e. using\n--with-linux=) before you can run this script\n") + if ($am_linuxdir eq ""); + + my $kernver = get_kernver($am_linuxdir, $am_linuxobjdir); + my $linuxdir =~ s/\//\./g; + generate_ver($tag, $local_version, $buildid, $linuxdir, $pristine, $kernver, + $ENV{LUSTRE_VERS}); +} elsif ($progname eq "make_META.pl") { + print "TAG = $tag\n"; + print "VERSION = $am_version\n"; + print "BUILDID = $buildid\n"; print "PRISTINE = $pristine\n"; - print "MTIME = $mtime\n"; + print "LOCAL_VERSION = $local_version\n"; } exit(0); -- 1.8.3.1