about summary refs log tree commit diff
path: root/xpcdeps
diff options
context:
space:
mode:
authormaxice8 <thinkabit.ukim@gmail.com>2018-03-16 14:41:51 -0300
committerLeah Neukirchen <leah@vuxu.org>2018-03-16 19:31:22 +0100
commit851d65814ba67848ad06b495e2a55a3a23036057 (patch)
tree8e7878f0b3c8cc36caf1115642d345eb0e4ee014 /xpcdeps
parentf1527b867e468db9f6de71f857133af559230a2e (diff)
downloadxtools-851d65814ba67848ad06b495e2a55a3a23036057.tar.gz
xtools-851d65814ba67848ad06b495e2a55a3a23036057.tar.xz
xtools-851d65814ba67848ad06b495e2a55a3a23036057.zip
xpcdeps: add
Closes: #82 [via git-merge-pr]
Diffstat (limited to 'xpcdeps')
-rwxr-xr-xxpcdeps65
1 files changed, 65 insertions, 0 deletions
diff --git a/xpcdeps b/xpcdeps
new file mode 100755
index 0000000..a594d01
--- /dev/null
+++ b/xpcdeps
@@ -0,0 +1,65 @@
+#!/bin/sh
+# xpcdeps pcfile ... - finds package matching the Requires: section of pkg-config files
+cleanup() {
+	[ -n "$tempdir" ] &&
+	[ -d "$tempdir" ] &&
+	rm -rf -- "$tempdir"
+}
+trap cleanup EXIT INT TERM
+
+tempdir="$(mktemp -d)"
+
+# This takes 1 argument which is the name of the file to write to and reads
+# lines from stdin in the form of '$pkgname $file'
+create_pcfile() {
+	branch=$(git symbolic-ref -q --short HEAD 2>/dev/null)
+	while read -r pkgname file ; do
+		for rpkg in $( xbps-query --repository=hostdir/binpkgs/"$branch" --cat="$file" "$pkgname" | grep Requires: | cut -d: -f2 ) ; do
+			# This makes the iterator ignore over the version specifier available for pkg-config
+			# >=, <=, >, <, =, and also ignore versions by ignoring everything that doesn't have
+			# a letter
+			[ -z "${rpkg##*[<=>]*}" ] && continue
+			[ -z "${rpkg##*[a-zA-Z]*}" ] || continue
+			printf "%s\\n" "$rpkg" >> "$tempdir/$1.pc"
+		done
+	done
+}
+
+grab_local() {
+	branch=$(git symbolic-ref -q --short HEAD 2>/dev/null)
+	for pkg in hostdir/binpkgs/$branch/* ; do
+		pkg="${pkg##*/}"
+		pcfile="$(xbps-query -i --repository=hostdir/binpkgs/"$branch" -f "${pkg%-*}" | grep "$1.pc")"
+		if [ -n "$pcfile" ] ; then
+			printf "%s %s\\n" "${pkg%-*}" "$pcfile"
+			touch "$tempdir/$1.pc"
+		fi
+	done | create_pcfile "$1"
+
+	# Check if the file doesn't exist, we can't check if it empty because emptyness
+	# means the Requires: is defined but is empty
+	[ -f "$tempdir/$1.pc" ] || return 1
+}
+
+grab_requires() {
+	for pkg; do
+		xlocate "usr/\(lib\|share\)/pkgconfig/$pkg.pc" |
+		{ grep . || { echo "xpcdeps: No pkg-config file for $pkg found." 1>&2 ; exit 1; } } |
+		create_pcfile "$pkg"
+	done
+}
+
+get_package_from_requires() {
+	while read -r pkg ; do
+		xlocate "usr/\(lib\|share\)/pkgconfig/$pkg.pc" |
+		{ grep . || { printf -- "UNKNOWN PKG PLEASE FIX -> %s\\n" "$pkg" 1>&2 ; return; } } |
+		while read -r pkgname file ; do
+			file="${file##*/}"
+			printf "%s -> %s\\n" "${pkgname%-*}" "${file%*.pc}"
+		done
+	done
+}
+
+for arg; do
+	grab_local "$arg" || grab_requires "$arg" && [ -f "$tempdir/$arg.pc" ] && get_package_from_requires < "$tempdir/$arg.pc"
+done