root/build-tools/build-srpms-common.sh
Scott Little 5003bb100d 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>
2020-06-10 17:48:26 -04:00

107 lines
3.0 KiB
Bash

#
# Copyright (c) 2018 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
#
# Functions common to build-srpm-serial and build-srpm-parallel.
#
SRC_BUILD_TYPE_SRPM="srpm"
SRC_BUILD_TYPE_SPEC="spec"
SRC_BUILD_TYPES="$SRC_BUILD_TYPE_SRPM $SRC_BUILD_TYPE_SPEC"
set_build_info () {
local info_file="$MY_WORKSPACE/BUILD_INFO"
local layer_prefix="${LAYER^^}_"
if [ "${LAYER}" == "" ]; then
layer_prefix=""
fi
mkdir -p "$(dirname ${info_file})"
echo "${layer_prefix}OS=\"centos\"" > "${info_file}"
echo "${layer_prefix}JOB=\"n/a\"" >> "${info_file}"
echo "${layer_prefix}BUILD_BY=\"${USER}\"" >> "${info_file}"
echo "${layer_prefix}BUILD_NUMBER=\"n/a\"" >> "${info_file}"
echo "${layer_prefix}BUILD_HOST=\"$(hostname)\"" >> "${info_file}"
echo "${layer_prefix}BUILD_DATE=\"$(date '+%Y-%m-%d %H:%M:%S %z')\"" >> "${info_file}"
}
str_lst_contains() {
TARGET="$1"
LST="$2"
if [[ $LST =~ (^|[[:space:]])$TARGET($|[[:space:]]) ]] ; then
return 0
else
return 1
fi
}
#
# 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
# build_srpm.data file has already been sourced.
#
# Arguments:
# src-build-type: Any single value from $SRC_BUILD_TYPES.
# e.g. 'srpm' or 'spec'
# srpm-or-spec-path: Absolute path to an src.rpm, or to a
# spec file.
# work-dir: Optional working directory. If a path is
# specified but does not exist, it will be created.
#
# Returns: output of md5sum command with canonical path names
#
md5sums_from_input_vars () {
local SRC_BUILD_TYPE="$1"
local SRPM_OR_SPEC_PATH="$2"
local WORK_DIR="$3"
local TMP_FLAG=0
local LINK_FILTER='[/]stx[/]downloads[/]'
if ! str_lst_contains "$SRC_BUILD_TYPE" "$SRC_BUILD_TYPES" ; then
>&2 echo "ERROR: $FUNCNAME (${LINENO}): invalid arg: SRC_BUILD_TYPE='$SRC_BUILD_TYPE'"
return 1
fi
if [ -z $WORK_DIR ]; then
WORK_DIR=$(mktemp -d /tmp/${FUNCNAME}_XXXXXX)
if [ $? -ne 0 ]; then
>&2 echo "ERROR: $FUNCNAME (${LINENO}): mktemp -d /tmp/${FUNCNAME}_XXXXXX"
return 1
fi
TMP_FLAG=1
else
mkdir -p "$WORK_DIR"
if [ $? -ne 0 ]; then
>&2 echo "ERROR: $FUNCNAME (${LINENO}): mkdir -p '$WORK_DIR'"
return 1
fi
fi
local INPUT_FILES_SORTED="$WORK_DIR/srpm_sorted_input.files"
# Create lists of input files (INPUT_FILES) and symlinks (INPUT_LINKS).
srpm_source_file_list "$SRC_BUILD_TYPE" "$SRPM_OR_SPEC_PATH" "$INPUT_FILES_SORTED"
if [ $? -eq 1 ]; then
return 1
fi
# 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
else
\rm -rf $WORK_DIR
fi
return 0
}