You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by no...@apache.org on 2020/12/29 12:55:20 UTC

[buildstream] 06/09: Adding darwin.py (MacOS) platform

This is an automated email from the ASF dual-hosted git repository.

not-in-ldap pushed a commit to branch workspace_list_error_message
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 2e2f280998506c69ba8ebafe16960d8f6e0aa21c
Author: knownexus <ph...@codethink.co.uk>
AuthorDate: Thu Aug 30 12:06:39 2018 +0100

    Adding darwin.py (MacOS) platform
    
    Adding functionality to recognise Darwin as a platform in plaform.py
---
 buildstream/_platform/darwin.py   | 50 +++++++++++++++++++++++++++++++++++++++
 buildstream/_platform/platform.py | 12 ++++++----
 2 files changed, 58 insertions(+), 4 deletions(-)

diff --git a/buildstream/_platform/darwin.py b/buildstream/_platform/darwin.py
new file mode 100644
index 0000000..89e022e
--- /dev/null
+++ b/buildstream/_platform/darwin.py
@@ -0,0 +1,50 @@
+#
+#  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)
+
+    @property
+    def artifactcache(self):
+        return self._artifact_cache
+
+    def create_sandbox(self, *args, **kwargs):
+        return SandboxDummy(*args, **kwargs)
+
+    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)
diff --git a/buildstream/_platform/platform.py b/buildstream/_platform/platform.py
index bf1e5e8..ac976cc 100644
--- a/buildstream/_platform/platform.py
+++ b/buildstream/_platform/platform.py
@@ -44,19 +44,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: