aboutsummaryrefslogtreecommitdiffstats
path: root/main/samba/split-pkg.lua
blob: e2de7b84e3ec65d6d8620e790a76b9ab24158dae (plain)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123

rev = {}
--[[ read from subpkgname.list file ]]--
--[[
for i = 1,#arg do
	pname = arg[i]
	local f = io.popen(([[
		xargs lddtree -l < %s | sort -u | while read f; do
			if [ -e pkg/*"$f" ]; then
				echo $f
			fi
		done
	] ]):format(pname))

	for filename in f:lines() do
		if rev[filename] == nil then
			rev[filename] = {}
		end
		table.insert(rev[filename], (pname:gsub(".list", "")))
	end
	f:close()
end
--]]


function shell_escape(args)
	local ret = {}
	for _,a in pairs(args) do
		s = tostring(a)
		if s:match("[^A-Za-z0-9_/:=-]") then
			s = "'"..s:gsub("'", "'\\''").."'"
		end
		table.insert(ret,s)
	end
	return table.concat(ret, " ")
end

-- read lines from stdin with: <subpackage> <filename>
pkgs = {}
revhash = {}
for line in io.lines() do
	local p, filename = line:match("(.*) (.*)")
	if pkgs[p] == nil then
		pkgs[p] = {bins={}, hasfile={}, needsfile={}}
	end
	table.insert(pkgs[p].bins, filename)
	pkgs[p].hasfile[filename] = true
end

for pkg, r in pairs(pkgs) do
	print("### ".. pkg)
	for _,binfile in pairs(r.bins) do
		local f = io.popen(([[
			lddtree -l %s | sort -u | while read f; do
				if [ -e pkg/*"$f" ]; then
					echo $f
				fi
			done
		]]):format(("pkg/"..pkg.."/"..binfile)))

		for filename in f:lines() do
			if rev[filename] == nil then
				rev[filename] = {}
				revhash[filename] = {}
			end
			if not revhash[filename][pkg] then
				revhash[filename][pkg]=true
				table.insert(rev[filename], pkg)
			end
			r.needsfile[filename]=true
		end
	end
end

-- sort list
keylist = {}
for k,v in pairs(rev) do
	table.insert(keylist, k)
	print(":::: "..k)
	table.sort(v)
end

combos = {}
for _,filename in pairs(keylist) do
	plist = rev[filename]
	s = ""
	for i = 1, #plist do
		if plist[i] ~= "samba-test" then
			s=s..plist[i]..":"
		end
	end
	if combos[s] == nil then
		combos[s] = {}
	end
	table.insert(combos[s], filename)
--	print(#rev[filename], s, filename)
end


combokeys = {}
for pn, filelist in pairs(combos) do
	table.insert(combokeys, pn)
	table.sort(filelist)
end

table.sort(combokeys, function(a,b)
	local _, counta = a:gsub(":", "")
	local _, countb = b:gsub(":", "")
	if counta == countb then
		return a < b
	end
	return counta < countb
end)

for i = 1,#combokeys do
	pn = combokeys[i]
	filelist = combos[pn]

	print(pn)
	for j = 1,#filelist do
		print("", filelist[j])
	end
end