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
    (
d586fa
        cd ${RPM_BUILD_ROOT}
d586fa
        find usr/src/debug/ -type d | sed "s,^,%dir /,"
d586fa
        find usr/src/debug/ -type f | sed "s,^,/,"
2e2de3
    )
2e2de3
}
2e2de3
2e2de3
finddebug()
2e2de3
{
2e2de3
    arch=$1 && shift
2e2de3
    declare -a dirs=()
2e2de3
    declare -a files=()
2e2de3
    declare -a excludes=()
2e2de3
d586fa
    pushd ${RPM_BUILD_ROOT} >/dev/null 2>&1
d586fa
    for x in $(find usr/lib/debug/ -type f -iname *.efi.debug); 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
d586fa
    for x in ${files[@]} ; do
d586fa
        declare 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
d586fa
            name=$(dirname ${name})
2e2de3
        done
2e2de3
    done
2e2de3
2e2de3
    popd >/dev/null 2>&1
d586fa
    for x in ${dirs[@]} ; do
2e2de3
        echo "%dir ${x}"
2e2de3
    done | sort | uniq
d586fa
    for x in ${files[@]} ; do
2e2de3
        echo "/${x}"
2e2de3
    done | sort | uniq
d586fa
    for x in ${excludes[@]} ; do
2e2de3
        echo "%exclude /${x}"
2e2de3
    done
2e2de3
}
2e2de3
d586fa
findsource > build-${mainarch}/debugsource.list
d586fa
finddebug ${mainarch} > build-${mainarch}/debugfiles.list
2e2de3
if [ -v altarch ]; then
d586fa
    finddebug ${altarch} > build-${altarch}/debugfiles.list
2e2de3
fi