diff --git a/scripts/libmakepkg/executable/debugedit.sh.in b/scripts/libmakepkg/executable/debugedit.sh.in new file mode 100644 index 00000000..55b9257a --- /dev/null +++ b/scripts/libmakepkg/executable/debugedit.sh.in @@ -0,0 +1,38 @@ +#!/usr/bin/bash +# +# debugedit.sh - Confirm presence of debugedit binary +# +# Copyright (c) 2022 Pacman Development Team +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +[[ -n "$LIBMAKEPKG_EXECUTABLE_DEBUGEDIT_SH" ]] && return +LIBMAKEPKG_EXECUTABLE_DEBUGEDIT_SH=1 + +LIBRARY=${LIBRARY:-'@libmakepkgdir@'} + +source "$LIBRARY/util/message.sh" +source "$LIBRARY/util/option.sh" + +executable_functions+=('executable_debugedit') + +executable_debugedit() { + if check_option "debug" "y"; then + if ! type -p debugedit >/dev/null; then + error "$(gettext "Cannot find the %s binary required for including source files in debug packages.")" "debugedit" + return 1 + fi + fi +} diff --git a/scripts/libmakepkg/tidy/strip.sh.in b/scripts/libmakepkg/tidy/strip.sh.in index 96602538..6955bb68 100644 --- a/scripts/libmakepkg/tidy/strip.sh.in +++ b/scripts/libmakepkg/tidy/strip.sh.in @@ -36,8 +36,20 @@ build_id() { } source_files() { - LANG=C readelf "$1" --debug-dump 2>/dev/null | \ - awk '/DW_AT_name +:/{name=$NF}/DW_AT_comp_dir +:/{{if (name == "") next}{if (name !~ /^[<\/]/) {printf "%s/", $NF}}{print name}}' + # This function does two things: + # + # 1) rewrites source file locations for packages not respecting prefix- + # map switches. This ensures all source file references in debug + # info point to $dbgsrcdir. + # + # 2) outputs a list of files from the package source files to stdout + # while stripping the $dbgsrcdir prefix + + LANG=C debugedit --no-recompute-build-id \ + --base-dir "${srcdir}" \ + --dest-dir "${dbgsrcdir}" \ + --list-file /dev/stdout "$1" \ + | sort -zu | tr '\0' '\n' } strip_file() { @@ -58,9 +70,9 @@ strip_file() { # copy source files to debug directory local file dest t while IFS= read -r t; do - file=${t/${dbgsrcdir}/"$srcdir"} - dest="${dbgsrc/"$dbgsrcdir"/}$t" - if ! [[ -f $dest ]]; then + file="${srcdir}/${t}" + dest="${dbgsrc}/${t}" + if [[ -f "$file" ]] && ! [[ -f $dest ]]; then mkdir -p "${dest%/*}" cp -- "$file" "$dest" fi