enable pbr version

Currently all flock packages have a common base version of 1.0 or 1.0.0
defined in specfiles. The build system creates tarballs and whl files
with the base version (without TIS_PATCH_VER) and the version is also
attached the generated RPM file (with TIS_PATCH_VER).

This patch addes PBR (OpenStack's Python Build Reasonableness) support,
which can generate the version by parsing semantically-versioned Git
tags and walking the Git history back to the last release tag.

A new variable named PBR_VERSION is supported in build_srpm.data. If its
is not set, the build system still uses TIS_PATCH_VER like before.
If PBR_VERSION=auto, the build system will generate the version by
PBR and create tarballs, whl files and RPM files with this version.
If PBR_VERSION is set manually, the build system will use it directly.

Story: 2006703
Task: 37014

Change-Id: Ic377e3ae3344b291d2d9c0d0fca8f681d1a007b5
Signed-off-by: Bin Yang <bin.yang@intel.com>
Signed-off-by: Yang, Bin <bin.yang@intel.com>
This commit is contained in:
Bin Yang 2019-10-28 07:13:43 +00:00
parent c70efec479
commit e01eb44f2c
5 changed files with 103 additions and 47 deletions

View File

@ -654,6 +654,7 @@ build_dir_srpm () {
local COPY_LIST_TO_TAR local COPY_LIST_TO_TAR
local SRC_DIR local SRC_DIR
local TIS_PATCH_VER local TIS_PATCH_VER
local PBR_VERSION
local BUILD_IS_BIG=0 local BUILD_IS_BIG=0
local BUILD_IS_SLOW=0 local BUILD_IS_SLOW=0
@ -751,8 +752,8 @@ build_dir_srpm () {
return 1 return 1
fi fi
echo "srpm_extract_to_git '$ORIG_SRPM_PATH' '$PKG_BASE' '$ROOT_DIR' '$BUILD_DIR' '$PKG_NAME_VER' '$NO_META_PATCH_FLAG' '$TIS_PATCH_VER'" echo "srpm_extract_to_git '$ORIG_SRPM_PATH' '$PKG_BASE' '$ROOT_DIR' '$BUILD_DIR' '$PKG_NAME_VER' '$NO_META_PATCH_FLAG' '$TIS_PATCH_VER' '$PBR_VERSION'"
srpm_extract_to_git $ORIG_SRPM_PATH $PKG_BASE $ROOT_DIR $BUILD_DIR $PKG_NAME_VER $NO_META_PATCH_FLAG $TIS_PATCH_VER srpm_extract_to_git $ORIG_SRPM_PATH $PKG_BASE $ROOT_DIR $BUILD_DIR $PKG_NAME_VER $NO_META_PATCH_FLAG $TIS_PATCH_VER $PBR_VERSION
RC=$? RC=$?
if [ $RC -ne 0 ]; then if [ $RC -ne 0 ]; then
if [ $RC -eq 1 ]; then if [ $RC -eq 1 ]; then
@ -819,7 +820,7 @@ build_dir_srpm () {
done done
fi fi
srpm_assemble $FULL_BUILD_DIR $TIS_PATCH_VER srpm_assemble $FULL_BUILD_DIR $TIS_PATCH_VER $PBR_VERSION
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "ERROR: $FUNCNAME (${LINENO}): failed to assemble srpm for '$PKG_NAME_VER'" echo "ERROR: $FUNCNAME (${LINENO}): failed to assemble srpm for '$PKG_NAME_VER'"
@ -973,6 +974,7 @@ build_dir_spec () {
local SRC_DIR local SRC_DIR
local OPT_DEP_LIST local OPT_DEP_LIST
local TIS_PATCH_VER local TIS_PATCH_VER
local PBR_VERSION
local BUILD_IS_BIG=0 local BUILD_IS_BIG=0
local BUILD_IS_SLOW=0 local BUILD_IS_SLOW=0
@ -1057,8 +1059,8 @@ build_dir_spec () {
return 1 return 1
fi fi
echo "tar_and_spec_extract_to_git '$SPEC' '$PKG_BASE' '$ROOT_DIR' '$BUILD_DIR' '$PKG_NAME_VER' '$NO_META_PATCH_FLAG' '$TIS_PATCH_VER'" echo "tar_and_spec_extract_to_git '$SPEC' '$PKG_BASE' '$ROOT_DIR' '$BUILD_DIR' '$PKG_NAME_VER' '$NO_META_PATCH_FLAG' '$TIS_PATCH_VER' '$PBR_VERSION'"
tar_and_spec_extract_to_git "$SPEC" "$PKG_BASE" "$ROOT_DIR" "$BUILD_DIR" "$PKG_NAME_VER" "$NO_META_PATCH_FLAG" "$TIS_PATCH_VER" tar_and_spec_extract_to_git "$SPEC" "$PKG_BASE" "$ROOT_DIR" "$BUILD_DIR" "$PKG_NAME_VER" "$NO_META_PATCH_FLAG" "$TIS_PATCH_VER" "$PBR_VERSION"
RC=$? RC=$?
if [ $RC -ne 0 ]; then if [ $RC -ne 0 ]; then
if [ $RC -eq 1 ]; then if [ $RC -eq 1 ]; then

View File

@ -632,6 +632,7 @@ build_dir_srpm () {
local COPY_LIST_TO_TAR local COPY_LIST_TO_TAR
local SRC_DIR local SRC_DIR
local TIS_PATCH_VER local TIS_PATCH_VER
local PBR_VERSION
local BUILD_IS_BIG=0 local BUILD_IS_BIG=0
local BUILD_IS_SLOW=0 local BUILD_IS_SLOW=0
@ -730,8 +731,8 @@ build_dir_srpm () {
return 1 return 1
fi fi
echo "srpm_extract_to_git '$ORIG_SRPM_PATH' '$PKG_BASE' '$ROOT_DIR' '$BUILD_DIR' '$PKG_NAME_VER' '$NO_META_PATCH_FLAG' '$TIS_PATCH_VER'" echo "srpm_extract_to_git '$ORIG_SRPM_PATH' '$PKG_BASE' '$ROOT_DIR' '$BUILD_DIR' '$PKG_NAME_VER' '$NO_META_PATCH_FLAG' '$TIS_PATCH_VER' '$PBR_VERSION'"
srpm_extract_to_git $ORIG_SRPM_PATH $PKG_BASE $ROOT_DIR $BUILD_DIR $PKG_NAME_VER $NO_META_PATCH_FLAG $TIS_PATCH_VER srpm_extract_to_git $ORIG_SRPM_PATH $PKG_BASE $ROOT_DIR $BUILD_DIR $PKG_NAME_VER $NO_META_PATCH_FLAG $TIS_PATCH_VER $PBR_VERSION
RC=$? RC=$?
if [ $RC -ne 0 ]; then if [ $RC -ne 0 ]; then
if [ $RC -eq 1 ]; then if [ $RC -eq 1 ]; then
@ -797,7 +798,7 @@ build_dir_srpm () {
done done
fi fi
srpm_assemble $FULL_BUILD_DIR $TIS_PATCH_VER srpm_assemble $FULL_BUILD_DIR $TIS_PATCH_VER $PBR_VERSION
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "ERROR: $FUNCNAME (${LINENO}): failed to assemble srpm for '$PKG_NAME_VER'" echo "ERROR: $FUNCNAME (${LINENO}): failed to assemble srpm for '$PKG_NAME_VER'"
SRPM_FAILED_REBUILD_LIST="$SRPM_FAILED_REBUILD_LIST $TARGET_FOUND" SRPM_FAILED_REBUILD_LIST="$SRPM_FAILED_REBUILD_LIST $TARGET_FOUND"
@ -948,6 +949,7 @@ build_dir_spec () {
local SRC_DIR local SRC_DIR
local OPT_DEP_LIST local OPT_DEP_LIST
local TIS_PATCH_VER local TIS_PATCH_VER
local PBR_VERSION
local BUILD_IS_BIG=0 local BUILD_IS_BIG=0
local BUILD_IS_SLOW=0 local BUILD_IS_SLOW=0
@ -1035,8 +1037,8 @@ build_dir_spec () {
return 1 return 1
fi fi
echo "tar_and_spec_extract_to_git '$SPEC' '$PKG_BASE' '$ROOT_DIR' '$BUILD_DIR' '$PKG_NAME_VER' '$NO_META_PATCH_FLAG' '$TIS_PATCH_VER'" echo "tar_and_spec_extract_to_git '$SPEC' '$PKG_BASE' '$ROOT_DIR' '$BUILD_DIR' '$PKG_NAME_VER' '$NO_META_PATCH_FLAG' '$TIS_PATCH_VER' '$PBR_VERSION'"
tar_and_spec_extract_to_git "$SPEC" "$PKG_BASE" "$ROOT_DIR" "$BUILD_DIR" "$PKG_NAME_VER" "$NO_META_PATCH_FLAG" "$TIS_PATCH_VER" tar_and_spec_extract_to_git "$SPEC" "$PKG_BASE" "$ROOT_DIR" "$BUILD_DIR" "$PKG_NAME_VER" "$NO_META_PATCH_FLAG" "$TIS_PATCH_VER" "$PBR_VERSION"
RC=$? RC=$?
if [ $RC -ne 0 ]; then if [ $RC -ne 0 ]; then
if [ $RC -eq 1 ]; then if [ $RC -eq 1 ]; then

View File

@ -18,6 +18,10 @@ if [ $? -ne 0 ]; then
exit 1 exit 1
fi fi
if [ "x$PBR_VERSION" != "x" ] && [ "x$PBR_VERSION" != "xNA" ]; then
VERSION=$PBR_VERSION
fi
if [ "x$VERSION" == "x" ]; then if [ "x$VERSION" == "x" ]; then
for SPEC in `find $SPECS_BASE -name '*.spec' | sort -V`; do for SPEC in `find $SPECS_BASE -name '*.spec' | sort -V`; do
SPEC_PATH="$SPEC" SPEC_PATH="$SPEC"
@ -253,9 +257,11 @@ for SPEC in `ls -1 $BUILD_DIR/SPECS`; do
echo "SPEC file: $SPEC_PATH" echo "SPEC file: $SPEC_PATH"
echo "SRPM build directory: $BUILD_DIR" echo "SRPM build directory: $BUILD_DIR"
echo "TIS_PATCH_VER: $TIS_PATCH_VER" echo "TIS_PATCH_VER: $TIS_PATCH_VER"
echo "PBR_VERSION: $PBR_VERSION"
sed -i -e "1 i%define _tis_build_type $BUILD_TYPE" $SPEC_PATH sed -i -e "1 i%define _tis_build_type $BUILD_TYPE" $SPEC_PATH
sed -i -e "1 i%define tis_patch_ver $TIS_PATCH_VER" $SPEC_PATH sed -i -e "1 i%define tis_patch_ver $TIS_PATCH_VER" $SPEC_PATH
sed -i -e "1 i%define pbr_version $PBR_VERSION" $SPEC_PATH
rpmbuild -bs $SPEC_PATH --define="%_topdir $BUILD_DIR" --undefine=dist --define="_tis_dist .tis" rpmbuild -bs $SPEC_PATH --define="%_topdir $BUILD_DIR" --undefine=dist --define="_tis_dist .tis"
else else
echo "SRPM build not needed" echo "SRPM build not needed"

View File

@ -4,6 +4,7 @@ spec_query_with_macros () {
local SPEC_FILE=$1; shift local SPEC_FILE=$1; shift
local BUILD_DIR=$1; shift local BUILD_DIR=$1; shift
local TIS_PATCH_VER=$1; shift local TIS_PATCH_VER=$1; shift
local PBR_VERSION=$1; shift
local rc local rc
TMPSPEC=$(mktemp /tmp/spec-utils-XXXXXX) TMPSPEC=$(mktemp /tmp/spec-utils-XXXXXX)
@ -13,6 +14,7 @@ spec_query_with_macros () {
--define="_tis_build_type ${BUILD_TYPE:-std}" \ --define="_tis_build_type ${BUILD_TYPE:-std}" \
--define="_tis_dist .tis" \ --define="_tis_dist .tis" \
--define="tis_patch_ver ${TIS_PATCH_VER:-0}" \ --define="tis_patch_ver ${TIS_PATCH_VER:-0}" \
--define="pbr_version ${PBR_VERSION:-0}" \
--define="platform_release ${PLATFORM_RELEASE:-00.00}" \ --define="platform_release ${PLATFORM_RELEASE:-00.00}" \
--define="%_topdir $BUILD_DIR" \ --define="%_topdir $BUILD_DIR" \
"${@}" \ "${@}" \
@ -78,6 +80,7 @@ spec_evaluate () {
_tis_build_type) MACRO_VALUE="${BUILD_TYPE}" ;; _tis_build_type) MACRO_VALUE="${BUILD_TYPE}" ;;
_tis_dist) MACRO_VALUE=".tis" ;; _tis_dist) MACRO_VALUE=".tis" ;;
tis_patch_ver) MACRO_VALUE="{TIS_PATCH_VER:-0}" ;; tis_patch_ver) MACRO_VALUE="{TIS_PATCH_VER:-0}" ;;
pbr_version) MACRO_VALUE="{PBR_VERSION:-0}" ;;
platform_release) MACRO_VALUE="$PLATFORM_RELEASE" ;; platform_release) MACRO_VALUE="$PLATFORM_RELEASE" ;;
_topdir) MACRO_VALUE="$BUILD_DIR" ;; _topdir) MACRO_VALUE="$BUILD_DIR" ;;
*) ;; *) ;;
@ -148,9 +151,9 @@ spec_find_macro_via_rpm () {
# >&2 echo "spec_find_macro_via_rpm: TARGET=$TARGET" # >&2 echo "spec_find_macro_via_rpm: TARGET=$TARGET"
case "$TARGET" in case "$TARGET" in
name|_name) (spec_query_with_macros $SPEC_FILE $RPMBUILD_DIR ${TIS_PATCH_VER:-0} -q --qf '%{NAME}\n' | head -n 1 ; exit ${PIPESTATUS[0]} ); RC=$? ;; name|_name) (spec_query_with_macros $SPEC_FILE $RPMBUILD_DIR ${TIS_PATCH_VER:-0} ${PBR_VERSION:-0} -q --qf '%{NAME}\n' | head -n 1 ; exit ${PIPESTATUS[0]} ); RC=$? ;;
version|_version) (spec_query_with_macros $SPEC_FILE $RPMBUILD_DIR ${TIS_PATCH_VER:-0} -q --qf '%{VERSION}\n' | head -n 1 ; exit ${PIPESTATUS[0]} ); RC=$? ;; version|_version) (spec_query_with_macros $SPEC_FILE $RPMBUILD_DIR ${TIS_PATCH_VER:-0} ${PBR_VERSION:-0} -q --qf '%{VERSION}\n' | head -n 1 ; exit ${PIPESTATUS[0]} ); RC=$? ;;
release|_release) (spec_query_with_macros $SPEC_FILE $RPMBUILD_DIR ${TIS_PATCH_VER:-0} -q --qf '%{RELEASE}\n' | head -n 1 ; exit ${PIPESTATUS[0]} ); RC=$? ;; release|_release) (spec_query_with_macros $SPEC_FILE $RPMBUILD_DIR ${TIS_PATCH_VER:-0} ${PBR_VERSION:-0} -q --qf '%{RELEASE}\n' | head -n 1 ; exit ${PIPESTATUS[0]} ); RC=$? ;;
*) ;; *) ;;
esac esac
@ -199,6 +202,7 @@ spec_find_tag () {
local SPEC_FILE=$2 local SPEC_FILE=$2
local RPMBUILD_DIR=$3 local RPMBUILD_DIR=$3
local TIS_PATCH_VER=$4 local TIS_PATCH_VER=$4
local PBR_VERSION=$5
local LINE="" local LINE=""
if [ "x$RPMBUILD_DIR" == "x" ];then if [ "x$RPMBUILD_DIR" == "x" ];then
@ -209,7 +213,7 @@ spec_find_tag () {
# Note: ${VAR:-val} is bash syntax for providing a default value. # Note: ${VAR:-val} is bash syntax for providing a default value.
# ie. if $VAR is not set, use 'val' as default value # ie. if $VAR is not set, use 'val' as default value
spec_query_with_macros $SPEC_FILE $RPMBUILD_DIR ${TIS_PATCH_VER:-0} > $SPEC_FILE2 spec_query_with_macros $SPEC_FILE $RPMBUILD_DIR ${TIS_PATCH_VER:-0} ${PBR_VERSION:-0} > $SPEC_FILE2
if [ $? != 0 ]; then if [ $? != 0 ]; then
# spec_query_with_macros can fail on grub2 if it's just a spec file without SOURCES # spec_query_with_macros can fail on grub2 if it's just a spec file without SOURCES
\cp $SPEC_FILE $SPEC_FILE2 \cp $SPEC_FILE $SPEC_FILE2
@ -326,14 +330,14 @@ spec_list_packages () {
if [ "$bd" == "SPECS" ]; then if [ "$bd" == "SPECS" ]; then
local dd=$(dirname $d) local dd=$(dirname $d)
spec_query_with_macros $SPEC_FILE $RPMBUILD_DIR ${TIS_PATCH_VER:-0} -q --qf '%{name}\n' --define="%_topdir $dd" 2>> /dev/null spec_query_with_macros $SPEC_FILE $RPMBUILD_DIR ${TIS_PATCH_VER:-0} ${PBR_VERSION:-0} -q --qf '%{name}\n' --define="%_topdir $dd" 2>> /dev/null
else else
spec_query_with_macros $SPEC_FILE $RPMBUILD_DIR ${TIS_PATCH_VER:-0} -q --qf '%{name}\n' 2>> /dev/null spec_query_with_macros $SPEC_FILE $RPMBUILD_DIR ${TIS_PATCH_VER:-0} ${PBR_VERSION:-0} -q --qf '%{name}\n' 2>> /dev/null
fi fi
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
# spec_query_with_macros can fail on grub2 if it's just a spec file without SOURCES # spec_query_with_macros can fail on grub2 if it's just a spec file without SOURCES
local NAME=$(spec_find_tag Name "$SPEC_FILE" $RPMBUILD_DIR ${TIS_PATCH_VER:-0}) local NAME=$(spec_find_tag Name "$SPEC_FILE" $RPMBUILD_DIR ${TIS_PATCH_VER:-0} ${PBR_VERSION:-0})
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
>&2 echo "ERROR: failed to evaluate 'Name'" >&2 echo "ERROR: failed to evaluate 'Name'"
return 1 return 1
@ -353,7 +357,7 @@ spec_list_packages () {
fi fi
# >&2 echo "spec_list_packages: PKG_NAME_TEMP=$PKG_NAME_TEMP" # >&2 echo "spec_list_packages: PKG_NAME_TEMP=$PKG_NAME_TEMP"
PKG_NAME=$(spec_evaluate "$PKG_NAME_TEMP" "$SPEC_FILE" $RPMBUILD_DIR ${TIS_PATCH_VER:-0}) PKG_NAME=$(spec_evaluate "$PKG_NAME_TEMP" "$SPEC_FILE" $RPMBUILD_DIR ${TIS_PATCH_VER:-0} ${PBR_VERSION:-0})
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
>&2 echo "ERROR: failed to evaluate package '$PACKAGE_LINE'" >&2 echo "ERROR: failed to evaluate package '$PACKAGE_LINE'"
return 1 return 1
@ -378,20 +382,20 @@ spec_list_versioned_packages () {
if [ "$bd" == "SPECS" ]; then if [ "$bd" == "SPECS" ]; then
local dd=$(dirname $d) local dd=$(dirname $d)
spec_query_with_macros $SPEC_FILE $RPMBUILD_DIR ${TIS_PATCH_VER:-0} -q --qf '%{name}-%{version}\n' --define="%_topdir $dd" 2>> /dev/null spec_query_with_macros $SPEC_FILE $RPMBUILD_DIR ${TIS_PATCH_VER:-0} ${PBR_VERSION:-0} -q --qf '%{name}-%{version}\n' --define="%_topdir $dd" 2>> /dev/null
else else
spec_query_with_macros $SPEC_FILE $RPMBUILD_DIR ${TIS_PATCH_VER:-0} -q --qf '%{name}-%{version}\n' 2>> /dev/null spec_query_with_macros $SPEC_FILE $RPMBUILD_DIR ${TIS_PATCH_VER:-0} ${PBR_VERSION:-0} -q --qf '%{name}-%{version}\n' 2>> /dev/null
fi fi
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
# spec_query_with_macros can fail on grub2 if it's just a spec file without SOURCES # spec_query_with_macros can fail on grub2 if it's just a spec file without SOURCES
local NAME=$(spec_find_tag Name "$SPEC_FILE" $RPMBUILD_DIR ${TIS_PATCH_VER:-0}) local NAME=$(spec_find_tag Name "$SPEC_FILE" $RPMBUILD_DIR ${TIS_PATCH_VER:-0} ${PBR_VERSION:-0})
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
>&2 echo "ERROR: failed to evaluate 'Name'" >&2 echo "ERROR: failed to evaluate 'Name'"
return 1 return 1
fi fi
local VERSION=$(spec_find_tag Version "$SPEC_FILE" $RPMBUILD_DIR ${TIS_PATCH_VER:-0}) local VERSION=$(spec_find_tag Version "$SPEC_FILE" $RPMBUILD_DIR ${TIS_PATCH_VER:-0} ${PBR_VERSION:-0})
echo "$NAME-$VERSION" echo "$NAME-$VERSION"
grep "^%package" $SPEC_FILE | while read PACKAGE_LINE; do grep "^%package" $SPEC_FILE | while read PACKAGE_LINE; do
@ -407,7 +411,7 @@ spec_list_versioned_packages () {
fi fi
# >&2 echo "spec_list_packages: PKG_NAME_TEMP=$PKG_NAME_TEMP" # >&2 echo "spec_list_packages: PKG_NAME_TEMP=$PKG_NAME_TEMP"
PKG_NAME=$(spec_evaluate "$PKG_NAME_TEMP" "$SPEC_FILE" $RPMBUILD_DIR ${TIS_PATCH_VER:-0}) PKG_NAME=$(spec_evaluate "$PKG_NAME_TEMP" "$SPEC_FILE" $RPMBUILD_DIR ${TIS_PATCH_VER:-0} ${PBR_VERSION:-0})
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
>&2 echo "ERROR: failed to evaluate package '$PACKAGE_LINE'" >&2 echo "ERROR: failed to evaluate package '$PACKAGE_LINE'"
return 1 return 1
@ -431,9 +435,9 @@ spec_name_ver_rel () {
RPMBUILD_DIR=$(dirname $(dirname $SPEC_FILE)) RPMBUILD_DIR=$(dirname $(dirname $SPEC_FILE))
fi fi
NAME=$(spec_find_tag Name $SPEC_FILE $RPMBUILD_DIR ${TIS_PATCH_VER:-0}) NAME=$(spec_find_tag Name $SPEC_FILE $RPMBUILD_DIR ${TIS_PATCH_VER:-0} ${PBR_VERSION:-0})
VERSION=$(spec_find_tag Version $SPEC_FILE $RPMBUILD_DIR ${TIS_PATCH_VER:-0}) VERSION=$(spec_find_tag Version $SPEC_FILE $RPMBUILD_DIR ${TIS_PATCH_VER:-0} ${PBR_VERSION:-0})
RELEASE=$(spec_find_tag Release $SPEC_FILE $RPMBUILD_DIR ${TIS_PATCH_VER:-0}) RELEASE=$(spec_find_tag Release $SPEC_FILE $RPMBUILD_DIR ${TIS_PATCH_VER:-0} ${PBR_VERSION:-0})
echo "$NAME-$VERSION-$RELEASE" echo "$NAME-$VERSION-$RELEASE"
} }
@ -450,21 +454,21 @@ spec_list_ver_rel_packages () {
if [ "$bd" == "SPECS" ]; then if [ "$bd" == "SPECS" ]; then
local dd=$(dirname $d) local dd=$(dirname $d)
spec_query_with_macros $SPEC_FILE $RPMBUILD_DIR ${TIS_PATCH_VER:-0} -q --qf '%{name}-%{version}-%{release}\n' --define="%_topdir $dd" 2>> /dev/null spec_query_with_macros $SPEC_FILE $RPMBUILD_DIR ${TIS_PATCH_VER:-0} ${PBR_VERSION:-0} -q --qf '%{name}-%{version}-%{release}\n' --define="%_topdir $dd" 2>> /dev/null
else else
spec_query_with_macros $SPEC_FILE $RPMBUILD_DIR ${TIS_PATCH_VER:-0} -q --qf '%{name}-%{version}-%{release}\n' 2>> /dev/null spec_query_with_macros $SPEC_FILE $RPMBUILD_DIR ${TIS_PATCH_VER:-0} ${PBR_VERSION:-0} -q --qf '%{name}-%{version}-%{release}\n' 2>> /dev/null
fi fi
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
# spec_query_with_macros can fail on grub2 if it's just a spec file without SOURCES # spec_query_with_macros can fail on grub2 if it's just a spec file without SOURCES
local NAME=$(spec_find_tag Name "$SPEC_FILE" $RPMBUILD_DIR ${TIS_PATCH_VER:-0}) local NAME=$(spec_find_tag Name "$SPEC_FILE" $RPMBUILD_DIR ${TIS_PATCH_VER:-0} ${PBR_VERSION:-0})
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
>&2 echo "ERROR: failed to evaluate 'Name'" >&2 echo "ERROR: failed to evaluate 'Name'"
return 1 return 1
fi fi
local VERSION=$(spec_find_tag Version "$SPEC_FILE" $RPMBUILD_DIR ${TIS_PATCH_VER:-0}) local VERSION=$(spec_find_tag Version "$SPEC_FILE" $RPMBUILD_DIR ${TIS_PATCH_VER:-0} ${PBR_VERSION:-0})
local RELEASE=$(spec_find_tag Release "$SPEC_FILE" $RPMBUILD_DIR ${TIS_PATCH_VER:-0}) local RELEASE=$(spec_find_tag Release "$SPEC_FILE" $RPMBUILD_DIR ${TIS_PATCH_VER:-0} ${PBR_VERSION:-0})
echo "$NAME-$VERSION-$RELEASE" echo "$NAME-$VERSION-$RELEASE"
grep "^%package" $SPEC_FILE | while read PACKAGE_LINE; do grep "^%package" $SPEC_FILE | while read PACKAGE_LINE; do
@ -480,7 +484,7 @@ spec_list_ver_rel_packages () {
fi fi
# >&2 echo "spec_list_packages: PKG_NAME_TEMP=$PKG_NAME_TEMP" # >&2 echo "spec_list_packages: PKG_NAME_TEMP=$PKG_NAME_TEMP"
PKG_NAME=$(spec_evaluate "$PKG_NAME_TEMP" "$SPEC_FILE" $RPMBUILD_DIR ${TIS_PATCH_VER:-0}) PKG_NAME=$(spec_evaluate "$PKG_NAME_TEMP" "$SPEC_FILE" $RPMBUILD_DIR)
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
>&2 echo "ERROR: failed to evaluate package '$PACKAGE_LINE'" >&2 echo "ERROR: failed to evaluate package '$PACKAGE_LINE'"
return 1 return 1
@ -505,9 +509,9 @@ spec_list_ver_rel_arch_packages () {
if [ "$bd" == "SPECS" ]; then if [ "$bd" == "SPECS" ]; then
local dd=$(dirname $d) local dd=$(dirname $d)
spec_query_with_macros $SPEC_FILE $RPMBUILD_DIR ${TIS_PATCH_VER:-0} -q --qf '%{name}-%{version}-%{release}.%{arch}\n' --define="%_topdir $dd" 2>> /dev/null spec_query_with_macros $SPEC_FILE $RPMBUILD_DIR ${TIS_PATCH_VER:-0} ${PBR_VERSION:-0} -q --qf '%{name}-%{version}-%{release}.%{arch}\n' --define="%_topdir $dd" 2>> /dev/null
else else
spec_query_with_macros $SPEC_FILE $RPMBUILD_DIR ${TIS_PATCH_VER:-0} -q --qf '%{name}-%{version}-%{release}.%{arch}\n' 2>> /dev/null spec_query_with_macros $SPEC_FILE $RPMBUILD_DIR ${TIS_PATCH_VER:-0} ${PBR_VERSION:-0} -q --qf '%{name}-%{version}-%{release}.%{arch}\n' 2>> /dev/null
fi fi
} }
@ -691,6 +695,10 @@ spec_untar_path () {
spec_validate_tis_release () { spec_validate_tis_release () {
local SPEC_FILE=$1 local SPEC_FILE=$1
if rpmspec --define='_tis_dist .tis' -P $SPEC_FILE 2>/dev/null | grep '^Version:' | grep '%{pbr_version}'; then
return 0
fi
# TIS Release value must include either %{?_tis_dist}.%{tis_patch_ver} or %{tis_patch_ver}%{?_tis_dist} # TIS Release value must include either %{?_tis_dist}.%{tis_patch_ver} or %{tis_patch_ver}%{?_tis_dist}
# Because spec_query_with_macros defines tis_patch_ver, we're using rpmspec directly here # Because spec_query_with_macros defines tis_patch_ver, we're using rpmspec directly here
rpmspec --define='_tis_dist .tis' -P $SPEC_FILE 2>/dev/null | grep '^Release:' \ rpmspec --define='_tis_dist .tis' -P $SPEC_FILE 2>/dev/null | grep '^Release:' \

View File

@ -155,8 +155,9 @@ srpm_create_raw_extract_script () {
local TIS_PATCH_VER=$5 local TIS_PATCH_VER=$5
local RAW_SCRIPT=$6 local RAW_SCRIPT=$6
local TAR_DIR=$7 local TAR_DIR=$7
local PBR_VERSION=${8:-0}
echo "SPEC_FILE=$SPEC_FILE ROOT_DIR=$ROOT_DIR RPMBUILD_DIR=$RPMBUILD_DIR TARGET_ARCH=$TARGET_ARCH TIS_PATCH_VER=$TIS_PATCH_VER RAW_SCRIPT=$RAW_SCRIPT TAR_DIR=$TAR_DIR" echo "SPEC_FILE=$SPEC_FILE ROOT_DIR=$ROOT_DIR RPMBUILD_DIR=$RPMBUILD_DIR TARGET_ARCH=$TARGET_ARCH TIS_PATCH_VER=$TIS_PATCH_VER RAW_SCRIPT=$RAW_SCRIPT TAR_DIR=$TAR_DIR PBR_VERSION=$PBR_VERSION"
local BUILD_DIR="$RPMBUILD_DIR/BUILD" local BUILD_DIR="$RPMBUILD_DIR/BUILD"
local ApplyPatchCount=0 local ApplyPatchCount=0
@ -184,11 +185,12 @@ srpm_create_raw_extract_script () {
local SAME=0 local SAME=0
# Build the srpm as though for std build, for naming consistency # Build the srpm as though for std build, for naming consistency
echo "stdbuf -oL -eL rpmbuild -bp $SPEC_FILE --root $ROOT_DIR --define='%_topdir $RPMBUILD_DIR' --define='_tis_dist .tis' --define='tis_patch_ver $TIS_PATCH_VER' --nodeps --target $TARGET_ARCH > $STDOUT_LOG 2> $STDERR_LOG" echo "stdbuf -oL -eL rpmbuild -bp $SPEC_FILE --root $ROOT_DIR --define='%_topdir $RPMBUILD_DIR' --define='_tis_dist .tis' --define='tis_patch_ver $TIS_PATCH_VER' --define='pbr_version $PBR_VERSION' --nodeps --target $TARGET_ARCH > $STDOUT_LOG 2> $STDERR_LOG"
stdbuf -oL -eL rpmbuild -bp $SPEC_FILE --root $ROOT_DIR \ stdbuf -oL -eL rpmbuild -bp $SPEC_FILE --root $ROOT_DIR \
--define="%_topdir $RPMBUILD_DIR" \ --define="%_topdir $RPMBUILD_DIR" \
--define='_tis_dist .tis' \ --define='_tis_dist .tis' \
--define="tis_patch_ver $TIS_PATCH_VER" \ --define="tis_patch_ver $TIS_PATCH_VER" \
--define="pbr_version $PBR_VERSION" \
--define="_tis_build_type $BUILD_TYPE" \ --define="_tis_build_type $BUILD_TYPE" \
--nodeps --target $TARGET_ARCH > $STDOUT_LOG 2> $STDERR_LOG --nodeps --target $TARGET_ARCH > $STDOUT_LOG 2> $STDERR_LOG
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
@ -212,6 +214,7 @@ srpm_create_raw_extract_script () {
--define="%_topdir $RPMBUILD_DIR" \ --define="%_topdir $RPMBUILD_DIR" \
--define='_tis_dist .tis' \ --define='_tis_dist .tis' \
--define="tis_patch_ver $TIS_PATCH_VER" \ --define="tis_patch_ver $TIS_PATCH_VER" \
--define="pbr_version $PBR_VERSION" \
--define="_tis_build_type $BUILD_TYPE" \ --define="_tis_build_type $BUILD_TYPE" \
--nodeps --target $TARGET_ARCH > $STDOUT_LOG 2> $STDERR_LOG --nodeps --target $TARGET_ARCH > $STDOUT_LOG 2> $STDERR_LOG
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
@ -1230,6 +1233,7 @@ srpm_build_std_dictionary () {
srpm_assemble () { srpm_assemble () {
local FULL_BUILD_DIR=$1 local FULL_BUILD_DIR=$1
local TIS_PATCH_VER=$2 local TIS_PATCH_VER=$2
local PBR_VERSION=$3
local SPEC_PATH local SPEC_PATH
local SPEC local SPEC
@ -1257,7 +1261,7 @@ srpm_assemble () {
fi fi
fi fi
RELEASE=$(spec_find_tag Release "$SPEC_PATH" "$(dirname $(dirname $SPEC_PATH))" "$TIS_PATCH_VER" 2>> /dev/null) RELEASE=$(spec_find_tag Release "$SPEC_PATH" "$(dirname $(dirname $SPEC_PATH))" "$TIS_PATCH_VER" "$PBR_VERSION" 2>> /dev/null)
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "ERROR: $FUNCNAME (${LINENO}): 'Release' not found in '$SPEC_PATH'" echo "ERROR: $FUNCNAME (${LINENO}): 'Release' not found in '$SPEC_PATH'"
RELEASE="0" RELEASE="0"
@ -1286,9 +1290,11 @@ srpm_assemble () {
echo "SPEC file: $SPEC_PATH" echo "SPEC file: $SPEC_PATH"
echo "SRPM build directory: $FULL_BUILD_DIR" echo "SRPM build directory: $FULL_BUILD_DIR"
echo "TIS_PATCH_VER: $TIS_PATCH_VER" echo "TIS_PATCH_VER: $TIS_PATCH_VER"
echo "PBR_VERSION: $PBR_VERSION"
sed -i -e "1 i%define _tis_build_type $BUILD_TYPE" $SPEC_PATH sed -i -e "1 i%define _tis_build_type $BUILD_TYPE" $SPEC_PATH
sed -i -e "1 i%define tis_patch_ver $TIS_PATCH_VER" $SPEC_PATH sed -i -e "1 i%define tis_patch_ver $TIS_PATCH_VER" $SPEC_PATH
sed -i -e "1 i%define pbr_version $PBR_VERSION" $SPEC_PATH
# Build the srpm as though for std build, for naming consistency # Build the srpm as though for std build, for naming consistency
if [ "x$PLATFORM_RELEASE" == "x" ]; then if [ "x$PLATFORM_RELEASE" == "x" ]; then
@ -1647,9 +1653,10 @@ tarball_extract () {
local TIS_PATCH_VER="${12}" local TIS_PATCH_VER="${12}"
local OUTPUT_FILE="${13}" local OUTPUT_FILE="${13}"
local NO_META_PATCH=${14} local NO_META_PATCH=${14}
local PBR_VERSION=${15}
# BUILD_TYPE exported from higher layers # BUILD_TYPE exported from higher layers
echo "tarball_extract SPEC_DIR=$SPEC_DIR SPEC=$SPEC SPEC_GIT=$SPEC_GIT SOURCE_DIR=$SOURCE_DIR BRANCH=$BRANCH ORIG_BRANCH=$ORIG_BRANCH TAR_DIR=$TAR_DIR ROOT_DIR=$ROOT_DIR PKG_DIR=$PKG_DIR BUILD_DIR=$BUILD_DIR TARGET_ARCH=$TARGET_ARCH TIS_PATCH_VER=$TIS_PATCH_VER OUTPUT_FILE=$OUTPUT_FILE NO_META_PATCH=$NO_META_PATCH" echo "tarball_extract SPEC_DIR=$SPEC_DIR SPEC=$SPEC SPEC_GIT=$SPEC_GIT SOURCE_DIR=$SOURCE_DIR BRANCH=$BRANCH ORIG_BRANCH=$ORIG_BRANCH TAR_DIR=$TAR_DIR ROOT_DIR=$ROOT_DIR PKG_DIR=$PKG_DIR BUILD_DIR=$BUILD_DIR TARGET_ARCH=$TARGET_ARCH TIS_PATCH_VER=$TIS_PATCH_VER OUTPUT_FILE=$OUTPUT_FILE NO_META_PATCH=$NO_META_PATCH PBR_VERSION=$PBR_VERSION"
if [ -f $OUTPUT_FILE ]; then if [ -f $OUTPUT_FILE ]; then
\rm -f $OUTPUT_FILE \rm -f $OUTPUT_FILE
@ -1706,8 +1713,8 @@ tarball_extract () {
RAW_SCRIPT=$ROOT_DIR/$PKG_DIR/raw_script RAW_SCRIPT=$ROOT_DIR/$PKG_DIR/raw_script
EXTRACT_SCRIPT=$ROOT_DIR/$PKG_DIR/extract_script EXTRACT_SCRIPT=$ROOT_DIR/$PKG_DIR/extract_script
echo "srpm_create_raw_extract_script '$SPEC_DIR/$SPEC' '$ROOT_DIR/$PKG_DIR' '$ROOT_DIR/$BUILD_DIR' '$TARGET_ARCH' '$TIS_PATCH_VER' '$RAW_SCRIPT' '$TAR_DIR'" echo "srpm_create_raw_extract_script '$SPEC_DIR/$SPEC' '$ROOT_DIR/$PKG_DIR' '$ROOT_DIR/$BUILD_DIR' '$TARGET_ARCH' '$TIS_PATCH_VER' '$RAW_SCRIPT' '$TAR_DIR' '$PBR_VERSION'"
srpm_create_raw_extract_script "$SPEC_DIR/$SPEC" "$ROOT_DIR/$PKG_DIR" "$ROOT_DIR/$BUILD_DIR" "$TARGET_ARCH" "$TIS_PATCH_VER" "$RAW_SCRIPT" "$TAR_DIR" srpm_create_raw_extract_script "$SPEC_DIR/$SPEC" "$ROOT_DIR/$PKG_DIR" "$ROOT_DIR/$BUILD_DIR" "$TARGET_ARCH" "$TIS_PATCH_VER" "$RAW_SCRIPT" "$TAR_DIR" "$PBR_VERSION"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "ERROR: $FUNCNAME (${LINENO}): srpm_create_raw_extract_script failed" echo "ERROR: $FUNCNAME (${LINENO}): srpm_create_raw_extract_script failed"
cd $ORIG_DIR cd $ORIG_DIR
@ -2194,6 +2201,7 @@ tar_and_spec_extract_to_git () {
local BRANCH=$5 local BRANCH=$5
local NO_META_PATCH=$6 local NO_META_PATCH=$6
local TIS_PATCH_VER=$7 local TIS_PATCH_VER=$7
local PBR_VERSION=$8
local USE_GIT=1 local USE_GIT=1
local TARGET_ARCH=x86_64 local TARGET_ARCH=x86_64
@ -2344,7 +2352,7 @@ tar_and_spec_extract_to_git () {
local RPMBUILD_BUILD_DIR="" local RPMBUILD_BUILD_DIR=""
local OUTPUT_FILE="$ROOT_DIR/$PKG_DIR/tarball_extract_result" local OUTPUT_FILE="$ROOT_DIR/$PKG_DIR/tarball_extract_result"
tarball_extract "$SPEC_DIR" "$SPEC" "$SPEC_GIT" "$SOURCE_DIR" "$BRANCH" "$ORIG_BRANCH" "$TAR_DIR" "$ROOT_DIR" "$PKG_DIR" "$BUILD_DIR" "$TARGET_ARCH" "$TIS_PATCH_VER" "$OUTPUT_FILE" tarball_extract "$SPEC_DIR" "$SPEC" "$SPEC_GIT" "$SOURCE_DIR" "$BRANCH" "$ORIG_BRANCH" "$TAR_DIR" "$ROOT_DIR" "$PKG_DIR" "$BUILD_DIR" "$TARGET_ARCH" "$TIS_PATCH_VER" "$OUTPUT_FILE" "$NO_META_PATCH" "$PBR_VERSION"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "ERROR: $FUNCNAME (${LINENO}): tarball_extract failed while extracting '$SPEC_PATH'" echo "ERROR: $FUNCNAME (${LINENO}): tarball_extract failed while extracting '$SPEC_PATH'"
cd $ORIG_DIR cd $ORIG_DIR
@ -2375,7 +2383,8 @@ srpm_extract_to_git () {
local BUILD_DIR=$4 local BUILD_DIR=$4
local BRANCH=$5 local BRANCH=$5
local NO_META_PATCH=$6 local NO_META_PATCH=$6
local TIS_PATCH_VER=$7 local TIS_PATCH_VER=${7:-0}
local PBR_VERSION=${8:-0}
local USE_GIT=1 local USE_GIT=1
local TARGET_ARCH=x86_64 local TARGET_ARCH=x86_64
@ -2491,7 +2500,7 @@ srpm_extract_to_git () {
local RPMBUILD_BUILD_DIR="" local RPMBUILD_BUILD_DIR=""
local OUTPUT_FILE="$ROOT_DIR/$PKG_DIR/tarball_extract_result" local OUTPUT_FILE="$ROOT_DIR/$PKG_DIR/tarball_extract_result"
tarball_extract "$SPEC_DIR" "$SPEC" "$SPEC_GIT" "$SOURCE_DIR" "$BRANCH" "$ORIG_BRANCH" "$TAR_DIR" "$ROOT_DIR" "$PKG_DIR" "$BUILD_DIR" "$TARGET_ARCH" "$TIS_PATCH_VER" "$OUTPUT_FILE" "$NO_META_PATCH" tarball_extract "$SPEC_DIR" "$SPEC" "$SPEC_GIT" "$SOURCE_DIR" "$BRANCH" "$ORIG_BRANCH" "$TAR_DIR" "$ROOT_DIR" "$PKG_DIR" "$BUILD_DIR" "$TARGET_ARCH" "$TIS_PATCH_VER" "$OUTPUT_FILE" "$NO_META_PATCH" "$PBR_VERSION"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "ERROR: $FUNCNAME (${LINENO}): tarball_extract failed while extracting '$ORIG_SRPM_PATH'" echo "ERROR: $FUNCNAME (${LINENO}): tarball_extract failed while extracting '$ORIG_SRPM_PATH'"
cd $ORIG_DIR cd $ORIG_DIR
@ -2580,8 +2589,8 @@ srpm_extract_to_git () {
fi fi
mkdir -p $RPMBUILD_BUILD_DIR2 mkdir -p $RPMBUILD_BUILD_DIR2
echo "srpm_create_raw_extract_script '$SPEC_DIR/$SPEC' '$ROOT_DIR/$PKG_DIR' '$ROOT_DIR/$BUILD_DIR' '$TARGET_ARCH' '$TIS_PATCH_VER' '$RAW_SCRIPT' '$TAR_DIR'" echo "srpm_create_raw_extract_script '$SPEC_DIR/$SPEC' '$ROOT_DIR/$PKG_DIR' '$ROOT_DIR/$BUILD_DIR' '$TARGET_ARCH' '$TIS_PATCH_VER' '$RAW_SCRIPT' '$TAR_DIR' '$PBR_VERSION'"
srpm_create_raw_extract_script "$SPEC_DIR/$SPEC" "$ROOT_DIR/$PKG_DIR" "$ROOT_DIR/$BUILD_DIR" "$TARGET_ARCH" "$TIS_PATCH_VER" "$RAW_SCRIPT" "$TAR_DIR" srpm_create_raw_extract_script "$SPEC_DIR/$SPEC" "$ROOT_DIR/$PKG_DIR" "$ROOT_DIR/$BUILD_DIR" "$TARGET_ARCH" "$TIS_PATCH_VER" "$RAW_SCRIPT" "$TAR_DIR" "$PBR_VERSION"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "ERROR: $FUNCNAME (${LINENO}): srpm_create_raw_extract_script post meta-patches failed" echo "ERROR: $FUNCNAME (${LINENO}): srpm_create_raw_extract_script post meta-patches failed"
cd $ORIG_DIR cd $ORIG_DIR
@ -3197,6 +3206,21 @@ srpm_git_revision_count_pkg () {
return 0 return 0
} }
srpm_pbr_version () {
local SRC_DIR=$1
local VER
pushd $SRC_DIR > /dev/null
VER=$(python setup.py -q rpm_version)
if [ $? -ne 0 ]; then
return 1
fi
popd > /dev/null
echo $VER
return 0
}
srpm_source_build_data () { srpm_source_build_data () {
local DATA_FILE=$1 local DATA_FILE=$1
if [ ! -f $DATA_FILE ]; then if [ ! -f $DATA_FILE ]; then
@ -3206,9 +3230,20 @@ srpm_source_build_data () {
source $DATA_FILE source $DATA_FILE
# TIS_PATCH_VER is mandatory # TIS_PATCH_VER is mandatory
if [ -z "$TIS_PATCH_VER" ]; then if [ -z "$TIS_PATCH_VER" ] && [ -z "$PBR_VERSION" ]; then
>&2 echo "ERROR: $FUNCNAME (${LINENO}): TIS_PATCH_VER must be set in $DATA_FILE" >&2 echo "ERROR: $FUNCNAME (${LINENO}): TIS_PATCH_VER or PBR_VERSION must be set in $DATA_FILE"
return 1 return 1
elif [[ "$PBR_VERSION" == "auto" ]]; then
TIS_PATCH_VER="0"
if [ ! -d "$SRC_DIR" ]; then
>&2 echo "ERROR: $FUNCNAME (${LINENO}): SRC_DIR must specify a subgit root path"
return 1
fi
PBR_VERSION=$(srpm_pbr_version $SRC_DIR)
if [ $? -ne 0 ] || [ "$PBR_VERSION" == "" ]; then
>&2 echo "ERROR: $FUNCNAME (${LINENO}): Invalid PBR_VERSION '$PBR_VERSION'"
return 1
fi
elif [[ "${TIS_PATCH_VER}" =~ [^0-9] ]]; then elif [[ "${TIS_PATCH_VER}" =~ [^0-9] ]]; then
# Expand TIS_PATCH_VER with supported variables # Expand TIS_PATCH_VER with supported variables
local -i PKG_GITREVCOUNT=0 local -i PKG_GITREVCOUNT=0
@ -3252,5 +3287,8 @@ srpm_source_build_data () {
TIS_PATCH_VER=$((TIS_PATCH_VER)) TIS_PATCH_VER=$((TIS_PATCH_VER))
fi fi
# to avoid mockbuild error
PBR_VERSION=${PBR_VERSION:=NA}
return 0 return 0
} }