aboutsummaryrefslogtreecommitdiff
blob: 218f01a05cb0edb22a9abb01a54b6b6365aaddee (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
#!/bin/bash
# Created by Tomáš Chvátal <scarabeus@gentoo.org>
# License WTFPL-2.0

if [[ -n ${1} ]]; then
	DIR="${1}"
	[[ -d ${DIR} ]] || mkdir -p ${DIR}
else
	DIR=$(pwd)
fi

#[[ $(type pquery 2> /dev/null) ]] || exit 1

TMPEAPIS="/tmp/$(basename $0).global.$$.tmp"
TMPECLASS="/tmp/$(basename $0).eclass.$$.tmp"
REPO_PATH=$(portageq get_repo_path / gentoo)
pushd "${REPO_PATH}/eclass" > /dev/null
ECLASSES=$(echo *.eclass)
popd > /dev/null

#pquery --attr eapi --attr inherited --raw --all --repo portdir > "${TMPEAPIS}"
find "${REPO_PATH}/metadata/md5-cache" -type f -exec awk -F= '
	BEGINFILE {
		n = split(FILENAME, f, "/")
		file = f[n-1] "/" f[n]
		eapi = "0"
		n_eclasses = 0
	}
	$1 == "EAPI" { eapi = $2 }
	$1 == "_eclasses_" { n_eclasses = split($2, eclasses, "\t") }
	ENDFILE {
		printf "%s eapi=\"%s\" inherited=\"", file, eapi
		for (i = 1; i <= n_eclasses; i += 2) {
			if (i != 1) printf " "
			printf "%s", eclasses[i]
		}
		printf "\"\n"
	}
	' '{}' \+ > "${TMPEAPIS}"

KNOWN_EAPIS=$(awk '
	{ e = gensub(/eapi="(.*)"/, "\\1", "", $2); eapi[e] = e }
	END { PROCINFO["sorted_in"]="@ind_num_asc"; for (e in eapi) print e }
	' "${TMPEAPIS}")

pushd ${DIR} > /dev/null
rm -rf *.eclass
for x in ${ECLASSES}; do
	echo "Processing eclass \"${x}\""
	rm -rf "${x}"
	mkdir "${x}"
	awk -F'=' '$3 ~ /[ "]'"${x%.eclass}"'[ "]/ {print $1" "$2}' "${TMPEAPIS}" > "${TMPECLASS}"
	pushd "${x}" > /dev/null
	echo "Overall statistic for eclass \"${x}\":" > "STATS.txt"
	for y in ${KNOWN_EAPIS}; do
		awk -F ' ' '$3 ~ /"'"${y}"'"/ {print $1}' "${TMPECLASS}" > "${y}.txt"
		tmpval=$(wc -l "${y}.txt" |cut -d' ' -f1)
		echo "EAPI=${y} count: ${tmpval}" >> "STATS.txt"
	done
	sed -e 's/$/<br>/' STATS.txt > README.html
	popd > /dev/null
done
popd > /dev/null

rm ${TMPEAPIS}
rm ${TMPECLASS}