bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#27532: getprogname: support for qemu


From: Jim Meyering
Subject: bug#27532: getprogname: support for qemu
Date: Thu, 29 Jun 2017 18:10:53 -0700

On Thu, Jun 29, 2017 at 9:50 AM, Assaf Gordon <address@hidden> wrote:
> Hello Bruno and all,
>
>> On Jun 29, 2017, at 12:26, Bruno Haible <address@hidden> wrote:
>>
...
> Luckily, many GNU test scripts already use "$prog" perl variable
> for the program's name in error message, so perhaps it would be possible
> to accomodate qemu without code changes.
>
> I've encountered the same for my program (datamash).
> and as an ugly hack added an undocumented option to print the program's name
> to set '$prog' accordingly:
> https://git.savannah.gnu.org/cgit/datamash.git/tree/tests/datamash-tests.pl#n37
>   ## Cross-Compiling portability hack:
>   ##  under qemu/binfmt, argv[0] (which is used to report errors) will contain
>   ##  the full path of the binary, if the binary is on the $PATH.
>   ##  So we try to detect what is the actual returned value of the program
>   ##  in case of an error.
>   my $prog = `$prog_bin ---print-progname`;
>   $prog = $prog_bin unless $prog;
>
>
> But this hack can be avoided, if we just run 'grep' with invalid
> arguments, triggering an error, then extracting the program name from STDERR.
>
> E.g. for 
> https://git.savannah.gnu.org/cgit/grep.git/tree/tests/filename-lineno.pl
> change the following on line 26 from:
>     my $prog = 'grep';
> to
>     my $prog = 'grep';
>     my $full_prog_name = `$prog --invalid-option-for-testing 2>&1 | head -n1 
> | cut -f1 -d:`;
>     $prog = $full_prog_name if $full_prog_name;
>
> This is untested code, but should work more-or-less.
> Once "$prog" is updated, all the tests should pass.

Thanks to both of you.
Does this patch solve the problem?

Attachment: grep-vs-qemu.diff
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]