Blame SOURCES/shim-find-debuginfo.sh

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