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