Skip to content
Snippets Groups Projects
Commit c74aa8d3 authored by knownexus's avatar knownexus
Browse files

Adding darwin.py platform

Adding functionality to recognise Darwin as a platform in plaform.py
parent a55ab4f6
No related branches found
No related tags found
No related merge requests found
#
# Copyright (C) 2017 Codethink Limited
# Copyright (C) 2018 Bloomberg Finance LP
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library. If not, see <http://www.gnu.org/licenses/>.
import os
import resource
from .._artifactcache.cascache import CASCache
from .._exceptions import PlatformError
from ..sandbox import SandboxChroot
from . import Platform
class Darwin(Platform):
def __init__(self, context):
super().__init__(context)
self._artifact_cache = CASCache(context)
# Need to set resources for _frontend/app.py as this is dependent on the platform
# SafeHardlinks FUSE needs to hold file descriptors for all processes in the sandbox.
# Avoid hitting the limit too quickly.
limits = resource.getrlimit(resource.RLIMIT_NOFILE)
if limits[0] != limits[1]:
resource.setrlimit(resource.RLIMIT_NOFILE, (49152, limits[1]))
# Not necessarily 100% reliable, but we want to fail early.
if os.geteuid() != 0:
raise PlatformError("Root privileges are required to run without bubblewrap.")
@property
def artifactcache(self):
return self._artifact_cache
def create_sandbox(self, *args, **kwargs):
return SandboxChroot(*args, **kwargs)
......@@ -40,19 +40,23 @@ class Platform():
@classmethod
def create_instance(cls, *args, **kwargs):
if sys.platform.startswith('linux'):
backend = 'linux'
else:
backend = 'unix'
# Meant for testing purposes and therefore hidden in the
# deepest corners of the source code. Try not to abuse this,
# please?
if os.getenv('BST_FORCE_BACKEND'):
backend = os.getenv('BST_FORCE_BACKEND')
elif sys.platform.startswith('linux'):
backend = 'linux'
elif sys.platform.startswith('darwin'):
backend = 'darwin'
else:
backend = 'unix'
if backend == 'linux':
from .linux import Linux as PlatformImpl
elif backend == 'darwin':
from .darwin import Darwin as PlatformImpl
elif backend == 'unix':
from .unix import Unix as PlatformImpl
else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment