summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2017-11-24 02:29:01 +0530
committerNirbheek Chauhan <nirbheek@centricular.com>2018-03-10 19:05:19 +0530
commite84c9e75efc9d82262a5ec6036cc737c6089ab30 (patch)
tree2df9b15c83f43f433869fc3458844b6e625b70b3
parent3a7d3eee01dd5213547290c2b01db0810d4f50cc (diff)
downloadgobject-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.
-rw-r--r--gir/meson.build8
-rw-r--r--girepository/meson.build8
-rw-r--r--giscanner/dumper.py7
-rw-r--r--giscanner/meson.build17
-rwxr-xr-xtools/g-ir-tool-template.in45
5 files changed, 62 insertions, 23 deletions
diff --git a/gir/meson.build b/gir/meson.build
index 5ae0acd1..e471b269 100644
--- a/gir/meson.build
+++ b/gir/meson.build
@@ -38,9 +38,6 @@ girdir = join_paths(get_option('datadir'), 'gir-1.0')
install_data(gir_files, install_dir: girdir)
scanner_command = [
- find_program('env'),
- 'UNINSTALLED_INTROSPECTION_SRCDIR=' + meson.source_root(),
- 'UNINSTALLED_INTROSPECTION_BUILDDIR=' + meson.build_root(),
girscanner,
'--output=@OUTPUT@',
'--no-libtool',
@@ -136,6 +133,7 @@ glib_gir = custom_target('gir-glib',
input: glib_files,
output: 'GLib-2.0.gir',
depends: giscanner_pymod,
+ depend_files: giscanner_built_files,
install: true,
install_dir: girdir,
command: glib_command + [
@@ -193,6 +191,7 @@ gobject_gir = custom_target('gir-gobject',
input: gobject_files,
output: 'GObject-2.0.gir',
depends: [glib_gir, giscanner_pymod],
+ depend_files: giscanner_built_files,
install: true,
install_dir: girdir,
command: gobject_command + [
@@ -234,6 +233,7 @@ gir_files += custom_target('gir-gmodule',
input: gmodule_files,
output: 'GModule-2.0.gir',
depends: [glib_gir, giscanner_pymod],
+ depend_files: giscanner_built_files,
install: true,
install_dir: girdir,
command: gmodule_command + [
@@ -316,6 +316,7 @@ gir_files += custom_target('gir-gio',
input: gio_files,
output: 'Gio-2.0.gir',
depends: [gobject_gir, giscanner_pymod],
+ depend_files: giscanner_built_files,
install: true,
install_dir: girdir,
command: gio_command + [
@@ -333,6 +334,7 @@ gir_files += custom_target('gir-girepository',
input: girepo_gir_sources,
output: 'GIRepository-2.0.gir',
depends: [gobject_gir, giscanner_pymod],
+ depend_files: giscanner_built_files,
install: true,
install_dir: girdir,
command: scanner_command + [
diff --git a/girepository/meson.build b/girepository/meson.build
index b020caa4..6a8c5b5d 100644
--- a/girepository/meson.build
+++ b/girepository/meson.build
@@ -136,8 +136,12 @@ girepo_lib = shared_library('girepository-1.0',
install: true,
)
-install_data('gdump.c',
- install_dir: join_paths(get_option('datadir'), 'gobject-introspection-1.0')
+# Copy to builddir for use with giscanner/dumper.py when running uninstalled
+configure_file(input : 'gdump.c',
+ output : 'gdump.c',
+ configuration : configuration_data(),
+ install_dir: join_paths(get_option('datadir'), 'gobject-introspection-1.0'),
+ install : true,
)
girepo_dep = declare_dependency(
diff --git a/giscanner/dumper.py b/giscanner/dumper.py
index 3c7220bc..8d255bfc 100644
--- a/giscanner/dumper.py
+++ b/giscanner/dumper.py
@@ -116,8 +116,11 @@ class DumpCompiler(object):
if self._uninst_srcdir is not None:
gdump_path = os.path.join(self._uninst_srcdir, 'girepository', 'gdump.c')
else:
- gdump_path = os.path.join(os.path.join(DATADIR), 'gobject-introspection-1.0',
- 'gdump.c')
+ try:
+ gdump_path = GDUMP_PATH
+ except NameError:
+ gdump_path = os.path.join(os.path.join(DATADIR),
+ 'gobject-introspection-1.0', 'gdump.c')
if not os.path.isfile(gdump_path):
raise SystemExit("Couldn't find %r" % (gdump_path, ))
with open(gdump_path) as gdump_file:
diff --git a/giscanner/meson.build b/giscanner/meson.build
index acf14863..5357ae52 100644
--- a/giscanner/meson.build
+++ b/giscanner/meson.build
@@ -1,6 +1,4 @@
-pkglibdir = join_paths(get_option('libdir'), meson.project_name())
-giscannerdir = join_paths(pkglibdir, 'giscanner')
-install_data([
+giscanner_files = [
'__init__.py',
'annotationmain.py',
'annotationparser.py',
@@ -27,8 +25,19 @@ install_data([
'transformer.py',
'utils.py',
'xmlwriter.py',
-], install_dir: giscannerdir)
+]
+
+pkglibdir = join_paths(get_option('libdir'), meson.project_name())
+giscannerdir = join_paths(pkglibdir, 'giscanner')
+giscanner_built_files = []
+blank_conf = configuration_data()
+foreach f : giscanner_files
+ giscanner_built_files += configure_file(input : f, output : f,
+ install : true,
+ install_dir : giscannerdir,
+ configuration : blank_conf)
+endforeach
install_subdir('doctemplates', install_dir: giscannerdir)
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))