Add the "notdef" value when no else-part is defined.

Remove the "notdef" values from the user-defined values.

svn path=/nixpkgs/trunk/; revision=13840
This commit is contained in:
Nicolas Pierron 2009-01-25 00:31:33 +00:00
parent 57f66db54c
commit 9581664fb9

View File

@ -403,6 +403,10 @@ rec {
}; };
isNotdef = attrs: (typeOf attrs) == "notdef";
mkNotdef = {_type = "notdef";};
isThenElse = attrs: (typeOf attrs) == "then-else"; isThenElse = attrs: (typeOf attrs) == "then-else";
mkThenElse = attrs: mkThenElse = attrs:
assert attrs ? thenPart && attrs ? elsePart; assert attrs ? thenPart && attrs ? elsePart;
@ -434,8 +438,7 @@ rec {
rmIf = pushIf (condition: val: val); rmIf = pushIf (condition: val: val);
evalIf = pushIf (condition: val: evalIf = pushIf (condition: val:
# guess: empty else part. if condition then val else mkNotdef
ifEnable condition val
); );
delayIf = pushIf (condition: val: delayIf = pushIf (condition: val:
@ -511,18 +514,33 @@ rec {
if all __isAttrs opts then if all __isAttrs opts then
zip (attr: opts: zip (attr: opts:
let let
# Compute the path to reach the attribute.
name = if path == "" then attr else path + "." + attr; name = if path == "" then attr else path + "." + attr;
# Divide the definitions of the attribute "attr" between
# declaration (isOption) and definitions (!isOption).
test = partition isOption opts; test = partition isOption opts;
decls = test.right; defs = test.wrong;
# Return the option declaration and add missing default
# attributes.
opt = { opt = {
inherit name; inherit name;
merge = mergeDefaultOption; merge = mergeDefaultOption;
apply = id; apply = id;
} // (head test.right); } // (head decls);
# Return the list of option sets.
optAttrs = map delayIf defs;
# return the list of option values.
# Remove undefined values that are coming from evalIf.
optValues = filter (x: !isNotdef x) (map evalIf defs);
in in
if test.right == [] then handleOptionSets optionHandler name (map delayIf test.wrong) if decls == [] then handleOptionSets optionHandler name optAttrs
else addLocation "while evaluating the option ${name}:" ( else addLocation "while evaluating the option ${name}:" (
if tail test.right != [] then throw "Multiple options." if tail decls != [] then throw "Multiple options."
else export opt (map evalIf test.wrong) else export opt optValues
) )
) opts ) opts
else addLocation "while evaluating ${path}:" (notHandle opts); else addLocation "while evaluating ${path}:" (notHandle opts);