aboutsummaryrefslogtreecommitdiffstats
path: root/gi-find-deps.sh.in
diff options
context:
space:
mode:
authorChristiaan Welvaart <cjw@mageia.org>2011-07-07 16:29:04 +0000
committerChristiaan Welvaart <cjw@mageia.org>2011-07-07 16:29:04 +0000
commit2b0222bf310ddfd221e18d0bae46e803c04db1d2 (patch)
tree31849aab2b50973f490dbbd9471e98a293530cfb /gi-find-deps.sh.in
parent61343fb5caf3dc815a8616cf912af1401ced05ec (diff)
downloadrpm-setup-2b0222bf310ddfd221e18d0bae46e803c04db1d2.tar
rpm-setup-2b0222bf310ddfd221e18d0bae46e803c04db1d2.tar.gz
rpm-setup-2b0222bf310ddfd221e18d0bae46e803c04db1d2.tar.bz2
rpm-setup-2b0222bf310ddfd221e18d0bae46e803c04db1d2.tar.xz
rpm-setup-2b0222bf310ddfd221e18d0bae46e803c04db1d2.zip
- extract gobject introspection typelib interdependencies using a helper program1.137
Diffstat (limited to 'gi-find-deps.sh.in')
-rwxr-xr-xgi-find-deps.sh.in91
1 files changed, 91 insertions, 0 deletions
diff --git a/gi-find-deps.sh.in b/gi-find-deps.sh.in
new file mode 100755
index 0000000..0a356c2
--- /dev/null
+++ b/gi-find-deps.sh.in
@@ -0,0 +1,91 @@
+#!/bin/sh
+
+# Automatically find Provides and Requires for typelib() gobject-introspection bindings.
+# can be started with -R (Requires) and -P (Provides)
+
+# Copyright 2011 by Dominique Leuenberger, Amsterdam, Netherlands (dimstar [at] opensuse.org)
+# This file is released under the GPLv2 or later.
+
+function split_name_version {
+base=$1
+tsymbol=${base%-*}
+# Sometimes we get a Requires on Gdk.Settings.foo, bebause you can directly use imports.gi.Gdk.Settings.Foo in Javascript.
+# We know that the symbol in this case is call Gdk, so we cut everything after the . away.
+symbol=$(echo $tsymbol | awk -F. '{print $1}')
+version=${base#*-}
+# In case there is no '-' in the filename, then the split above 'fails' and version == symbol (thus: no version specified)
+if [ "$tsymbol" = "$version" ]; then
+ unset version
+fi
+}
+
+function print_req_prov {
+echo -n "typelib($symbol)"
+if [ ! -z "$version" ]; then
+ echo " = ${version}"
+else
+ echo ""
+fi
+}
+
+function find_provides {
+while read file; do
+ case $file in
+ *.typelib)
+ split_name_version $(basename $file | sed 's,.typelib$,,')
+ print_req_prov
+ ;;
+ esac
+done
+}
+
+function find_requires {
+# FIXME: There are multiple ways gi bindings can be imported. We only catch the 'basic' one
+# Currently, we detect:
+# - in python:
+# . from gi.repository import foo [Unversioned requirement of 'foo']
+# . from gi.repository import foo-1.0 [versioned requirement]
+# . And we do not stumble over:
+# from gi.repository import foo as _bar
+# from gi.repository import foo, bar
+# - in JS:
+# . imports.gi.foo; [unversioned requirement of 'foo']
+# . imports.gi.goo-1.0; [versioned requirement]
+# . The imports can be listed on one line, and we catch them.
+# Forms currently not detected:
+# - js: imports.gi.versions.Gtk = '3.0';
+# - py: gi.require_version('Gtk', '3.0')
+
+while read file; do
+ case $file in
+ *.js)
+ for module in $(grep -h -P -o "imports.gi.([^\s'\";]+)" $file | grep -v "imports.gi.version" | sed 's,imports.gi.,,'); do
+ split_name_version $module
+ print_req_prov
+ done
+ ;;
+ *.py)
+ for module in $(grep -h -P "from gi.repository import (\w+)" $file | sed 's:#.*::' | sed -e 's,from gi.repository import,,' -r -e 's:\s+as\s+\w+::g' -e 's:,::g'); do
+ split_name_version $module
+ print_req_prov
+ done
+ ;;
+ *.typelib)
+ for module in $(@RPMVENDORDIR@/g-ir-extract-deps $file | tr '|' ' '); do
+ split_name_version $module
+ print_req_prov
+ done
+ ;;
+ esac
+done
+}
+
+case $1 in
+ -P)
+ find_provides
+ ;;
+ -R)
+ find_requires
+ ;;
+esac
+