strip: Use debugedit instead of AWK to parse source files
This moves us from the fairly ugly AWK parsing line to debugedit which
originally comes out of the rpm project.
The original code has issues parsing anything that was not straight
C/C++ and languages like Rust or Go would return invalid source code
files. debugedit handles all these cases better.
Fixes FS#66755
Fixes FS#66888
Fixes FS#65677
Signed-off-by: Morten Linderud <morten@linderud.pw>
Signed-off-by: Allan McRae <allan@archlinux.org>
(cherry picked from commit ae2f506ddf
)
This commit is contained in:
parent
23e337ba5a
commit
c4a21f333a
2 changed files with 55 additions and 5 deletions
38
scripts/libmakepkg/executable/debugedit.sh.in
Normal file
38
scripts/libmakepkg/executable/debugedit.sh.in
Normal file
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/bash
|
||||
#
|
||||
# debugedit.sh - Confirm presence of debugedit binary
|
||||
#
|
||||
# Copyright (c) 2022 Pacman Development Team <pacman-dev@lists.archlinux.org>
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
[[ -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
|
||||
}
|
|
@ -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 == "<artificial>") 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
|
||||
|
|
Loading…
Add table
Reference in a new issue