mirror of
https://github.com/nmattia/snack.git
synced 2024-09-11 11:55:36 +03:00
Add support for package extensions
This commit is contained in:
parent
eea3e08843
commit
21d49b86f0
@ -80,6 +80,11 @@ pushd tests/library-2
|
||||
./test
|
||||
popd
|
||||
|
||||
banner "Test extensions"
|
||||
pushd tests/extensions
|
||||
./test
|
||||
popd
|
||||
|
||||
banner "Test stack-exe formatting"
|
||||
list=$(shfmt -i 2 -l bin/snack)
|
||||
if [[ -n "$list" ]]; then
|
||||
|
@ -25,7 +25,8 @@ let
|
||||
buildModule = ghcWith: modSpec:
|
||||
let
|
||||
ghc = ghcWith modSpec.moduleDependencies;
|
||||
ghcOpts = modSpec.moduleGhcOpts;
|
||||
exts = modSpec.moduleExtensions;
|
||||
ghcOpts = modSpec.moduleGhcOpts ++ (map (x: "-X${x}") exts);
|
||||
ghcOptsArgs = lib.strings.escapeShellArgs ghcOpts;
|
||||
objectName = modSpec.moduleName;
|
||||
builtDeps = map (buildModule ghcWith) modSpec.moduleImports;
|
||||
@ -154,7 +155,8 @@ let
|
||||
|
||||
ghciWithModules = ghcWith: modSpecs:
|
||||
let
|
||||
ghcOpts = allTransitiveGhcOpts modSpecs;
|
||||
ghcOpts = allTransitiveGhcOpts modSpecs
|
||||
++ (map (x: "-X${x}") (allTransitiveExtensions modSpecs));
|
||||
ghc = ghcWith (allTransitiveDeps modSpecs);
|
||||
ghciArgs = lib.strings.escapeShellArgs
|
||||
(ghcOpts ++ absoluteModuleFiles);
|
||||
@ -213,6 +215,11 @@ let
|
||||
modName).packageDependencies
|
||||
modName
|
||||
;
|
||||
extsByModuleName = modName:
|
||||
(pkgSpecByModuleName
|
||||
pkgSpec
|
||||
(abort "asking extensions for external module: ${modName}")
|
||||
modName).packageExtensions;
|
||||
ghcOptsByModuleName = modName:
|
||||
(pkgSpecByModuleName
|
||||
pkgSpec
|
||||
@ -224,6 +231,7 @@ let
|
||||
filesByModuleName = pkgSpec.packageExtraFiles;
|
||||
dirsByModuleName = pkgSpec.packageExtraDirectories;
|
||||
depsByModuleName = depsByModuleName;
|
||||
extsByModuleName = extsByModuleName;
|
||||
ghcOptsByModuleName = ghcOptsByModuleName;
|
||||
};
|
||||
|
||||
|
@ -15,6 +15,7 @@ rec {
|
||||
modDirs:
|
||||
modBase:
|
||||
modDeps:
|
||||
modExts:
|
||||
modGhcOpts:
|
||||
{ moduleName = modName;
|
||||
|
||||
@ -29,6 +30,7 @@ rec {
|
||||
then modDeps
|
||||
else abort "module dependencies should be a list";
|
||||
moduleGhcOpts = modGhcOpts;
|
||||
moduleExtensions = modExts;
|
||||
};
|
||||
|
||||
|
||||
@ -37,6 +39,7 @@ rec {
|
||||
, filesByModuleName
|
||||
, dirsByModuleName
|
||||
, depsByModuleName
|
||||
, extsByModuleName
|
||||
, ghcOptsByModuleName
|
||||
}:
|
||||
result:
|
||||
@ -56,6 +59,7 @@ rec {
|
||||
(dirsByModuleName modName)
|
||||
(baseByModuleName modName)
|
||||
(depsByModuleName modName)
|
||||
(extsByModuleName modName)
|
||||
(ghcOptsByModuleName modName);
|
||||
};
|
||||
empty = {} ;
|
||||
@ -71,6 +75,7 @@ rec {
|
||||
|
||||
allTransitiveDeps = allTransitiveLists "moduleDependencies" lib.id;
|
||||
allTransitiveGhcOpts = allTransitiveLists "moduleGhcOpts" lib.id;
|
||||
allTransitiveExtensions = allTransitiveLists "moduleExtensions" lib.id;
|
||||
allTransitiveDirectories =
|
||||
allTransitiveLists
|
||||
"moduleDirectories"
|
||||
|
@ -13,6 +13,7 @@ rec {
|
||||
, main ? null
|
||||
, ghcOpts ? []
|
||||
, dependencies ? []
|
||||
, extensions ? []
|
||||
, extra-files ? []
|
||||
, extra-directories ? []
|
||||
, packages ? []
|
||||
@ -20,6 +21,7 @@ rec {
|
||||
{ packageMain = main;
|
||||
packageBase = src;
|
||||
packageGhcOpts = ghcOpts;
|
||||
packageExtensions = extensions;
|
||||
packageDependencies = mkPerModuleAttr dependencies;
|
||||
|
||||
# TODO: merge extra files and extra dirs together
|
||||
|
5
tests/extensions/Main.hs
Normal file
5
tests/extensions/Main.hs
Normal file
@ -0,0 +1,5 @@
|
||||
module Main where
|
||||
|
||||
import Data.Text
|
||||
|
||||
main = putStrLn $ unpack "hello"
|
1
tests/extensions/golden
Normal file
1
tests/extensions/golden
Normal file
@ -0,0 +1 @@
|
||||
hello
|
5
tests/extensions/snack.nix
Normal file
5
tests/extensions/snack.nix
Normal file
@ -0,0 +1,5 @@
|
||||
{ main = "Main";
|
||||
src = ./.;
|
||||
dependencies = [ "text" ];
|
||||
extensions = [ "OverloadedStrings" ];
|
||||
}
|
14
tests/extensions/test
Executable file
14
tests/extensions/test
Executable file
@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
# vim: ft=sh sw=2 et
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
$SNACK build
|
||||
$SNACK run | diff golden -
|
||||
|
||||
TMP_FILE=$(mktemp)
|
||||
|
||||
capture_io "$TMP_FILE" main | $SNACK ghci
|
||||
|
||||
diff golden $TMP_FILE
|
||||
rm $TMP_FILE
|
Loading…
Reference in New Issue
Block a user