Giter Club home page Giter Club logo

Comments (8)

maxice8 avatar maxice8 commented on July 17, 2024

example output of the script (if you refuse to run such a ugly script in your machine, which is understandable )

$ xpcdeps gio-2.0
libglib-devel -> glib-2.0
libglib-devel -> gobject-2.0

$ xpcdeps gtk+-3.0
gtk+3-devel -> gdk-3.0
atk-devel -> atk
cairo-devel -> cairo
cairo-devel -> cairo-gobject
gdk-pixbuf-devel -> gdk-pixbuf-2.0
libglib-devel -> gio-2.0

$ xpcdeps libgxps
libglib-devel -> gio-2.0
libarchive-devel -> libarchive
cairo-devel -> cairo
libglib-devel -> gobject-2.0

$ xpcdeps libxbps

$ xpcdeps pangoft2
pango-devel -> pango
freetype-devel -> freetype2
fontconfig-devel -> fontconfig

from xtools.

maxice8 avatar maxice8 commented on July 17, 2024

it should be fair to ignore Requires.private since those only apply to static linking.

from xtools.

maxice8 avatar maxice8 commented on July 17, 2024

ideas: handle pcfiles for packages available via hostdir/binpkgs, this allows people adding new packages to find the dependencies required, use a tempfile with a env override so pkg-config --print-requires can be used.

from xtools.

maxice8 avatar maxice8 commented on July 17, 2024

bad news for handling pcfiles via pkg-config --print-requires.

$ env PKG_CONFIG_PATH=/run/user/1000/tmp.jQ2zFNCzHC/ pkg-config --print-requires libpeas-1.0
Package gobject-introspection-1.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gobject-introspection-1.0.pc'
to the PKG_CONFIG_PATH environment variable
Package 'gobject-introspection-1.0', required by 'libpeas-1.0', not found

from xtools.

maxice8 avatar maxice8 commented on July 17, 2024

This script uses a local file, this will allow in the future for us to extend it to use local packages in hostdir/binpkgs

#!/bin/sh
cleanup() {
	[ -n "$tempdir" ] && 
	[ -d "$tempdir" ] && 
	rm -rf -- "$tempdir"
}
trap cleanup EXIT

tempdir="$(mktemp -d)"

grab_requires() {
	for pkg in "$@" ; do
		xlocate "usr/\(lib\|share\)/pkgconfig/$pkg.pc" |
		{ grep . || { echo "xpcdeps: No pkg-config file for $pkg found." 1>&2 ; exit 1; } } |
		while read -r pkgname file ; do
			for rpkg in $( xbps-query --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 expecting a single letter
				[ -z "${rpkg##*=*}" ] && continue
				[ -z "${rpkg##*<*}" ] && continue
				[ -z "${rpkg##*>*}" ] && continue
				[ -z "${rpkg##*[a-zA-Z]*}" ] || continue
				[ -z "$rpkg" ] && continue
				echo "$rpkg" >> "$tempdir/$pkg.pc"
			done
		done
	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 ; continue; } } |
		while read -r pkgname file ; do
			file="${file##*/}"
			printf -- "%s -> %s\\n" "${pkgname%-*}" "${file%*.pc}"
		done
	done
}

grab_requires "$@" && cat "$tempdir"/* | get_package_from_requires

from xtools.

maxice8 avatar maxice8 commented on July 17, 2024

This is a poorly optimized version that handles local packages in hostdir/binpkgs/$branch

#!/bin/sh
cleanup() {
	[ -n "$tempdir" ] && 
	[ -d "$tempdir" ] && 
	rm -rf -- "$tempdir"
}
trap cleanup EXIT INT TERM 

tempdir="$(mktemp -d)"

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"
		fi
	done | 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 expecting a single letter
			[ -z "${rpkg##*[<=>]*}" ] && continue
			[ -z "${rpkg##*[a-zA-Z]*}" ] || continue
			echo "$rpkg" >> "$tempdir/$1.pc"
		done
		# touch the file, it indicates we have found the file here, so it won't try to
		# grab the .pc file from the outside
		touch "$tempdir/$1.pc"
	done

	# 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 in "$@" ; do
		xlocate "usr/\(lib\|share\)/pkgconfig/$pkg.pc" |
		{ grep . || { echo "xpcdeps: No pkg-config file for $pkg found." 1>&2 ; exit 1; } } |
		while read -r pkgname file ; do
			for rpkg in $( xbps-query --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 expecting a single letter, we don't
				# skip empty lines, because those lines indicate that there are no requirements
				[ -z "${rpkg##*[<=>]*}" ] && continue
				[ -z "${rpkg##*[a-zA-Z]*}" ] || continue
				echo "$rpkg" >> "$tempdir/$pkg.pc"
			done
		done
	done

	# 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" ] || exit 1
}

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 ; continue; } } |
		while read -r pkgname file ; do
			file="${file##*/}"
			printf -- "%s -> %s\\n" "${pkgname%-*}" "${file%*.pc}"
		done
	done
}

grab_local "$@" || grab_requires "$@" && cat "$tempdir"/* | get_package_from_requires

UPDATE1: changed the 3 < = > checks with [<=>], thanks leah for the suggestion

from xtools.

maxice8 avatar maxice8 commented on July 17, 2024
#!/bin/sh
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 expecting a single letter
			[ -z "${rpkg##*[<=>]*}" ] && continue
			[ -z "${rpkg##*[a-zA-Z]*}" ] || continue
			echo "$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 in "$@" ; 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 ; continue; } } |
		while read -r pkgname file ; do
			file="${file##*/}"
			printf -- "%s -> %s\\n" "${pkgname%-*}" "${file%*.pc}"
		done
	done
}

grab_local "$@" || grab_requires "$@" && cat "$tempdir"/* | get_package_from_requires

from xtools.

maxice8 avatar maxice8 commented on July 17, 2024

Here is a final-ish version.

#!/bin/sh
# xpcdeps PKGS... 
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
			echo "$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 in "$@" ; 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

from xtools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.