nixpkgs/pkgs/development/tools/misc/dejagnu/default.nix
Sergei Trofimovich 5ac9fcfc60 dejagnu: fix target passing for 'runtest' wrapper
The problem was initially noticed in https://sourceware.org/PR30052#c5
where 'runtest' was passing bogus target name when ran without
parameters:

    $ ./result/bin/runtest
    ...
    Target is .runtest-wrapped
    Host   is x86_64-pc-linux-gnu

Note that runtest switches to non-native mode and uses wrapper name as a
target name. Mechanics of it is a bit involved: 'runtest' itself detects
targets passing via ${0} parameter:

    # somewhere in runtest:
    mypath=${0-.}
    ...
    if [ "$target" != runtest ] ; then
        target="--target ${target}"
    else
        target=""
    fi

which would be fine if we ran 'runtest'.

In `nixpkgs` `runtest` is a shell wrapper:

    $ cat /<<NIX>>/dejagnu-1.6.3/bin/runtest
    #! /<<NIX>>/bash-5.2-p15/bin/bash -e
    ...
    exec -a "$0" "/<<NIX>>/dejagnu-1.6.3/bin/.runtest-wrapped"  "$@"

You would expect that `.runtest-wrapped` would get `$0` as an `argv[0]`
here, but no. If both are `bash` scripts `bash` peeks original
`argv[0]` and breaks `runtest`:

    https://lists.gnu.org/archive/html/bug-bash/2023-01/msg00082.html

The workaround here is to drop the wrapper and place `expect` symlink
into a place where `dejagnu` and `runtest` expect it to be without a
wrapper creation.
2023-01-26 00:07:16 +00:00

67 lines
2.2 KiB
Nix

{ fetchurl, lib, stdenv, expect, makeWrapper }:
stdenv.mkDerivation rec {
pname = "dejagnu";
version = "1.6.3";
src = fetchurl {
url = "mirror://gnu/${pname}/${pname}-${version}.tar.gz";
sha256 = "1qx2cv6qkxbiqg87jh217jb62hk3s7dmcs4cz1llm2wmsynfznl7";
};
nativeBuildInputs = [ makeWrapper ];
buildInputs = [ expect ];
# dejagnu-1.6.3 can't successfully run tests in source tree:
# https://wiki.linuxfromscratch.org/lfs/ticket/4871
preConfigure = ''
mkdir build
cd build
'';
configureScript = "../configure";
doCheck = !(with stdenv; isDarwin && isAarch64);
# Note: The test-suite *requires* /dev/pts among the `build-chroot-dirs' of
# the build daemon when building in a chroot. See
# <https://www.mail-archive.com/nix-dev@cs.uu.nl/msg01056.html> for
# details.
# The test-suite needs to have a non-empty stdin:
# https://lists.gnu.org/archive/html/bug-dejagnu/2003-06/msg00002.html
checkPhase = ''
# Provide `runtest' with a log name, otherwise it tries to run
# `whoami', which fails when in a chroot.
LOGNAME="nix-build-daemon" make check < /dev/zero
'';
postInstall = ''
# 'runtest' and 'dejagnu' look up 'expect' in their 'bin' path
# first. We avoid use of 'wrapProgram' here because wrapping
# of shell scripts does not preserve argv[0] for schell scripts:
# https://sourceware.org/PR30052#c5
ln -s ${expect}/bin/expect $out/bin/expect
'';
meta = with lib; {
description = "Framework for testing other programs";
longDescription = ''
DejaGnu is a framework for testing other programs. Its purpose
is to provide a single front end for all tests. Think of it as a
custom library of Tcl procedures crafted to support writing a
test harness. A test harness is the testing infrastructure that
is created to support a specific program or tool. Each program
can have multiple testsuites, all supported by a single test
harness. DejaGnu is written in Expect, which in turn uses Tcl --
Tool command language.
'';
homepage = "https://www.gnu.org/software/dejagnu/";
license = licenses.gpl2Plus;
platforms = platforms.unix;
maintainers = with maintainers; [ vrthra ];
};
}