* Backward compatibility with Nix 0.10.
svn path=/nixpkgs/trunk/; revision=9449
This commit is contained in:
parent
77a46300fa
commit
2243a1f496
@ -3,7 +3,8 @@
|
|||||||
let
|
let
|
||||||
|
|
||||||
inherit (builtins)
|
inherit (builtins)
|
||||||
head tail isList stringLength substring lessThan sub listToAttrs;
|
head tail isList stringLength substring lessThan sub
|
||||||
|
listToAttrs attrNames hasAttr;
|
||||||
|
|
||||||
in
|
in
|
||||||
|
|
||||||
@ -183,7 +184,7 @@ rec {
|
|||||||
name (tail (tail list)) checker;
|
name (tail (tail list)) checker;
|
||||||
|
|
||||||
# calls a function (f attr value ) for each record item. returns a list
|
# calls a function (f attr value ) for each record item. returns a list
|
||||||
mapRecordFlatten = f : r : map (attr: f attr (__getAttr attr r) ) (__attrNames r);
|
mapRecordFlatten = f : r : map (attr: f attr (builtins.getAttr attr r) ) (attrNames r);
|
||||||
|
|
||||||
# to be used with listToAttrs (_a_ttribute _v_alue)
|
# to be used with listToAttrs (_a_ttribute _v_alue)
|
||||||
av = attr : value : { inherit attr value; };
|
av = attr : value : { inherit attr value; };
|
||||||
@ -198,11 +199,11 @@ rec {
|
|||||||
any = f : l : fold logicalOR false (map f l);
|
any = f : l : fold logicalOR false (map f l);
|
||||||
|
|
||||||
# iterates over a list of attributes collecting the attribute attr if it exists
|
# iterates over a list of attributes collecting the attribute attr if it exists
|
||||||
catAttrs = attr : l : fold ( s : l : if (__hasAttr attr s) then [(__getAttr attr s)] ++ l else l) [] l;
|
catAttrs = attr : l : fold ( s : l : if (hasAttr attr s) then [(builtins.getAttr attr s)] ++ l else l) [] l;
|
||||||
|
|
||||||
mergeAttrs = fold ( x : y : x // y) {};
|
mergeAttrs = fold ( x : y : x // y) {};
|
||||||
|
|
||||||
flattenAttrs = set : map ( attr : __getAttr attr set) (__attrNames set);
|
flattenAttrs = set : map ( attr : builtins.getAttr attr set) (attrNames set);
|
||||||
mapIf = cond : f : fold ( x : l : if (cond x) then [(f x)] ++ l else l) [];
|
mapIf = cond : f : fold ( x : l : if (cond x) then [(f x)] ++ l else l) [];
|
||||||
|
|
||||||
# Marc 2nd proposal: (not everything has been tested in detail yet..)
|
# Marc 2nd proposal: (not everything has been tested in detail yet..)
|
||||||
@ -214,10 +215,10 @@ rec {
|
|||||||
|
|
||||||
chooseOptionsByFlags = { flagConfig, args, optionals ? [], defaults ? [],
|
chooseOptionsByFlags = { flagConfig, args, optionals ? [], defaults ? [],
|
||||||
collectExtraPhaseActions ? [] } :
|
collectExtraPhaseActions ? [] } :
|
||||||
let passedOptionals = filter ( x : __hasAttr x args ) optionals; # these are in optionals and in args
|
let passedOptionals = filter ( x : hasAttr x args ) optionals; # these are in optionals and in args
|
||||||
# we simply merge in <optional_name> = { buildInputs = <arg.<optional_name>; pass = <arg.optional_name>; }
|
# we simply merge in <optional_name> = { buildInputs = <arg.<optional_name>; pass = <arg.optional_name>; }
|
||||||
flagConfigWithOptionals = flagConfig // ( listToAttrs
|
flagConfigWithOptionals = flagConfig // ( listToAttrs
|
||||||
(map ( o : av o ( { buildInputs = o; pass = avs o (__getAttr o args); }
|
(map ( o : av o ( { buildInputs = o; pass = avs o (builtins.getAttr o args); }
|
||||||
// getAttr [o] {} flagConfig )
|
// getAttr [o] {} flagConfig )
|
||||||
)
|
)
|
||||||
passedOptionals ) );
|
passedOptionals ) );
|
||||||
@ -230,13 +231,13 @@ rec {
|
|||||||
# helper function
|
# helper function
|
||||||
collectFlags = # state : flags :
|
collectFlags = # state : flags :
|
||||||
fold ( flag : s : (
|
fold ( flag : s : (
|
||||||
if (__hasAttr flag s.result) then s # this state has already been visited
|
if (hasAttr flag s.result) then s # this state has already been visited
|
||||||
else if (! __hasAttr flag flagConfig) then throw "unkown flag `${flag}' specified"
|
else if (! hasAttr flag flagConfig) then throw "unkown flag `${flag}' specified"
|
||||||
else let fDesc = (__getAttr flag flagConfig);
|
else let fDesc = (builtins.getAttr flag flagConfig);
|
||||||
implied = flatten ( getAttr ["implies"] [] fDesc );
|
implied = flatten ( getAttr ["implies"] [] fDesc );
|
||||||
blocked = flatten ( getAttr ["blocks"] [] fDesc );
|
blocked = flatten ( getAttr ["blocks"] [] fDesc );
|
||||||
# add this flag
|
# add this flag
|
||||||
s2 = s // { result = ( setAttr s.result flag (__getAttr flag flagConfig) );
|
s2 = s // { result = ( setAttr s.result flag (builtins.getAttr flag flagConfig) );
|
||||||
blockedFlagsBy = s.blockedFlagsBy
|
blockedFlagsBy = s.blockedFlagsBy
|
||||||
// listToAttrs (map (b: av b flag ) blocked); };
|
// listToAttrs (map (b: av b flag ) blocked); };
|
||||||
# add implied flags
|
# add implied flags
|
||||||
@ -246,17 +247,17 @@ rec {
|
|||||||
# chosen contains flagConfig but only having those attributes elected by flags
|
# chosen contains flagConfig but only having those attributes elected by flags
|
||||||
# (or by implies attributes of elected attributes)
|
# (or by implies attributes of elected attributes)
|
||||||
options = let stateOpts = collectFlags { blockedFlagsBy = {}; result = {}; }
|
options = let stateOpts = collectFlags { blockedFlagsBy = {}; result = {}; }
|
||||||
(flags ++ ( if (__hasAttr "mandatory" flagConfig) then ["mandatory"] else [] ));
|
(flags ++ ( if (hasAttr "mandatory" flagConfig) then ["mandatory"] else [] ));
|
||||||
# these options have not been chosen (neither by flags nor by implies)
|
# these options have not been chosen (neither by flags nor by implies)
|
||||||
unsetOptions = filter ( x : (! __hasAttr x stateOpts.result) && (__hasAttr ("no_"+x) flagConfig))
|
unsetOptions = filter ( x : (! hasAttr x stateOpts.result) && (hasAttr ("no_"+x) flagConfig))
|
||||||
( __attrNames flagConfig );
|
( attrNames flagConfig );
|
||||||
# no add the corresponding no_ attributes as well ..
|
# no add the corresponding no_ attributes as well ..
|
||||||
state = collectFlags stateOpts (map ( x : "no_" + x ) unsetOptions);
|
state = collectFlags stateOpts (map ( x : "no_" + x ) unsetOptions);
|
||||||
in # check for blockings:
|
in # check for blockings:
|
||||||
assert ( all id ( map ( b: if (__hasAttr b state.result)
|
assert ( all id ( map ( b: if (hasAttr b state.result)
|
||||||
then throw "flag ${b} is blocked by flag ${__getAttr b state.blockedFlagsBy}"
|
then throw "flag ${b} is blocked by flag ${__getAttr b state.blockedFlagsBy}"
|
||||||
else true )
|
else true )
|
||||||
(__attrNames state.blockedFlagsBy) ) );
|
(attrNames state.blockedFlagsBy) ) );
|
||||||
state.result;
|
state.result;
|
||||||
flatOptions = flattenAttrs options;
|
flatOptions = flattenAttrs options;
|
||||||
|
|
||||||
@ -275,13 +276,13 @@ rec {
|
|||||||
# compared to flags flagsSet does also contain the implied flags.. This makes it easy to write assertions. ( assert args.
|
# compared to flags flagsSet does also contain the implied flags.. This makes it easy to write assertions. ( assert args.
|
||||||
inherit options flatOptions collectAttrs optsConcatStrs;
|
inherit options flatOptions collectAttrs optsConcatStrs;
|
||||||
|
|
||||||
buildInputs = map ( attr: if (! __hasAttr attr args) then throw "argument ${attr} is missing!" else (__getAttr attr args) )
|
buildInputs = map ( attr: if (! hasAttr attr args) then throw "argument ${attr} is missing!" else (builtins.getAttr attr args) )
|
||||||
(flatten (catAttrs "buildInputs" flatOptions));
|
(flatten (catAttrs "buildInputs" flatOptions));
|
||||||
|
|
||||||
configureFlags = optsConcatStrs " " "cfgOption";
|
configureFlags = optsConcatStrs " " "cfgOption";
|
||||||
|
|
||||||
#flags = listToAttrs (map ( flag: av flag (__hasAttr flag options) ) (__attrNames flagConfig) );
|
#flags = listToAttrs (map ( flag: av flag (hasAttr flag options) ) (attrNames flagConfig) );
|
||||||
flags_prefixed = listToAttrs (map ( flag: av ("flag_set_"+flag) (__hasAttr flag options) ) (__attrNames flagConfig) );
|
flags_prefixed = listToAttrs (map ( flag: av ("flag_set_"+flag) (hasAttr flag options) ) (attrNames flagConfig) );
|
||||||
|
|
||||||
pass = mergeAttrs (flatten (collectAttrs "pass") );
|
pass = mergeAttrs (flatten (collectAttrs "pass") );
|
||||||
} # now add additional phase actions (see examples)
|
} # now add additional phase actions (see examples)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user