Build hangs on macro resolution in spec file

Problem:
Hung on a spec file that contains a seemingly self referential macro ...
   Version: %{_version}

Normally 'Version: x.y.z' has the effect of setting macro %{_version}.
In effect we have 'x=x'.  Not sure how rpm handles this, but we need to
prevent a recursion in our evaluation scripts.

Solution:
1) Test for recursion in spec_evaluate() and fail rather than
entering into a recursion.

2) Record the version from the srpm file name into an environment variable.
If we fail to read the version from the spec file directly, substitute
the one from the environment variable, if defined.

Note: Tripped up on mismatched '`' during testing, so substituted
all occurances with $().  Now a good browser should be able to
highlight an future mismatches.

Story: 2002839
Task: 22778
Change-Id: Ib69f879e531d842ff007d473bd3ad34db46cabf1
Signed-off-by: Scott Little <scott.little@windriver.com>
This commit is contained in:
Scott Little 2018-08-10 14:43:33 -04:00
parent f31c793761
commit 8744c5f598
4 changed files with 153 additions and 82 deletions

View File

@ -490,6 +490,9 @@ build_dir_srpm () {
local TARGET_FOUND="" local TARGET_FOUND=""
local RC=0 local RC=0
export SRPM_EXPORT_NAME=$NAME
export SRPM_EXPORT_VER=$VER
local NEED_BUILD=0 local NEED_BUILD=0
if [ "x$TARGETS" == "x" ]; then if [ "x$TARGETS" == "x" ]; then
@ -1140,20 +1143,24 @@ reaper () {
reaped=$((reaped+1)) reaped=$((reaped+1))
release_build_env $i release_build_env $i
if [ $ret -ne 0 ]; then if [ $ret -ne 0 ]; then
# if [ $ret -eq 1 ]; then VERB="build"
VERB="build"
if [ $EDIT_FLAG ]; then if [ $EDIT_FLAG -eq 1 ]; then
VERB="edit" VERB="edit"
if [ $CLEAN_FLAG -eq 1 ]; then
VERB="edit clean"
fi fi
if [ $CLEAN_FLAG ]; then fi
VERB="clean"
fi if [ $CLEAN_FLAG -eq 1 ]; then
sleep 1 VERB="clean"
echo "ERROR: Failed to $VERB src.rpm from source at 'b$i'" fi
cat "$LOG_DIR/$i" >> $LOG_DIR/errors
echo "ERROR: Failed to $VERB src.rpm from source at 'b$i'" >> $LOG_DIR/errors sleep 1
echo "" >> $LOG_DIR/errors echo "ERROR: Failed to $VERB src.rpm from source at 'b$i'"
# fi cat "$LOG_DIR/$i" >> $LOG_DIR/errors
echo "ERROR: Failed to $VERB src.rpm from source at 'b$i'" >> $LOG_DIR/errors
echo "" >> $LOG_DIR/errors
STOP_SCHEDULING=1 STOP_SCHEDULING=1
fi fi
fi fi

View File

@ -452,11 +452,15 @@ build_dir_srpm () {
local ORIG_SRPM=$(basename $ORIG_SRPM_PATH) local ORIG_SRPM=$(basename $ORIG_SRPM_PATH)
local NAME=`rpm -q --queryformat '%{NAME}\n' --nosignature -p $ORIG_SRPM_PATH` local NAME=`rpm -q --queryformat '%{NAME}\n' --nosignature -p $ORIG_SRPM_PATH`
local VER=`rpm -q --queryformat '%{VERSION}\n' --nosignature -p $ORIG_SRPM_PATH`
local PKG_NAME_VER=`rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}\n' --nosignature -p $ORIG_SRPM_PATH` local PKG_NAME_VER=`rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}\n' --nosignature -p $ORIG_SRPM_PATH`
local PKG_DIR="$NAME" local PKG_DIR="$NAME"
local TARGET_FOUND="" local TARGET_FOUND=""
local RC=0 local RC=0
export SRPM_EXPORT_NAME=$NAME
export SRPM_EXPORT_VER=$VER
local NEED_BUILD=0 local NEED_BUILD=0
if [ "x$TARGETS" == "x" ]; then if [ "x$TARGETS" == "x" ]; then
@ -1011,10 +1015,15 @@ for g in `find "$SRC_BASE" -type d -name .git | sort -V`; do
if [ $RC -ne 0 ]; then if [ $RC -ne 0 ]; then
if [ $RC -eq 1 ]; then if [ $RC -eq 1 ]; then
VERB="build" VERB="build"
if [ $EDIT_FLAG ]; then
if [ $EDIT_FLAG -eq 1 ]; then
VERB="edit" VERB="edit"
if [ $CLEAN_FLAG -eq 1 ]; then
VERB="edit clean"
fi
fi fi
if [ $CLEAN_FLAG ]; then
if [ $CLEAN_FLAG -eq 1 ]; then
VERB="clean" VERB="clean"
fi fi
echo "ERROR: Failed to $VERB src.rpm from source at '$p'" echo "ERROR: Failed to $VERB src.rpm from source at '$p'"
@ -1113,7 +1122,6 @@ if [ $ALL -eq 1 ]; then
fi fi
fi fi
done done
set +x
fi fi
if [ $CLEAN_FLAG -eq 1 ]; then if [ $CLEAN_FLAG -eq 1 ]; then

View File

@ -28,35 +28,50 @@ spec_evaluate () {
local SPEC_FILE=$2 local SPEC_FILE=$2
local RPMBUILD_DIR=$3 local RPMBUILD_DIR=$3
local LAST_SPEC_EVALUATING="$SPEC_EVALUATING"
local MACRO="" local MACRO=""
local MACRO_VALUE="" local MACRO_VALUE=""
local RC=0
if [ "x$RPMBUILD_DIR" == "x" ];then if [ "x$RPMBUILD_DIR" == "x" ];then
RPMBUILD_DIR=$(dirname $(dirname $SPEC_FILE)) RPMBUILD_DIR=$(dirname $(dirname $SPEC_FILE))
fi fi
MACRO=`expr match "$RAW_VALUE" '.*\(%{[^}]*}\)'` MACRO=$(expr match "$RAW_VALUE" '.*\(%{[^}]*}\)')
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "$RAW_VALUE" echo "$RAW_VALUE"
return 0 return 0
fi fi
if [ "x$SPEC_EVALUATING" == "x" ]; then
SPEC_EVALUATING=":$MACRO:"
else
echo "$SPEC_EVALUATING" | grep -q ":$MACRO:"
if [ $? -eq 0 ]; then
# Break a recursion
>&2 echo "ERROR: evaluation of macro '$MACRO' failed due to recursion"
return 1
fi
SPEC_EVALUATING="$LAST_SPEC_EVALUATING$MACRO:"
fi
# >&2 echo "spec_evaluate: MACRO=$MACRO" # >&2 echo "spec_evaluate: MACRO=$MACRO"
local MACRO_NAME2=${MACRO#%{} local MACRO_NAME2=${MACRO#%{}
local MACRO_NAME3=${MACRO_NAME2%\}} local MACRO_NAME3=${MACRO_NAME2%\}}
local PREFIX=`expr match "$MACRO_NAME3" '\([!?]*\)'` local PREFIX=$(expr match "$MACRO_NAME3" '\([!?]*\)')
local MACRO_NAME=${MACRO_NAME3#${PREFIX}} local MACRO_NAME=${MACRO_NAME3#${PREFIX}}
# >&2 echo "spec_evaluate: MACRO_NAME=$MACRO_NAME" # >&2 echo "spec_evaluate: MACRO_NAME=$MACRO_NAME"
MACRO_VALUE=`spec_find_macro $MACRO_NAME $SPEC_FILE $RPMBUILD_DIR` MACRO_VALUE=$(spec_find_macro $MACRO_NAME $SPEC_FILE $RPMBUILD_DIR)
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
MACRO_VALUE=`spec_find_global $MACRO_NAME $SPEC_FILE $RPMBUILD_DIR` # >&2 echo "CALL: spec_find_global $MACRO_NAME $SPEC_FILE $RPMBUILD_DIR"
MACRO_VALUE=$(spec_find_global $MACRO_NAME $SPEC_FILE $RPMBUILD_DIR)
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
MACRO_VALUE=`spec_find_tag ${MACRO_NAME^} $SPEC_FILE $RPMBUILD_DIR` MACRO_VALUE=$(spec_find_tag ${MACRO_NAME^} $SPEC_FILE $RPMBUILD_DIR)
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
MACRO_VALUE=`macro_find_macro $MACRO_NAME $SPEC_FILE $RPMBUILD_DIR` MACRO_VALUE=$(macro_find_macro $MACRO_NAME $SPEC_FILE $RPMBUILD_DIR)
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
MACRO_VALUE=`spec_find_macro_via_rpm $MACRO_NAME $SPEC_FILE $RPMBUILD_DIR` MACRO_VALUE=$(spec_find_macro_via_rpm $MACRO_NAME $SPEC_FILE $RPMBUILD_DIR)
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
case "$MACRO_NAME" in case "$MACRO_NAME" in
@ -73,6 +88,7 @@ spec_evaluate () {
>&2 echo "NOTE: optional macro '$MACRO' not defined" >&2 echo "NOTE: optional macro '$MACRO' not defined"
else else
>&2 echo "ERROR: evaluation of macro '$MACRO' failed" >&2 echo "ERROR: evaluation of macro '$MACRO' failed"
SPEC_EVALUATING="$LAST_SPEC_EVALUATING"
return 1 return 1
fi fi
fi fi
@ -86,6 +102,9 @@ spec_evaluate () {
local NEW_VALUE=${RAW_VALUE/"${MACRO}"/${MACRO_VALUE}} local NEW_VALUE=${RAW_VALUE/"${MACRO}"/${MACRO_VALUE}}
# >&2 echo "spec_evaluate: NEW_VALUE=$NEW_VALUE" # >&2 echo "spec_evaluate: NEW_VALUE=$NEW_VALUE"
spec_evaluate "$NEW_VALUE" "$SPEC_FILE" "$RPMBUILD_DIR" spec_evaluate "$NEW_VALUE" "$SPEC_FILE" "$RPMBUILD_DIR"
RC=$?
SPEC_EVALUATING="$LAST_SPEC_EVALUATING"
return $RC
} }
macro_find_macro () { macro_find_macro () {
@ -99,7 +118,7 @@ macro_find_macro () {
fi fi
# >&2 echo "grep ^%$TARGET $RPM_MACRO_FILE" # >&2 echo "grep ^%$TARGET $RPM_MACRO_FILE"
LINE=`grep "^%$TARGET[[:space:]]" $RPM_MACRO_FILE` LINE=$(grep "^%$TARGET[[:space:]]" $RPM_MACRO_FILE)
if [ $? -eq 1 ]; then if [ $? -eq 1 ]; then
>&2 echo "macro_find_macro: '%$TARGET' not found in file '$RPM_MACRO_FILE'" >&2 echo "macro_find_macro: '%$TARGET' not found in file '$RPM_MACRO_FILE'"
echo "" echo ""
@ -153,11 +172,11 @@ spec_find_macro () {
fi fi
# >&2 echo "grep ^%define $TARGET $SPEC_FILE" # >&2 echo "grep ^%define $TARGET $SPEC_FILE"
LINE=`grep "^%define $TARGET[[:space:]]" $SPEC_FILE` LINE=$(grep "^%define $TARGET[[:space:]]" $SPEC_FILE)
if [ $? -eq 1 ]; then if [ $? -eq 1 ]; then
LINE=`grep "^%$TARGET[[:space:]]" $SPEC_FILE` LINE=$(grep "^%$TARGET[[:space:]]" $SPEC_FILE)
if [ $? -eq 1 ]; then if [ $? -eq 1 ]; then
>&2 echo "spec_find_macro: Neither '%define $TARGET' nor '%$TARGET' not found in file '$SPEC_FILE'" >&2 echo "spec_find_macro: Neither '%define $TARGET' nor '%$TARGET' found in file '$SPEC_FILE'"
echo "" echo ""
return 1 return 1
else else
@ -252,7 +271,7 @@ spec_find_global () {
RPMBUILD_DIR=$(dirname $(dirname $SPEC_FILE)) RPMBUILD_DIR=$(dirname $(dirname $SPEC_FILE))
fi fi
LINE=`grep "^%global $TARGET" $SPEC_FILE` LINE=$(grep "^%global $TARGET" $SPEC_FILE)
if [ $? -eq 1 ]; then if [ $? -eq 1 ]; then
>&2 echo "spec_find_global: '%global $TARGET' not found in file '$SPEC_FILE'" >&2 echo "spec_find_global: '%global $TARGET' not found in file '$SPEC_FILE'"
echo "" echo ""
@ -282,7 +301,7 @@ spec_find_patch_args () {
fi fi
PATCH_LOWER_NO=$(echo $PATCH_NO | tr '[:upper:]' '[:lower:]') PATCH_LOWER_NO=$(echo $PATCH_NO | tr '[:upper:]' '[:lower:]')
LINE=`grep "^%$PATCH_LOWER_NO " $SPEC_FILE` LINE=$(grep "^%$PATCH_LOWER_NO " $SPEC_FILE)
if [ $? -eq 1 ]; then if [ $? -eq 1 ]; then
>&2 echo "pec_find_patch_args: $PATCH_LOWER_NO' not found in file '$SPEC_FILE'" >&2 echo "pec_find_patch_args: $PATCH_LOWER_NO' not found in file '$SPEC_FILE'"
echo "-p1" echo "-p1"
@ -505,7 +524,7 @@ spec_match_package_list () {
RPMBUILD_DIR=$(dirname $(dirname $SPEC_FILE)) RPMBUILD_DIR=$(dirname $(dirname $SPEC_FILE))
fi fi
for PKG_NAME in `spec_list_packages "$SPEC_FILE" "$RPMBUILD_DIR"`; do for PKG_NAME in $(spec_list_packages "$SPEC_FILE" "$RPMBUILD_DIR"); do
for TARGET in "${TARGET_LIST[@]}"; do for TARGET in "${TARGET_LIST[@]}"; do
if [ "$PKG_NAME" == "$TARGET" ]; then if [ "$PKG_NAME" == "$TARGET" ]; then
echo $TARGET echo $TARGET
@ -532,7 +551,7 @@ spec_match_package () {
RPMBUILD_DIR=$(dirname $(dirname $SPEC_FILE)) RPMBUILD_DIR=$(dirname $(dirname $SPEC_FILE))
fi fi
for PKG_NAME in `spec_list_packages "$SPEC_FILE" "$RPMBUILD_DIR"`; do for PKG_NAME in $(spec_list_packages "$SPEC_FILE" "$RPMBUILD_DIR"); do
if [ "$PKG_NAME" == "$TARGET" ]; then if [ "$PKG_NAME" == "$TARGET" ]; then
echo "found target '$TARGET' in file '$SPEC_FILE' as a package name" echo "found target '$TARGET' in file '$SPEC_FILE' as a package name"
return 0 return 0
@ -556,7 +575,7 @@ spec_match_target_list () {
RPMBUILD_DIR=$(dirname $(dirname $SPEC_FILE)) RPMBUILD_DIR=$(dirname $(dirname $SPEC_FILE))
fi fi
NAME=`spec_find_tag Name "$SPEC_FILE" "$RPMBUILD_DIR"` NAME=$(spec_find_tag Name "$SPEC_FILE" "$RPMBUILD_DIR")
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
for TARGET in "${TARGET_LIST[@]}"; do for TARGET in "${TARGET_LIST[@]}"; do
if [ "$NAME" == "$TARGET" ]; then if [ "$NAME" == "$TARGET" ]; then
@ -570,7 +589,7 @@ spec_match_target_list () {
done done
fi fi
SERVICE=`spec_find_global service "$SPEC_FILE" "$RPMBUILD_DIR"` SERVICE=$(spec_find_global service "$SPEC_FILE" "$RPMBUILD_DIR")
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
for TARGET in "${TARGET_LIST[@]}"; do for TARGET in "${TARGET_LIST[@]}"; do
if [ "$SERVICE" == "$TARGET" ]; then if [ "$SERVICE" == "$TARGET" ]; then
@ -605,7 +624,7 @@ spec_match_target () {
RPMBUILD_DIR=$(dirname $(dirname $SPEC_FILE)) RPMBUILD_DIR=$(dirname $(dirname $SPEC_FILE))
fi fi
NAME=`spec_find_tag Name "$SPEC_FILE" "$RPMBUILD_DIR"` NAME=$(spec_find_tag Name "$SPEC_FILE" "$RPMBUILD_DIR")
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
if [ "$NAME" == "$TARGET" ]; then if [ "$NAME" == "$TARGET" ]; then
echo "found target '$TARGET' in file '$SPEC_FILE' as a name" echo "found target '$TARGET' in file '$SPEC_FILE' as a name"
@ -613,7 +632,7 @@ spec_match_target () {
fi fi
fi fi
SERVICE=`spec_find_global service "$SPEC_FILE" "$RPMBUILD_DIR"` SERVICE=$(spec_find_global service "$SPEC_FILE" "$RPMBUILD_DIR")
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
if [ "$SERVICE" == "$TARGET" ]; then if [ "$SERVICE" == "$TARGET" ]; then
echo "found target '$TARGET' in file '$SPEC_FILE' as a service" echo "found target '$TARGET' in file '$SPEC_FILE' as a service"

View File

@ -13,6 +13,36 @@ METHOD_NO_RPMBUILD=0
METHOD_RPMBUILD_UNPATCH=1 METHOD_RPMBUILD_UNPATCH=1
METHOD_RPMBUILD_SCRIPT=2 METHOD_RPMBUILD_SCRIPT=2
srpm_spec_find_version () {
local SPEC_PATH="$1"
local PKG_VER=$(spec_find_tag Version $SPEC_PATH 2>> /dev/null)
if [ "x$PKG_VER" == "x" ]; then
if [ "x$SRPM_EXPORT_VER" != "x" ]; then
PKG_VER="$SRPM_EXPORT_VER"
else
PKG_VER="0"
fi
fi
echo "$PKG_VER"
}
srpm_spec_find_name () {
local SPEC_PATH="$1"
local PKG_VER=$(spec_find_tag Name $SPEC_PATH 2>> /dev/null)
if [ "x$PKG_VER" == "x" ]; then
if [ "x$SRPM_EXPORT_NAME" != "x" ]; then
PKG_VER="$SRPM_EXPORT_NAME"
else
PKG_VER="0"
fi
fi
echo "$PKG_VER"
}
# Find the common root directory of a tar file. # Find the common root directory of a tar file.
# This form take as input command syntax to list the tar file contents. # This form take as input command syntax to list the tar file contents.
# Prefered from is to use tar -tvf ... plus any additional args. # Prefered from is to use tar -tvf ... plus any additional args.
@ -1160,8 +1190,8 @@ srpm_build_dictionary () {
local srpm_path local srpm_path
local name local name
for srpm_path in `find $srpm_dir -name '*.src.rpm' | sort -V`; do for srpm_path in $(find $srpm_dir -name '*.src.rpm' | sort -V); do
name=`rpm_get_name $srpm_path` name=$(rpm_get_name $srpm_path)
SRPM_PKG_NAME_TO_PATH[$name]="$srpm_path" SRPM_PKG_NAME_TO_PATH[$name]="$srpm_path"
SRPM_PKG_NAMES+=("$name") SRPM_PKG_NAMES+=("$name")
done done
@ -1172,8 +1202,8 @@ srpm_build_std_dictionary () {
local srpm_path local srpm_path
local name local name
for srpm_path in `find $srpm_dir -name '*.src.rpm' | sort -V`; do for srpm_path in $(find $srpm_dir -name '*.src.rpm' | sort -V); do
name=`rpm_get_name $srpm_path` name=$(rpm_get_name $srpm_path)
STD_SRPM_PKG_NAME_TO_PATH[$name]="$srpm_path" STD_SRPM_PKG_NAME_TO_PATH[$name]="$srpm_path"
STD_SRPM_PKG_NAMES+=("$name") STD_SRPM_PKG_NAMES+=("$name")
done done
@ -1194,20 +1224,27 @@ srpm_assemble () {
for SPEC in $(cd $FULL_BUILD_DIR/SPECS/; ls -1 *.spec); do for SPEC in $(cd $FULL_BUILD_DIR/SPECS/; ls -1 *.spec); do
SPEC_PATH="$FULL_BUILD_DIR/SPECS/$SPEC" SPEC_PATH="$FULL_BUILD_DIR/SPECS/$SPEC"
NAME=`spec_find_tag Name "$SPEC_PATH" 2>> /dev/null` NAME=$(srpm_spec_find_name "$SPEC_PATH" 2>> /dev/null)
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "ERROR: $FUNCNAME (${LINENO}): 'Name' not found in '$SPEC_PATH'" echo "ERROR: $FUNCNAME (${LINENO}): 'Name' not found in '$SPEC_PATH'"
fi fi
VERSION=`spec_find_tag Version "$SPEC_PATH" 2>> /dev/null`
VERSION=$(srpm_spec_find_version "$SPEC_PATH" 2>> /dev/null)
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "ERROR: $FUNCNAME (${LINENO}): 'Version' not found in '$SPEC_PATH'" echo "ERROR: $FUNCNAME (${LINENO}): 'Version' not found in '$SPEC_PATH'"
VERSION="0" if [ "x$SRPM_EXPORT_NAME" != "x" ]; then
VERSION="$SRPM_EXPORT_NAME"
else
VERSION="0"
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" 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"
fi fi
SRPM="$NAME-$VERSION-$RELEASE.src.rpm" SRPM="$NAME-$VERSION-$RELEASE.src.rpm"
SRPM_PATH="$FULL_BUILD_DIR/SRPMS/$SRPM" SRPM_PATH="$FULL_BUILD_DIR/SRPMS/$SRPM"
@ -1219,7 +1256,7 @@ srpm_assemble () {
BUILD_NEEDED=0 BUILD_NEEDED=0
if [ -f $SRPM_PATH ]; then if [ -f $SRPM_PATH ]; then
n=`find $FULL_BUILD_DIR -cnewer $SRPM_PATH | wc -l` n=$(find $FULL_BUILD_DIR -cnewer $SRPM_PATH | wc -l)
if [ $n -gt 0 ]; then if [ $n -gt 0 ]; then
BUILD_NEEDED=1 BUILD_NEEDED=1
fi fi
@ -1270,8 +1307,8 @@ srpm_extract () {
local BRANCH=$5 local BRANCH=$5
local USE_GIT=0 local USE_GIT=0
local ORIG_DIR=`pwd` local ORIG_DIR=$(pwd)
local PKG_DIR=`rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}\n' --nosignature -p $ORIG_SRPM_PATH` local PKG_DIR=$(rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}\n' --nosignature -p $ORIG_SRPM_PATH)
if [ "x$ROOT_DIR" == "x" ]; then if [ "x$ROOT_DIR" == "x" ]; then
ROOT_DIR="$MY_WORKSPACE/srpm_assemble" ROOT_DIR="$MY_WORKSPACE/srpm_assemble"
@ -1302,8 +1339,8 @@ srpm_extract () {
for SPEC in $(cd $SPEC_DIR; ls -1 *.spec); do for SPEC in $(cd $SPEC_DIR; ls -1 *.spec); do
echo $SPEC; echo $SPEC;
SPEC_GIT="$GIT_DIR/$SPEC" SPEC_GIT="$GIT_DIR/$SPEC"
PKG_NAME=$(spec_find_tag Name $SPEC_DIR/$SPEC 2>> /dev/null) PKG_NAME=$(srpm_spec_find_name $SPEC_DIR/$SPEC 2>> /dev/null)
PKG_VER=$(spec_find_tag Version $SPEC_DIR/$SPEC 2>> /dev/null) PKG_VER=$(srpm_spec_find_version $SPEC_DIR/$SPEC 2>> /dev/null)
TAR_DIR="$PKG_NAME-$PKG_VER" TAR_DIR="$PKG_NAME-$PKG_VER"
PATCH_TARGET_DIR="$SPEC_GIT/$TAR_DIR" PATCH_TARGET_DIR="$SPEC_GIT/$TAR_DIR"
echo " $TAR_DIR" echo " $TAR_DIR"
@ -1330,7 +1367,7 @@ srpm_apply_meta_patches () {
local ARCH=$4 local ARCH=$4
local BRANCH=$5 local BRANCH=$5
local ORIG_DIR=`pwd` local ORIG_DIR=$(pwd)
local META_PATCH_DIR local META_PATCH_DIR
local PATCH_DIR local PATCH_DIR
local PATCH local PATCH
@ -1362,7 +1399,7 @@ srpm_apply_meta_patches () {
return 1 return 1
fi fi
for PATCH in `cat $PO_PATH`; do for PATCH in $(cat $PO_PATH); do
PATCH_PATH="$META_PATCH_DIR/$PATCH" PATCH_PATH="$META_PATCH_DIR/$PATCH"
if [ ! -f "$PATCH_PATH" ]; then if [ ! -f "$PATCH_PATH" ]; then
echo "ERROR: $FUNCNAME (${LINENO}): patch '$PATCH_PATH' not found." echo "ERROR: $FUNCNAME (${LINENO}): patch '$PATCH_PATH' not found."
@ -1395,7 +1432,7 @@ srpm_apply_meta_patches () {
return 1 return 1
fi fi
for dd in `find . -type d | sort -V`; do for dd in $(find . -type d | sort -V); do
d=${dd:2} d=${dd:2}
mkdir -p "$META_PATCH_TARGET_DIR/SOURCES/$d" mkdir -p "$META_PATCH_TARGET_DIR/SOURCES/$d"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
@ -1405,7 +1442,7 @@ srpm_apply_meta_patches () {
fi fi
done done
for ff in `find . -type f | sort -V`; do for ff in $(find . -type f | sort -V); do
f=${ff:2} f=${ff:2}
d=$(dirname $f) d=$(dirname $f)
\cp -L -f -v "$PATCH_DIR/$f" "$META_PATCH_TARGET_DIR/SOURCES/$d" \cp -L -f -v "$PATCH_DIR/$f" "$META_PATCH_TARGET_DIR/SOURCES/$d"
@ -2003,7 +2040,7 @@ tarball_extract () {
if [ $NEED_PATCH_ROLLBACK -eq 1 ]; then if [ $NEED_PATCH_ROLLBACK -eq 1 ]; then
# But we don't want patches yet, so roll them back. # But we don't want patches yet, so roll them back.
# Use the log from rpmbuild to learn what patches to roll back, in what order, and with what arguements # Use the log from rpmbuild to learn what patches to roll back, in what order, and with what arguements
for n in `grep '^[Pp]atch #' $RPMBUILD_BP_LOG | tac | awk '{ print $2 }' | sed 's/#//'`; do for n in $(grep '^[Pp]atch #' $RPMBUILD_BP_LOG | tac | awk '{ print $2 }' | sed 's/#//'); do
cmd1=$(cat $RPMBUILD_BP_LOG | sed -n "/^[Pp]atch #$n /,/^patching/p" | grep '^+' | sed 's/^+ //' | grep '[/]cat') cmd1=$(cat $RPMBUILD_BP_LOG | sed -n "/^[Pp]atch #$n /,/^patching/p" | grep '^+' | sed 's/^+ //' | grep '[/]cat')
cmd2=$(cat $RPMBUILD_BP_LOG | sed -n "/^[Pp]atch #$n /,/^patching/p" | grep '^+' | sed 's/^+ //' | grep '[/]patch') cmd2=$(cat $RPMBUILD_BP_LOG | sed -n "/^[Pp]atch #$n /,/^patching/p" | grep '^+' | sed 's/^+ //' | grep '[/]patch')
cmd="$cmd1 | $cmd2 -R" cmd="$cmd1 | $cmd2 -R"
@ -2142,7 +2179,7 @@ tar_and_spec_extract_to_git () {
return 1 return 1
fi fi
local ORIG_DIR=`pwd` local ORIG_DIR=$(pwd)
if [ "x$ROOT_DIR" == "x" ]; then if [ "x$ROOT_DIR" == "x" ]; then
ROOT_DIR="$MY_WORKSPACE/srpm_work" ROOT_DIR="$MY_WORKSPACE/srpm_work"
@ -2324,8 +2361,8 @@ srpm_extract_to_git () {
return 1 return 1
fi fi
local ORIG_DIR=`pwd` local ORIG_DIR=$(pwd)
local PKG_DIR=`rpm -q --queryformat '%{NAME}\n' --nosignature -p $ORIG_SRPM_PATH` local PKG_DIR=$(rpm -q --queryformat '%{NAME}\n' --nosignature -p $ORIG_SRPM_PATH)
if [ "x$ROOT_DIR" == "x" ]; then if [ "x$ROOT_DIR" == "x" ]; then
ROOT_DIR="$MY_WORKSPACE/srpm_work" ROOT_DIR="$MY_WORKSPACE/srpm_work"
@ -2415,8 +2452,8 @@ srpm_extract_to_git () {
for SPEC in $(cd $SPEC_DIR; ls -1 *.spec); do for SPEC in $(cd $SPEC_DIR; ls -1 *.spec); do
echo $SPEC; echo $SPEC;
SPEC_GIT="$GIT_DIR/$SPEC" SPEC_GIT="$GIT_DIR/$SPEC"
PKG_NAME=$(spec_find_tag Name $SPEC_DIR/$SPEC 2>> /dev/null) PKG_NAME=$(srpm_spec_find_name $SPEC_DIR/$SPEC 2>> /dev/null)
PKG_VER=$(spec_find_tag Version $SPEC_DIR/$SPEC 2>> /dev/null) PKG_VER=$(srpm_spec_find_version $SPEC_DIR/$SPEC 2>> /dev/null)
TAR_DIR="$PKG_NAME-$PKG_VER" TAR_DIR="$PKG_NAME-$PKG_VER"
echo " $TAR_DIR" echo " $TAR_DIR"
@ -2456,7 +2493,7 @@ srpm_extract_to_git () {
cd $PATCH_TARGET_DIR cd $PATCH_TARGET_DIR
# Verify we are on the correct branch # Verify we are on the correct branch
CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD` CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ "$CURRENT_BRANCH" != "$BRANCH" ]; then if [ "$CURRENT_BRANCH" != "$BRANCH" ]; then
echo "git checkout -b $BRANCH" echo "git checkout -b $BRANCH"
git checkout -b $BRANCH git checkout -b $BRANCH
@ -2596,7 +2633,7 @@ srpm_apply_spec_patches () {
local PATCH local PATCH
local PATCH_ARGS local PATCH_ARGS
local ORIG_DIR=`pwd` local ORIG_DIR=$(pwd)
echo "Applying patches" echo "Applying patches"
if [ ! -f "$SPEC_PATH" ]; then if [ ! -f "$SPEC_PATH" ]; then
@ -2722,7 +2759,7 @@ srpm_apply_patch() {
# echo "srpm_apply_patch: PATCH=$PATCH PATCH_ARGS=$PATCH_ARGS TARGET_DIR=$TARGET_DIR USE_GIT=$USE_GIT COMMENT_PREFIX=$COMMENT_PREFIX METHOD=$METHOD RAW_SCRIPT=$RAW_SCRIPT ROOT_DIR=$ROOT_DIR RPMBUILD_BUILD_DIR=$RPMBUILD_BUILD_DIR SPEC_GIT=$SPEC_GIT PATCH_NO=$PATCH_NO" # echo "srpm_apply_patch: PATCH=$PATCH PATCH_ARGS=$PATCH_ARGS TARGET_DIR=$TARGET_DIR USE_GIT=$USE_GIT COMMENT_PREFIX=$COMMENT_PREFIX METHOD=$METHOD RAW_SCRIPT=$RAW_SCRIPT ROOT_DIR=$ROOT_DIR RPMBUILD_BUILD_DIR=$RPMBUILD_BUILD_DIR SPEC_GIT=$SPEC_GIT PATCH_NO=$PATCH_NO"
local ORIG_DIR local ORIG_DIR
ORIG_DIR=`pwd` ORIG_DIR=$(pwd)
if [ ! -f $PATCH ]; then if [ ! -f $PATCH ]; then
echo "ERROR: $FUNCNAME (${LINENO}): Patch '$PATCH' not found" echo "ERROR: $FUNCNAME (${LINENO}): Patch '$PATCH' not found"
@ -2752,7 +2789,7 @@ srpm_apply_patch() {
fi fi
local TAG="v$BRANCH" local TAG="v$BRANCH"
local PFN=`basename $PATCH` local PFN=$(basename $PATCH)
local MSG="$PFN" local MSG="$PFN"
local HASH="" local HASH=""
@ -2760,7 +2797,7 @@ srpm_apply_patch() {
local ADD_WC local ADD_WC
if [ $USE_GIT -gt 0 ]; then if [ $USE_GIT -gt 0 ]; then
HASH=`git log --pretty=format:'%H' --grep="$MSG\$"` HASH=$(git log --pretty=format:'%H' --grep="$MSG\$")
fi fi
if [ "x$HASH" == "x" ]; then if [ "x$HASH" == "x" ]; then
@ -2810,7 +2847,7 @@ srpm_apply_patch() {
fi fi
else else
echo "patch $PATCH_ARGS < $PATCH" echo "patch $PATCH_ARGS < $PATCH"
patch $PATCH_ARGS --no-backup-if-mismatch < $PATCH patch -f $PATCH_ARGS --no-backup-if-mismatch < $PATCH
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "failed to apply patch '$PATCH'" echo "failed to apply patch '$PATCH'"
return 1 return 1
@ -2819,7 +2856,7 @@ srpm_apply_patch() {
if [ $PWD = $HOME ]; then if [ $PWD = $HOME ]; then
echo "DPENNEY: in the home dir somehow" echo "DPENNEY: in the home dir somehow"
exit 1 return 1
fi fi
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
@ -2865,7 +2902,7 @@ srpm_find_tag () {
local TAG=$1 local TAG=$1
local SRPM_FILE=$2 local SRPM_FILE=$2
local VALUE=`rpm -q --queryformat "%{$TAG}\n" --nosignature -p $SRPM_FILE` local VALUE=$(rpm -q --queryformat "%{$TAG}\n" --nosignature -p $SRPM_FILE)
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "" echo ""
return 1 return 1
@ -2879,7 +2916,7 @@ srpm_find_tag () {
srpm_list_packages () { srpm_list_packages () {
local SRPM_FILE=$1 local SRPM_FILE=$1
local TMPDIR=`mktemp -d /tmp/srpm_list_packages_XXXXXX` local TMPDIR=$(mktemp -d /tmp/srpm_list_packages_XXXXXX)
( (
cd $TMPDIR &>> /dev/null cd $TMPDIR &>> /dev/null
@ -2887,7 +2924,7 @@ srpm_list_packages () {
rpm -i --root=$TMPDIR --nosignature $SRPM_FILE rpm -i --root=$TMPDIR --nosignature $SRPM_FILE
) )
for SPEC in `find $TMPDIR -name '*.spec' | sort -V`; do for SPEC in $(find $TMPDIR -name '*.spec' | sort -V); do
spec_list_packages $SPEC spec_list_packages $SPEC
done done
@ -2898,7 +2935,7 @@ srpm_list_packages () {
srpm_list_versioned_packages () { srpm_list_versioned_packages () {
local SRPM_FILE=$1 local SRPM_FILE=$1
local TMPDIR=`mktemp -d /tmp/srpm_list_packages_XXXXXX` local TMPDIR=$(mktemp -d /tmp/srpm_list_packages_XXXXXX)
( (
cd $TMPDIR &>> /dev/null cd $TMPDIR &>> /dev/null
@ -2906,7 +2943,7 @@ srpm_list_versioned_packages () {
rpm -i --root=$TMPDIR --nosignature $SRPM_FILE rpm -i --root=$TMPDIR --nosignature $SRPM_FILE
) )
for SPEC in `find $TMPDIR -name '*.spec' | sort -V`; do for SPEC in $(find $TMPDIR -name '*.spec' | sort -V); do
spec_list_versioned_packages $SPEC spec_list_versioned_packages $SPEC
done done
@ -2917,7 +2954,7 @@ srpm_list_versioned_packages () {
srpm_list_ver_rel_packages () { srpm_list_ver_rel_packages () {
local SRPM_FILE=$1 local SRPM_FILE=$1
local TMPDIR=`mktemp -d /tmp/srpm_list_packages_XXXXXX` local TMPDIR=$(mktemp -d /tmp/srpm_list_packages_XXXXXX)
( (
cd $TMPDIR &>> /dev/null cd $TMPDIR &>> /dev/null
@ -2925,7 +2962,7 @@ srpm_list_ver_rel_packages () {
rpm -i --root=$TMPDIR --nosignature $SRPM_FILE rpm -i --root=$TMPDIR --nosignature $SRPM_FILE
) )
for SPEC in `find $TMPDIR -name '*.spec' | sort -V`; do for SPEC in $(find $TMPDIR -name '*.spec' | sort -V); do
spec_list_ver_rel_packages $SPEC spec_list_ver_rel_packages $SPEC
done done
@ -2936,7 +2973,7 @@ srpm_list_ver_rel_packages () {
srpm_list_ver_rel_arch_packages () { srpm_list_ver_rel_arch_packages () {
local SRPM_FILE=$1 local SRPM_FILE=$1
local TMPDIR=`mktemp -d /tmp/srpm_list_packages_XXXXXX` local TMPDIR=$(mktemp -d /tmp/srpm_list_packages_XXXXXX)
( (
cd $TMPDIR &>> /dev/null cd $TMPDIR &>> /dev/null
@ -2944,7 +2981,7 @@ srpm_list_ver_rel_arch_packages () {
rpm -i --root=$TMPDIR --nosignature $SRPM_FILE rpm -i --root=$TMPDIR --nosignature $SRPM_FILE
) )
for SPEC in `find $TMPDIR -name '*.spec' | sort -V`; do for SPEC in $(find $TMPDIR -name '*.spec' | sort -V); do
spec_list_ver_rel_arch_packages $SPEC spec_list_ver_rel_arch_packages $SPEC
done done
@ -2955,7 +2992,7 @@ srpm_list_ver_rel_arch_packages () {
srpm_build_requires () { srpm_build_requires () {
local SRPM_FILE=$1 local SRPM_FILE=$1
local TMPDIR=`mktemp -d /tmp/srpm_list_packages_XXXXXX` local TMPDIR=$(mktemp -d /tmp/srpm_list_packages_XXXXXX)
( (
cd $TMPDIR &>> /dev/null cd $TMPDIR &>> /dev/null
@ -2963,7 +3000,7 @@ srpm_build_requires () {
rpm -i --root=$TMPDIR $SRPM_FILE rpm -i --root=$TMPDIR $SRPM_FILE
) )
for SPEC in `find $TMPDIR -name '*.spec' | sort -V`; do for SPEC in $(find $TMPDIR -name '*.spec' | sort -V); do
spec_build_requires $SPEC spec_build_requires $SPEC
done done
@ -2978,7 +3015,7 @@ srpm_match_package_list () {
local TARGET local TARGET
local PKG_NAME local PKG_NAME
for PKG_NAME in `srpm_list_packages "$SRPM_FILE"`; do for PKG_NAME in $(srpm_list_packages "$SRPM_FILE"); do
for TARGET in "${TARGET_LIST[@]}"; do for TARGET in "${TARGET_LIST[@]}"; do
if [ "$PKG_NAME" == "$TARGET" ]; then if [ "$PKG_NAME" == "$TARGET" ]; then
>&2 echo "found target '$TARGET' in file '$SRPM_FILE' as a package name" >&2 echo "found target '$TARGET' in file '$SRPM_FILE' as a package name"
@ -2996,7 +3033,7 @@ srpm_match_package () {
local SRPM_FILE=$2 local SRPM_FILE=$2
local PKG_NAME local PKG_NAME
for PKG_NAME in `srpm_list_packages "$SRPM_FILE"`; do for PKG_NAME in $(srpm_list_packages "$SRPM_FILE"); do
if [ "$PKG_NAME" == "$TARGET" ]; then if [ "$PKG_NAME" == "$TARGET" ]; then
echo "found target '$TARGET' in file '$SRPM_FILE' as a package name" echo "found target '$TARGET' in file '$SRPM_FILE' as a package name"
return 0 return 0
@ -3016,7 +3053,7 @@ srpm_match_target_list () {
local SERVICE local SERVICE
local PKG_NAME local PKG_NAME
NAME=`srpm_find_tag Name "$SRPM_FILE"` NAME=$(srpm_find_tag Name "$SRPM_FILE")
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
for TARGET in "${TARGET_LIST[@]}"; do for TARGET in "${TARGET_LIST[@]}"; do
if [ "$NAME" == "$TARGET" ]; then if [ "$NAME" == "$TARGET" ]; then
@ -3032,7 +3069,7 @@ srpm_match_target_list () {
done done
fi fi
SERVICE=`srpm_find_tag Service "$SRPM_FILE"` SERVICE=$(srpm_find_tag Service "$SRPM_FILE")
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
for TARGET in "${TARGET_LIST[@]}"; do for TARGET in "${TARGET_LIST[@]}"; do
if [ "$SERVICE" == "$TARGET" ]; then if [ "$SERVICE" == "$TARGET" ]; then
@ -3057,7 +3094,7 @@ srpm_match_target () {
local SERVICE local SERVICE
local PKG_NAME local PKG_NAME
NAME=`srpm_find_tag Name "$SRPM_FILE"` NAME=$(srpm_find_tag Name "$SRPM_FILE")
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
if [ "$NAME" == "$TARGET" ]; then if [ "$NAME" == "$TARGET" ]; then
echo "found target '$TARGET' in file '$SRPM_FILE' as a name" echo "found target '$TARGET' in file '$SRPM_FILE' as a name"
@ -3065,7 +3102,7 @@ srpm_match_target () {
fi fi
fi fi
SERVICE=`srpm_find_tag Service "$SRPM_FILE"` SERVICE=$(srpm_find_tag Service "$SRPM_FILE")
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
if [ "$SERVICE" == "$TARGET" ]; then if [ "$SERVICE" == "$TARGET" ]; then
echo "found target '$TARGET' in file '$SRPM_FILE' as a service" echo "found target '$TARGET' in file '$SRPM_FILE' as a service"