Phillip Smyth pushed to branch mac_fixes at BuildStream / buildstream
Commits:
3 changed files:
Changes:
| 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 .._artifactcache.cascache import CASCache
|
|
| 22 |
+from .._exceptions import PlatformError
|
|
| 23 |
+from ..sandbox import SandboxChroot
|
|
| 24 |
+ |
|
| 25 |
+from . import Platform
|
|
| 26 |
+ |
|
| 27 |
+ |
|
| 28 |
+class Darwin(Platform):
|
|
| 29 |
+ |
|
| 30 |
+ def __init__(self, context):
|
|
| 31 |
+ |
|
| 32 |
+ super().__init__(context)
|
|
| 33 |
+ self._artifact_cache = CASCache(context)
|
|
| 34 |
+ |
|
| 35 |
+ # Need to set resources for _frontend/app.py as this is dependent on the platform
|
|
| 36 |
+ # SafeHardlinks FUSE needs to hold file descriptors for all processes in the sandbox.
|
|
| 37 |
+ # Avoid hitting the limit too quickly.
|
|
| 38 |
+ limits = resource.getrlimit(resource.RLIMIT_NOFILE)
|
|
| 39 |
+ if limits[0] != limits[1]:
|
|
| 40 |
+ resource.setrlimit(resource.RLIMIT_NOFILE, (49152, limits[1]))
|
|
| 41 |
+ |
|
| 42 |
+ # Not necessarily 100% reliable, but we want to fail early.
|
|
| 43 |
+ if os.geteuid() != 0:
|
|
| 44 |
+ raise PlatformError("Root privileges are required to run without bubblewrap.")
|
|
| 45 |
+ |
|
| 46 |
+ @property
|
|
| 47 |
+ def artifactcache(self):
|
|
| 48 |
+ return self._artifact_cache
|
|
| 49 |
+ |
|
| 50 |
+ def create_sandbox(self, *args, **kwargs):
|
|
| 51 |
+ return SandboxChroot(*args, **kwargs)
|
|
| 52 |
+ |
|
| 53 |
+ def get_cpu_count(self):
|
|
| 54 |
+ return str(min(len(os.cpu_count())))
|
| ... | ... | @@ -40,19 +40,23 @@ class Platform(): |
| 40 | 40 |
|
| 41 | 41 |
@classmethod
|
| 42 | 42 |
def create_instance(cls, *args, **kwargs):
|
| 43 |
- if sys.platform.startswith('linux'):
|
|
| 44 |
- backend = 'linux'
|
|
| 45 |
- else:
|
|
| 46 |
- backend = 'unix'
|
|
| 47 | 43 |
|
| 48 | 44 |
# Meant for testing purposes and therefore hidden in the
|
| 49 | 45 |
# deepest corners of the source code. Try not to abuse this,
|
| 50 | 46 |
# please?
|
| 51 | 47 |
if os.getenv('BST_FORCE_BACKEND'):
|
| 52 | 48 |
backend = os.getenv('BST_FORCE_BACKEND')
|
| 49 |
+ elif sys.platform.startswith('linux'):
|
|
| 50 |
+ backend = 'linux'
|
|
| 51 |
+ elif sys.platform.startswith('darwin'):
|
|
| 52 |
+ backend = 'darwin'
|
|
| 53 |
+ else:
|
|
| 54 |
+ backend = 'unix'
|
|
| 53 | 55 |
|
| 54 | 56 |
if backend == 'linux':
|
| 55 | 57 |
from .linux import Linux as PlatformImpl
|
| 58 |
+ elif backend == 'darwin':
|
|
| 59 |
+ from .darwin import Darwin as PlatformImpl
|
|
| 56 | 60 |
elif backend == 'unix':
|
| 57 | 61 |
from .unix import Unix as PlatformImpl
|
| 58 | 62 |
else:
|
| ... | ... | @@ -92,3 +96,6 @@ class Platform(): |
| 92 | 96 |
def create_sandbox(self, *args, **kwargs):
|
| 93 | 97 |
raise ImplError("Platform {platform} does not implement create_sandbox()"
|
| 94 | 98 |
.format(platform=type(self).__name__))
|
| 99 |
+ |
|
| 100 |
+ def get_cpu_count(self):
|
|
| 101 |
+ return str(min(len(os.sched_getaffinity(0)), 8))
|
| ... | ... | @@ -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
|
| ... | ... | @@ -140,6 +142,7 @@ class Project(): |
| 140 | 142 |
profile_start(Topics.LOAD_PROJECT, self.directory.replace(os.sep, '-'))
|
| 141 | 143 |
self._load(parent_loader=parent_loader, tempdir=tempdir)
|
| 142 | 144 |
profile_end(Topics.LOAD_PROJECT, self.directory.replace(os.sep, '-'))
|
| 145 |
+ self.platform = Platform.get_platform()
|
|
| 143 | 146 |
|
| 144 | 147 |
self._partially_loaded = True
|
| 145 | 148 |
|
| ... | ... | @@ -594,7 +597,7 @@ class Project(): |
| 594 | 597 |
# Based on some testing (mainly on AWS), maximum effective
|
| 595 | 598 |
# max-jobs value seems to be around 8-10 if we have enough cores
|
| 596 | 599 |
# users should set values based on workload and build infrastructure
|
| 597 |
- output.base_variables['max-jobs'] = str(min(len(os.sched_getaffinity(0)), 8))
|
|
| 600 |
+ output.base_variables['max-jobs'] = self.platform.get_cpu_count()
|
|
| 598 | 601 |
|
| 599 | 602 |
# Export options into variables, if that was requested
|
| 600 | 603 |
output.options.export_variables(output.base_variables)
|
