From 2dbf8f4ea4992ca33c272786f860d7fc291ba89b Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Wed, 11 Jul 2018 18:49:27 +0200 Subject: [PATCH] meson: Add a "python" option to make the python to build against configurable This allows us to build with Python 2 and run tests with it. This requires the new "python" meson module which was added in 0.46.0 so bump the required meson version (glib needs a newer one anyway). Also fixes a small test error under Python 2. --- .gitlab-ci.yml | 23 +++++++++++++++++++++-- .gitlab-ci/Dockerfile | 3 +++ .gitlab-ci/test-msys2.sh | 5 ++++- gir/meson.build | 16 ++++++++-------- giscanner/introspectablepass.py | 2 +- giscanner/meson.build | 4 ++-- meson.build | 6 +++--- meson_options.txt | 4 ++++ tests/scanner/meson.build | 2 +- tests/warn/meson.build | 2 +- tools/meson.build | 3 +-- 11 files changed, 49 insertions(+), 21 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 74052943e..457b8921e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,14 +5,33 @@ cache: paths: - _ccache/ -fedora-x86_64: +fedora-x86_64-python3: stage: build image: registry.gitlab.gnome.org/gnome/gobject-introspection:v1 variables: CCACHE_BASEDIR: "${CI_PROJECT_DIR}" CCACHE_DIR: "${CI_PROJECT_DIR}/_ccache" script: - - meson --prefix /usr --libdir /usr/lib64 --buildtype debug -Dcairo=true _build . + - meson --prefix /usr --libdir /usr/lib64 --buildtype debug -Dcairo=true -Dpython=python3 _build . + - cd _build + - ninja + - meson test --print-errorlogs --suite=gobject-introspection --no-suite=glib + except: + - tags + artifacts: + when: on_failure + name: "gi-_${CI_COMMIT_REF_NAME}" + paths: + - "${CI_PROJECT_DIR}/_build/meson-logs" + +fedora-x86_64-python2: + stage: build + image: registry.gitlab.gnome.org/gnome/gobject-introspection:v1 + variables: + CCACHE_BASEDIR: "${CI_PROJECT_DIR}" + CCACHE_DIR: "${CI_PROJECT_DIR}/_ccache" + script: + - meson --prefix /usr --libdir /usr/lib64 --buildtype debug -Dcairo=true -Dpython=python2 _build . - cd _build - ninja - meson test --print-errorlogs --suite=gobject-introspection --no-suite=glib diff --git a/.gitlab-ci/Dockerfile b/.gitlab-ci/Dockerfile index 8b13de05e..c232b6c5a 100644 --- a/.gitlab-ci/Dockerfile +++ b/.gitlab-ci/Dockerfile @@ -36,6 +36,9 @@ RUN dnf -y install \ python3-mako \ python3-pip \ python3-wheel \ + python2 \ + python2-devel \ + python2-mako \ redhat-rpm-config \ systemtap-sdt-devel \ zlib-devel \ diff --git a/.gitlab-ci/test-msys2.sh b/.gitlab-ci/test-msys2.sh index ef69fe8f8..6260ac155 100644 --- a/.gitlab-ci/test-msys2.sh +++ b/.gitlab-ci/test-msys2.sh @@ -32,7 +32,10 @@ export CCACHE_DIR="${CCACHE_BASEDIR}/_ccache" pip3 install --upgrade --user meson==0.47.1 export PATH="$HOME/.local/bin:$PATH" -meson --buildtype debug _build +# FIXME: https://github.com/Alexpux/MINGW-packages/pull/4064 +# Passing the full interpreter path works around the issue +PYTHON="$(which python3)" +meson -Dpython="${PYTHON}" --buildtype debug _build cd _build ninja diff --git a/gir/meson.build b/gir/meson.build index 4a3b4508b..607bbc452 100644 --- a/gir/meson.build +++ b/gir/meson.build @@ -38,7 +38,7 @@ girdir = join_paths(get_option('datadir'), 'gir-1.0') install_data(gir_files, install_dir: girdir) scanner_command = [ - python3, + python, girscanner, '--output=@OUTPUT@', '--no-libtool', @@ -93,7 +93,7 @@ if dep_type == 'pkgconfig' glib_files += join_paths(glib_incdir, 'glib-unix.h') endif # Parse glob to get installed header list - ret = run_command(python3, '-c', globber.format(join_paths(glib_incdir, 'glib', '*.h'))) + ret = run_command(python, '-c', globber.format(join_paths(glib_incdir, 'glib', '*.h'))) if ret.returncode() != 0 error('Failed to get glib header list') endif @@ -101,7 +101,7 @@ if dep_type == 'pkgconfig' # Get a list of all source files glib_srcdir = get_option('glib-src-dir') if glib_srcdir != '' - ret = run_command(python3, '-c', globber.format(join_paths(glib_srcdir, 'glib', '*.c'))) + ret = run_command(python, '-c', globber.format(join_paths(glib_srcdir, 'glib', '*.c'))) if ret.returncode() != 0 error('Failed to get glib source list') endif @@ -200,13 +200,13 @@ gobject_command = scanner_command + [ if dep_type == 'pkgconfig' gobject_command += ['--external-library', '--pkg=gobject-2.0'] # Get the installed header list - ret = run_command(python3, '-c', globber.format(join_paths(glib_incdir, 'gobject', '*.h'))) + ret = run_command(python, '-c', globber.format(join_paths(glib_incdir, 'gobject', '*.h'))) if ret.returncode() != 0 error('Failed to get gobject header list') endif gobject_headers = ret.stdout().strip().split('\n') if glib_srcdir != '' - ret = run_command(python3, '-c', globber.format(join_paths(glib_srcdir, 'gobject', '*.c'))) + ret = run_command(python, '-c', globber.format(join_paths(glib_srcdir, 'gobject', '*.c'))) if ret.returncode() != 0 error('Failed to get gobject source list') endif @@ -307,7 +307,7 @@ gio_command = scanner_command + [ if dep_type == 'pkgconfig' gio_command += ['--external-library', '--pkg=gio-2.0'] # Get the installed header list - ret = run_command(python3, '-c', globber.format(join_paths(glib_incdir, 'gio', '*.h'))) + ret = run_command(python, '-c', globber.format(join_paths(glib_incdir, 'gio', '*.h'))) if ret.returncode() != 0 error('Failed to get gio header list') endif @@ -316,7 +316,7 @@ if dep_type == 'pkgconfig' # probably fine since it matches what Autotools does. We are more exact in # the subproject case. if glib_srcdir != '' - ret = run_command(python3, '-c', globber.format(join_paths(glib_srcdir, 'gio', '*.c'))) + ret = run_command(python, '-c', globber.format(join_paths(glib_srcdir, 'gio', '*.c'))) if ret.returncode() != 0 error('Failed to get gio source list') endif @@ -341,7 +341,7 @@ if giounix_dep.found() gio_command += ['--pkg=gio-unix-2.0'] giounix_includedir = join_paths(giounix_dep.get_pkgconfig_variable('includedir'), 'gio-unix-2.0') # Get the installed gio-unix header list - ret = run_command(python3, '-c', globber.format(join_paths(giounix_includedir, 'gio', '*.h'))) + ret = run_command(python, '-c', globber.format(join_paths(giounix_includedir, 'gio', '*.h'))) if ret.returncode() != 0 error('Failed to get gio-unix header list') endif diff --git a/giscanner/introspectablepass.py b/giscanner/introspectablepass.py index 19d1388f4..072494bde 100644 --- a/giscanner/introspectablepass.py +++ b/giscanner/introspectablepass.py @@ -84,7 +84,7 @@ class IntrospectablePass(object): if not node.type.resolved: self._parameter_warning(parent, node, - "Unresolved type: %r" % (node.type.unresolved_string, )) + "Unresolved type: '%s'" % (node.type.unresolved_string, )) parent.introspectable = False return diff --git a/giscanner/meson.build b/giscanner/meson.build index 5a1e44c9e..b4ec37962 100644 --- a/giscanner/meson.build +++ b/giscanner/meson.build @@ -79,12 +79,12 @@ giscanner_lib = static_library('giscanner', dependencies: [glib_dep, gobject_dep, gio_dep, gmodule_dep], ) -giscanner_pymod = py3.extension_module('_giscanner', 'giscannermodule.c', +giscanner_pymod = python.extension_module('_giscanner', ['giscannermodule.c'], link_with: giscanner_lib, c_args: [gi_hidden_visibility_cflags], include_directories : configinc, dependencies: [glib_dep, gobject_dep, gio_dep, gmodule_dep, - dependency('python3')], + python.dependency()], install: true, install_dir: giscannerdir, ) diff --git a/meson.build b/meson.build index 07446553f..f5d7561a7 100644 --- a/meson.build +++ b/meson.build @@ -1,6 +1,6 @@ project('gobject-introspection', 'c', version: '1.57.1', - meson_version: '>= 0.42.0', + meson_version: '>= 0.46.0', default_options: [ 'warning_level=1', 'buildtype=debugoptimized', @@ -12,8 +12,8 @@ gi_versions = meson.project_version().split('.') configinc = include_directories('.') -py3 = import('python3') -python3 = py3.find_python() +pymod = import('python') +python = pymod.find_installation(get_option('python')) cc = meson.get_compiler('c') config = configuration_data() diff --git a/meson_options.txt b/meson_options.txt index 282442083..49726be60 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -17,3 +17,7 @@ option('gtk-doc', type: 'boolean', value: false, option('cairo-libname', type: 'string', description: 'Custom name for the cairo-gobject library name' ) + +option('python', type: 'string', value: 'python3', + description: 'Path or name of the Python interpreter to build for' +) diff --git a/tests/scanner/meson.build b/tests/scanner/meson.build index cd8df9912..e64345a07 100644 --- a/tests/scanner/meson.build +++ b/tests/scanner/meson.build @@ -13,6 +13,6 @@ if host_system != 'windows' endif foreach f : scanner_test_files - test(f, python3, args: files(f), env: scanner_test_env) + test(f, python, args: files(f), env: scanner_test_env) endforeach diff --git a/tests/warn/meson.build b/tests/warn/meson.build index 53d00cc7f..f14590ca5 100644 --- a/tests/warn/meson.build +++ b/tests/warn/meson.build @@ -32,7 +32,7 @@ warn_test_env.set( if host_system != 'windows' foreach warn_fn : warn_tests test( - 'warn-' + warn_fn.split('.')[0], files(python3.path()), + 'warn-' + warn_fn.split('.')[0], python, workdir: meson.current_source_dir(), env: warn_test_env, args: ['warningtester.py', warn_fn], diff --git a/tools/meson.build b/tools/meson.build index 8971a9d53..aaf4bc843 100644 --- a/tools/meson.build +++ b/tools/meson.build @@ -1,6 +1,5 @@ libdir_abs = join_paths(get_option('prefix'), get_option('libdir')) datadir_abs = join_paths(get_option('prefix'), get_option('datadir')) -python_path = python3.path() tools = [ ['g-ir-scanner', 'scannermain', 'scanner_main'], @@ -15,7 +14,7 @@ foreach tool : tools tools_conf = configuration_data() tools_conf.set('libdir', libdir_abs) tools_conf.set('datarootdir', datadir_abs) - tools_conf.set('PYTHON', python_path) + tools_conf.set('PYTHON', 'python' + python.language_version()) tools_conf.set('TOOL_MODULE', tool[1]) tools_conf.set('TOOL_FUNCTION', tool[2]) -- GitLab