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 .._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=self.OPEN_MAX, hard_limit=None):
|
|
49 |
+ super().set_resources(soft_limit)
|
... | ... | @@ -44,19 +44,23 @@ class Platform(): |
44 | 44 |
|
45 | 45 |
@classmethod
|
46 | 46 |
def create_instance(cls, *args, **kwargs):
|
47 |
- if sys.platform.startswith('linux'):
|
|
48 |
- backend = 'linux'
|
|
49 |
- else:
|
|
50 |
- backend = 'unix'
|
|
51 | 47 |
|
52 | 48 |
# Meant for testing purposes and therefore hidden in the
|
53 | 49 |
# deepest corners of the source code. Try not to abuse this,
|
54 | 50 |
# please?
|
55 | 51 |
if os.getenv('BST_FORCE_BACKEND'):
|
56 | 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'
|
|
57 | 59 |
|
58 | 60 |
if backend == 'linux':
|
59 | 61 |
from .linux import Linux as PlatformImpl
|
62 |
+ elif backend == 'darwin':
|
|
63 |
+ from .darwin import Darwin as PlatformImpl
|
|
60 | 64 |
elif backend == 'unix':
|
61 | 65 |
from .unix import Unix as PlatformImpl
|
62 | 66 |
else:
|
... | ... | @@ -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 |
|