Blame SOURCES/shim-find-debuginfo.sh

2e2de3
#!/bin/bash
2e2de3
#
2e2de3
# shim-find-debuginfo.sh
2e2de3
# Copyright (C) 2017 Peter Jones <Peter Jones@random>
2e2de3
#
2e2de3
# Distributed under terms of the GPLv3 license.
2e2de3
#
2e2de3
set -e
2e2de3
set -u
2e2de3
2e2de3
mainarch=$1 && shift
2e2de3
if [ $# == 1 ]; then
2e2de3
    altarch=$1 && shift
2e2de3
fi
2e2de3
if ! [ -v RPM_BUILD_ROOT ]; then
2e2de3
    echo "RPM_BUILD_ROOT must be set" 1>&2
2e2de3
    exit 1
2e2de3
fi
2e2de3
2e2de3
findsource()
2e2de3
{
2e2de3
    (
c634ca
        cd "${RPM_BUILD_ROOT}"
c634ca
        find usr/src/debug/ -type d | sed -e "s,^,%dir /," | sort -u | tac
c634ca
        find usr/src/debug/ -type f | sed -e "s,^,/," | sort -u | tac
2e2de3
    )
2e2de3
}
2e2de3
2e2de3
finddebug()
2e2de3
{
2e2de3
    arch=$1 && shift
2e2de3
    declare -a dirs=()
2e2de3
    declare -a files=()
2e2de3
    declare -a excludes=()
c634ca
    declare -a tmp=()
2e2de3
c634ca
    pushd "${RPM_BUILD_ROOT}" >/dev/null 2>&1
c634ca
c634ca
    mapfile -t tmp < <(find usr/lib/debug/ -type f -iname "*.efi.debug")
c634ca
    for x in "${tmp[@]}" ; do
2e2de3
        if ! [ -e "${x}" ]; then
2e2de3
            break
2e2de3
        fi
2e2de3
        if [[ ${x} =~ ${arch}\.efi\.debug$ ]]; then
2e2de3
            files[${#files[@]}]=${x}
2e2de3
        else
2e2de3
            excludes[${#excludes[@]}]=${x}
2e2de3
        fi
2e2de3
    done
2e2de3
    for x in usr/lib/debug/.build-id/*/*.debug ; do
2e2de3
        if ! [ -e "${x}" ]; then
2e2de3
            break
2e2de3
        fi
2e2de3
        link=$(readlink "${x}")
2e2de3
        if [[ ${link} =~ ${arch}\.efi\.debug$ ]]; then
2e2de3
            files[${#files[@]}]=${x}
2e2de3
            files[${#files[@]}]=${x%%.debug}
2e2de3
        else
2e2de3
            excludes[${#excludes[@]}]=${x}
2e2de3
            excludes[${#excludes[@]}]=${x%%.debug}
2e2de3
        fi
2e2de3
    done
c634ca
    for x in "${files[@]}" ; do
c634ca
        declare name
c634ca
c634ca
        name=$(dirname "/${x}")
2e2de3
        while [ "${name}" != "/" ]; do
2e2de3
            case "${name}" in
2e2de3
            "/usr/lib/debug"|"/usr/lib"|"/usr")
2e2de3
                ;;
2e2de3
            *)
2e2de3
                dirs[${#dirs[@]}]=${name}
2e2de3
                ;;
2e2de3
            esac
c634ca
            name=$(dirname "${name}")
2e2de3
        done
2e2de3
    done
2e2de3
2e2de3
    popd >/dev/null 2>&1
c634ca
    for x in "${dirs[@]}" ; do
2e2de3
        echo "%dir ${x}"
2e2de3
    done | sort | uniq
c634ca
    for x in "${files[@]}" ; do
2e2de3
        echo "/${x}"
2e2de3
    done | sort | uniq
c634ca
    for x in "${excludes[@]}" ; do
2e2de3
        echo "%exclude /${x}"
2e2de3
    done
2e2de3
}
2e2de3
c634ca
findsource > "build-${mainarch}/debugsource.list"
c634ca
finddebug "${mainarch}" > "build-${mainarch}/debugfiles.list"
2e2de3
if [ -v altarch ]; then
c634ca
    finddebug "${altarch}" > "build-${altarch}/debugfiles.list"
2e2de3
fi