diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2017-11-24 02:29:01 +0530 |
---|---|---|
committer | Nirbheek Chauhan <nirbheek@centricular.com> | 2018-03-10 19:05:19 +0530 |
commit | e84c9e75efc9d82262a5ec6036cc737c6089ab30 (patch) | |
tree | 2df9b15c83f43f433869fc3458844b6e625b70b3 /tools | |
parent | 3a7d3eee01dd5213547290c2b01db0810d4f50cc (diff) | |
download | gobject-introspection-e84c9e75efc9d82262a5ec6036cc737c6089ab30.tar.gz |
g-ir-scanner: Don't require SRCDIR and BUILDDIR env vars
When building with Meson, we cannot set environment variables while
running custom targets and our builddir layout is different from
Autotools anyway.
Now g-ir-scanner and friends can autodetect when they're being run
uninstalled by Meson and will find _giscanner.so and the giscanner
python files in the build directory. This is very similar to what
gdbus-codegen uses in glib/gio.
Same for girepository/gdump.c.
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/g-ir-tool-template.in | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/tools/g-ir-tool-template.in b/tools/g-ir-tool-template.in index 2eac21fd..10082171 100755 --- a/tools/g-ir-tool-template.in +++ b/tools/g-ir-tool-template.in @@ -47,24 +47,45 @@ if debug: pdb.pm() sys.excepthook = on_exception -if os.name == 'nt': - datadir = os.path.join(os.path.dirname(__file__), '..', 'share') - pylibdir = os.path.join(os.path.dirname(__file__), '..', 'lib', 'gobject-introspection') -else: +# Detect and set datadir, pylibdir, etc as applicable +# Similar to the method used in gdbus-codegen +filedir = os.path.dirname(__file__) + +# Try using relative paths first so that the installation prefix is relocatable +datadir = os.path.abspath(os.path.join(filedir, '..', 'share')) +# Fallback to hard-coded paths if the relocatable paths are wrong +if not os.path.isdir(os.path.join(datadir, 'gir-1.0')): datadir = "@datarootdir@" - pylibdir = os.path.join('@libdir@', 'gobject-introspection') builtins.__dict__['DATADIR'] = datadir -srcdir = os.getenv('UNINSTALLED_INTROSPECTION_SRCDIR', None) -if srcdir is not None: - pylibdir = srcdir +# Again, relative paths first so that the installation prefix is relocatable +pylibdir = os.path.abspath(os.path.join(filedir, '..', 'lib', 'gobject-introspection')) +if not os.path.isfile(os.path.join(pylibdir, 'giscanner', '_giscanner.so')): + # Running uninstalled? + builddir = os.getenv('UNINSTALLED_INTROSPECTION_BUILDDIR', None) + if builddir is not None: + # Autotools, most likely + builddir = os.path.abspath(builddir) + # For _giscanner.so + sys.path.insert(0, os.path.join(builddir, 'giscanner')) + srcdir = os.getenv('UNINSTALLED_INTROSPECTION_SRCDIR', None) + if srcdir: + # For the giscanner python files + pylibdir = srcdir + elif os.path.isdir(os.path.join(filedir, '..', 'giscanner')): + # We're running uninstalled inside meson + builddir = os.path.abspath(os.path.join(filedir, '..')) + pylibdir = builddir + gdump_path = os.path.join(builddir, 'girepository', 'gdump.c') + if os.path.isfile(gdump_path): + builtins.__dict__['GDUMP_PATH'] = gdump_path + else: + # Okay, we're not running uninstalled and the prefix is not + # relocatable. Use hard-coded libdir. + pylibdir = os.path.join('@libdir@', 'gobject-introspection') sys.path.insert(0, pylibdir) -builddir = os.getenv('UNINSTALLED_INTROSPECTION_BUILDDIR', None) -if builddir is not None: - sys.path.insert(0, os.path.join(builddir, 'giscanner')) - from giscanner.@TOOL_MODULE@ import @TOOL_FUNCTION@ sys.exit(@TOOL_FUNCTION@(sys.argv)) |