about summary refs log tree commit diff
path: root/pkgs/development/compilers
diff options
context:
space:
mode:
authorJulian Stecklina <julian.stecklina@cyberus-technology.de>2020-05-08 17:10:26 +0200
committerJulian Stecklina <julian.stecklina@cyberus-technology.de>2020-05-08 17:29:38 +0200
commit3dbb32f6265bfacea10059500b9ae2ad1db80058 (patch)
treea499084e4e51b9f07700853988e21a466972988f /pkgs/development/compilers
parent50684f118ab83034bd027e026052ac8db1be6ab1 (diff)
downloadnixlib-3dbb32f6265bfacea10059500b9ae2ad1db80058.tar
nixlib-3dbb32f6265bfacea10059500b9ae2ad1db80058.tar.gz
nixlib-3dbb32f6265bfacea10059500b9ae2ad1db80058.tar.bz2
nixlib-3dbb32f6265bfacea10059500b9ae2ad1db80058.tar.lz
nixlib-3dbb32f6265bfacea10059500b9ae2ad1db80058.tar.xz
nixlib-3dbb32f6265bfacea10059500b9ae2ad1db80058.tar.zst
nixlib-3dbb32f6265bfacea10059500b9ae2ad1db80058.zip
open-watcom-bin: fix EOVERFLOW on stat() calls
We've already worked around failing stat() calls in the installer by
running it in qemu-user. Turns out on some systems this workaround is
also needed to run `wlib', the archiver of the Open Watcom toolchain.

This issue manifested itself in broken VirtualBox builds due to
/build/virtualbox/out/linux.amd64/dbgopt/obj/VBoxPcBios32/pci32.obj
not being found by `wlib'.

We now just wrap all binaries in qemu-user to avoid this.
Diffstat (limited to 'pkgs/development/compilers')
-rw-r--r--pkgs/development/compilers/open-watcom-bin/default.nix77
1 files changed, 66 insertions, 11 deletions
diff --git a/pkgs/development/compilers/open-watcom-bin/default.nix b/pkgs/development/compilers/open-watcom-bin/default.nix
index 0cd80b6e1df3..a9c6b221065c 100644
--- a/pkgs/development/compilers/open-watcom-bin/default.nix
+++ b/pkgs/development/compilers/open-watcom-bin/default.nix
@@ -1,15 +1,62 @@
-{ stdenvNoCC, fetchurl, qemu, expect, writeScript, ncurses }:
+{ stdenvNoCC, fetchurl, qemu, expect, writeScript, writeScriptBin, ncurses, bash, coreutils }:
 
 let
 
-  # We execute the installer in qemu-user, because otherwise the
-  # installer fails to open itself due to a failed stat() call. This
-  # seems like an incompatibility of new Linux kernels to run this
-  # ancient binary.
-  performInstall = writeScript "perform-ow-install" ''
+  # We execute all OpenWatcom binaries in qemu-user, because otherwise
+  # some binaries (most notably the installer itself and wlib) fail to
+  # use the stat() systemcall. The failure mode is that it returns
+  # EOVERFLOW for completely legitimate requests. This seems like an
+  # incompatibility of new Linux kernels to run this ancient binary.
+  wrapLegacyBinary = writeScript "wrapLegacyBinary" ''
+    #!${bash}/bin/bash
+
+    set -eu
+
+    if [ $# -ne 2 ]; then
+       echo "Usage: $0 unwrapped-binary wrapped-binary"
+       exit 1
+    fi
+
+    IN="$(${coreutils}/bin/realpath $1)"
+    OUT="$2"
+    ARGV0="$(basename $2)"
+
+    cat > "$OUT" <<EOF
+    #!${bash}/bin/bash
+
+    TERMINFO=${ncurses}/share/terminfo TERM=vt100 exec ${qemu}/bin/qemu-i386 -0 $ARGV0 $IN "\$@"
+    EOF
+
+    chmod +x "$OUT"
+  '';
+
+  wrapInPlace = writeScriptBin "wrapInPlace" ''
+    #!${bash}/bin/bash
+
+    set -eu
+
+    if [ $# -ne 1 ]; then
+       echo "Usage: $0 unwrapped-binary"
+       exit 1
+    fi
+
+    TARGET="$1"
+
+    mv "$TARGET" "$TARGET-unwrapped"
+    chmod +x "$TARGET-unwrapped"
+
+    exec ${wrapLegacyBinary} "$TARGET-unwrapped" "$TARGET"
+  '';
+
+  # Do a scripted installation of OpenWatcom with its original installer.
+  #
+  # If maintaining this expect script turns out to be too much of a
+  # hassle, we can switch to just using `unzip' on the installer and
+  # the correct file permissions manually.
+  performInstall = writeScriptBin "performInstall" ''
     #!${expect}/bin/expect -f
 
-    spawn env TERMINFO=${ncurses}/share/terminfo TERM=vt100 ${qemu}/bin/qemu-i386 [lindex $argv 0]
+    spawn [lindex $argv 0]
 
     # Wait for button saying "I agree" with escape sequences.
     expect "gree"
@@ -46,15 +93,23 @@ stdenvNoCC.mkDerivation rec {
     sha256 = "1wzkvc6ija0cjj5mcyjng5b7hnnc5axidz030c0jh05pgvi4nj7p";
   };
 
+  nativeBuildInputs = [ wrapInPlace performInstall ];
+
   dontUnpack = true;
-  dontBuild = true;
   dontConfigure = true;
 
+  buildPhase = ''
+    cp ${src} install-bin-unwrapped
+    wrapInPlace install-bin-unwrapped
+  '';
+
   installPhase = ''
-    cp ${src} install-bin
-    chmod +x install-bin
+    performInstall ./install-bin-unwrapped
 
-    ${performInstall} install-bin
+    for e in $(find $out/binl -type f -executable); do
+      echo "Wrapping $e"
+      wrapInPlace "$e"
+    done
   '';
 
   meta = with stdenvNoCC.lib; {