Blame SOURCES/shim-find-debuginfo.sh

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