2011-04-27 16:45:13 +02:00
|
|
|
#!/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
|
2011-05-31 10:01:33 +02:00
|
|
|
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}')
|
2011-04-27 16:45:13 +02:00
|
|
|
version=${base#*-}
|
|
|
|
# In case there is no '-' in the filename, then the split above 'fails' and version == symbol (thus: no version specified)
|
2011-05-31 10:01:33 +02:00
|
|
|
if [ "$tsymbol" = "$version" ]; then
|
2011-04-27 16:45:13 +02:00
|
|
|
unset version
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function print_req_prov {
|
2011-08-17 21:52:54 +02:00
|
|
|
echo -n "typelib($symbol)"
|
2011-04-27 16:45:13 +02:00
|
|
|
if [ ! -z "$version" ]; then
|
|
|
|
echo " = ${version}"
|
|
|
|
else
|
|
|
|
echo ""
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function find_provides {
|
|
|
|
while read file; do
|
|
|
|
case $file in
|
2011-05-27 10:40:53 +02:00
|
|
|
*.typelib)
|
2011-04-27 16:45:13 +02:00
|
|
|
split_name_version $(basename $file | sed 's,.typelib$,,')
|
|
|
|
print_req_prov
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
function find_requires {
|
2011-04-27 16:49:19 +02:00
|
|
|
# FIXME: There are multiple ways gi bindings can be imported. We only catch the 'basic' one
|
2011-04-27 16:45:13 +02:00
|
|
|
# Currently, we detect:
|
|
|
|
# - in python:
|
|
|
|
# . from gi.repository import foo [Unversioned requirement of 'foo']
|
|
|
|
# . from gi.repository import foo-1.0 [versioned requirement]
|
2011-04-27 16:49:19 +02:00
|
|
|
# . And we do not stumble over:
|
|
|
|
# from gi.repository import foo as _bar
|
|
|
|
# from gi.repository import foo, bar
|
2011-04-27 16:45:13 +02:00
|
|
|
# - 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.
|
2011-04-27 16:49:19 +02:00
|
|
|
# Forms currently not detected:
|
|
|
|
# - js: imports.gi.versions.Gtk = '3.0';
|
|
|
|
# - py: gi.require_version('Gtk', '3.0')
|
2011-04-27 16:45:13 +02:00
|
|
|
|
|
|
|
while read file; do
|
|
|
|
case $file in
|
|
|
|
*.js)
|
2011-07-20 10:09:38 +02:00
|
|
|
for module in $(grep -h -P -o "imports.gi.([^\s'\";]+)" $file | grep -v "imports.gi.version" | sed -r -e 's,\s+$,,g' -e 's,imports.gi.,,'); do
|
2011-04-27 16:45:13 +02:00
|
|
|
split_name_version $module
|
|
|
|
print_req_prov
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
*.py)
|
2011-08-17 21:50:04 +02:00
|
|
|
for module in $(grep -h -P "from gi.repository import (\w+)" $file | sed -e 's:#.*::' -e 's:raise ImportError.*::' | sed -e 's,from gi.repository import,,' -r -e 's:\s+$::g' -e 's:\s+as\s+\w+::g' -e 's:,: :g'); do
|
2011-04-27 16:45:13 +02:00
|
|
|
split_name_version $module
|
|
|
|
print_req_prov
|
|
|
|
done
|
|
|
|
;;
|
2011-12-12 16:44:10 +01:00
|
|
|
*.typelib)
|
|
|
|
split_name_version $(basename $file | sed 's,.typelib$,,')
|
|
|
|
oldIFS=$IFS
|
|
|
|
IFS=$'\n'
|
|
|
|
for req in $(g-ir-dep-tool $symbol $version); do
|
|
|
|
case $req in
|
|
|
|
typelib:*)
|
|
|
|
module=${req#typelib: }
|
|
|
|
split_name_version $module
|
|
|
|
print_req_prov
|
|
|
|
;;
|
|
|
|
shlib:*)
|
|
|
|
echo "${req#shlib: }${shlib_64}"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
IFS=$oldIFS
|
|
|
|
;;
|
2011-04-27 16:45:13 +02:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2011-12-23 16:19:31 +01:00
|
|
|
for path in \
|
|
|
|
$(for tlpath in \
|
2012-02-08 13:54:04 +01:00
|
|
|
$(find ${RPM_BUILD_ROOT}/usr/lib64 ${RPM_BUILD_ROOT}/usr/lib /usr/lib64 /usr/lib -name '*.typelib' 2>/dev/null); do
|
2011-12-23 16:19:31 +01:00
|
|
|
dirname $tlpath; done | uniq ); do
|
|
|
|
export GI_TYPELIB_PATH=$GI_TYPELIB_PATH:$path
|
|
|
|
done
|
2011-12-12 16:44:10 +01:00
|
|
|
|
2012-02-08 13:54:04 +01:00
|
|
|
if [ "${HOSTTYPE}" == "x86_64" -o "${HOSTTYPE}" == "ppc64" -o "${HOSTTYPE}" == "s390x" -o "${HOSTTYPE}" == "ia64" ]; then
|
2011-12-12 16:44:10 +01:00
|
|
|
shlib_64="()(64bit)"
|
|
|
|
fi
|
2011-04-27 16:45:13 +02:00
|
|
|
case $1 in
|
|
|
|
-P)
|
|
|
|
find_provides
|
|
|
|
;;
|
|
|
|
-R)
|
|
|
|
find_requires
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|