Extend GITREVCOUNT to inputs other than SRC_DIR and PKG_BASE

Changes in brief:

1) TIS_PATCH_VER will now accept new automatic variables
'OTHER_GITREVCOUNT' and 'SRC_GITREVCOUNT'.

2) New BASE_SRCREV variables are supported, 'SRC_BASE_SRCREV' and
'BASE_SRCREV_FOR_PATH'

3) OPT_DEP_LIST_FOR_BUILD_TYPE[<build-type>] joins OPT_DEP_LIST as
a way to list files that affect the build, but are not included
in the assembled src.rpm.

4) Some code relating to interpreting build_srpm.data files,
and producing a list of files that affect the build, are relocated
to 'srpm-util' and restructured for greater utility.

The details:

TIS_PATCH_VER=<expression>
                     # An integer, or one of the supported
                     # variables listed below, or the sum of
                     # variables and integers.
                     #  e.g.
                     #  TIS_PATCH_VER=PKG_GITREVCOUNT+SRC_GITREVCOUNT+5

   PKG_GITREVCOUNT   # Count git revisions relative to PKG_BASE.
                     # Optionally only count from PKG_BASE_SRCREV

   SRC_GITREVCOUNT   # Count git revisions relative to SRC_DIR.
                     # Optionally only count from SRC_BASE_SRCREV

   GITREVCOUNT       # Deprecated, please use SRC_GITREVCOUNT instead.
                     # Count git revisions relative to SRC_DIR.
                     # Optionally only count from TIS_BASE_SRCREV

   OTHER_GITREVCOUNT # count git revisions from all sources excluding
                     # PKG_BASE and SRC_DIR
                     # Optionally only count from
                     # BASE_SRCREV_FOR_PATH[<path>]

PKG_BASE_SRCREV=<sha>   # Limit PKG_GITREVCOUNT revision count to
                        # commits since <sha>

SRC_BASE_SRCREV=<sha>   # Limit SRC_GITREVCOUNT revision count to
                        # commits since <sha>

TIS_BASE_SRCREV=<sha>   # Deprecated, please use SRC_BASE_SRCREV
                        # instead
                        # Limit GITREVCOUNT revision count to commits
                        # since <sha>

BASE_SRCREV_FOR_PATH[<path>]=[<sha>|OTHER_PKG_BASE_SRCREV]
                        # Limit OTHER_GITREVCOUNT revision count for
                        # commits under <path> to commits since <sha>.
                        # If <path> is the PKG_BASE of another package
                        # (not the current package) then the keyword
                        # 'OTHER_PKG_BASE_SRCREV' can be used to extract
                        # the 'PKG_BASE_SRCREV' value of the other
                        # package.
                        #
                        # The <path> can reference variables like
                        # $STX_BASE and $GIT_BASE.

OPT_DEP_LIST=<path-list>  # Add a space separated list of paths that
                          # don't contribute to the content of a src.rpm
                          # but do contribute to triggering a rebuild,
                          # and possibly modifying the TIS_PATCH_VER via
                          # use of OTHER_GITREVCOUNT.

OPT_DEP_LIST_FOR_BUILD_TYPE[<build-type>]=<path-list>
                          # For a specific build type only, add a space
                          # separated list of paths that don't
                          # contribute to the content of src.rpm,
                          # but do contribute to triggering a
                          # rebuild, and possibly modifying the
                          # TIS_PATCH_VER via use of OTHER_GITREVCOUNT.

Story: 2006166
Task: 39765
Change-Id: I9e7d409d4eefdb41a7083db1b801d531c443b678
Signed-off-by: Scott Little <scott.little@windriver.com>
This commit is contained in:
Scott Little 2020-06-04 23:58:11 -04:00
parent e01eb44f2c
commit 5003bb100d
7 changed files with 362 additions and 145 deletions

View File

