add check_arch.py

This commit is contained in:
Alex 2019-05-31 13:46:30 +00:00
parent 5f0ba6d71b
commit e968a0bfa1
2 changed files with 49 additions and 49 deletions

View file

@ -290,8 +290,11 @@ do
fi fi
fi fi
$MOCK_BIN -v --configdir=$config_dir --buildsrpm --spec=$build_package/${spec_name} --sources=$build_package --no-cleanup-after --no-clean $extra_build_src_rpm_options --resultdir=$OUTPUT_FOLDER $MOCK_BIN -v --configdir=$config_dir --buildsrpm --spec=$build_package/${spec_name} --sources=$build_package --no-cleanup-after --no-clean $extra_build_src_rpm_options --resultdir=$OUTPUT_FOLDER
python /mdv/check_arch.py "${OUTPUT_FOLDER}"/*.src.rpm ${platform_arch}
rc=$?; if [[ $rc != 0 ]]; then exit 6; fi
else else
$MOCK_BIN -v --configdir=$config_dir --buildsrpm --spec=$build_package/${spec_name} --sources=$build_package --no-cleanup-after $extra_build_src_rpm_options --resultdir=$OUTPUT_FOLDER $MOCK_BIN -v --configdir=$config_dir --buildsrpm --spec=$build_package/${spec_name} --sources=$build_package --no-cleanup-after $extra_build_src_rpm_options --resultdir=$OUTPUT_FOLDER
python /mdv/check_arch.py "${OUTPUT_FOLDER}"/*.src.rpm ${platform_arch}
fi fi
rc=${PIPESTATUS[0]} rc=${PIPESTATUS[0]}
@ -391,52 +394,6 @@ else
fi fi
} }
validate_arch() {
# check if spec file have set ExcludeArch or ExclusiveArch against build arch target
BUILD_TYPE=`grep -i '^excludearch:.*$\|^exclusivearch:.*$' *.spec | awk -F'[:]' '{print $1}'`
# check if spec file have both ExcludeArch and ExclusiveArch set up
[[ ${#BUILD_TYPE} -gt 15 ]] && echo "Spec file has set ExcludeArch and ExclusiveArch. Exiting!" && exit 1
SPEC_ARCH=(`grep -i '^excludearch:.*$\|^exclusivearch:.*$' *.spec | awk -F'[[:blank:]]' '{$1="";print $0}' | sort -u`)
# validate platform against spec file settings
validate_build() {
local _PLATFORM=($1)
# count for occurences
for item in ${SPEC_ARCH[@]}; do
if [[ "${_PLATFORM[@]}" =~ "${item}" ]] ; then
FOUND_MATCH=1
echo "--> Found match of ${item} in ${_PLATFORM[@]} for ${BUILD_TYPE}"
fi
done
if [ -n "${FOUND_MATCH}" -a "${BUILD_TYPE,,}" = "excludearch" ]; then
echo "--> Build for this architecture is forbidden because of ${BUILD_TYPE} set in spec file!"
exit 6
elif [ -z "${FOUND_MATCH}" -a "${BUILD_TYPE,,}" = "exclusivearch" ]; then
echo "--> Build for this architecture is forbidden because of ${BUILD_TYPE} set in spec file!"
exit 6
else
echo "--> Spec validated for ExcludeArch and ExclusiveArch. Continue building."
fi
}
# translate arch into various options that may be set up in spec file
case ${PLATFORM_ARCH,,} in
armv7hl)
validate_build "armx %armx %{armx} armv7hl"
;;
aarch64)
validate_build "armx %armx %{armx} aarch64"
;;
i386|i586|i686)
validate_build "ix86 %ix86 %{ix86} i686 %i686 %{i686} i586 %i586 %{i586} i386 %i386 %{i386}"
;;
x86_64)
validate_build "x86_64 %x86_64 %{x86_64}"
;;
*)
echo "--> ${BUILD_TYPE} validated."
;;
esac
}
clone_repo() { clone_repo() {
@ -476,9 +433,6 @@ done
pushd ${HOME}/${PACKAGE} pushd ${HOME}/${PACKAGE}
# count number of specs (should be 1) # count number of specs (should be 1)
find_spec find_spec
# check for excludearch or exclusivearch
# rework me
validate_arch
# download sources from .abf.yml # download sources from .abf.yml
/bin/bash /mdv/download_sources.sh /bin/bash /mdv/download_sources.sh
popd popd

46
check_arch.py Normal file
View file

@ -0,0 +1,46 @@
#!/usr/bin/python2
#
# Check if a package can be built for the given architecture
# (i.e., arch is not forbidden by ExcludeArch or included
# in ExclusiveArch set if the latter is defined)
#
import sys
import glob
import os.path
import rpm
if len(sys.argv) < 3:
sys.exit('Usage: %s srpm arch' % sys.argv[0])
srpm = sys.argv[1]
platform_arch = sys.argv[2]
ts = rpm.TransactionSet()
ts.setVSFlags(~(rpm.RPMVSF_NEEDPAYLOAD))
fdno = os.open(srpm, os.O_RDONLY)
hdr = ts.hdrFromFdno(fdno)
if hdr['excludearch']:
for a in hdr['excludearch']:
if a == platform_arch:
print("Architecture is excluded per package spec file (ExcludeArch tag)")
sys.exit(1)
exit_code = 0
if hdr['exclusivearch']:
exit_code = 1
for a in hdr['exclusivearch']:
print(a)
if a == platform_arch:
exit_code = 0
break
if exit_code == 1:
print("The package has ExclusiveArch tag set, but the current architecture is not mentioned there")
sys.exit(exit_code)