Blame SOURCES/shim-find-debuginfo.sh

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