1
1
mirror of https://github.com/nmattia/snack.git synced 2024-11-24 12:16:17 +03:00

Allow multiple source directories

This commit is contained in:
Nicolas Mattia 2018-11-18 13:59:53 +04:00
parent 1337e52094
commit ed7f604ecf
4 changed files with 42 additions and 17 deletions

View File

@ -40,7 +40,7 @@ let
libraryModSpecs = pkgSpec:
let
moduleSpecFold' = modSpecFoldFromPackageSpec pkgSpec;
modNames = listModulesInDir pkgSpec.packageBase;
modNames = pkgs.lib.concatMap listModulesInDir pkgSpec.packageSourceDirs;
fld = moduleSpecFold' modSpecs';
modSpecs' = foldDAG fld modNames;
modSpecs = builtins.attrValues modSpecs';

View File

@ -37,7 +37,13 @@ in
packageLib = withAttr package "library" null (component:
{ src =
let base = builtins.dirOf packageYaml;
in builtins.toPath "${builtins.toString base}/${component.source-dirs}";
in
if builtins.isList component.source-dirs
then builtins.map (sourceDir:
builtins.toPath "${builtins.toString base}/${sourceDir}"
) component.source-dirs
else
builtins.toPath "${builtins.toString base}/${component.source-dirs}";
dependencies = topDeps ++ mkDeps component;
extensions = topExtensions ++ (optAttr component "extensions" []);
}
@ -55,9 +61,14 @@ in
in
{ main = fileToModule component.main;
src =
let
base = builtins.dirOf packageYaml;
in builtins.toPath "${builtins.toString base}/${component.source-dirs}";
let base = builtins.dirOf packageYaml;
in
if builtins.isList component.source-dirs
then builtins.map (sourceDir:
builtins.toPath "${builtins.toString base}/${sourceDir}"
) component.source-dirs
else
builtins.toPath "${builtins.toString base}/${component.source-dirs}";
dependencies = topDeps ++ dropVersionBounds depOrPack.wrong;
extensions = topExtensions ++ (optAttr component "extensions" []);
packages = map (_: packageLib) depOrPack.right;

View File

@ -100,8 +100,8 @@ rec {
modSpecFoldFromPackageSpec = pkgSpec:
let
baseByModuleName = modName:
let res = pkgSpecByModuleName pkgSpec null modName;
in if res == null then null else res.packageBase;
let res = pkgSpecAndBaseByModuleName pkgSpec modName;
in if res == null then null else res.base;
depsByModuleName = modName:
(pkgSpecByModuleName
pkgSpec

View File

@ -18,7 +18,10 @@ rec {
, packages ? []
}:
{ packageMain = main;
packageBase = src;
packageSourceDirs =
if builtins.isList src
then src
else [src];
packageGhcOpts = ghcOpts;
packageExtensions = extensions;
packageDependencies = mkPerModuleAttr dependencies;
@ -45,14 +48,25 @@ rec {
# Traverses all transitive packages and returns the first package spec that
# contains a module with given name. If none is found, returns the supplied
# default value.
pkgSpecByModuleName = topPkgSpec: def: modName:
( lib.findFirst
pkgSpecAndBaseByModuleName = topPkgSpec: modName:
let
foo = pkgSpec:
lib.findFirst
(base: lib.lists.elem modName (listModulesInDir base))
null
pkgSpec.packageSourceDirs;
bar = lib.concatMap
(pkgSpec:
lib.lists.elem
modName
(listModulesInDir pkgSpec.packageBase)
)
def
(flattenPackages topPkgSpec)
);
let base = foo pkgSpec;
in if base == null then [] else [ { inherit pkgSpec base; } ])
(flattenPackages topPkgSpec);
in if lib.length bar <= 0 then null else
if lib.length bar == 1 then lib.head bar
else abort
"Refusing to return base, module name was found more than once: ${modName}";
pkgSpecByModuleName = topPkgSpec: def: modName:
let
res = pkgSpecAndBaseByModuleName topPkgSpec modName;
in if res == null then def else res.pkgSpec;
}