@ -1461,7 +1461,6 @@ while true ; do
esac
done
# Reset variables
if [ -n "$MY_WORKSPACE" ]; then
export MY_WORKSPACE_TOP=${MY_WORKSPACE_TOP:-$MY_WORKSPACE}

View File

@ -41,7 +41,7 @@ str_lst_contains() {
#
# capture_md5sum_from_input_vars <src-build-type> <srpm-or-spec-path> <work-dir>
# md5sums_from_input_vars <src-build-type> <srpm-or-spec-path> <work-dir>
#
# Returns md5 data for all input files of a src.rpm.
# Assumes PKG_BASE, ORIG_SRPM_PATH have been defined and the
@ -85,115 +85,19 @@ md5sums_from_input_vars () {
fi
fi
local INPUT_FILES="$WORK_DIR/srpm_input.files"
local INPUT_LINKS="$WORK_DIR/srpm_input.links"
local INPUT_FILES_SORTED="$WORK_DIR/srpm_sorted_input.files"
if [ -f "$INPUT_LINKS" ]; then
\rm -f "$INPUT_LINKS"
fi
# Create lists of input files (INPUT_FILES) and symlinks (INPUT_LINKS).
# First elements are absolute paths...
find "$PKG_BASE" -type f > $INPUT_FILES
if [ $? -ne 0 ]; then
>&2 echo "ERROR: $FUNCNAME (${LINENO}): find '$PKG_BASE' -type f"
return 1
fi
if [ "$SRC_BUILD_TYPE" == "$SRC_BUILD_TYPE_SRPM" ]; then
find "$SRPM_OR_SPEC_PATH" -type f >> $INPUT_FILES
if [ $? -ne 0 ]; then
>&2 echo "ERROR: $FUNCNAME (${LINENO}): find '$SRPM_OR_SPEC_PATH' -type f"
return 1
fi
fi
# ...additional elements are based on values already sourced from
# build_srpm.data (COPY_LIST, SRC_DIR, COPY_LIST_TO_TAR, OPT_DEP_LIST)
# and may be relative to $PKG_BASE
#
# Use a subshell so any directory changes have no lastin effect.
(
cd $PKG_BASE
if [ "x$COPY_LIST" != "x" ]; then
ABS_COPY_LIST=$(readlink -f $COPY_LIST)
if [ $? -ne 0 ]; then
>&2 echo "ERROR: $FUNCNAME (${LINENO}): readlink -f '$COPY_LIST'"
return 1
fi
find $ABS_COPY_LIST -type f >> $INPUT_FILES
if [ $? -ne 0 ]; then
>&2 echo "ERROR: $FUNCNAME (${LINENO}): find '$ABS_COPY_LIST' -type f"
return 1
fi
# Treat most links normally
find $ABS_COPY_LIST -type l | grep -v "$LINK_FILTER" >> $INPUT_FILES
# Links in the downloads directory likely point outside of $MY_REPO
# and might not be 'portable' from a build avoidance prespective.
# We'll treat these specially.
find $ABS_COPY_LIST -type l | grep "$LINK_FILTER" >> $INPUT_LINKS
fi
if [ "$SRC_BUILD_TYPE" == "$SRC_BUILD_TYPE_SPEC" ]; then
if [ "x$SRC_DIR" != "x" ]; then
if [ -d "$SRC_DIR" ]; then
find $(readlink -f "$SRC_DIR") -type f | grep -v '[/][.]git$' | grep -v '[/][.]git[/]' >> $INPUT_FILES
if [ $? -ne 0 ]; then
>&2 echo "ERROR: $FUNCNAME (${LINENO}): find '$SRC_DIR' -type f"
return 1
fi
fi
fi
if [ "x$COPY_LIST_TO_TAR" != "x" ]; then
for x in $COPY_LIST_TO_TAR; do
find $(readlink -f $x) -type f >> $INPUT_FILES
if [ $? -ne 0 ]; then
>&2 echo "ERROR: $FUNCNAME (${LINENO}): find '$x' -type f"
return 1
fi
done
fi
fi
if [ "x$OPT_DEP_LIST" != "x" ]; then
for x in $OPT_DEP_LIST; do
find $(readlink -f $x) -type f >> $INPUT_FILES 2> /dev/null || true
done
fi
)
srpm_source_file_list "$SRC_BUILD_TYPE" "$SRPM_OR_SPEC_PATH" "$INPUT_FILES_SORTED"
if [ $? -eq 1 ]; then
return 1
fi
# Create sorted, unique list of cononical paths
(
# Regular files, get canonical path
cat $INPUT_FILES | xargs readlink -f
# A Symlink that likely points outside of $MY_REPO.
# get canonical path to the symlink itself, and not
# to what the symlink points to.
if [ -f $INPUT_LINKS ]; then
while IFS= read -r f; do
echo "$(readlink -f $(dirname $f))/$(basename $f)"
done < "$INPUT_LINKS"
fi
) | sort --unique > $INPUT_FILES_SORTED
# Remove $MY_REPO prefix from paths
cat $INPUT_FILES_SORTED | xargs md5sum | sed "s# $(readlink -f $MY_REPO)/# #"
if [ $TMP_FLAG -eq 0 ]; then
\rm -f $INPUT_FILES_SORTED
\rm -f $INPUT_FILES
if [ -f $INPUT_LINKS ]; then
\rm -f $INPUT_LINKS
fi
else
\rm -rf $WORK_DIR
fi

View File

@ -650,16 +650,9 @@ build_dir_srpm () {
# Load data from build_srpm.data
#
export DATA="$DATA_PATH/$SRPM_DATA"
local COPY_LIST
local COPY_LIST_TO_TAR
local SRC_DIR
local TIS_PATCH_VER
local PBR_VERSION
local BUILD_IS_BIG=0
local BUILD_IS_SLOW=0
if [ -f $DATA ]; then
srpm_source_build_data $DATA
if [ -f "$DATA" ]; then
srpm_source_build_data "$DATA" "$SRC_BUILD_TYPE_SRPM" "$ORIG_SRPM_PATH"
if [ $? -ne 0 ]; then
echo "ERROR: $FUNCNAME (${LINENO}): failed to source $DATA"
return 1
@ -778,7 +771,7 @@ build_dir_srpm () {
if [ -f $PKG_BASE/$DATA ]; then
AGE2=$(
cd $PKG_BASE
srpm_source_build_data $DATA
srpm_source_build_data "$DATA" "$SRC_BUILD_TYPE_SRPM" "$ORIG_SRPM_PATH"
PATH_LIST=""
# NOTE: SRC_DIR is not honored in this build path
@ -969,16 +962,8 @@ build_dir_spec () {
#
# Load data from build_srpm.data
#
local COPY_LIST
local COPY_LIST_TO_TAR
local SRC_DIR
local OPT_DEP_LIST
local TIS_PATCH_VER
local PBR_VERSION
local BUILD_IS_BIG=0
local BUILD_IS_SLOW=0
srpm_source_build_data $DATA
srpm_source_build_data "$DATA" "$SRC_BUILD_TYPE_SPEC" "$SPEC"
if [ $? -ne 0 ]; then
echo "ERROR: $FUNCNAME (${LINENO}): failed to source $DATA"
return 1
@ -1084,9 +1069,13 @@ build_dir_spec () {
return 0
fi
export SRC_BUILD_TYPE="$SRC_BUILD_TYPE_SPEC"
export SRPM_OR_SPEC_PATH="$SPEC"
echo "MAKE_SRPM=$MAKE_SRPM"
echo "DATA=$DATA"
echo "SRC_BUILD_TYPE=$SRC_BUILD_TYPE"
echo "SRPM_OR_SPEC_PATH=$SRPM_OR_SPEC_PATH"
if [ -d "$RPMBUILD_BASE/SRPMS" ]; then
clean_srpm_dir $build_idx "$RPMBUILD_BASE/SRPMS" 1
@ -1129,7 +1118,7 @@ build_dir_spec () {
if [ -f $PKG_BASE/$DATA ]; then
AGE2=$(
cd $PKG_BASE
srpm_source_build_data $DATA
srpm_source_build_data "$DATA" "$SRC_BUILD_TYPE_SPEC" "$SPEC"
PATH_LIST=""
if [ "x$SRC_DIR" != "x" ]; then
if [ -d "$SRC_DIR" ]; then

View File

@ -628,16 +628,9 @@ build_dir_srpm () {
# Load data from build_srpm.data
#
export DATA="$DATA_PATH/$SRPM_DATA"
local COPY_LIST
local COPY_LIST_TO_TAR
local SRC_DIR
local TIS_PATCH_VER
local PBR_VERSION
local BUILD_IS_BIG=0
local BUILD_IS_SLOW=0
if [ -f $DATA ]; then
srpm_source_build_data $DATA
if [ -f "$DATA" ]; then
srpm_source_build_data "$DATA" "$SRC_BUILD_TYPE_SRPM" "$ORIG_SRPM_PATH"
if [ $? -ne 0 ]; then
echo "ERROR: $FUNCNAME (${LINENO}): failed to source $DATA"
return 1
@ -944,17 +937,9 @@ build_dir_spec () {
#
# Load data from build_srpm.data
#
local COPY_LIST
local COPY_LIST_TO_TAR
local SRC_DIR
local OPT_DEP_LIST
local TIS_PATCH_VER
local PBR_VERSION
local BUILD_IS_BIG=0
local BUILD_IS_SLOW=0
if [ -f $DATA ]; then
srpm_source_build_data $DATA
if [ -f "$DATA" ]; then
srpm_source_build_data "$DATA" "$SRC_BUILD_TYPE_SPEC" "$SPEC"
if [ $? -ne 0 ]; then
echo "ERROR: $FUNCNAME (${LINENO}): failed to source $DATA"
return 1
@ -1063,8 +1048,13 @@ build_dir_spec () {
fi
export SRC_BUILD_TYPE="$SRC_BUILD_TYPE_SPEC"
export SRPM_OR_SPEC_PATH="$SPEC"
echo "MAKE_SRPM=$MAKE_SRPM"
echo "DATA=$DATA"
echo "SRC_BUILD_TYPE=$SRC_BUILD_TYPE"
echo "SRPM_OR_SPEC_PATH=$SRPM_OR_SPEC_PATH"
if [ -d "$RPMBUILD_BASE/SRPMS" ]; then
clean_srpm_dir "$RPMBUILD_BASE/SRPMS" 1

View File

@ -12,7 +12,7 @@ if [ "x$DATA" == "x" ]; then
exit 1
fi
srpm_source_build_data $DATA
srpm_source_build_data "$DATA" "$SRC_BUILD_TYPE" "$SRPM_OR_SPEC_PATH"
if [ $? -ne 0 ]; then
echo "ERROR: default_build_srpm (${LINENO}): Failed to source build data from $DATA"
exit 1

View File

@ -96,6 +96,9 @@ git_list_containing_tag () {
git_root () {
local DIR="${1:-${PWD}}"
if [ ! -d "${DIR}" ]; then
DIR="$(dirname "${DIR}")"
fi
if [ ! -d "${DIR}" ]; then
echo_stderr "No such directory: ${DIR}"
return 1

View File

@ -3221,14 +3221,278 @@ srpm_pbr_version () {
return 0
}
srpm_git_revision_count_list () {
local SRC_DIR="${1}" ; shift
local BASE_SRCREV="${1}" ; shift
local -i COUNT=0
local -i DIRTY=0
if [ $# -eq 0 ]; then
echo 0
return 0
fi
pushd $SRC_DIR > /dev/null
if [ -z "${BASE_SRCREV}" ]; then
COUNT=$(git rev-list --count HEAD -- $@)
else
COUNT=$(git rev-list --count $BASE_SRCREV..HEAD -- $@)
fi
if [ $? -ne 0 ]; then
popd > /dev/null
return 1
fi
DIRTY=$(git status --porcelain $@ | wc -l)
if [ "$DIRTY" -ne 0 ]; then
# add an extra value for uncommitted work.
COUNT=$((COUNT+1))
fi
popd > /dev/null
echo $COUNT
return 0
}
srpm_canonical_path_single () {
local path="$1"
local canonical_path
if [[ "${path}" =~ /stx/downloads/|/cgcs-centos-repo/ ]]; then
# Expand all but final symlink.
# These symlinks often point outside of the source code repository.
canonical_path="$(readlink -f "$(dirname "${path}")")"
if [ $? -ne 0 ]; then
>&2 echo "ERROR: $FUNCNAME (${LINENO}): readlink -f '${path}'"
return 1
fi
canonical_path+="/$(basename "${path}")"
else
# expand all symlinks
canonical_path="$(readlink -f "${path}")"
if [ $? -ne 0 ]; then
>&2 echo "ERROR: $FUNCNAME (${LINENO}): readlink -f '${path}'"
return 1
fi
fi
echo "${canonical_path}"
}
srpm_canonical_path () {
local path
if [ $# -eq 0 ] ; then
while IFS= read -r path; do
srpm_canonical_path_single "${path}" || return 1
done
else
while [ $# -ne 0 ] ; do
srpm_canonical_path_single "${1}" || return 1
shift
done
fi
}
#
# Write to a file the list of input for a package.
# Assumes PKG_BASE is defined, and build_srpm.data file has been sourced.
#
srpm_source_list () {
local SRC_BUILD_TYPE="$1"
local SRPM_OR_SPEC_PATH="$2"
local INPUT_FILES_SORTED="$3"
local INPUT_FILES
if [ -z "${INPUT_FILES_SORTED}" ]; then
>&2 echo "ERROR: $FUNCNAME (${LINENO}): missing arguement"
return 1
fi
INPUT_FILES="$(mktemp --tmpdir input_files_XXXXXX)"
# Create lists of input files (INPUT_FILES) and symlinks (INPUT_LINKS).
# First elements are absolute paths...
srpm_canonical_path "${PKG_BASE}" > "${INPUT_FILES}"
if [ $? -ne 0 ]; then
>&2 echo "ERROR: $FUNCNAME (${LINENO}): srpm_canonical_path PKG_BASE='${PKG_BASE}'"
\rm "${INPUT_FILES}"
return 1
fi
if [ "${SRC_BUILD_TYPE}" == "${SRC_BUILD_TYPE_SRPM}" ]; then
srpm_canonical_path "${SRPM_OR_SPEC_PATH}" >> "${INPUT_FILES}"
if [ $? -ne 0 ]; then
>&2 echo "ERROR: $FUNCNAME (${LINENO}): srpm_canonical_path SRPM_OR_SPEC_PATH='$SRPM_OR_SPEC_PATH'"
\rm "${INPUT_FILES}"
return 1
fi
fi
# ...additional elements are based on values already sourced from
# build_srpm.data (COPY_LIST, SRC_DIR, COPY_LIST_TO_TAR, OPT_DEP_LIST)
# and may be relative to $PKG_BASE
#
# Use a subshell so any directory changes have no lasting effect.
(
cd "${PKG_BASE}"
if [ "x${COPY_LIST}" != "x" ]; then
srpm_canonical_path ${COPY_LIST} >> "${INPUT_FILES}"
if [ $? -ne 0 ]; then
>&2 echo "ERROR: $FUNCNAME (${LINENO}): srpm_canonical_path COPY_LIST='${COPY_LIST}'"
return 1
fi
fi
if [ "${SRC_BUILD_TYPE}" == "${SRC_BUILD_TYPE_SPEC}" ]; then
if [ "x${SRC_DIR}" != "x" ]; then
srpm_canonical_path "${SRC_DIR}" >> "${INPUT_FILES}"
fi
if [ "x${COPY_LIST_TO_TAR}" != "x" ]; then
srpm_canonical_path ${COPY_LIST_TO_TAR} >> "${INPUT_FILES}"
if [ $? -ne 0 ]; then
>&2 echo "ERROR: $FUNCNAME (${LINENO}): srpm_canonical_path COPY_LIST_TO_TAR='${COPY_LIST_TO_TAR}'"
return 1
fi
fi
fi
if [ "x${OPT_DEP_LIST}" != "x" ]; then
srpm_canonical_path ${OPT_DEP_LIST} >> "${INPUT_FILES}" 2> /dev/null || true
fi
if [ "x$BUILD_TYPE" != "x" ]; then
if [ "x${OPT_DEP_LIST_FOR_BUILD_TYPE[$BUILD_TYPE]}" != "x" ]; then
srpm_canonical_path ${OPT_DEP_LIST_FOR_BUILD_TYPE[$BUILD_TYPE]} >> "${INPUT_FILES}" 2> /dev/null || true
fi
fi
)
if [ $? -ne 0 ]; then
\rm "${INPUT_FILES}"
return 1
fi
# Create sorted, unique list of canonical paths
cat "${INPUT_FILES}" | sort --unique > "${INPUT_FILES_SORTED}"
\rm "${INPUT_FILES}"
}
#
# Write to a file the list of input files for a package.
# Assumes PKG_BASE is defined, and build_srpm.data file has been sourced.
#
srpm_source_file_list () {
local SRC_BUILD_TYPE="$1"
local SRPM_OR_SPEC_PATH="$2"
local INPUT_FILES_SORTED="$3"
LINK_FILTER='\([/]stx[/]downloads[/]\|[/]cgcs-centos-repo[/]\)'
local INPUT_FILES
local INPUT_LINKS
local INPUT_SOURCES
local path
if [ -z "${INPUT_FILES_SORTED}" ]; then
>&2 echo "ERROR: $FUNCNAME (${LINENO}): missing arguement"
return 1
fi
INPUT_SOURCES="$(mktemp --tmpdir input_sources_XXXXXX)"
INPUT_FILES="$(mktemp --tmpdir input_files_XXXXXX)"
INPUT_LINKS="$(mktemp --tmpdir input_links_XXXXXX)"
srpm_source_list "${SRC_BUILD_TYPE}" "${SRPM_OR_SPEC_PATH}" "${INPUT_SOURCES}"
# Create lists of input files (INPUT_FILES) and symlinks (INPUT_LINKS).
# First elements are absolute paths...
while read path; do
find "${path}" -type f | grep -v -e '[/][.]git$' -e '[/][.]git[/]' >> $INPUT_FILES
find "${path}" -type l | grep -v -e '[/][.]git$' -e '[/][.]git[/]' >> $INPUT_LINKS
done < "${INPUT_SOURCES}"
# Create sorted, unique list of canonical paths
(
while IFS= read -r path; do
srpm_canonical_path "${path}"
done < "${INPUT_FILES}"
while IFS= read -r path; do
link_path="$(srpm_canonical_path "${path}")"
# only report the path if it points to a file
if [ -f ${link_path} ]; then
echo "${link_path}"
fi
done < "${INPUT_LINKS}"
) | sort --unique > "${INPUT_FILES_SORTED}"
\rm "${INPUT_FILES}" "${INPUT_SOURCES}"
}
srpm_source_build_data () {
local DATA_FILE=$1
local DATA_FILE="$1"
local SRC_BUILD_TYPE="$2"
local SRPM_OR_SPEC_PATH="$3"
if [ ! -f $DATA_FILE ]; then
>&2 echo "ERROR: $FUNCNAME (${LINENO}): $DATA_FILE not found"
return 1
fi
unset SRC_DIR
unset COPY_LIST
unset COPY_LIST_TO_TAR
unset OPT_DEP_LIST
unset OPT_DEP_LIST_FOR_BUILD_TYPE
unset TIS_PATCH_VER
unset PBR_VERSION
unset BUILD_IS_BIG
unset BUILD_IS_SLOW
unset PKG_BASE_SRCREV
unset SRC_BASE_SRCREV
unset TIS_BASE_SRCREV
unset BASE_SRCREV_FOR_PATH
unset ABS_BASE_SRCREV_FOR_PATH
declare -g SRC_DIR
declare -g COPY_LIST
declare -g COPY_LIST_TO_TAR
declare -g OPT_DEP_LIST
declare -g -A OPT_DEP_LIST_FOR_BUILD_TYPE
declare -g TIS_PATCH_VER
declare -g PBR_VERSION
declare -g BUILD_IS_BIG
declare -g BUILD_IS_SLOW
declare -g PKG_BASE_SRCREV
declare -g SRC_BASE_SRCREV
declare -g TIS_BASE_SRCREV
declare -g -A BASE_SRCREV_FOR_PATH
declare -g -A ABS_BASE_SRCREV_FOR_PATH
BUILD_IS_BIG=0
BUILD_IS_SLOW=0
source $DATA_FILE
# Hope to phase out TIS_BASE_SRCREV in favor of SRC_BASE_SRCREV,
# but will need this for backward compatibility during the transition.
if [ -z ${SRC_BASE_SRCREV} ] && ! [ -z ${TIS_BASE_SRCREV} ]; then
SRC_BASE_SRCREV=${TIS_BASE_SRCREV}
fi
for path in ${!BASE_SRCREV_FOR_PATH[@]}; do
abs_path="$(readlink -f "${path}")"
ABS_BASE_SRCREV_FOR_PATH[${abs_path}]=${BASE_SRCREV_FOR_PATH[${path}]}
done
# TIS_PATCH_VER is mandatory
if [ -z "$TIS_PATCH_VER" ] && [ -z "$PBR_VERSION" ]; then
>&2 echo "ERROR: $FUNCNAME (${LINENO}): TIS_PATCH_VER or PBR_VERSION must be set in $DATA_FILE"
@ -3258,18 +3522,86 @@ srpm_source_build_data () {
>&2 echo "ERROR: $FUNCNAME (${LINENO}): Failed to calculate PKG_GITREVCOUNT"
return 1
fi
elif [ "${varname}" = "GITREVCOUNT" ]; then
elif [ "${varname}" = "GITREVCOUNT" ] || [ "${varname}" = "SRC_GITREVCOUNT" ]; then
# Calculate GITREVCOUNT
if [ -z "$TIS_BASE_SRCREV" ]; then
>&2 echo "ERROR: $FUNCNAME (${LINENO}): TIS_BASE_SRCREV must be set in $DATA_FILE"
if [ -z "$SRC_BASE_SRCREV" ]; then
>&2 echo "ERROR: $FUNCNAME (${LINENO}): SRC_BASE_SRCREV must be set in $DATA_FILE"
return 1
fi
GITREVCOUNT=$(srpm_git_revision_count $SRC_DIR $TIS_BASE_SRCREV)
SRC_GITREVCOUNT=$(srpm_git_revision_count $SRC_DIR $SRC_BASE_SRCREV)
if [ $? -ne 0 ]; then
>&2 echo "ERROR: $FUNCNAME (${LINENO}): Failed to calculate GITREVCOUNT"
>&2 echo "ERROR: $FUNCNAME (${LINENO}): Failed to calculate ${varname}"
return 1
fi
GITREVCOUNT=${SRC_GITREVCOUNT}
elif [ "${varname}" = "OTHER_GITREVCOUNT" ]; then
OTHER_GITREVCOUNT=0
local git_root
local temp_list
local temp_list_filtered
local temp_list_git_filtered
temp_list="$(mktemp --tmpdir srpm_src_list_XXXXXX)"
temp_list_filtered="$(mktemp --tmpdir srpm_src_list_filtered_XXXXXX)"
temp_list_git_filtered="$(mktemp --tmpdir srpm_src_list_git_filtered_XXXXXX)"
# Collect a list of inputs files and directories
srpm_source_list "${SRC_BUILD_TYPE}" "${SRPM_OR_SPEC_PATH}" "${temp_list}"
# Create a filtered list of input files and directoies, excluding stuff under $PKG_BASE and $SRC_DIR
if [ "${SRC_DIR}" == "" ]; then
grep -v "^$(readlink -f "${PKG_BASE}")" "${temp_list}" > "${temp_list_filtered}"
else
grep -v "^$(readlink -f "${PKG_BASE}")" "${temp_list}" | grep -v "^$(readlink -f "${SRC_DIR}")" > "${temp_list_filtered}"
fi
for git_root in $GIT_LIST; do
local abs_git_root
local SRCREV=""
local path
local git_rev_count=0
# Further filter the list of inputs to just those from a particular git
abs_git_root="$(readlink -f "${git_root}")"
cat "${temp_list_filtered}" | grep "^${abs_git_root}" > "${temp_list_git_filtered}"
# If not inputs for this git, skip to the next git
if [ $(cat "${temp_list_git_filtered}" | wc -l) -eq 0 ]; then
continue
fi
# If there is exactly one input listed for the git, then there are a few special options.
# If the path matches a dictionary key of BASE_SRCREV_FOR_PATH, then pull the SRCREV
# from BASE_SRCREV_FOR_PATH. Further, if that SRCREV is "OTHER_PKG_BASE_SRCREV", then
# assume that path is a PKG_BASE for another package, and try to extract the
# PKG_BASE_SRCREV=xxx value from the build_srpm.data of that package.
if [ $(cat "${temp_list_git_filtered}" | wc -l) -eq 1 ]; then
path=$(head -n 1 "${temp_list_git_filtered}")
SRCREV=${ABS_BASE_SRCREV_FOR_PATH[${path}]}
if [ "${SRCREV}" == "OTHER_PKG_BASE_SRCREV" ] && [ -f ${path}/${DISTRO}/build_srpm.data ] ; then
SRCREV=$(grep PKG_BASE_SRCREV= ${path}/${DISTRO}/build_srpm.data | sed 's#PKG_BASE_SRCREV=##')
if [ -z ${SRCREV} ]; then
>&2 echo "ERROR: $FUNCNAME (${LINENO}): Tried to evaluate 'OTHER_PKG_BASE_SRCREV', but failed to extract 'PKG_BASE_SRCREV' from '${path}/${DISTRO}/build_srpm.data'"
return 1
fi
fi
fi
if [ -z "${SRCREV}" ]; then
SRCREV=${ABS_BASE_SRCREV_FOR_PATH[${abs_git_root}]}
fi
git_rev_count=$(srpm_git_revision_count_list "${abs_git_root}" "${SRCREV}" $(cat "${temp_list_git_filtered}"))
OTHER_GITREVCOUNT=$((OTHER_GITREVCOUNT+git_rev_count))
done
\rm "${temp_list}"
\rm "${temp_list_filtered}"
\rm "${temp_list_git_filtered}"
elif [[ "${varname}" =~ [^0-9] ]]; then
# TIS_PATCH_VER has some unsupported var or characters
>&2 echo "ERROR: $FUNCNAME (${LINENO}): Unsupported value in TIS_PATCH_VER: ${varname}"