77576b7207
This update will retain support for CentOS-7/yum/mock-1.4 based builds. The build environment will be queried to discover which environment it is building in, and modify the commands we issue accordingly. In CentOS 8, DNF replaces both YUM and REPOQUERY. While DNF tries to be a transparent replacement of the old tools, there are also subtle changes to the supported arguments. I will provide independent mock.cfg.prototypes for centos7 vs centos8. Changes in generate-centos-repo.sh under stx-tools will be required to select the correct prototype. Add support for mock 2.6. Mock 2.6 is python 3, and it processes the 'root' and 'rootdir' arguments slightly differently. Also change the order of arguments to tar within default_build_srpm. The latest tar only honors '--exclude' if it precedes other arguments. Story: 2006729 Depends-On: https://review.opendev.org/762700 Signed-off-by: Scott Little <scott.little@windriver.com> Change-Id: I826be2051e535e6a4c08ad17124f453b04210668
201 lines
7.2 KiB
Bash
Executable File
201 lines
7.2 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
#
|
|
# Copyright (c) 2018-2020 Wind River Systems, Inc.
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
|
|
# This script modifies a mock configuration file (typically $MY_BUILD_CFG)
|
|
# to add build time environment variables to the mock environment (things
|
|
# like what branch we're building on, etc).
|
|
#
|
|
# For reasons of security, the host environment variables cannot normally be
|
|
# passed through to the mock environment, so this scripts sets the variables
|
|
# to literal values.
|
|
#
|
|
# usage: modify-build-cfg [file.cfg] [<layer>]
|
|
#
|
|
|
|
MODIFY_BUILD_CFG_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}" )" )"
|
|
|
|
# Set PKG_MANAGER for our build environment.
|
|
source "${MODIFY_BUILD_CFG_DIR}/pkg-manager-utils.sh"
|
|
|
|
LAYER=${2:-$LAYER}
|
|
|
|
# For backward compatibility. Old repo location or new?
|
|
CENTOS_REPO=${MY_REPO}/centos-repo
|
|
if [ ! -d ${CENTOS_REPO} ]; then
|
|
CENTOS_REPO=${MY_REPO}/cgcs-centos-repo
|
|
if [ ! -d ${CENTOS_REPO} ]; then
|
|
echo "ERROR: directory ${MY_REPO}/centos-repo not found."
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# Preferred python
|
|
if rpm -q --whatprovides --quiet python3; then
|
|
PYTHON_PKG=python3
|
|
else
|
|
PYTHON_PKG=python2
|
|
fi
|
|
|
|
# Try to find a layer specific mock.cfg.proto
|
|
MOCK_CFG_PROTO="${CENTOS_REPO}/mock.cfg.${LAYER}.proto"
|
|
echo "==== Try MOCK_CFG_PROTO=$MOCK_CFG_PROTO ===="
|
|
if [ ! -f "$MOCK_CFG_PROTO" ]; then
|
|
# Not present, Use default mock.cfg.proto
|
|
MOCK_CFG_PROTO="${CENTOS_REPO}/mock.cfg.proto"
|
|
fi
|
|
|
|
echo "==== Use MOCK_CFG_PROTO=$MOCK_CFG_PROTO ===="
|
|
if [ ! -f "$MOCK_CFG_PROTO" ]; then
|
|
echo "ERROR: Couldn't find mock config prototype at '$MOCK_CFG_PROTO'"
|
|
exit 1
|
|
fi
|
|
|
|
if [ "${1}x" == "x" ]; then
|
|
FILE=$MY_BUILD_CFG
|
|
else
|
|
FILE=$1
|
|
fi
|
|
|
|
if [ -f $MOCK_CFG_PROTO ]; then
|
|
if [ -f $FILE ]; then
|
|
NEWER=$(find "$MOCK_CFG_PROTO" -newer "$FILE")
|
|
if [ "x$NEWER" != "x" ]; then
|
|
\rm -f -v "$FILE"
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
if [ ! -f $FILE ]; then
|
|
if [ -z $MY_BUILD_ENVIRONMENT ] || [ -z $MY_BUILD_DIR ] || [ -z $MY_REPO ]; then
|
|
echo "Can't create $FILE without MY_BUILD_ENVIRONMENT, MY_BUILD_DIR and MY_REPO environment variables"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Recreating $FILE"
|
|
\cp -f -v "$MOCK_CFG_PROTO" "$FILE"
|
|
if [ $? -ne 0 ]; then
|
|
echo "Couldn't find config file '$FILE', nor construct it from '$MOCK_CFG_PROTO'"
|
|
exit 1
|
|
fi
|
|
|
|
sed -i "s%LOCAL_BASE%http://127.0.0.1:8088%g" "$FILE"
|
|
sed -i "s%MIRROR_BASE%http://127.0.0.1:8088%g" "$FILE"
|
|
sed -i "s%BUILD_ENV%$MY_BUILD_ENVIRONMENT%g" "$FILE"
|
|
sed -i "s%/MY_BUILD_DIR%$MY_BUILD_DIR_TOP%g" "$FILE"
|
|
sed -i "s%/MY_REPO_DIR%$MY_REPO%g" "$FILE"
|
|
|
|
# Disable all local-* repos for the build-types other than the current one
|
|
for bt in std rt; do
|
|
if [ "$bt" != "$BUILD_TYPE" ]; then
|
|
# Use the range of lines starting with pattern [local-$bt] until the next line starting with []
|
|
sed -i "/^\[local-$bt\]/,/^\[/ s/enabled=1/enabled=0/" $FILE
|
|
sed -i "/^\[StxCentos7Distro-$bt\]/,/^\[/ s/enabled=1/enabled=0/" $FILE
|
|
fi
|
|
done
|
|
fi
|
|
|
|
|
|
# Add environment variables to mock config if they don't exist
|
|
grep -q "config_opts\['environment'\]\['BUILD_BY'\]" $FILE || \
|
|
echo "config_opts['environment']['BUILD_BY']" >> $FILE
|
|
|
|
grep -q "config_opts\['environment'\]\['BUILD_DATE'\]" $FILE || \
|
|
echo "config_opts['environment']['BUILD_DATE']" >> $FILE
|
|
|
|
grep -q "config_opts\['environment'\]\['REPO'\]" $FILE || \
|
|
echo "config_opts['environment']['REPO']" >> $FILE
|
|
|
|
grep -q "config_opts\['environment'\]\['WRS_GIT_BRANCH'\]" $FILE || \
|
|
echo "config_opts['environment']['WRS_GIT_BRANCH']" >> $FILE
|
|
|
|
grep -q "config_opts\['environment'\]\['CGCS_GIT_BRANCH'\]" $FILE || \
|
|
echo "config_opts['environment']['CGCS_GIT_BRANCH']" >> $FILE
|
|
|
|
if [ -z $FORMAL_BUILD ]; then
|
|
grep -q "config_opts\['macros'\]\['%_no_cgcs_license_check'\] = '1'" $FILE || \
|
|
echo "config_opts['macros']['%_no_cgcs_license_check'] = '1'" >> $FILE
|
|
else
|
|
sed -i "/config_opts\['macros'\]\['%_no_cgcs_license_check'\] = '1'/d" $FILE
|
|
fi
|
|
|
|
grep -q "config_opts\['macros'\]\['%_tis_build_type'\] = '$BUILD_TYPE'" $FILE || \
|
|
echo "config_opts['macros']['%_tis_build_type'] = '$BUILD_TYPE'" >> $FILE
|
|
|
|
if [ -f /usr/lib64/nosync/nosync.so ]; then
|
|
grep -q "config_opts\['nosync'\] = True" $FILE || \
|
|
echo "config_opts['nosync'] = True" >> $FILE
|
|
fi
|
|
|
|
NETWORK_PKGS=""
|
|
if [ "containers" == "$BUILD_TYPE" ]; then
|
|
NETWORK_PKGS="bind-utils"
|
|
fi
|
|
|
|
BUILD_PKGS=''
|
|
if [ "${PKG_MANAGER}" == "yum" ]; then
|
|
BUILD_PKGS='@buildsys-build'
|
|
elif [ "${PKG_MANAGER}" == "dnf" ]; then
|
|
# buildsys-build group was dropped when Centos-8 switched to dnf.
|
|
# We must list all the members plus a few new ones (fedpkg-minimal, epel-rpm-macros).
|
|
BUILD_PKGS='bash bzip2 coreutils cpio diffutils epel-release epel-rpm-macros fedpkg-minimal findutils gawk gcc gcc-c++ grep gzip info make patch redhat-rpm-config redhat-release rpm-build sed shadow-utils tar unzip util-linux which xz'
|
|
fi
|
|
|
|
STX_PKGS='pigz lbzip2 bash'
|
|
|
|
PKGS="${BUILD_PKGS} ${STX_PKGS} ${PKG_MANAGER} ${PYTHON_PKG} ${NETWORK_PKGS}"
|
|
|
|
grep -q "config_opts\['chroot_setup_cmd'\] = 'install ${PKGS}'" $FILE || \
|
|
echo "config_opts['chroot_setup_cmd'] = 'install ${PKGS}'" >> $FILE
|
|
|
|
# Special case for containers.
|
|
# rpmbuild_networking is required for invoking helm commands within mock
|
|
# building containers requires the std repo to be enabled.
|
|
if [ "containers" == "$BUILD_TYPE" ]; then
|
|
grep -q "config_opts\['rpmbuild_networking'\] = True" $FILE || \
|
|
echo "config_opts['rpmbuild_networking'] = True" >> $FILE
|
|
|
|
grep -q "config_opts\['use_host_resolv'\] = True" $FILE || \
|
|
echo "config_opts['use_host_resolv'] = True" >> $FILE
|
|
|
|
sed -i "/^\[local-std\]/,/^\[/ s/enabled=0/enabled=1/" $FILE
|
|
fi
|
|
|
|
#
|
|
# Read macros from tis.macros to add to the build config file,
|
|
# for use in RPM spec files
|
|
#
|
|
RPM_MACROS=$MY_REPO/build-tools/tis.macros
|
|
sed 's/#.*//' $RPM_MACROS | grep '=' | while IFS='=' read name value; do
|
|
# Check if the entry already exists. If so, go to next line
|
|
grep -q "^config_opts\['macros'\]\['${name}'\] = '${value}'$" $FILE && continue
|
|
|
|
# Update or add the entry
|
|
grep -q "^config_opts\['macros'\]\['${name}'\]" $FILE
|
|
if [ $? -eq 0 ]; then
|
|
sed -i -r "s#^(config_opts\['macros'\]\['${name}'\]).*#\1 = '${value}'#" $FILE
|
|
else
|
|
echo "config_opts['macros']['${name}'] = '${value}'" >> $FILE
|
|
fi
|
|
done
|
|
|
|
# okay, now we have lines for each env var. Generate the correct values
|
|
|
|
BUILD_DATE=`date "+%F %T %z"`
|
|
CGCS_GIT_BRANCH=`cd $MY_REPO/stx/; git rev-parse --abbrev-ref HEAD`
|
|
WRS_GIT_BRANCH=`cd $MY_REPO; git rev-parse --abbrev-ref HEAD`
|
|
REPO=$MY_REPO
|
|
|
|
# Finally, our good friend sed will place the values in the mock config file
|
|
sed -i \
|
|
-e "s#config_opts\['environment'\]\['BUILD_BY'\].*#config_opts\['environment'\]\['BUILD_BY'\] = '$USER'#" \
|
|
-e "s#config_opts\['environment'\]\['BUILD_DATE'\].*#config_opts\['environment'\]\['BUILD_DATE'\] = '$BUILD_DATE'#" \
|
|
-e "s#config_opts\['environment'\]\['REPO'\].*#config_opts\['environment'\]\['REPO'\] = '$REPO'#" \
|
|
-e "s#config_opts\['environment'\]\['WRS_GIT_BRANCH'\].*#config_opts\['environment'\]\['WRS_GIT_BRANCH'\] = '$WRS_GIT_BRANCH'#" \
|
|
-e "s#config_opts\['environment'\]\['CGCS_GIT_BRANCH'\].*#config_opts\['environment'\]\['CGCS_GIT_BRANCH'\] = '$CGCS_GIT_BRANCH'#" \
|
|
$FILE
|