Phillip Smyth pushed to branch mac_fixes at BuildStream / buildstream
Commits:
- 
73cb2955
by knownexus at 2018-09-13T12:52:41Z
5 changed files:
- buildstream/_platform/darwin.py
- buildstream/_platform/linux.py
- buildstream/_platform/platform.py
- buildstream/sandbox/__init__.py
- + buildstream/sandbox/_dummysandbox.py
Changes:
| ... | ... | @@ -19,7 +19,7 @@ import os | 
| 19 | 19 |  import resource
 | 
| 20 | 20 |  | 
| 21 | 21 |  from .._exceptions import PlatformError
 | 
| 22 | -from ..sandbox import SandboxChroot
 | |
| 22 | +from ..sandbox import SandboxChroot, DummySandbox
 | |
| 23 | 23 |  | 
| 24 | 24 |  from . import Platform
 | 
| 25 | 25 |  | 
| ... | ... | @@ -38,7 +38,10 @@ class Darwin(Platform): | 
| 38 | 38 |          return self._artifact_cache
 | 
| 39 | 39 |  | 
| 40 | 40 |      def create_sandbox(self, *args, **kwargs):
 | 
| 41 | -        return SandboxChroot(*args, **kwargs)
 | |
| 41 | +        if os.path.exists('/dev/fuse'):
 | |
| 42 | +            return SandboxChroot(*args, **kwargs)
 | |
| 43 | +        else:
 | |
| 44 | +            return DummySandbox(*args, **kwargs)
 | |
| 42 | 45 |  | 
| 43 | 46 |      def get_cpu_count(self, cap=None):
 | 
| 44 | 47 |          if cap < os.cpu_count():
 | 
| ... | ... | @@ -24,7 +24,7 @@ from .. import _site | 
| 24 | 24 |  from .. import utils
 | 
| 25 | 25 |  from .._artifactcache.cascache import CASCache
 | 
| 26 | 26 |  from .._message import Message, MessageType
 | 
| 27 | -from ..sandbox import SandboxBwrap
 | |
| 27 | +from ..sandbox import SandboxBwrap, DummySandbox
 | |
| 28 | 28 |  | 
| 29 | 29 |  from . import Platform
 | 
| 30 | 30 |  | 
| ... | ... | @@ -48,10 +48,13 @@ class Linux(Platform): | 
| 48 | 48 |          return self._artifact_cache
 | 
| 49 | 49 |  | 
| 50 | 50 |      def create_sandbox(self, *args, **kwargs):
 | 
| 51 | -        # Inform the bubblewrap sandbox as to whether it can use user namespaces or not
 | |
| 52 | -        kwargs['user_ns_available'] = self._user_ns_available
 | |
| 53 | -        kwargs['die_with_parent_available'] = self._die_with_parent_available
 | |
| 54 | -        return SandboxBwrap(*args, **kwargs)
 | |
| 51 | +        if not (os.path.exists(utils.get_host_tool('bwrap')) and os.path.exists('/dev/fuse')):
 | |
| 52 | +            return DummySandbox(*args, **kwargs)
 | |
| 53 | +        else:
 | |
| 54 | +            # Inform the bubblewrap sandbox as to whether it can use user namespaces or not
 | |
| 55 | +            kwargs['user_ns_available'] = self._user_ns_available
 | |
| 56 | +            kwargs['die_with_parent_available'] = self._die_with_parent_available
 | |
| 57 | +            return SandboxBwrap(*args, **kwargs)
 | |
| 55 | 58 |  | 
| 56 | 59 |      ################################################
 | 
| 57 | 60 |      #              Private Methods                 #
 | 
| ... | ... | @@ -54,6 +54,8 @@ class Platform(): | 
| 54 | 54 |              backend = 'linux'
 | 
| 55 | 55 |          elif sys.platform.startswith('darwin'):
 | 
| 56 | 56 |              backend = 'darwin'
 | 
| 57 | +        elif not (os.path.exists(utils.get_host_tool('bwrap')) and os.path.exists('/dev/fuse')):
 | |
| 58 | +            backend = 'no_local'
 | |
| 57 | 59 |          else:
 | 
| 58 | 60 |              backend = 'unix'
 | 
