|
9 | 9 | from distutils.version import LooseVersion |
10 | 10 |
|
11 | 11 |
|
12 | | -class memoryCheck(): |
13 | | - """Checks memory of a given system""" |
14 | | - |
15 | | - def __init__(self): |
16 | | - |
17 | | - if os.name == "posix": |
18 | | - self.value = self.linuxRam() |
19 | | - else: |
20 | | - self.value = -1 |
21 | | - |
22 | | - def linuxRam(self): |
23 | | - """Returns the RAM of a linux system""" |
24 | | - totalMemory = os.popen("free -m").readlines()[1].split()[1] |
25 | | - return int(totalMemory) |
26 | | - |
27 | | - |
28 | 12 | class CMakeExtension(Extension): |
29 | 13 | def __init__(self, name, sourcedir=''): |
30 | 14 | Extension.__init__(self, name, sources=[]) |
@@ -59,24 +43,33 @@ def build_extension(self, ext): |
59 | 43 | cfg = 'Debug' if self.debug else 'Release' |
60 | 44 | build_args = ['--config', cfg] |
61 | 45 |
|
| 46 | + # Memcheck (guard if it fails) |
| 47 | + totalMemory = 4000 |
| 48 | + if platform.system() == "Linux": |
| 49 | + try: |
| 50 | + totalMemory = int(os.popen("free -m").readlines()[1].split()[1]) |
| 51 | + except (KeyboardInterrupt, SystemExit): |
| 52 | + raise |
| 53 | + except: |
| 54 | + totalMemory = 4000 |
| 55 | + |
62 | 56 | if platform.system() == "Windows": |
63 | 57 | cmake_args += ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format(cfg.upper(), extdir)] |
64 | 58 | if sys.maxsize > 2**32: |
65 | 59 | cmake_args += ['-A', 'x64'] |
66 | 60 | build_args += ['--', '/m'] |
67 | 61 | else: |
68 | 62 | cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg] |
69 | | - |
| 63 | + |
70 | 64 | #Memcheck |
71 | | - M = memoryCheck() |
72 | | - if M.value < 1000: |
73 | | - build_args += ['--', '-j1'] |
| 65 | + parallel_args = ['--', '-j'] |
| 66 | + if totalMemory < 1000: |
| 67 | + parallel_args = ['--', '-j1'] |
74 | 68 | cmake_args += ['-DHUNTER_JOBS_NUMBER=1'] |
75 | | - elif M.value < 2000: |
76 | | - build_args += ['--', '-j2'] |
| 69 | + elif totalMemory < 2000: |
| 70 | + parallel_args = ['--', '-j2'] |
77 | 71 | cmake_args += ['-DHUNTER_JOBS_NUMBER=2'] |
78 | | - else: |
79 | | - build_args += ['--', '-j'] |
| 72 | + build_args += parallel_args |
80 | 73 |
|
81 | 74 | # Hunter configuration to release only |
82 | 75 | cmake_args += ['-DHUNTER_CONFIGURATION_TYPES=Release'] |
|
0 commit comments