From aa6327c3f630c9b7b7ceef8d07f3a57ca03cccf1 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Tue, 14 Jun 2022 19:12:53 +0200 Subject: Early-catch large show output with -interactive-print --- bwrap-files/entry.sh | 6 ------ bwrap-files/start.sh | 6 +++--- bwrap-files/workdir/Yahb2Defs.hs | 8 ++++++++ bwrap-files/workdir/entry.sh | 6 ++++++ src/Ghci.hs | 3 +++ 5 files changed, 20 insertions(+), 9 deletions(-) delete mode 100755 bwrap-files/entry.sh create mode 100644 bwrap-files/workdir/Yahb2Defs.hs create mode 100755 bwrap-files/workdir/entry.sh diff --git a/bwrap-files/entry.sh b/bwrap-files/entry.sh deleted file mode 100755 index f9c4ad3..0000000 --- a/bwrap-files/entry.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -set -euo pipefail - -cd "$(dirname "$0")" - -ghcup --offline run -- ghci 2>&1 diff --git a/bwrap-files/start.sh b/bwrap-files/start.sh index 03bf77e..f0d0fa1 100755 --- a/bwrap-files/start.sh +++ b/bwrap-files/start.sh @@ -20,6 +20,7 @@ args=( --ro-bind "${ghcup_base}/bin" "${ghcup_base}/bin" --ro-bind "${ghcup_base}/ghc" "${ghcup_base}/ghc" --ro-bind "${ghcup_base}/cache" "${ghcup_base}/cache" + --ro-bind "${filesdir}/workdir" /workdir --setenv PATH "/bin:/usr/bin:${ghcup_base}/bin" --setenv GHCUP_INSTALL_BASE_PREFIX "$(dirname ${ghcup_base})" --proc /proc @@ -27,8 +28,7 @@ args=( --new-session --unshare-all --die-with-parent - --file 4 "/tmp/entry.sh" - /bin/bash "/tmp/entry.sh" + /bin/bash "/workdir/entry.sh" ) # Turn off core files @@ -40,4 +40,4 @@ ulimit -u 10000 # Limit memory to 500 MiB. ulimit -d $(( 500 * 1024 )) -exec bwrap "${args[@]}" 4<"${filesdir}/entry.sh" +exec bwrap "${args[@]}" diff --git a/bwrap-files/workdir/Yahb2Defs.hs b/bwrap-files/workdir/Yahb2Defs.hs new file mode 100644 index 0000000..c0dfbfd --- /dev/null +++ b/bwrap-files/workdir/Yahb2Defs.hs @@ -0,0 +1,8 @@ +module Yahb2Defs where + + +limitedPrint :: Show a => a -> IO () +limitedPrint x = + case splitAt 200 (show x) of + (s, "") -> putStrLn s + (s, _) -> putStrLn (take 197 s ++ "...") diff --git a/bwrap-files/workdir/entry.sh b/bwrap-files/workdir/entry.sh new file mode 100755 index 0000000..1a466da --- /dev/null +++ b/bwrap-files/workdir/entry.sh @@ -0,0 +1,6 @@ +#!/bin/bash +set -euo pipefail + +cd "$(dirname "$0")" + +ghcup --offline run -- ghci Yahb2Defs.hs 2>&1 diff --git a/src/Ghci.hs b/src/Ghci.hs index 13eb4ca..649403f 100644 --- a/src/Ghci.hs +++ b/src/Ghci.hs @@ -47,6 +47,9 @@ makeGhci = do , std_in = CreatePipe , std_out = UseHandle pipeIn , std_err = UseHandle pipeIn } + hPutStrLn stdinH ":set -interactive-print=Yahb2Defs.limitedPrint" + hPutStrLn stdinH ":m" + hFlush stdinH return Ghci { ghciProc = proch , ghciStdin = stdinH , ghciStdout = pipeOut } -- cgit v1.2.3