| 59 | 61 |  | 
| ... | ... | @@ -63,6 +65,8 @@ class Platform(): | 
| 63 | 65 |              from .darwin import Darwin as PlatformImpl
 | 
| 64 | 66 |          elif backend == 'unix':
 | 
| 65 | 67 |              from .unix import Unix as PlatformImpl
 | 
| 68 | +        elif backend == 'no_local':
 | |
| 69 | +            from .nolocal import Nolocal as PlatformImpl
 | |
| 66 | 70 |          else:
 | 
| 67 | 71 |              raise PlatformError("No such platform: '{}'".format(backend))
 | 
| 68 | 72 |  | 
| ... | ... | @@ -21,3 +21,4 @@ from .sandbox import Sandbox, SandboxFlags | 
| 21 | 21 |  from ._sandboxchroot import SandboxChroot
 | 
| 22 | 22 |  from ._sandboxbwrap import SandboxBwrap
 | 
| 23 | 23 |  from ._sandboxremote import SandboxRemote
 | 
| 24 | +from ._dummysandbox import DummySandbox | 
| 1 | +#
 | |
| 2 | +#  Copyright (C) 2017 Codethink Limited
 | |
| 3 | +#
 | |
| 4 | +#  This program is free software; you can redistribute it and/or
 | |
| 5 | +#  modify it under the terms of the GNU Lesser General Public
 | |
| 6 | +#  License as published by the Free Software Foundation; either
 | |
| 7 | +#  version 2 of the License, or (at your option) any later version.
 | |
| 8 | +#
 | |
| 9 | +#  This library is distributed in the hope that it will be useful,
 | |
| 10 | +#  but WITHOUT ANY WARRANTY; without even the implied warranty of
 | |
| 11 | +#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
 | |
| 12 | +#  Lesser General Public License for more details.
 | |
| 13 | +#
 | |
| 14 | +#  You should have received a copy of the GNU Lesser General Public
 | |
| 15 | +#  License along with this library. If not, see <http://www.gnu.org/licenses/>.
 | |
| 16 | +#
 | |
| 17 | +#  Authors:
 | |
| 18 | + | |
| 19 | +from .._exceptions import SandboxError
 | |
| 20 | +from . import Sandbox
 | |
| 21 | + | |
| 22 | + | |
| 23 | +class DummySandbox(Sandbox):
 | |
| 24 | +    def __init__(self, *args, **kwargs):
 | |
| 25 | +        super().__init__(*args, **kwargs)
 | |
| 26 | + | |
| 27 | +        uid = self._get_config().build_uid
 | |
| 28 | +        gid = self._get_config().build_gid
 | |
| 29 | +        if uid != 0 or gid != 0:
 | |
| 30 | +            raise SandboxError("Chroot sandboxes cannot specify a non-root uid/gid "
 | |
| 31 | +                               "({},{} were supplied via config)".format(uid, gid))
 | |
| 32 | + | |
| 33 | +        self.mount_map = None
 | |
| 34 | + | |
| 35 | +    def run(self, command, flags, *, cwd=None, env=None):
 | |
| 36 | + | |
| 37 | +        # Default settings
 | |
| 38 | +        if cwd is None:
 | |
| 39 | +            cwd = self._get_work_directory()
 | |
| 40 | + | |
| 41 | +        if cwd is None:
 | |
| 42 | +            cwd = '/'
 | |
| 43 | + | |
| 44 | +        if env is None:
 | |
| 45 | +            env = self._get_environment()
 | |
| 46 | + | |
| 47 | +        # Naive getcwd implementations can break when bind-mounts to different
 | |
| 48 | +        # paths on the same filesystem are present. Letting the command know
 | |
| 49 | +        # what directory it is in makes it unnecessary to call the faulty
 | |
| 50 | +        # getcwd.
 | |
| 51 | +        env['PWD'] = cwd
 | |
| 52 | + | |
| 53 | +        if not self._has_command(command[0], env):
 | |
| 54 | +            raise SandboxError("Staged artifacts do not provide command "
 | |
| 55 | +                               "'{}'".format(command[0]),
 | |
| 56 | +                               reason='missing-command')
 | |
| 57 | + | |
| 58 | +        raise SandboxError("This platform does not support local builds") | 
