You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by ro...@apache.org on 2020/12/29 13:39:16 UTC

[buildstream] 02/17: meson: Add dependency checks

This is an automated email from the ASF dual-hosted git repository.

root pushed a commit to branch sam/meson
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 852f23c31b426e0fcf9e6e3562bbaedae0a1c57e
Author: Sam Thursfield <sa...@codethink.co.uk>
AuthorDate: Wed Dec 13 18:25:58 2017 +0000

    meson: Add dependency checks
    
    We don't check for our Python dependencies so far. Adding support upstream
    to do this would be the best approach.
    
    See: https://github.com/mesonbuild/meson/issues/2377
---
 meson-ostree-check | 17 +++++++++++++++
 meson.build        | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 meson_options.txt  |  2 ++
 3 files changed, 82 insertions(+)

diff --git a/meson-ostree-check b/meson-ostree-check
new file mode 100755
index 0000000..19c21ca
--- /dev/null
+++ b/meson-ostree-check
@@ -0,0 +1,17 @@
+#!/usr/bin/env python3
+
+import sys
+
+try:
+    import gi
+    gi.require_version('OSTree', '1.0')
+    from gi.repository import OSTree
+except (ImportError, ValueError):
+    sys.stderr.write("OSTree not found.\n")
+    sys.exit(1)
+
+try:
+    print('{}.{}'.format(OSTree.YEAR_VERSION, OSTree.RELEASE_VERSION))
+except AttributeError:
+    sys.stderr.write("OSTree found, but it is probably too old as it does not "
+                     "provide the expected version information.\n")
diff --git a/meson.build b/meson.build
index 66a6b44..0e0fa78 100644
--- a/meson.build
+++ b/meson.build
@@ -1,5 +1,22 @@
 project('buildstream', version: '0.1')
 
+if get_option('check_backend') == 'auto'
+  platform = host_machine.system()
+  if platform == 'linux'
+    backend = 'linux'
+  else
+    backend = 'posix'
+  endif
+else
+  backend = get_option('check_backend')
+endif
+
+message('Checking dependencies for backend: @0@'.format(backend))
+
+
+##################################################################
+# Python requirements
+##################################################################
 
 python = find_program('python3', required: true)
 
@@ -9,6 +26,52 @@ if python_version_check.returncode() != 0
 endif
 python_version = python_version_check.stdout()
 
+if not python_version.version_compare('>= 3.4')
+  error('BuildStream requires Python >= 3.4')
+endif
+
+##################################################################
+# Bubblewrap requirements
+##################################################################
+
+if backend == 'linux'
+  bwrap = find_program('bwrap', required: false)
+  if not bwrap.found()
+    error('Bubblewrap not found. BuildStream requires Bubblewrap (bwrap) for' +
+          ' sandboxing the build environment. Install it using your package manager' +
+          ' (usually bwrap or bubblewrap)')
+  endif
+endif
+
+
+##################################################################
+# OSTree version requirements
+##################################################################
+
+REQUIRED_OSTREE = '>= 2017.8'
+
+if backend == 'linux'
+  message('Checking for OSTree @0@ with PyGObject bindings'.format(REQUIRED_OSTREE))
+  gi_check = run_command(python, '-c', 'import gi')
+  if gi_check.returncode() != 0
+    error('BuildStream requires PyGObject (aka PyGI). Install it using' +
+          ' your package manager (usually pygobject3 or python-gi).')
+  endif
+
+  ostree_version_check = run_command('meson-ostree-check')
+  if ostree_version_check.returncode() != 0
+    message = ostree_version_check.stderr().strip()
+    error(message + '\nBuildStream requires OSTree @0@ with Python bindings.'.format(REQUIRED_OSTREE) +
+          ' Install it using your package manager (usually ostree or gir1.2-ostree-1.0).')
+  else
+    ostree_version = ostree_version_check.stdout().strip()
+    if not ostree_version.version_compare(REQUIRED_OSTREE)
+      error('OSTree is too old; found version @0@ but we require @1@'.format(ostree_version, REQUIRED_OSTREE))
+    endif
+  endif
+endif
+
+
 python_name = 'python' + python_version
 python_site_packages_dir = join_paths(get_option('prefix'), get_option('libdir'), python_name, 'site-packages')
 
diff --git a/meson_options.txt b/meson_options.txt
new file mode 100644
index 0000000..01ef12d
--- /dev/null
+++ b/meson_options.txt
@@ -0,0 +1,2 @@
+option('check_backend', type: 'combo', choices: ['auto', 'linux', 'unix'],
+        description: 'Check for dependencies needed for a specific backend (default: autodetect backend)')