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

BEGIN {
	stages = " "
}

/^target: / {
	n = split(stages, l, " ")
	for (i = 1; i <= n; i++) {
		switch (l[i]) {
			case /.*\.(get|extract|prepare|compile|install|targetinstall|urlcheck)(.[a-z]+)?/:
				break
			# other stuff, such as archive downloads may not have a explicit end
			# so stop them when the next target starts
			default:
				drop(l[i])
				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|images)\/.*\..*\] Error [1-9][0-9]*$/ {
	stage = gensub(/.*\/(state|images)\/(.+\..+)\] Error.*/, "\\2", 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)
}

/^({{{|}})/ {
	for (stage in cache)
		drop(stage)
}