aboutsummaryrefslogtreecommitdiff
blob: fa3b21143da90ba6aa073a523e78d5b5e3cd9508 (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
#!/bin/sh
# get reverse dependencies for a specific arch from 
# the gentoo tinderbox and print the atoms 
# (with USE-dep syntax) out, so your arch-testing tool
# can emerge them.

REPODIR="${HOME}/git/gentoo"
BASE_URL="http://qa-reports.gentoo.org/output/genrdeps/dindex/"

if [[ $# -ne 2 ]]; then
	echo "usage:"
	echo "	${0} arch category/package"
	echo
	echo "Examples: ${0} arm media-gfx/graphviz"
	exit 1
fi

arch="${1}"
pkg="${2}"
pkg="${pkg/=/}"
pkg="${pkg/-[0-9]*/}"

if [[ ! -d ${REPODIR} ]]; then
	echo "your \${REPODIR}='${REPODIR}' does not exist."
	exit 1
fi

if [[ ! -x $(which q) ]] ; then
	echo "you need portage-utils"
	echo "emerge app-portage/portage-utils"
	exit 1
fi

if [[ $(egrep "\<${arch/\~/}\>" ${REPODIR}/profiles/arch.list | wc -l) == 0 ]]; then
	echo "invalid arch ${arch}"
	exit 1
fi

if [[ ! -d ${REPODIR}/${pkg} ]]; then
	echo "package ${pkg} not found"
	exit 1
fi

tmp="$(mktemp)"
wget -o /dev/null -O "${tmp}" "${BASE_URL}/${pkg}"
res=$?
if [[ ${res} -ne 0 ]] ; then
	echo "failed to fetch reverse deps (wget returned ${res})"
	rm "${tmp}"
	exit 1
fi

last_pn=""

for p in $(grep -v '^[B]' ${tmp}); do
	cpv="${p/:*/}"
	use="${p/*:/}"
	[[ ${use} == ${p} ]] && use=""
	# negative use deps are !use and no -use
	# multiple use-deps are separated by '+'
	if [[ -n ${use} ]]; then
		use="${use//!/-}"
		use="${use//+/,}"
	fi

	# split up the category/package-version with q
	declare -a qatom
	qatom=($(qatom ${cpv}))
	[[ ${qatom#} < 2 ]] && die "invalid atom ${cpv}"
	category=${qatom[0]/=}
	pn=${qatom[1]}
	version=${qatom[2]}
	revision=${qatom[3]}
	[[ -n "${revision}" ]] && version="${version}-${revision}"

	# make sure that the file exists, as the local or remote tree
	# may be out of date
	ebuild="${REPODIR}/${category}/${pn}/${pn}-${version}.ebuild"
	[[ "${arch}" != "${arch/\~/}" ]] && expr="KEYWORDS=.*\<${arch/\~/}\>" \
		|| expr="KEYWORDS=.*( |\")\<${arch}\>"
	if [[ -e ${ebuild} && $(egrep -H "${expr}" \
			${ebuild} | wc -l) == 1 ]]; then
		slot=$(portageq metadata / ebuild ${cpv} SLOT)
		slot=${slot/\/*/} # kill subslot
		if [[ ${last_pn} != ${category}/${pn}:${slot} ]]; then
			[[ -z ${use} ]] && echo "${category}/${pn}:${slot}" || echo "${category}/${pn}:${slot}[${use}]"
		fi
		last_pn="${category}/${pn}:${slot}"
	fi
done
rm "${tmp}"