summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorknownexus <phillip.smyth@codethink.co.uk>2018-08-30 12:06:39 +0100
committerJürg Billeter <j@bitron.ch>2018-09-27 15:22:24 +0100
commit0f3ef369299948e5567c012bf995789944d7fef6 (patch)
treeb7f47b591aa694557f0847a711ad00e01ce5f0f6
parent3c93fe97b656b36e5a25eb4d9289adbb4e5ce65f (diff)
downloadbuildstream-0f3ef369299948e5567c012bf995789944d7fef6.tar.gz
Adding darwin.py (MacOS) platform
Adding functionality to recognise Darwin as a platform in plaform.py
-rw-r--r--buildstream/_platform/darwin.py50
-rw-r--r--buildstream/_platform/platform.py13
2 files changed, 58 insertions, 5 deletions
diff --git a/buildstream/_platform/darwin.py b/buildstream/_platform/darwin.py
new file mode 100644
index 000000000..7092eb2aa
--- /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 SandboxDummy
+
+from . import Platform
+
+
+class Darwin(Platform):
+
+ # This value comes from OPEN_MAX in syslimits.h
+ OPEN_MAX = 10240
+
+ def __init__(self):
+
+ super().__init__()
+
+ 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)
diff --git a/buildstream/_platform/platform.py b/buildstream/_platform/platform.py
index 9e5051dd7..bc6a624c4 100644
--- a/buildstream/_platform/platform.py
+++ b/buildstream/_platform/platform.py
@@ -37,19 +37,22 @@ class Platform():
@classmethod
def _create_instance(cls):
- 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: