summaryrefslogtreecommitdiffstats
path: root/scripts/split-error-log.awk
blob: cf73798bcb11938d1e47404f385df398d3cb38c9 (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
#!/usr/bin/awk -f

BEGIN {
	stages = " "
}

/^target: / {
	n = split(stages, l, " ")
	for (i = 0; i < n; i++) {
		switch (l[i]) {
			case ".*.(get|extract|prepare|compile|install|targetinstall|urlcheck)(.[a-z]+)?":
				stages = stages " " l[i]
				break
			# other stuff, such as archive downloads may not have a explicit end
			default:
				break
		}
	}
	stages = stages $2 " "
	cache[$2][0] = last
}

function drop(stage) {
	delete cache[stage]
	do {
		old = stages
		stages = gensub(" " stage " ", " ", "g", stages)
	} while (old != stages)
}

/\<finished target / {
	drop($NF)
}

{
	n = split(stages, l, " ")
	for (i = 1; i <= n; i++) {
		j = length(cache[l[i]])
		cache[l[i]][j] = $0
	}
	last = $0
}

/.*platform.*\/state\/.*\..*\] Error [1-9][0-9]*$/ {
	stage = gensub(/.*\/state\/(.+\..+)\] Error.*/, "\\1", 1, $0)
	targetfile = FILENAME "." stage ".txt"

	print targetfile

	len = length(cache[stage])
	for (i = 0; i < len; i++) {
		print cache[stage][i] >> targetfile
	}
	close(targetfile)

	drop(stage)
}