simplify compare_archive API

OBS-URL: https://build.opensuse.org/package/show/openSUSE:Tools/build-compare?expand=0&rev=263
This commit is contained in:
Olaf Hering 2020-01-15 15:59:48 +00:00 committed by Git OBS Bridge
parent 76e9d71125
commit 6052501a80
2 changed files with 146 additions and 98 deletions

View File

@ -21,7 +21,7 @@ Summary: Build Result Compare Script
License: GPL-2.0+ License: GPL-2.0+
Group: Development/Tools/Building Group: Development/Tools/Building
Url: https://github.com/openSUSE/build-compare Url: https://github.com/openSUSE/build-compare
Version: 20200110T222328.b5aa37b Version: 20200115T165709.b82e1e5
Release: 0 Release: 0
Source1: COPYING Source1: COPYING
Source2: same-build-result.sh Source2: same-build-result.sh

View File

@ -43,56 +43,6 @@ function wprint
watchdog_reset watchdog_reset
} }
function findunjarbin
{
if [[ $(type -p fastjar) ]]; then
UNJAR=fastjar
elif [[ $(type -p jar) ]]; then
UNJAR=jar
elif [[ $(type -p unzip) ]]; then
UNJAR=unzip
else
echo "ERROR: jar, fastjar, or unzip is not installed (trying file $file)"
exit 1
fi
}
#usage unjar <file>
function unjar()
{
local file
file=$1
findunjarbin
case $UNJAR in
jar|fastjar)
# echo jar -xf $file
${UNJAR} -xf $file
;;
unzip)
unzip -oqq $file
;;
esac
}
# list files in given jar file
#usage unjar_l <file>
function unjar_l()
{
local file
file=$1
findunjarbin
case $UNJAR in
jar|fastjar)
${UNJAR} -tf $file
;;
unzip)
unzip -Z -1 $file
;;
esac
}
filter_disasm() filter_disasm()
{ {
[[ $nofilter ]] && return [[ $nofilter ]] && return
@ -641,86 +591,184 @@ normalize_file()
esac esac
} }
a_list() archive_a()
{ {
ar t "$1" local cmd=$1
} local file=$2
a_extract() case "${cmd}" in
{ f)
ar x "$1" test -x "$(type -P ar)" && return 0
echo "ERROR: ar missing for ${file}"
return 1
;;
l)
ar t "${file}"
test "$?" = "0" && return 0
return 1
;;
x)
ar x "${file}"
test "$?" = "0" && return 0
return 1
;;
esac
} }
cpio_list() archive_cpio()
{ {
cpio --quiet --list --force-local < "$1" local cmd=$1
} local file=$2
cpio_extract() case "${cmd}" in
{ f)
cpio --quiet --extract --force-local < "$1" test -x "$(type -P cpio)" && return 0
echo "ERROR: cpio missing for ${file}"
return 1
;;
l)
cpio --quiet --list --force-local < "${file}"
test "$?" = "0" && return 0
return 1
;;
x)
cpio --quiet --extract --force-local < "${file}"
test "$?" = "0" && return 0
return 1
;;
esac
} }
squashfs_list() archive_squashfs()
{ {
unsquashfs -no-progress -ls -dest '' "$1" | grep -Ev '^(Parallel unsquashfs:|[0-9]+ inodes )' local cmd=$1
} local file=$2
squashfs_extract() case "${cmd}" in
{ f)
unsquashfs -no-progress -dest "." "$1" test -x "$(type -P unsquashfs)" && return 0
echo "ERROR: unsquashfs missing for ${file}"
return 1
;;
l)
unsquashfs -no-progress -ls -dest '' "${file}" | grep -Ev '^(Parallel unsquashfs:|[0-9]+ inodes )'
test "$?" = "0" && return 0
return 1
;;
x)
unsquashfs -no-progress -dest "." "${file}"
test "$?" = "0" && return 0
return 1
;;
esac
} }
tar_list() archive_tar()
{ {
tar tf "$1" local cmd=$1
} local file=$2
tar_extract() case "${cmd}" in
{ f)
tar xf "$1" test -x "$(type -P tar)" && return 0
echo "ERROR: tar missing for ${file}"
return 1
;;
l)
tar tf "${file}"
test "$?" = "0" && return 0
return 1
;;
x)
tar xf "${file}"
test "$?" = "0" && return 0
return 1
;;
esac
} }
zip_list() UNJAR=
archive_zip()
{ {
unjar_l "$1" local cmd=$1
} local file=$2
zip_extract() case "${cmd}" in
{ f)
unjar "$1" if test -x "$(type -P fastjar)"
then
UNJAR="${_}"
elif test -x "$(type -P jar)"
then
UNJAR="${_}"
elif test -x "$(type -P unzip)"
then
UNJAR="${_}"
else
echo "ERROR: jar/fastjar/unzip missing for ${file}"
return 1
fi
return 0
;;
l)
case "${UNJAR##*/}" in
jar|fastjar)
"${UNJAR}" -tf "${file}"
;;
unzip)
"${UNJAR}" -Z -1 "${file}"
;;
esac
test "$?" = "0" && return 0
return 1
;;
x)
case "${UNJAR##*/}" in
jar|fastjar)
"${UNJAR}" -xf "${file}"
;;
unzip)
"${UNJAR}" -oqq "${file}"
;;
esac
test "$?" = "0" && return 0
return 1
;;
esac
} }
# returns 0 if content is identical # returns 0 if content is identical
# returns 1 if at least one file differs # returns 1 if at least one file differs
# handler f returns 1 if required tool for inspection is missing
# handler l lists content, returns 1 if tool failed
# handler x extracts content, returns 1 if tool failed
compare_archive() compare_archive()
{ {
local file="$1" local file="$1"
local old="$2" local handler="$2"
local new="$3" local old="`readlink -f \"old/$file\"`"
local tool="$4" local new="`readlink -f \"new/$file\"`"
local fn_list="$5" local f
local fn_extr="$6"
local f=
local -a content local -a content
local -i ret=1 local -i ret=1
test -x "$(type -P ${tool})" || return 1 "${handler}" 'f' "${file}" || return 1
mkdir -p "d/old/${file}" "d/new/${file}" mkdir -p "d/old/${file}" "d/new/${file}"
if pushd "d" > /dev/null if pushd "d" > /dev/null
then then
${fn_list} "${old}" | ${sort} > 'co' "${handler}" 'l' "${old}" | ${sort} > 'co'
${fn_list} "${new}" | ${sort} > 'cn' test "${PIPESTATUS[0]}" = "0" || return 1
"${handler}" 'l' "${new}" | ${sort} > 'cn'
test "${PIPESTATUS[0]}" = "0" || return 1
if cmp -s 'co' 'cn' if cmp -s 'co' 'cn'
then then
if pushd "old/${file}" > /dev/null if pushd "old/${file}" > /dev/null
then then
"${fn_extr}" "${old}" "${handler}" 'x' "${old}" || return 1
popd > /dev/null popd > /dev/null
fi fi
if pushd "new/${file}" > /dev/null if pushd "new/${file}" > /dev/null
then then
"${fn_extr}" "${new}" "${handler}" 'x' "${new}" || return 1
popd > /dev/null popd > /dev/null
fi fi
readarray -t content < 'cn' readarray -t content < 'cn'
compare_archive_content "${file}" "${content[@]}"
for f in "${content[@]}" for f in "${content[@]}"
do do
if ! check_single_file "${file}/${f}" if ! check_single_file "${file}/${f}"
@ -772,23 +820,23 @@ check_single_file()
case "$file" in case "$file" in
*.a) *.a)
compare_archive "${file}" "`readlink -f \"old/$file\"`" "`readlink -f \"new/$file\"`" 'ar' 'a_list' 'a_extract' compare_archive "${file}" 'archive_a'
return $? return $?
;; ;;
*.cpio) *.cpio)
compare_archive "${file}" "`readlink -f \"old/$file\"`" "`readlink -f \"new/$file\"`" 'cpio' 'cpio_list' 'cpio_extract' compare_archive "${file}" 'archive_cpio'
return $? return $?
;; ;;
*.squashfs) *.squashfs)
compare_archive "${file}" "`readlink -f \"old/$file\"`" "`readlink -f \"new/$file\"`" 'unsquashfs' 'squashfs_list' 'squashfs_extract' compare_archive "${file}" 'archive_squashfs'
return $? return $?
;; ;;
*.tar|*.tar.bz2|*.tar.gz|*.tgz|*.tbz2) *.tar|*.tar.bz2|*.tar.gz|*.tgz|*.tbz2)
compare_archive "${file}" "`readlink -f \"old/$file\"`" "`readlink -f \"new/$file\"`" 'tar' 'tar_list' 'tar_extract' compare_archive "${file}" 'archive_tar'
return $? return $?
;; ;;
*.zip|*.egg|*.jar|*.war) *.zip|*.egg|*.jar|*.war)
compare_archive "${file}" "`readlink -f \"old/$file\"`" "`readlink -f \"new/$file\"`" 'true' 'zip_list' 'zip_extract' compare_archive "${file}" 'archive_zip'
return $? return $?
;; ;;
*.bz2) *.bz2)