| 
									
										
										
										
											2017-07-28 20:05:35 -04:00
										 |  |  | { lib }: | 
					
						
							| 
									
										
										
										
											2008-01-17 11:14:00 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  | Usage: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   You define you custom builder script by adding all build steps to a list. | 
					
						
							|  |  |  |   for example: | 
					
						
							| 
									
										
										
										
											2009-05-19 23:26:08 +00:00
										 |  |  |        builder = writeScript "fsg-4.4-builder" | 
					
						
							|  |  |  |                (textClosure [doUnpack addInputs preBuild doMake installPhase doForceShare]); | 
					
						
							| 
									
										
										
										
											2008-01-17 11:14:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-19 23:25:58 +00:00
										 |  |  |   a step is defined by noDepEntry, fullDepEntry or packEntry. | 
					
						
							| 
									
										
										
										
											2008-01-17 11:14:00 +00:00
										 |  |  |   To ensure that prerequisite are met those are added before the task itself by | 
					
						
							|  |  |  |   textClosureDupList. Duplicated items are removed again. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   See trace/nixpkgs/trunk/pkgs/top-level/builder-defs.nix for some predefined build steps | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-19 23:26:08 +00:00
										 |  |  |   Attention: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let | 
					
						
							| 
									
										
										
										
											2016-03-13 18:24:55 +00:00
										 |  |  |     pkgs = (import <nixpkgs>) {}; | 
					
						
							| 
									
										
										
										
											2009-05-19 23:26:08 +00:00
										 |  |  |   in let | 
					
						
							|  |  |  |     inherit (pkgs.stringsWithDeps) fullDepEntry packEntry noDepEntry textClosureMap; | 
					
						
							|  |  |  |     inherit (pkgs.lib) id; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     nameA = noDepEntry "Text a"; | 
					
						
							|  |  |  |     nameB = fullDepEntry "Text b" ["nameA"]; | 
					
						
							|  |  |  |     nameC = fullDepEntry "Text c" ["nameA"]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     stages = { | 
					
						
							|  |  |  |       nameHeader = noDepEntry "#! /bin/sh \n"; | 
					
						
							|  |  |  |       inherit nameA nameB nameC; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |   in | 
					
						
							|  |  |  |     textClosureMap id stages | 
					
						
							|  |  |  |     [ "nameHeader" "nameA" "nameB" "nameC" | 
					
						
							|  |  |  |       nameC # <- added twice. add a dep entry if you know that it will be added once only [1] | 
					
						
							|  |  |  |       "nameB" # <- this will not be added again because the attr name (reference) is used | 
					
						
							|  |  |  |     ] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   # result: Str("#! /bin/sh \n\nText a\nText b\nText c\nText c",[]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   [1] maybe this behaviour should be removed to keep things simple (?) | 
					
						
							| 
									
										
										
										
											2008-01-17 11:14:00 +00:00
										 |  |  | */ | 
					
						
							| 
									
										
										
										
											2007-08-26 21:59:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 13:47:24 +02:00
										 |  |  | let | 
					
						
							|  |  |  |   inherit (lib) | 
					
						
							|  |  |  |     concatStringsSep | 
					
						
							|  |  |  |     head | 
					
						
							|  |  |  |     isAttrs | 
					
						
							|  |  |  |     listToAttrs | 
					
						
							|  |  |  |     tail | 
					
						
							|  |  |  |     ; | 
					
						
							|  |  |  | in | 
					
						
							| 
									
										
										
										
											2009-05-11 11:55:05 +00:00
										 |  |  | rec { | 
					
						
							| 
									
										
										
										
											2007-11-08 14:34:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-11 15:21:42 +00:00
										 |  |  |   /* !!! 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. */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   textClosureList = predefined: arg: | 
					
						
							|  |  |  |     let | 
					
						
							|  |  |  |       f = done: todo: | 
					
						
							|  |  |  |         if todo == [] then {result = []; inherit done;} | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           let entry = head todo; in | 
					
						
							|  |  |  |           if isAttrs entry then | 
					
						
							| 
									
										
										
										
											2009-08-26 14:13:05 +00:00
										 |  |  |             let x = f done entry.deps; | 
					
						
							| 
									
										
										
										
											2009-05-11 15:21:42 +00:00
										 |  |  |                 y = f x.done (tail todo); | 
					
						
							|  |  |  |             in { result = x.result ++ [entry.text] ++ y.result; | 
					
						
							|  |  |  |                  done = y.done; | 
					
						
							| 
									
										
										
										
											2009-08-22 18:13:56 +00:00
										 |  |  |                } | 
					
						
							| 
									
										
										
										
											2014-10-05 00:03:52 +02:00
										 |  |  |           else if done ? ${entry} then f done (tail todo) | 
					
						
							|  |  |  |           else f (done // listToAttrs [{name = entry; value = 1;}]) ([predefined.${entry}] ++ tail todo); | 
					
						
							| 
									
										
										
										
											2009-08-26 14:13:05 +00:00
										 |  |  |     in (f {} arg).result; | 
					
						
							| 
									
										
										
										
											2009-05-19 23:26:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-11 15:21:42 +00:00
										 |  |  |   textClosureMap = f: predefined: names: | 
					
						
							|  |  |  |     concatStringsSep "\n" (map f (textClosureList predefined names)); | 
					
						
							| 
									
										
										
										
											2009-05-11 11:55:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   noDepEntry = text: {inherit text; deps = [];}; | 
					
						
							|  |  |  |   fullDepEntry = text: deps: {inherit text deps;}; | 
					
						
							|  |  |  |   packEntry = deps: {inherit deps; text="";}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-13 15:31:06 +00:00
										 |  |  |   stringAfter = deps: text: { inherit text deps; }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-08-26 21:59:31 +00:00
										 |  |  | } |