[Notes] [Git][BuildStream/buildstream][mac_fixes] 2 commits: Adding darwin.py platform



Title: GitLab

Phillip Smyth pushed to branch mac_fixes at BuildStream / buildstream

Commits:

6 changed files:

Changes:

  • buildstream/_platform/darwin.py
    1
    +#
    
    2
    +#  Copyright (C) 2017 Codethink Limited
    
    3
    +#  Copyright (C) 2018 Bloomberg Finance LP
    
    4
    +#
    
    5
    +#  This program is free software; you can redistribute it and/or
    
    6
    +#  modify it under the terms of the GNU Lesser General Public
    
    7
    +#  License as published by the Free Software Foundation; either
    
    8
    +#  version 2 of the License, or (at your option) any later version.
    
    9
    +#
    
    10
    +#  This library is distributed in the hope that it will be useful,
    
    11
    +#  but WITHOUT ANY WARRANTY; without even the implied warranty of
    
    12
    +#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
    
    13
    +#  Lesser General Public License for more details.
    
    14
    +#
    
    15
    +#  You should have received a copy of the GNU Lesser General Public
    
    16
    +#  License along with this library. If not, see <http://www.gnu.org/licenses/>.
    
    17
    +
    
    18
    +import os
    
    19
    +import resource
    
    20
    +
    
    21
    +from .._exceptions import PlatformError
    
    22
    +from ..sandbox import SandboxChroot
    
    23
    +
    
    24
    +from . import Platform
    
    25
    +
    
    26
    +
    
    27
    +class Darwin(Platform):
    
    28
    +
    
    29
    +    def __init__(self, context):
    
    30
    +
    
    31
    +        # This value comes from OPEN_MAX in syslimits.h
    
    32
    +        OPEN_MAX = 10240
    
    33
    +        super().__init__(context)
    
    34
    +
    
    35
    +    @property
    
    36
    +    def artifactcache(self):
    
    37
    +        return self._artifact_cache
    
    38
    +
    
    39
    +    def create_sandbox(self, *args, **kwargs):
    
    40
    +        return SandboxChroot(*args, **kwargs)
    
    41
    +
    
    42
    +    def get_cpu_count(self, cap=None):
    
    43
    +        if cap < os.cpu_count():
    
    44
    +            return cap
    
    45
    +        else:
    
    46
    +            return os.cpu_count()
    
    47
    +
    
    48
    +    def set_resources(self, soft_limit=OPEN_MAX, hard_limit=None):
    
    49
    +        super().set_resources(soft_limit)

  • buildstream/_platform/linux.py
    ... ... @@ -41,6 +41,7 @@ class Linux(Platform):
    41 41
                 self._user_ns_available = self._check_user_ns_available(context)
    
    42 42
             else:
    
    43 43
                 self._user_ns_available = False
    
    44
    +
    
    44 45
             self._artifact_cache = CASCache(context, enable_push=self._user_ns_available)
    
    45 46
     
    
    46 47
         @property
    

  • buildstream/_platform/platform.py
    ... ... @@ -22,6 +22,7 @@ import sys
    22 22
     import resource
    
    23 23
     
    
    24 24
     from .._exceptions import PlatformError, ImplError
    
    25
    +from .._artifactcache.cascache import CASCache
    
    25 26
     
    
    26 27
     
    
    27 28
     class Platform():
    
    ... ... @@ -39,22 +40,27 @@ class Platform():
    39 40
         def __init__(self, context):
    
    40 41
             self.context = context
    
    41 42
             self.set_resources()
    
    43
    +        self._artifact_cache = CASCache(context)
    
    42 44
     
    
    43 45
         @classmethod
    
    44 46
         def create_instance(cls, *args, **kwargs):
    
    45
    -        if sys.platform.startswith('linux'):
    
    46
    -            backend = 'linux'
    
    47
    -        else:
    
    48
    -            backend = 'unix'
    
    49 47
     
    
    50 48
             # Meant for testing purposes and therefore hidden in the
    
    51 49
             # deepest corners of the source code. Try not to abuse this,
    
    52 50
             # please?
    
    53 51
             if os.getenv('BST_FORCE_BACKEND'):
    
    54 52
                 backend = os.getenv('BST_FORCE_BACKEND')
    
    53
    +        elif sys.platform.startswith('linux'):
    
    54
    +            backend = 'linux'
    
    55
    +        elif sys.platform.startswith('darwin'):
    
    56
    +            backend = 'darwin'
    
    57
    +        else:
    
    58
    +            backend = 'unix'
    
    55 59
     
    
    56 60
             if backend == 'linux':
    
    57 61
                 from .linux import Linux as PlatformImpl
    
    62
    +        elif backend == 'darwin':
    
    63
    +            from .darwin import Darwin as PlatformImpl
    
    58 64
             elif backend == 'unix':
    
    59 65
                 from .unix import Unix as PlatformImpl
    
    60 66
             else:
    

  • buildstream/_platform/unix.py
    ... ... @@ -20,7 +20,6 @@
    20 20
     import os
    
    21 21
     import resource
    
    22 22
     
    
    23
    -from .._artifactcache.cascache import CASCache
    
    24 23
     from .._exceptions import PlatformError
    
    25 24
     from ..sandbox import SandboxChroot
    
    26 25
     
    
    ... ... @@ -32,7 +31,6 @@ class Unix(Platform):
    32 31
         def __init__(self, context):
    
    33 32
     
    
    34 33
             super().__init__(context)
    
    35
    -        self._artifact_cache = CASCache(context)
    
    36 34
     
    
    37 35
             # Not necessarily 100% reliable, but we want to fail early.
    
    38 36
             if os.geteuid() != 0:
    

  • buildstream/_project.py
    ... ... @@ -19,6 +19,7 @@
    19 19
     #        Tiago Gomes <tiago gomes codethink co uk>
    
    20 20
     
    
    21 21
     import os
    
    22
    +import sys
    
    22 23
     from collections import Mapping, OrderedDict
    
    23 24
     from pluginbase import PluginBase
    
    24 25
     from . import utils
    
    ... ... @@ -38,6 +39,7 @@ from ._loader import Loader
    38 39
     from .element import Element
    
    39 40
     from ._message import Message, MessageType
    
    40 41
     from ._includes import Includes
    
    42
    +from ._platform import Platform
    
    41 43
     
    
    42 44
     
    
    43 45
     # Project Configuration file
    
    ... ... @@ -605,7 +607,8 @@ class Project():
    605 607
             # Based on some testing (mainly on AWS), maximum effective
    
    606 608
             # max-jobs value seems to be around 8-10 if we have enough cores
    
    607 609
             # users should set values based on workload and build infrastructure
    
    608
    -        output.base_variables['max-jobs'] = str(min(len(os.sched_getaffinity(0)), 8))
    
    610
    +        platform = Platform.get_platform()
    
    611
    +        output.base_variables['max-jobs'] = str(platform.get_cpu_count(8))
    
    609 612
     
    
    610 613
             # Export options into variables, if that was requested
    
    611 614
             output.options.export_variables(output.base_variables)
    

  • buildstream/utils.py
    ... ... @@ -35,6 +35,7 @@ import tempfile
    35 35
     import itertools
    
    36 36
     import functools
    
    37 37
     from contextlib import contextmanager
    
    38
    +from stat import S_ISDIR
    
    38 39
     
    
    39 40
     import psutil
    
    40 41
     
    
    ... ... @@ -328,25 +329,25 @@ def safe_remove(path):
    328 329
         Raises:
    
    329 330
            UtilError: In the case of unexpected system call failures
    
    330 331
         """
    
    331
    -    if os.path.lexists(path):
    
    332
    +    if not S_ISDIR(os.lstat(path).st_mode):
    
    332 333
     
    
    333 334
             # Try to remove anything that is in the way, but issue
    
    334 335
             # a warning instead if it removes a non empty directory
    
    335 336
             try:
    
    336 337
                 os.unlink(path)
    
    338
    +            return True
    
    337 339
             except OSError as e:
    
    338
    -            if e.errno != errno.EISDIR:
    
    339
    -                raise UtilError("Failed to remove '{}': {}"
    
    340
    -                                .format(path, e))
    
    341
    -
    
    342
    -            try:
    
    343
    -                os.rmdir(path)
    
    344
    -            except OSError as e:
    
    345
    -                if e.errno == errno.ENOTEMPTY:
    
    346
    -                    return False
    
    347
    -                else:
    
    348
    -                    raise UtilError("Failed to remove '{}': {}"
    
    349
    -                                    .format(path, e))
    
    340
    +            raise UtilError("Failed to remove '{}': {}"
    
    341
    +                            .format(path, e))
    
    342
    +
    
    343
    +    try:
    
    344
    +        os.rmdir(path)
    
    345
    +    except OSError as e:
    
    346
    +        if e.errno == errno.ENOTEMPTY:
    
    347
    +            return False
    
    348
    +        else:
    
    349
    +            raise UtilError("Failed to remove '{}': {}"
    
    350
    +                            .format(path, e))
    
    350 351
     
    
    351 352
         return True
    
    352 353
     
    



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]