[PATCH 1/1] strip: Use debugedit instead of AWK to parse source files

Xiretza xiretza+archml at xiretza.xyz
Sun Jan 2 13:25:56 UTC 2022


On 02/01/2022 06.08, Allan McRae wrote:
> On 2/1/22 10:28, Morten Linderud wrote:
>>   scripts/libmakepkg/tidy/strip.sh.in | 13 ++++++++-----
>>   1 file changed, 8 insertions(+), 5 deletions(-)
>>
>> diff --git a/scripts/libmakepkg/tidy/strip.sh.in b/scripts/libmakepkg/tidy/strip.sh.in
>> index 92a6fb15..c1d8ee3c 100644
>> --- a/scripts/libmakepkg/tidy/strip.sh.in
>> +++ b/scripts/libmakepkg/tidy/strip.sh.in
>> @@ -36,8 +36,11 @@ 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}}'
>> +    dbgsrcdir="${DBGSRCDIR:-/usr/src/debug}"
>> +    local dbgsrclist="$(mktemp  "${startdir}/dbgsrclist.${binary##*/}.XXXXXXXXX")"
> 
> I really do not like making temporary files.  Particularly not in ${startdir}, which can be readonly provided BUILDDIR, SRCDIR, etc are set.
> 
> I may accept using $srcdir if writing this to a file is *essential*>
>> +    LANG=C debugedit -n -b "${srcdir}" -d "${dbgsrcdir}" -l "${dbgsrclist}" "$1" > /dev/null
>> +    sort -zu "${dbgsrclist}" | tr '\0' '\n'
>> +    rm -f "$dbgsrclist"

I haven't been able to produce any unrelated output on stdout, so just using /dev/stdout for --list-file would probably work ok - to make extra sure, this also works:

debugedit --list-file=/dev/fd/3 "$1" 3>&1 >/dev/null | sort [...]

Tangentially related, what's the opinion on using short vs. long options? Personally, I find that long options make scripts much easier to grok because they save a lot of looking at man pages/--help outputs, but I can also see how they might make things too crowded and busy, especially for common commands. Either way, might be something to include in HACKING.

>>   }
>>   strip_file() {
>> @@ -58,9 +61,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
> 



More information about the pacman-dev mailing list