Skip to content

Commit 6d26d07

Browse files
committed
[hostpython] Fix build for MacOS 🍎
It turns out that the generated binary for MacOS and Cygwin is not `python`...it's `python.exe` Also: - add attribute `HostPythonRecipe.python_bin` (in here we decide if we are in mac platform or not) - implement `HostPythonRecipe.should_build` to refactor a little See also: https://github.com/python/cpython/blob/3.7/README.rst#build-instructions
1 parent 3dabded commit 6d26d07

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

pythonforandroid/python.py

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from pythonforandroid.util import (
1717
current_directory, ensure_dir, walk_valid_filens,
1818
BuildInterruptingException, build_platform)
19+
from pythonforandroid.patching import is_darwin
1920

2021

2122
class GuestPythonRecipe(TargetPythonRecipe):
@@ -382,6 +383,22 @@ class HostPythonRecipe(Recipe):
382383
'''The default url to download our host python recipe. This url will
383384
change depending on the python version set in attribute :attr:`version`.'''
384385

386+
@property
387+
def python_bin(self):
388+
if is_darwin():
389+
return 'python.exe'
390+
return 'python'
391+
392+
def should_build(self, arch):
393+
python_bin = join(
394+
self.get_build_dir(arch.arch), self.build_subdir, self.python_bin
395+
)
396+
if exists(python_bin):
397+
# no need to build, but we must set:
398+
self.ctx.hostpython = python_bin
399+
return False
400+
return True
401+
385402
def get_build_container_dir(self, arch=None):
386403
choices = self.check_recipe_choices()
387404
dir_name = '-'.join([self.name] + choices)
@@ -404,22 +421,18 @@ def build_arch(self, arch):
404421
build_dir = join(recipe_build_dir, self.build_subdir)
405422
ensure_dir(build_dir)
406423

407-
if not exists(join(build_dir, 'python')):
408-
with current_directory(recipe_build_dir):
409-
# Configure the build
410-
with current_directory(build_dir):
411-
if not exists('config.status'):
412-
shprint(
413-
sh.Command(join(recipe_build_dir, 'configure')))
424+
with current_directory(recipe_build_dir):
425+
# Configure the build
426+
with current_directory(build_dir):
427+
if not exists('config.status'):
428+
shprint(
429+
sh.Command(join(recipe_build_dir, 'configure')))
414430

415-
# Create the Setup file. This copying from Setup.dist
416-
# seems to be the normal and expected procedure.
417-
shprint(sh.cp, join('Modules', 'Setup.dist'),
418-
join(build_dir, 'Modules', 'Setup'))
431+
# Create the Setup file. This copying from Setup.dist
432+
# seems to be the normal and expected procedure.
433+
shprint(sh.cp, join('Modules', 'Setup.dist'),
434+
join(build_dir, 'Modules', 'Setup'))
419435

420-
shprint(sh.make, '-j', str(cpu_count()), '-C', build_dir)
421-
else:
422-
info('Skipping {name} ({version}) build, as it has already '
423-
'been completed'.format(name=self.name, version=self.version))
436+
shprint(sh.make, '-j', str(cpu_count()), '-C', build_dir)
424437

425-
self.ctx.hostpython = join(build_dir, 'python')
438+
self.ctx.hostpython = join(build_dir, self.python_bin)

0 commit comments

Comments
 (0)