Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 65 additions & 48 deletions src/pkgdev/tatt/template.sh.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ GNU General Public License for more details.

main() {
trap "echo 'signal captured, exiting the entire script...'; exit" SIGHUP SIGINT SIGTERM
echo -e "USE tests started on $(date)\n" >> "{{ report_file }}"

local test_ret=0

echo '# bug: {{ job_name }}' > "{{ report_file }}"
echo "# time: $(date -u +"%Y-%m-%d %H:%M:%S")" >> "{{ report_file }}"

{% for atom, is_test, use_flags in jobs %}
{% if is_test %}
TUSE="{{ use_flags }}" tatt_test_pkg '{{ atom }}' --test || test_ret=1
Expand All @@ -39,89 +41,104 @@ cleanup() {
rm -v -f $0
}

tatt_json_report_error() {
echo -e "failure_str: ${1}" >> "{{ report_file }}"
}

tatt_pkg_error() {
local eout=${2}

echo "${eout}"

if [[ -n ${TUSE} ]]; then
echo -n "USE='${TUSE}'" >> "{{ report_file }}"
fi
if [[ -n ${FEATURES} ]]; then
echo -n " FEATURES='${FEATURES}'" >> "{{ report_file }}"
local CP=${1#=}
local PORTAGE_TMPDIR=$( pinspect portageq envvar2 / PORTAGE_TMPDIR )
local BUILDDIR=${PORTAGE_TMPDIR:-/var/tmp}/portage/${CP}
local BUILDLOG=${BUILDDIR}/temp/build.log
if [[ -s ${BUILDLOG} ]]; then
mkdir -p {{ log_dir }}
local LOGNAME=$( mktemp -p {{ log_dir }} "${CP/\//_}_use_XXXXX" )
cp "${BUILDLOG}" "${LOGNAME}"
echo "log_file: ${LOGNAME}" >> "{{ report_file }}"
readarray -d '' TESTLOGS < <(find "${BUILDDIR}/work" -iname '*test*log*' -print0)
if [[ {{ "${#TESTLOGS[@]}" }} -gt 0 ]]; then
tar cf "${LOGNAME}.tar" "${TESTLOGS[@]}"
echo "extra_logs: ${LOGNAME}.tar" >> "{{ report_file }}"
fi
fi

if [[ ${eout} =~ REQUIRED_USE ]] ; then
echo " : REQUIRED_USE not satisfied (probably) for ${1:?}" >> "{{ report_file }}"
tatt_json_report_error "REQUIRED_USE not satisfied (probably)"
elif [[ ${eout} =~ USE\ changes ]] ; then
echo " : USE dependencies not satisfied (probably) for ${1:?}" >> "{{ report_file }}"
tatt_json_report_error "USE dependencies not satisfied (probably)"
elif [[ ${eout} =~ keyword\ changes ]]; then
echo " : unkeyworded dependencies (probably) for ${1:?}" >> "{{ report_file }}"
tatt_json_report_error "unkeyworded dependencies (probably)"
elif [[ ${eout} =~ Error:\ circular\ dependencies: ]]; then
echo " : circular dependencies (probably) for ${1:?}" >> "{{ report_file }}"
tatt_json_report_error "circular dependencies (probably)"
elif [[ ${eout} =~ Blocked\ Packages ]]; then
echo " : blocked packages (probably) for ${1:?}" >> "{{ report_file }}"
else
echo " failed for ${1:?}" >> "{{ report_file }}"
tatt_json_report_error "blocked packages (probably)"
elif [[ ${eout} =~ have\ been\ masked ]]; then
tatt_json_report_error "masked packages (probably)"
fi
}

local CP=${1#=}
local BUILDDIR=/var/tmp/portage/${CP}
local BUILDLOG=${BUILDDIR}/temp/build.log
if [[ -s ${BUILDLOG} ]]; then
mkdir -p {{ log_dir }}
local LOGNAME=$(mktemp -p {{ log_dir }} "${CP/\//_}_use_XXXXX")
cp "${BUILDLOG}" "${LOGNAME}"
echo " log has been saved as ${LOGNAME}" >> "{{ report_file }}"
TESTLOGS=($(find ${BUILDDIR}/work -iname '*test*log*'))
if [[ {{ "${#TESTLOGS[@]}" }} -gt 0 ]]; then
tar cf ${LOGNAME}.tar ${TESTLOGS[@]}
echo " test-suite logs have been saved as ${LOGNAME}.tar" >> "{{ report_file }}"
fi
fi
tattoo_emerge() {
emerge "$@" {{ emerge_opts }} 2>&1 1>${EMERGE_OUTPUT:?}
}

tatt_test_pkg() {
echo >> "{{ report_file }}"
echo "---" >> "{{ report_file }}"
echo "time: $(date -u +"%Y-%m-%d %H:%M:%S")" >> "{{ report_file }}"
echo "atom: ${1:?}" >> "{{ report_file }}"
echo "useflags: ${TUSE}" >> "{{ report_file }}"

local CP=${1#=}
CP=${CP/\//_}

local EMERGE_OUTPUT=/dev/null
if [[ -t 1 ]]; then
EMERGE_OUTPUT=/dev/tty
fi

# --usepkg-exclude needs the package name, so let's extract it
# from the atom we have
#
# A --with-test-deps quirk (bug #639588) means --usepkg-exclude should be passed to all invocations.
#
# If one happens to set EMERGE_DEFAULT_OPTS="--buildpkg", exclude it for the tested pkg (which is
# ACCEPT_KEYWORDS, and built several times).
local name=$( pquery --raw --no-version "${1}" )
local commonopts=( --oneshot --usepkg-exclude="${name}" --buildpkg-exclude="${name}" )

if [[ ${2} == "--test" ]]; then
# Do a first pass to avoid circular dependencies
# --onlydeps should mean we're avoiding (too much) duplicate work
USE="minimal -doc" emerge --onlydeps -q1 --with-test-deps {{ emerge_opts }} "${1:?}"
USE="minimal -doc" tattoo_emerge "${1}" --onlydeps --quiet "${commonopts[@]}" --with-test-deps

if ! emerge --onlydeps -q1 --with-test-deps {{ emerge_opts }} "${1:?}"; then
echo "merging test dependencies of ${1} failed" >> "{{ report_file }}"
if ! tattoo_emerge "${1}" --onlydeps --quiet "${commonopts[@]}" --with-test-deps; then
tatt_json_report_error "merging test dependencies failed"
return 1
fi
printf "%s pkgdev_tatt_{{ job_name }}_test\n" "${1:?}"> "/etc/portage/package.env/pkgdev_tatt_{{ job_name }}/${CP}"
local TFEATURES="${FEATURES} test"
printf "%s pkgdev_tatt_{{ job_name }}_test\n" "${1}"> "/etc/portage/package.env/pkgdev_tatt_{{ job_name }}/${CP}"
echo "features: test" >> "{{ report_file }}"
else
printf "%s pkgdev_tatt_{{ job_name }}_no_test\n" "${1:?}" > "/etc/portage/package.env/pkgdev_tatt_{{ job_name }}/${CP}"
local TFEATURES="${FEATURES}"
printf "%s pkgdev_tatt_{{ job_name }}_no_test\n" "${1}" > "/etc/portage/package.env/pkgdev_tatt_{{ job_name }}/${CP}"
echo "features: " >> "{{ report_file }}"
fi
{% for env in extra_env_files %}
printf "%s {{env}}\n" "${1}" >> "/etc/portage/package.env/pkgdev_tatt_{{ job_name }}/${CP}"
{% endfor %}

printf "%s %s\n" "${1:?}" "${TUSE}" > "/etc/portage/package.use/pkgdev_tatt_{{ job_name }}/${CP}"
printf "%s %s\n" "${1}" "${TUSE}" > "/etc/portage/package.use/pkgdev_tatt_{{ job_name }}/${CP}"

# --usepkg-exclude needs the package name, so let's extract it
# from the atom we have
local name=$(portageq pquery "${1:?}" -n)

eout=$( emerge -1 --getbinpkg=n --usepkg-exclude="${name}" {{ emerge_opts }} "${1:?}" 2>&1 1>/dev/tty )
eout=$( tattoo_emerge "${1}" "${commonopts[@]}" )
local RES=$?

rm -v -f /etc/portage/package.{env,use}/pkgdev_tatt_{{ job_name }}/${CP}

if [[ ${RES} == 0 ]] ; then
if [[ -n ${TFEATURES} ]]; then
echo -n "FEATURES='${TFEATURES}' " >> "{{ report_file }}"
fi
echo "USE='${TUSE}' succeeded for ${1:?}" >> "{{ report_file }}"
if [[ ${RES} -eq 0 ]] ; then
echo "result: true" >> "{{ report_file }}"
else
FEATURES="${TFEATURES}" tatt_pkg_error "${1:?}" "${eout}"
echo "result: false" >> "{{ report_file }}"
tatt_pkg_error "${1}" "${eout}"
return 1
fi
}
Expand Down