From f22d19c12813f3f5f330ed3d0db8d1f2a6c147a4 Mon Sep 17 00:00:00 2001 From: Marc Weber Date: Sat, 19 Jan 2008 01:23:48 +0000 Subject: [PATCH] slightly modified stringsWithDeps script Builder proposal adding the feature overriding steps and has better documentation (IMHO) reusing as much as possible of the code already written by raskin svn path=/nixpkgs/trunk/; revision=10225 --- pkgs/lib/strings-with-deps2.nix | 47 +++++++++++++++++++++++++++++ pkgs/top-level/all-packages.nix | 4 +++ pkgs/top-level/builder-defs2.nix | 52 ++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 pkgs/lib/strings-with-deps2.nix create mode 100644 pkgs/top-level/builder-defs2.nix diff --git a/pkgs/lib/strings-with-deps2.nix b/pkgs/lib/strings-with-deps2.nix new file mode 100644 index 000000000000..85c3526ee22a --- /dev/null +++ b/pkgs/lib/strings-with-deps2.nix @@ -0,0 +1,47 @@ +/* propoal Marc Weber (original idea and implementation: Michael Raskin) + This should not be a complete rewrite of Michael Raskins code. + I only fear having to override one step.. + (which could be done using textClosureMap = f: .. and telling f to substitute a text string) + But I don't like this solution + + I've rewritten the part creating the actual step hoping that it's easier to understand. + + Baisc idea keeps the same: assemble a custom builder script by concatenating + text snippets with dependencies. + + Difference: Instead of concatenating the text snippets only aliases are concatenated [1] + Then those alias names are looked up from an attribute set [2] + (this way giving you full control overriding steps) + + All script snippets written by Michael Raskin will be reused thankfully :) +*/ + +/* Example: +setup = { + name = "setup"; + value = "echo setup"; # the text snippet (by calling it value it fits the attr name expected by listToAttrs +} + +unpack = { + name = "unpack"; + value = "tar xf ... "; + dependencies = [ "setup" ]; # createScript ensures that these are prependend to this text snipped +} + +script = createScript { steps = [setup unpack] } +is equal to +script = createScript { steps = [unpack] } + +# overriding example: +script_overridden_setup = createScript { steps = [unpack]; override = { setup = "overridden setup"; }; }; +*/ +lib : +let inherit (builtins) listToAttrs; + inherit (lib) intersperse concatLists uniqList concatStrings; + in { + createScript = { steps, override ? {} } : let + addNameToDeps = r : ( if (r ? dependencies) then r.dependencies else [] ) ++ [r.name]; + names = uniqList { inputList = concatLists ( map addNameToDeps steps ) ; }; # [1] + scriptsAsAttrs = listToAttrs steps; # [2] + in concatStrings ( intersperse "\n" (map (x : __getAttr x (scriptsAsAttrs // override ) ) names) ); + } diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 2d388be3c511..58386e4852db 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -229,6 +229,10 @@ rec { inherit stdenv lib; }; + builderDefs2 = lib.sumArgs ((import ./builder-defs2.nix) (builderDefs null)); + + stringsWithDeps2 = (import ../lib/strings-with-deps2.nix) lib; + # Call a specific version of a Nix expression, that is, # `selectVersion ./foo {version = "0.1.2"; args...}' evaluates to # `import ./foo/0.1.2.nix args'. diff --git a/pkgs/top-level/builder-defs2.nix b/pkgs/top-level/builder-defs2.nix new file mode 100644 index 000000000000..69b24a470681 --- /dev/null +++ b/pkgs/top-level/builder-defs2.nix @@ -0,0 +1,52 @@ +# documentation see ../lib/strings-with-deps2.nix +# coverts Michael Raskin builder script snippets so that they can be used with createScript from strings-with-deps2.nix + +raskin_defs : rec { + + defAddToSearchPath = { + name = "defAddToSearchPath"; + value = raskin_defs.defAddToSearchPath.text; + dependencies = [ "defNest" ]; + }; + defNest = { + name = "defNest"; + value = raskin_defs.defNest.text; + }; + minInit = { + name = "minInit"; + value = raskin_defs.minInit.text; + dependencies = [ "defNest" "defAddToSearchPath" ]; + }; + + addInputs = { + name = "addInputs"; + value = raskin_defs.addInputs.text; + dependencies = [ "minInit" ]; + }; + + toSrcDir = s : { + name = "toSrcDir"; + value = (raskin_defs.toSrcDir s).text; + dependencies = [ "minInit" ]; + }; + + doConfigure = { + name = "doConfigure"; + value = raskin_defs.doConfigure.text; + dependencies = [ "minInit" "addInputs" "doUnpack" ]; + }; + + doAutotools = { + name = "doAutotools"; + value = raskin_defs.doAutotools.text; + dependencies = [ "minInit" "addInputs" "doUnpack" ]; + }; + + doMake = { + name = "doMake"; + value = raskin_defs.doMake.text; + dependencies = [ "minInit" "addInputs" "doUnpack" ]; + }; + +# more have to be added here! +}