From c46a7e878ad94c856083fc84dbc09fc9f6126ff3 Mon Sep 17 00:00:00 2001
From: Daniel Silverstone <daniel.silverstone@codethink.co.uk>
Date: Tue, 2 Oct 2018 13:39:15 +0100
Subject: [PATCH] setup.py: Change bwrap assertion to a warning

Since there are use-cases where BuildStream could be installed
onto systems which do not have BubbleWrap (e.g. for remote-build-only
scenarios) it is not correct to assert a dependency on bwrap during
installation.  This patch makes the assertion a warning, and also
clarifies the message somewhat.  This should fix #644

Signed-off-by: Daniel Silverstone <daniel.silverstone@codethink.co.uk>
---
 setup.py | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/setup.py b/setup.py
index 405a390614..74ccfc24ae 100755
--- a/setup.py
+++ b/setup.py
@@ -54,12 +54,13 @@ REQUIRED_BWRAP_MINOR = 1
 REQUIRED_BWRAP_PATCH = 2
 
 
-def exit_bwrap(reason):
+def warn_bwrap(reason):
     print(reason +
-          "\nBuildStream requires Bubblewrap (bwrap) for"
-          " sandboxing the build environment. Install it using your package manager"
-          " (usually bwrap or bubblewrap)")
-    sys.exit(1)
+          "\nBuildStream requires Bubblewrap (bwrap {}.{}.{} or better),"
+          " during local builds, for"
+          " sandboxing the build environment.\nInstall it using your package manager"
+          " (usually bwrap or bubblewrap) otherwise you will be limited to"
+          " remote builds only.".format(REQUIRED_BWRAP_MAJOR, REQUIRED_BWRAP_MINOR, REQUIRED_BWRAP_PATCH))
 
 
 def bwrap_too_old(major, minor, patch):
@@ -76,18 +77,19 @@ def bwrap_too_old(major, minor, patch):
         return False
 
 
-def assert_bwrap():
+def check_for_bwrap():
     platform = os.environ.get('BST_FORCE_BACKEND', '') or sys.platform
     if platform.startswith('linux'):
         bwrap_path = shutil.which('bwrap')
         if not bwrap_path:
-            exit_bwrap("Bubblewrap not found")
+            warn_bwrap("Bubblewrap not found")
+            return
 
         version_bytes = subprocess.check_output([bwrap_path, "--version"]).split()[1]
         version_string = str(version_bytes, "utf-8")
         major, minor, patch = map(int, version_string.split("."))
         if bwrap_too_old(major, minor, patch):
-            exit_bwrap("Bubblewrap too old")
+            warn_bwrap("Bubblewrap too old")
 
 
 ###########################################
@@ -126,7 +128,7 @@ bst_install_entry_points = {
 }
 
 if not os.environ.get('BST_ARTIFACTS_ONLY', ''):
-    assert_bwrap()
+    check_for_bwrap()
     bst_install_entry_points['console_scripts'] += [
         'bst = buildstream._frontend:cli'
     ]
-- 
GitLab