From b84950ccb799d2284dee675bdbd11f753231e601 Mon Sep 17 00:00:00 2001 From: Michael Peyton Jones Date: Tue, 22 Jan 2019 14:46:28 +0000 Subject: [PATCH] Make the Plutus Tx plugin an internal library The documentation for `addCorePlugin` says it has to be in a separate package to the plugin. However it appears that in GHC's eyes internal libraries in a Cabal package are separate packages, so we can hide all of this in a single package, which is much nicer. We can then organize things a bit more neatly inside. We then have to do some shennanigans to get doctest to work. The normal tests work fine, since Cabal registers the built internal library as a package, and that's fine. But doctest interprets things, which *doesn't* work. Now, I initially tried to just pass the appropriate `-package-db` arguments to `doctest`, but in doing so I hit what appears to be a [Cabal bug with internal libraries](https://github.com/haskell/cabal/issues/5857). However, somehow `cabal repl` and friends seem to get around this, and fortunately there is now a `cabal doctest` command, which amazingly also seems to pass the right set of obscure flags. So we use that. Finally, in an extremely irritating discovery, apparently [Haddock doesn't work with internal libraries] (https://github.com/haskell/cabal/issues/4969) (possibly fixed in a newer Cabal, who knows), so I ended up having to exclude `plutus-tx` from Haddock generation for now. --- nix/overlays/required.nix | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/nix/overlays/required.nix b/nix/overlays/required.nix index d351c0ba76..b86c80fa0b 100644 --- a/nix/overlays/required.nix +++ b/nix/overlays/required.nix @@ -7,15 +7,20 @@ let addRealTimeTestLogs = drv: overrideCabal drv (attrs: { testTarget = "--show-details=streaming"; }); + doctest = opts: drv: overrideCabal drv (attrs: { + postCheck = "./Setup doctest --doctest-options=\"${opts}\""; + }); in self: super: { ######################################################################## # Overides of local packages + language-plutus-core = addRealTimeTestLogs super.language-plutus-core; + # cabal doctest doesn't seem to be clever enough to pick these up from the cabal file + plutus-tx = doctest "-pgmL markdown-unlit -XTemplateHaskell -XDeriveFunctor -XScopedTypeVariables" super.plutus-tx; ######################################################################## - language-plutus-core = addRealTimeTestLogs super.language-plutus-core; # The base Haskell package builder mkDerivation = args: super.mkDerivation (args //