at 15.09-beta 2.6 kB view raw
1/* 2Usage: 3 4 You define you custom builder script by adding all build steps to a list. 5 for example: 6 builder = writeScript "fsg-4.4-builder" 7 (textClosure [doUnpack addInputs preBuild doMake installPhase doForceShare]); 8 9 a step is defined by noDepEntry, fullDepEntry or packEntry. 10 To ensure that prerequisite are met those are added before the task itself by 11 textClosureDupList. Duplicated items are removed again. 12 13 See trace/nixpkgs/trunk/pkgs/top-level/builder-defs.nix for some predefined build steps 14 15 Attention: 16 17 let 18 pkgs = (import /etc/nixos/nixpkgs/pkgs/top-level/all-packages.nix) {}; 19 in let 20 inherit (pkgs.stringsWithDeps) fullDepEntry packEntry noDepEntry textClosureMap; 21 inherit (pkgs.lib) id; 22 23 nameA = noDepEntry "Text a"; 24 nameB = fullDepEntry "Text b" ["nameA"]; 25 nameC = fullDepEntry "Text c" ["nameA"]; 26 27 stages = { 28 nameHeader = noDepEntry "#! /bin/sh \n"; 29 inherit nameA nameB nameC; 30 }; 31 in 32 textClosureMap id stages 33 [ "nameHeader" "nameA" "nameB" "nameC" 34 nameC # <- added twice. add a dep entry if you know that it will be added once only [1] 35 "nameB" # <- this will not be added again because the attr name (reference) is used 36 ] 37 38 # result: Str("#! /bin/sh \n\nText a\nText b\nText c\nText c",[]) 39 40 [1] maybe this behaviour should be removed to keep things simple (?) 41*/ 42 43with import ./lists.nix; 44with import ./attrsets.nix; 45with import ./strings.nix; 46 47rec { 48 49 /* !!! The interface of this function is kind of messed up, since 50 it's way too overloaded and almost but not quite computes a 51 topological sort of the depstrings. */ 52 53 textClosureList = predefined: arg: 54 let 55 f = done: todo: 56 if todo == [] then {result = []; inherit done;} 57 else 58 let entry = head todo; in 59 if isAttrs entry then 60 let x = f done entry.deps; 61 y = f x.done (tail todo); 62 in { result = x.result ++ [entry.text] ++ y.result; 63 done = y.done; 64 } 65 else if done ? ${entry} then f done (tail todo) 66 else f (done // listToAttrs [{name = entry; value = 1;}]) ([predefined.${entry}] ++ tail todo); 67 in (f {} arg).result; 68 69 textClosureMap = f: predefined: names: 70 concatStringsSep "\n" (map f (textClosureList predefined names)); 71 72 noDepEntry = text: {inherit text; deps = [];}; 73 fullDepEntry = text: deps: {inherit text deps;}; 74 packEntry = deps: {inherit deps; text="";}; 75 76 stringAfter = deps: text: { inherit text deps; }; 77 78}