1
1
mirror of https://github.com/nmattia/snack.git synced 2024-12-01 03:03:55 +03:00

Factor out module spec from main

This commit is contained in:
Nicolas Mattia 2018-06-23 14:43:02 +02:00
parent 4facdfb869
commit a9d94fba25

View File

@ -194,39 +194,44 @@ let
'';
traceType = x: builtins.trace (builtins.typeOf x) x;
executable = pkgDescr:
let
topPkgSpec = mkPackageSpec pkgDescr;
baseByModuleName = modName:
let res = pkgSpecByModuleName topPkgSpec null modName;
in if res == null then null else res.packageBase;
# Takes a package spec and returns (modSpecs -> Fold)
modSpecFoldFromPackageSpec = pkgSpec:
let
baseByModuleName = modName:
let res = pkgSpecByModuleName pkgSpec null modName;
in if res == null then null else res.packageBase;
depsByModuleName = modName:
(pkgSpecByModuleName
topPkgSpec
pkgSpec
(abort "asking dependencies for external module: ${modName}")
modName).packageDependencies
modName
;
ghcOptsByModuleName = modName:
(pkgSpecByModuleName
topPkgSpec
pkgSpec
(abort "asking ghc options for external module: ${modName}")
modName).packageGhcOpts;
base = pkgSpec.packageBase;
extraFiles = pkgSpec.packageExtraFiles;
extraDirs = pkgSpec.packageExtraDirectories;
in
moduleSpecFold
{ baseByModuleName = baseByModuleName;
filesByModuleName = extraFiles;
dirsByModuleName = extraDirs;
depsByModuleName = depsByModuleName;
ghcOptsByModuleName = ghcOptsByModuleName;
};
executable = pkgDescr:
let
moduleSpecFold' = modSpecFoldFromPackageSpec topPkgSpec;
topPkgSpec = mkPackageSpec pkgDescr;
ghcWith = deps: haskellPackages.ghcWithPackages
(ps: map (p: ps.${p}) deps);
base = topPkgSpec.packageBase;
extraFiles = topPkgSpec.packageExtraFiles;
extraDirs = topPkgSpec.packageExtraDirectories;
mainModName = topPkgSpec.packageMain;
moduleSpecFold' = moduleSpecFold
{ baseByModuleName = baseByModuleName;
filesByModuleName = extraFiles;
dirsByModuleName = extraDirs;
depsByModuleName = depsByModuleName;
ghcOptsByModuleName = ghcOptsByModuleName;
} ;
topModuleSpec =
let
fld = moduleSpecFold' modSpecs;