Allow using tagetContents for modules needing preprocessing
authorDaniel Gröber <dxld@darkboxed.org>
Mon, 20 May 2019 09:58:55 +0000 (11:58 +0200)
committerMarge Bot <ben+marge-bot@smart-cactus.org>
Wed, 29 May 2019 14:41:02 +0000 (10:41 -0400)
commit5b90e0a173f69c9babb3201f62cd5096798c5240
tree3055ef0fd6120a8e305cdd4c71d2f44c41831fd7
parentcc0d05a78c3c731c771aaadd29c2c5c8d772d619
Allow using tagetContents for modules needing preprocessing

This allows GHC API clients, most notably tooling such as
Haskell-IDE-Engine, to pass unsaved files to GHC more easily.

Currently when targetContents is used but the module requires preprocessing
'preprocessFile' simply throws an error because the pipeline does not
support passing a buffer.

This change extends `runPipeline` to allow passing the input buffer into
the pipeline. Before proceeding with the actual pipeline loop the input
buffer is immediately written out to a new tempfile.

I briefly considered refactoring the pipeline at large to pass around
in-memory buffers instead of files, but this seems needlessly complicated
since no pipeline stages other than Hsc could really support this at the
moment.
compiler/main/DriverPipeline.hs
compiler/main/GhcMake.hs
compiler/main/HscTypes.hs
testsuite/tests/ghc-api/target-contents/TargetContents.hs [new file with mode: 0644]
testsuite/tests/ghc-api/target-contents/TargetContents.stderr [new file with mode: 0644]
testsuite/tests/ghc-api/target-contents/all.T [new file with mode: 0644]