Skip to content

Commit 6e9f843

Browse files
committed
Silence warnings from linker when run from doctest
``` clang: warning: argument unused during compilation: '-no-pie' [-Wunused-command-line-argument] tests/haskell_doctest/Bar.hs:11: failure in expression `bar' expected: 9 but got: ld: warning: -undefined dynamic_lookup may not work with chained fixups ^ 9 Examples: 3 Tried: 2 Errors: 0 Failures: 1 ``` If the linker writes some output to stderr, this interferes with the expected output in the doctest. Note, that if the linker fails, the output will be written to stdout/stderr in any case.
1 parent faf7eec commit 6e9f843

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

haskell/doctest.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ def _haskell_doctest_single(target, ctx):
148148
{env}
149149
# doctest needs PATH to call GHC and the C compiler and linker.
150150
export PATH
151+
# signal our cc_wrapper to silence linker outputs as GHC < 9.4 writes that to
152+
# the GHCI ouput which interferes with doctest's expected ouput
153+
export RULES_HASKELL_SILENCE_LINKER=1
151154
{doctest} "$@" {inputs} > {output} 2>&1 || (rc=$? && cat {output} && exit $rc)
152155
""".format(
153156
doctest = toolchain.doctest[0].path,

haskell/private/cc_wrapper.py.tpl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,10 @@ def link(output, libraries, rpaths, args):
570570
rpaths = shorten_rpaths(rpaths, libraries, output)
571571

572572
args.extend(rpath_args(rpaths))
573-
run_cc(args, exit_on_error=True)
573+
# Note: `RULES_HASKELL_SILENCE_LINKER` is only set if called from doctest,
574+
# which is used to silence the linker output to not interfere with the output
575+
# from GHCi
576+
run_cc(args, capture_output="RULES_HASKELL_SILENCE_LINKER" in os.environ, exit_on_error=True)
574577

575578
if is_darwin():
576579
darwin_rewrite_load_commands(darwin_rewrites, output)

0 commit comments

Comments
 (0)