mirror of
https://github.com/nmattia/snack.git
synced 2024-08-16 07:10:57 +03:00
Add mainModule in spec to allow -main-is compiling
This commit is contained in:
parent
05d8cfe0b7
commit
a76301a911
@ -18,11 +18,11 @@ rec {
|
||||
# Returns an attribute set where the keys are all the built module names and
|
||||
# the values are the paths to the object files.
|
||||
# mainModSpec: a "main" module
|
||||
buildMain = ghcWith: mainModSpec:
|
||||
buildMain = ghcWith: mainModSpec: mainModName:
|
||||
buildModulesRec ghcWith
|
||||
# XXX: the main modules need special handling regarding the object name
|
||||
{ "${mainModSpec.moduleName}" =
|
||||
"${buildModule ghcWith mainModSpec}/Main.o";}
|
||||
"${buildModule ghcWith mainModSpec}/${mainModName}.o";}
|
||||
mainModSpec.moduleImports;
|
||||
|
||||
# returns a attrset where the keys are the module names and the values are
|
||||
@ -34,9 +34,10 @@ rec {
|
||||
{ ghcWith
|
||||
, moduleSpec # The module to build
|
||||
, name # The name to give the executable
|
||||
, mainModName
|
||||
}:
|
||||
let
|
||||
objAttrs = buildMain ghcWith moduleSpec;
|
||||
objAttrs = buildMain ghcWith moduleSpec mainModName;
|
||||
objList = lib.attrsets.mapAttrsToList (x: y: y) objAttrs;
|
||||
deps = allTransitiveDeps [moduleSpec];
|
||||
ghc = ghcWith deps;
|
||||
|
@ -46,7 +46,8 @@ with rec
|
||||
let
|
||||
moduleSpec = executableMainModSpec pkgSpec;
|
||||
name = pkgSpec.packageName;
|
||||
drv = linkMainModule { inherit moduleSpec name ghcWith; };
|
||||
mainModName = pkgSpec.packageMainModule;
|
||||
drv = linkMainModule { inherit moduleSpec name ghcWith mainModName; };
|
||||
in
|
||||
{ out = drv.out;
|
||||
exe_path = "${drv.out}/${drv.relExePath}";
|
||||
|
@ -11,6 +11,7 @@ rec {
|
||||
{ src ? []
|
||||
, name ? null
|
||||
, main ? null
|
||||
, mainModule ? "Main"
|
||||
, ghcOpts ? []
|
||||
, dependencies ? []
|
||||
, extensions ? []
|
||||
@ -29,11 +30,20 @@ rec {
|
||||
{ packageIsExe = ! builtins.isNull main;
|
||||
packageName = pName;
|
||||
packageMain = main;
|
||||
packageMainModule = mainModule;
|
||||
packageSourceDirs =
|
||||
if builtins.isList src
|
||||
then src
|
||||
else [src];
|
||||
packageGhcOpts = ghcOpts;
|
||||
packageGhcOpts = let
|
||||
addition =
|
||||
if mainModule == "Main"
|
||||
then
|
||||
[]
|
||||
else
|
||||
["-main-is" mainModule];
|
||||
in
|
||||
ghcOpts ++ addition;
|
||||
packageExtensions = extensions;
|
||||
packageDependencies = mkPerModuleAttr dependencies;
|
||||
|
||||
|
12
tests/main-is-different/Spec.hs
Normal file
12
tests/main-is-different/Spec.hs
Normal file
@ -0,0 +1,12 @@
|
||||
{-|
|
||||
Copyright:
|
||||
© 2018 Nicolas Mattia
|
||||
-}
|
||||
module Spec
|
||||
( main
|
||||
) where
|
||||
|
||||
import Numeric.Natural (Natural)
|
||||
|
||||
main :: IO ()
|
||||
main = putStrLn "hello, test!"
|
1
tests/main-is-different/golden
Normal file
1
tests/main-is-different/golden
Normal file
@ -0,0 +1 @@
|
||||
hello, test!
|
4
tests/main-is-different/package.nix
Normal file
4
tests/main-is-different/package.nix
Normal file
@ -0,0 +1,4 @@
|
||||
{ main = "Spec";
|
||||
mainModule = "Spec";
|
||||
src = ./.;
|
||||
}
|
18
tests/main-is-different/test
Executable file
18
tests/main-is-different/test
Executable file
@ -0,0 +1,18 @@
|
||||
#!/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
|
Loading…
Reference in New Issue
Block a user