* textClosure: don't use uniqList, and don't rely on buggy behaviour

in the Nix expression evaluator (namely that comparison of attribute
  sets works properly).
* Removed some redundant parentheses in builder-defs.

svn path=/nixpkgs/trunk/; revision=15551
This commit is contained in:
Eelco Dolstra 2009-05-11 15:21:42 +00:00
parent 2f33cdec38
commit abf71d5352
3 changed files with 38 additions and 42 deletions

View file

@ -90,8 +90,7 @@ args: with args; with stringsWithDeps; with lib;
NIX_GCC=${stdenv.gcc} NIX_GCC=${stdenv.gcc}
export SHELL=${stdenv.shell} export SHELL=${stdenv.shell}
PATH_DELIMITER=':' PATH_DELIMITER=':'
" + (if ((stdenv ? preHook) && (stdenv.preHook != null) && " + (if stdenv ? preHook && stdenv.preHook != null && toString stdenv.preHook != "" then
((toString stdenv.preHook) != "")) then
" "
param1=${stdenv.param1} param1=${stdenv.param1}
param2=${stdenv.param2} param2=${stdenv.param2}
@ -354,24 +353,24 @@ args: with args; with stringsWithDeps; with lib;
/*debug = x:(__trace x x); /*debug = x:(__trace x x);
debugX = x:(__trace (__toXML x) x);*/ debugX = x:(__trace (__toXML x) x);*/
replaceScriptVar = file: name: value: ("sed -e 's`^${name}=.*`${name}='\\''${value}'\\''`' -i ${file}"); replaceScriptVar = file: name: value: "sed -e 's`^${name}=.*`${name}='\\''${value}'\\''`' -i ${file}";
replaceInScript = file: l: (concatStringsSep "\n" ((pairMap (replaceScriptVar file) l))); replaceInScript = file: l: concatStringsSep "\n" ((pairMap (replaceScriptVar file) l));
replaceScripts = l:(concatStringsSep "\n" (pairMap replaceInScript l)); replaceScripts = l: concatStringsSep "\n" (pairMap replaceInScript l);
doReplaceScripts = FullDepEntry (replaceScripts (getAttr ["shellReplacements"] [] args)) [minInit]; doReplaceScripts = FullDepEntry (replaceScripts (getAttr ["shellReplacements"] [] args)) ["minInit"];
makeNest = x:(if x==defNest.text then x else "startNest\n" + x + "\nstopNest\n"); makeNest = x: if x == defNest.text then x else "startNest\n" + x + "\nstopNest\n";
textClosure = a : steps : textClosureMapOveridable makeNest a (["defNest"] ++ steps); textClosure = a: steps: textClosureMap makeNest a (["defNest"] ++ steps);
inherit noDepEntry FullDepEntry PackEntry; inherit noDepEntry FullDepEntry PackEntry;
defList = (getAttr ["defList"] [] args); defList = getAttr ["defList"] [] args;
getVal = getValue args defList; getVal = getValue args defList;
check = checkFlag args; check = checkFlag args;
reqsList = getAttr ["reqsList"] [] args; reqsList = getAttr ["reqsList"] [] args;
buildInputsNames = filter (x: (null != getVal x)) buildInputsNames = filter (x: null != getVal x)
(uniqList {inputList = (uniqList {inputList =
(concatLists (map (concatLists (map
(x:(if (x==[]) then [] else builtins.tail x)) (x: if x==[] then [] else builtins.tail x)
reqsList));}); reqsList));});
configFlags = getAttr ["configFlags"] [] args; configFlags = getAttr ["configFlags"] [] args;
buildFlags = getAttr ["buildFlags"] [] args; buildFlags = getAttr ["buildFlags"] [] args;
nameSuffixes = getAttr ["nameSuffixes"] [] args; nameSuffixes = getAttr ["nameSuffixes"] [] args;
@ -440,8 +439,7 @@ args: with args; with stringsWithDeps; with lib;
stdenv.mkDerivation ((rec { stdenv.mkDerivation ((rec {
inherit (localDefs) name; inherit (localDefs) name;
builder = writeScript (name + "-builder") buildCommand = textClosure localDefs localDefs.realPhaseNames;
(textClosure localDefs localDefs.realPhaseNames);
meta = localDefs.meta; meta = localDefs.meta;
passthru = localDefs.passthru // {inherit (localDefs) src; }; passthru = localDefs.passthru // {inherit (localDefs) src; };
}) // (if localDefs ? propagatedBuildInputs then { }) // (if localDefs ? propagatedBuildInputs then {

View file

@ -160,7 +160,8 @@ rec {
(val!=null) && (val!=false)) (val!=null) && (val!=false))
(tail x))))) condList)) ; (tail x))))) condList)) ;
# !!! This function has O(n^2) performance, so you probably don't want to use it!
uniqList = {inputList, outputList ? []}: uniqList = {inputList, outputList ? []}:
if (inputList == []) then outputList else if (inputList == []) then outputList else
let x=head inputList; let x=head inputList;

View file

@ -13,38 +13,35 @@ Usage:
See trace/nixpkgs/trunk/pkgs/top-level/builder-defs.nix for some predefined build steps See trace/nixpkgs/trunk/pkgs/top-level/builder-defs.nix for some predefined build steps
*/ */
args:
with args; {stdenv, lib}:
with lib; with lib;
let
inherit (builtins) head tail isList isAttrs;
in
rec { rec {
textClosureDupList = arg: /* !!! The interface of this function is kind of messed up, since
if isList arg then it's way too overloaded and almost but not quite computes a
textClosureDupList {text = ""; deps = arg;} topological sort of the depstrings. */
else
concatLists (map textClosureDupList arg.deps) ++ [arg];
textClosureDupListOverridable = predefined: arg: textClosureList = predefined: arg:
if isList arg then let
textClosureDupListOverridable predefined {text = ""; deps = arg;} f = done: todo:
else if isAttrs arg then if todo == [] then {result = []; inherit done;}
concatLists (map (textClosureDupListOverridable predefined) arg.deps) ++ [arg] else
else let entry = head todo; in
textClosureDupListOverridable predefined (getAttr [arg] [] predefined); if isAttrs entry then
let x = f done entry.deps;
textClosureListOverridable = predefined: arg: y = f x.done (tail todo);
map (x: x.text) (uniqList {inputList = textClosureDupListOverridable predefined arg;}); in { result = x.result ++ [entry.text] ++ y.result;
done = y.done;
textClosureOverridable = predefined: arg: concatStringsSep "\n" (textClosureListOverridable predefined arg); }
else if hasAttr entry done then f done (tail todo)
textClosureMapOveridable = f: predefined: arg: else f (done // listToAttrs [{name = entry; value = 1;}]) ([(builtins.getAttr entry predefined)] ++ tail todo);
concatStringsSep "\n" (map f (textClosureListOverridable predefined arg)); in (f {} arg).result;
textClosureMap = f: predefined: names:
concatStringsSep "\n" (map f (textClosureList predefined names));
noDepEntry = text: {inherit text; deps = [];}; noDepEntry = text: {inherit text; deps = [];};
fullDepEntry = text: deps: {inherit text deps;}; fullDepEntry = text: deps: {inherit text deps;};