summary refs log tree commit diff
path: root/pkgs/lib/strings-with-deps.nix
blob: 4fb4fe150a7cf7ff2d287d4548a4cfb3de3076e5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
Usage:

  You define you custom builder script by adding all build steps to a list.
  for example:
	builder = writeScript "fsg-4.4-builder"
		(textClosure [doUnpack addInputs preBuild doMake installPhase doForceShare]);

  a step is defined by noDepEntry, FullDepEntry or PackEntry.
  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

*/
args: 
	with args;
	with lib;
	let 
		inherit (builtins)	
			head tail isList isAttrs;
in
rec {

/*
	let  shelllib = rec {
		a= {
			text = "aaaa";
			deps = [b c];
		};
		b = {
			text = "b";
		};
		c = {
			text = "c";
			deps = [];
		};
	};
	in
	
	[textClosure [shelllib.a]
		textclosure shelllib.a];

	
*/
	
	textClosureDupList = arg: 
	(
		if isList arg then 
			textClosureDupList {text = ""; deps = arg;} 
		else
			(concatLists (map textClosureDupList arg.deps)) ++ [arg]
	);

	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));

	noDepEntry = text : {inherit text;deps = [];};
	FullDepEntry = text : deps: {inherit text deps;};
	PackEntry = deps: {inherit deps; text="";};
}