Add location to declared sub-modules.

svn path=/nixpkgs/trunk/; revision=17252
This commit is contained in:
Nicolas Pierron 2009-09-18 15:10:05 +00:00
parent a727aa8d8b
commit e07f5d2a2c
2 changed files with 30 additions and 21 deletions

View File

@ -54,9 +54,10 @@ rec {
removeAttrs (delayProperties m) ["require"]; removeAttrs (delayProperties m) ["require"];
in in
if isModule m then if isModule m then
m { key = "<unknow location>"; } // m
else else
{ {
key = "<unknow location>";
imports = getImportedPaths m; imports = getImportedPaths m;
config = getConfig m; config = getConfig m;
} // ( } // (
@ -72,8 +73,7 @@ rec {
moduleImport = m: moduleImport = m:
(unifyModuleSyntax (applyIfFunction (importIfPath m) args)) // { (unifyModuleSyntax (applyIfFunction (importIfPath m) args)) // {
# used by generic closure to avoid duplicated imports. # used by generic closure to avoid duplicated imports.
key = if isPath m then m else key = if isPath m then m else "<unknow location>";
/bad/developer/implies/bad/error/messages;
}; };
getImports = m: attrByPath ["imports"] [] m; getImports = m: attrByPath ["imports"] [] m;
@ -188,9 +188,25 @@ rec {
moduleZip { moduleZip {
options = lib.zip (name: values: options = lib.zip (name: values:
if any isOption values then if any isOption values then
let
# locations to sub-options declarations
decls =
map (m:
mapSubOptions (subModule:
let module = lib.applyIfFunction subModule {}; in
if lib.isModule module then
{ inherit (m) key; } // subModule
else
args: {
inherit (m) key;
options = lib.applyIfFunction subModule args;
}
) m.options
) (declarationsOf name);
in
addOptionMakeUp addOptionMakeUp
{ name = addName name; recurseInto = recurseForOption; } { name = addName name; recurseInto = recurseForOption; }
(mergeOptionDecls values) (mergeOptionDecls decls)
else if all isAttrs values then else if all isAttrs values then
(recurseInto name modules).options (recurseInto name modules).options
else else

View File

@ -27,6 +27,14 @@ rec {
# options (set of sub-options declarations & definitions) # options (set of sub-options declarations & definitions)
}; };
mapSubOptions = f: opt:
if opt ? options then
opt // {
options = map f (toList opt.options);
}
else
opt;
# Make the option declaration more user-friendly by adding default # Make the option declaration more user-friendly by adding default
# settings and some verifications based on the declaration content (like # settings and some verifications based on the declaration content (like
# type correctness). # type correctness).
@ -68,20 +76,6 @@ rec {
} }
else opt; else opt;
convertOptionsToModules = opt:
if opt ? options then
opt // {
options = map (decl:
let module = lib.applyIfFunction decl {}; in
if lib.isModule module then
decl
else
arg: { options = lib.applyIfFunction decl arg; }
) opt.options;
}
else
opt;
handleOptionSets = opt: handleOptionSets = opt:
if decl ? type && decl.type.hasOptions then if decl ? type && decl.type.hasOptions then
let let
@ -119,7 +113,6 @@ rec {
# override settings # override settings
ensureMergeInputType ensureMergeInputType
ensureDefaultType ensureDefaultType
convertOptionsToModules
handleOptionSets handleOptionSets
]; ];