Commit 06a03dba authored by knownexus's avatar knownexus Committed by Jürg Billeter
Browse files

Adding darwin.py (MacOS) platform

Adding functionality to recognise Darwin as a platform in plaform.py
parent ee2a6e49
Loading
Loading
Loading
Loading
+50 −0
Original line number Original line Diff line number Diff line
#
#  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 .._exceptions import PlatformError
from ..sandbox import SandboxChroot, SandboxDummy

from . import Platform


class Darwin(Platform):

    # This value comes from OPEN_MAX in syslimits.h
    OPEN_MAX = 10240

    def __init__(self, context):

        super().__init__(context)

    def create_sandbox(self, *args, **kwargs):
        return SandboxDummy(*args, **kwargs)

    def check_sandbox_config(self, config):
        # Accept all sandbox configs as it's irrelevant with the dummy sandbox (no Sandbox.run).
        return True

    def get_cpu_count(self, cap=None):
        if cap < os.cpu_count():
            return cap
        else:
            return os.cpu_count()

    def set_resource_limits(self, soft_limit=OPEN_MAX, hard_limit=None):
        super().set_resource_limits(soft_limit)
+8 −5
Original line number Original line Diff line number Diff line
@@ -37,19 +37,22 @@ class Platform():


    @classmethod
    @classmethod
    def _create_instance(cls):
    def _create_instance(cls):
        if sys.platform.startswith('linux'):
            backend = 'linux'
        else:
            backend = 'unix'

        # Meant for testing purposes and therefore hidden in the
        # Meant for testing purposes and therefore hidden in the
        # deepest corners of the source code. Try not to abuse this,
        # deepest corners of the source code. Try not to abuse this,
        # please?
        # please?
        if os.getenv('BST_FORCE_BACKEND'):
        if os.getenv('BST_FORCE_BACKEND'):
            backend = 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':
        if backend == 'linux':
            from .linux import Linux as PlatformImpl
            from .linux import Linux as PlatformImpl
        elif backend == 'darwin':
            from .darwin import Darwin as PlatformImpl
        elif backend == 'unix':
        elif backend == 'unix':
            from .unix import Unix as PlatformImpl
            from .unix import Unix as PlatformImpl
        else:
        else: