1
1
mirror of https://github.com/nmattia/snack.git synced 2024-08-16 07:10:57 +03:00

Use ghc-options in HPack

This commit is contained in:
Nicolas Mattia 2019-01-31 18:59:25 +01:00
parent 443bb89c5b
commit 5d4bada51d
6 changed files with 44 additions and 1 deletions

View File

@ -34,6 +34,7 @@ in
mkDeps = obj: dropVersionBounds (optAttr obj "dependencies" []);
topDeps = mkDeps package;
topExtensions = optAttr package "default-extensions" [];
topGhcOpts = optAttr package "ghc-options" [];
packageLib = withAttr package "library" null (component:
{ src =
let
@ -48,6 +49,7 @@ in
builtins.toPath "${builtins.toString base}/${source-dirs}";
dependencies = topDeps ++ mkDeps component;
extensions = topExtensions ++ (optAttr component "extensions" []);
ghcOpts = topGhcOpts ++ (optAttr component "ghc-options" []);
}
);
@ -76,7 +78,8 @@ in
builtins.toPath "${builtins.toString base}/${source-dirs}";
dependencies = topDeps ++ dropVersionBounds depOrPack.wrong;
extensions = topExtensions ++ (optAttr component "extensions" []);
packages = map (_: packageLib) depOrPack.right;
ghcOpts = topGhcOpts ++ (optAttr component "ghc-options" []);
packages = map (_: packageLib) depOrPack.right;
};
in
{ library = packageLib;

View File

@ -0,0 +1,5 @@
module Main where
import Data.Text
main = putStrLn $ unpack "hello"

1
tests/ghc-options/golden Normal file
View File

@ -0,0 +1 @@
hello

View File

@ -0,0 +1,5 @@
{ main = "Main";
src = ./.;
dependencies = [ "text" ];
ghcOpts = ["-XOverloadedStrings"];
}

View File

@ -0,0 +1,9 @@
name: snack-extensions-test
ghc-options:
- -XOverloadedStrings
dependencies:
- text
executable:
main: Main.hs
source-dirs: .

20
tests/ghc-options/test Executable file
View File

@ -0,0 +1,20 @@
#!/usr/bin/env bash
# vim: ft=sh sw=2 et
set -euo pipefail
test() {
$SNACK build
$SNACK run | diff golden -
TMP_FILE=$(mktemp)
capture_io "$TMP_FILE" main | $SNACK ghci
diff golden $TMP_FILE
rm $TMP_FILE
}
SNACK="snack --package-file ./package.nix" test
SNACK="snack --package-file ./package.nix -l ../../snack-lib" test
SNACK="snack --package-file ./package.yaml" test