Skip to content

Commit 015c0eb

Browse files
authored
Merge pull request kivy#1651 from AndreMiras/feature/python_build_parallel_jobs
Speed up Python and NumPy compilation process
2 parents b168978 + b4a6a66 commit 015c0eb

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

pythonforandroid/python.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
'''
55

66
from os.path import dirname, exists, join
7+
from multiprocessing import cpu_count
78
from shutil import copy2
89
from os import environ
910
import subprocess
@@ -250,7 +251,7 @@ def build_arch(self, arch):
250251
py_version = self.major_minor_version_string
251252
if self.major_minor_version_string[0] == '3':
252253
py_version += 'm'
253-
shprint(sh.make, 'all',
254+
shprint(sh.make, 'all', '-j', str(cpu_count()),
254255
'INSTSONAME=libpython{version}.so'.format(
255256
version=py_version), _env=env)
256257

@@ -420,7 +421,7 @@ def build_arch(self, arch):
420421
shprint(sh.cp, join('Modules', 'Setup.dist'),
421422
join(build_dir, 'Modules', 'Setup'))
422423

423-
result = shprint(sh.make, '-C', build_dir)
424+
result = shprint(sh.make, '-j', str(cpu_count()), '-C', build_dir)
424425
else:
425426
info('Skipping {name} ({version}) build, as it has already '
426427
'been completed'.format(name=self.name, version=self.version))

pythonforandroid/recipes/numpy/__init__.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from pythonforandroid.recipe import CompiledComponentsPythonRecipe
2+
from multiprocessing import cpu_count
23
from os.path import join
34

45

@@ -7,7 +8,6 @@ class NumpyRecipe(CompiledComponentsPythonRecipe):
78
version = '1.15.1'
89
url = 'https://pypi.python.org/packages/source/n/numpy/numpy-{version}.zip'
910
site_packages_name = 'numpy'
10-
1111
depends = [('python2', 'python3', 'python3crystax')]
1212

1313
patches = [
@@ -18,6 +18,16 @@ class NumpyRecipe(CompiledComponentsPythonRecipe):
1818
join('patches', 'python-fixes.patch')
1919
]
2020

21+
def build_compiled_components(self, arch):
22+
self.setup_extra_args = ['-j', str(cpu_count())]
23+
super(NumpyRecipe, self).build_compiled_components(arch)
24+
self.setup_extra_args = []
25+
26+
def rebuild_compiled_components(self, arch, env):
27+
self.setup_extra_args = ['-j', str(cpu_count())]
28+
super(NumpyRecipe, self).rebuild_compiled_components(arch, env)
29+
self.setup_extra_args = []
30+
2131
def get_recipe_env(self, arch):
2232
env = super(NumpyRecipe, self).get_recipe_env(arch)
2333

@@ -44,8 +54,5 @@ def get_recipe_env(self, arch):
4454
env['LD'] += flags + ' -shared'
4555
return env
4656

47-
def prebuild_arch(self, arch):
48-
super(NumpyRecipe, self).prebuild_arch(arch)
49-
5057

5158
recipe = NumpyRecipe()

0 commit comments

Comments
 (0)