diff --git a/pkgs/build-support/builder-defs/builder-defs.nix b/pkgs/build-support/builder-defs/builder-defs.nix index 0cd9aa34722..11ad854c1e1 100644 --- a/pkgs/build-support/builder-defs/builder-defs.nix +++ b/pkgs/build-support/builder-defs/builder-defs.nix @@ -90,8 +90,7 @@ args: with args; with stringsWithDeps; with lib; NIX_GCC=${stdenv.gcc} export SHELL=${stdenv.shell} PATH_DELIMITER=':' - " + (if ((stdenv ? preHook) && (stdenv.preHook != null) && - ((toString stdenv.preHook) != "")) then + " + (if stdenv ? preHook && stdenv.preHook != null && toString stdenv.preHook != "" then " param1=${stdenv.param1} param2=${stdenv.param2} @@ -354,24 +353,24 @@ args: with args; with stringsWithDeps; with lib; /*debug = x:(__trace x x); debugX = x:(__trace (__toXML x) x);*/ - replaceScriptVar = file: name: value: ("sed -e 's`^${name}=.*`${name}='\\''${value}'\\''`' -i ${file}"); - replaceInScript = file: l: (concatStringsSep "\n" ((pairMap (replaceScriptVar file) l))); - replaceScripts = l:(concatStringsSep "\n" (pairMap replaceInScript l)); - doReplaceScripts = FullDepEntry (replaceScripts (getAttr ["shellReplacements"] [] args)) [minInit]; - makeNest = x:(if x==defNest.text then x else "startNest\n" + x + "\nstopNest\n"); - textClosure = a : steps : textClosureMapOveridable makeNest a (["defNest"] ++ steps); + replaceScriptVar = file: name: value: "sed -e 's`^${name}=.*`${name}='\\''${value}'\\''`' -i ${file}"; + replaceInScript = file: l: concatStringsSep "\n" ((pairMap (replaceScriptVar file) l)); + replaceScripts = l: concatStringsSep "\n" (pairMap replaceInScript l); + doReplaceScripts = FullDepEntry (replaceScripts (getAttr ["shellReplacements"] [] args)) ["minInit"]; + makeNest = x: if x == defNest.text then x else "startNest\n" + x + "\nstopNest\n"; + textClosure = a: steps: textClosureMap makeNest a (["defNest"] ++ steps); inherit noDepEntry FullDepEntry PackEntry; - defList = (getAttr ["defList"] [] args); + defList = getAttr ["defList"] [] args; getVal = getValue args defList; check = checkFlag args; reqsList = getAttr ["reqsList"] [] args; - buildInputsNames = filter (x: (null != getVal x)) + buildInputsNames = filter (x: null != getVal x) (uniqList {inputList = - (concatLists (map - (x:(if (x==[]) then [] else builtins.tail x)) - reqsList));}); + (concatLists (map + (x: if x==[] then [] else builtins.tail x) + reqsList));}); configFlags = getAttr ["configFlags"] [] args; buildFlags = getAttr ["buildFlags"] [] args; nameSuffixes = getAttr ["nameSuffixes"] [] args; @@ -440,8 +439,7 @@ args: with args; with stringsWithDeps; with lib; stdenv.mkDerivation ((rec { inherit (localDefs) name; - builder = writeScript (name + "-builder") - (textClosure localDefs localDefs.realPhaseNames); + buildCommand = textClosure localDefs localDefs.realPhaseNames; meta = localDefs.meta; passthru = localDefs.passthru // {inherit (localDefs) src; }; }) // (if localDefs ? propagatedBuildInputs then { diff --git a/pkgs/lib/misc.nix b/pkgs/lib/misc.nix index 21dd6d6c034..b8e49bad977 100644 --- a/pkgs/lib/misc.nix +++ b/pkgs/lib/misc.nix @@ -160,7 +160,8 @@ rec { (val!=null) && (val!=false)) (tail x))))) condList)) ; - + + # !!! This function has O(n^2) performance, so you probably don't want to use it! uniqList = {inputList, outputList ? []}: if (inputList == []) then outputList else let x=head inputList; diff --git a/pkgs/lib/strings-with-deps.nix b/pkgs/lib/strings-with-deps.nix index 7664689647c..98ce4871da8 100644 --- a/pkgs/lib/strings-with-deps.nix +++ b/pkgs/lib/strings-with-deps.nix @@ -13,38 +13,35 @@ Usage: See trace/nixpkgs/trunk/pkgs/top-level/builder-defs.nix for some predefined build steps */ -args: -with args; +{stdenv, lib}: + with lib; -let - inherit (builtins) head tail isList isAttrs; -in - rec { - textClosureDupList = arg: - if isList arg then - textClosureDupList {text = ""; deps = arg;} - else - concatLists (map textClosureDupList arg.deps) ++ [arg]; + /* !!! The interface of this function is kind of messed up, since + it's way too overloaded and almost but not quite computes a + topological sort of the depstrings. */ - textClosureDupListOverridable = predefined: arg: - if isList arg then - textClosureDupListOverridable predefined {text = ""; deps = arg;} - else if isAttrs arg then - concatLists (map (textClosureDupListOverridable predefined) arg.deps) ++ [arg] - else - textClosureDupListOverridable predefined (getAttr [arg] [] predefined); - - textClosureListOverridable = predefined: arg: - map (x: x.text) (uniqList {inputList = textClosureDupListOverridable predefined arg;}); - - textClosureOverridable = predefined: arg: concatStringsSep "\n" (textClosureListOverridable predefined arg); - - textClosureMapOveridable = f: predefined: arg: - concatStringsSep "\n" (map f (textClosureListOverridable predefined arg)); + textClosureList = predefined: arg: + let + f = done: todo: + if todo == [] then {result = []; inherit done;} + else + let entry = head todo; in + if isAttrs entry then + let x = f done entry.deps; + y = f x.done (tail todo); + in { result = x.result ++ [entry.text] ++ y.result; + done = y.done; + } + else if hasAttr entry done then f done (tail todo) + else f (done // listToAttrs [{name = entry; value = 1;}]) ([(builtins.getAttr entry predefined)] ++ tail todo); + in (f {} arg).result; + + textClosureMap = f: predefined: names: + concatStringsSep "\n" (map f (textClosureList predefined names)); noDepEntry = text: {inherit text; deps = [];}; fullDepEntry = text: deps: {inherit text deps;};