Skip to content

Commit

Permalink
Add CFLAGS env var to hostpython3 to fix pyconfig.h error
Browse files Browse the repository at this point in the history
  • Loading branch information
rdbisme committed Apr 10, 2020
1 parent 47c9c33 commit a28cdcb
Showing 1 changed file with 45 additions and 29 deletions.
74 changes: 45 additions & 29 deletions pythonforandroid/recipes/hostpython3/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sh
import os

from multiprocessing import cpu_count
from os.path import exists, join, isfile
Expand All @@ -13,7 +14,7 @@


class Hostpython3Recipe(Recipe):
'''
"""
The hostpython3's recipe.
.. versionchanged:: 2019.10.06.post0
Expand All @@ -22,34 +23,34 @@ class Hostpython3Recipe(Recipe):
.. versionchanged:: 0.6.0
Refactored into the new class
:class:`~pythonforandroid.python.HostPythonRecipe`
'''
"""

version = '3.8.1'
name = 'hostpython3'
version = "3.8.1"
name = "hostpython3"

build_subdir = 'native-build'
'''Specify the sub build directory for the hostpython3 recipe. Defaults
to ``native-build``.'''
build_subdir = "native-build"
"""Specify the sub build directory for the hostpython3 recipe. Defaults
to ``native-build``."""

url = 'https://www.python.org/ftp/python/{version}/Python-{version}.tgz'
'''The default url to download our host python recipe. This url will
change depending on the python version set in attribute :attr:`version`.'''
url = "https://www.python.org/ftp/python/{version}/Python-{version}.tgz"
"""The default url to download our host python recipe. This url will
change depending on the python version set in attribute :attr:`version`."""

@property
def _exe_name(self):
'''
"""
Returns the name of the python executable depending on the version.
'''
"""
if not self.version:
raise BuildInterruptingException(
'The hostpython recipe must have set version'
"The hostpython recipe must have set version"
)
version = self.version.split('.')[0]
return 'python{major_version}'.format(major_version=version)
version = self.version.split(".")[0]
return "python{major_version}".format(major_version=version)

@property
def python_exe(self):
'''Returns the full path of the hostpython executable.'''
"""Returns the full path of the hostpython executable."""
return join(self.get_path_to_python(), self._exe_name)

def should_build(self, arch):
Expand All @@ -61,14 +62,14 @@ def should_build(self, arch):

def get_build_container_dir(self, arch=None):
choices = self.check_recipe_choices()
dir_name = '-'.join([self.name] + choices)
return join(self.ctx.build_dir, 'other_builds', dir_name, 'desktop')
dir_name = "-".join([self.name] + choices)
return join(self.ctx.build_dir, "other_builds", dir_name, "desktop")

def get_build_dir(self, arch=None):
'''
"""
.. note:: Unlike other recipes, the hostpython build dir doesn't
depend on the target arch
'''
"""
return join(self.get_build_container_dir(), self.name)

def get_path_to_python(self):
Expand All @@ -81,34 +82,49 @@ def build_arch(self, arch):
build_dir = join(recipe_build_dir, self.build_subdir)
ensure_dir(build_dir)

# ... And add that dir into the include flags
env = os.environ
cflags = " -I{build_dir}".format(build_dir=build_dir)

try:
env["CFLAGS"] += cflags
except KeyError:
env["CFLAGS"] = cflags

with current_directory(recipe_build_dir):
# Configure the build
with current_directory(build_dir):
if not exists('config.status'):
shprint(sh.Command(join(recipe_build_dir, 'configure')))
if not exists("config.status"):
shprint(sh.Command(join(recipe_build_dir, "configure")))

# Create the Setup file. This copying from Setup.dist is
# the normal and expected procedure before Python 3.8, but
# after this the file with default options is already named "Setup"
setup_dist_location = join('Modules', 'Setup.dist')
setup_dist_location = join("Modules", "Setup.dist")
if exists(setup_dist_location):
shprint(sh.cp, setup_dist_location,
join(build_dir, 'Modules', 'Setup'))
shprint(
sh.cp,
setup_dist_location,
join(build_dir, "Modules", "Setup"),
)
else:
# Check the expected file does exist
setup_location = join('Modules', 'Setup')
setup_location = join("Modules", "Setup")
if not exists(setup_location):
raise BuildInterruptingException(
"Could not find Setup.dist or Setup in Python build")
"Could not find Setup.dist or Setup in Python build"
)

shprint(sh.make, '-j', str(cpu_count()), '-C', build_dir)
shprint(
sh.make, "-j", str(cpu_count()), "-C", build_dir, _env=_env
)

# make a copy of the python executable giving it the name we want,
# because we got different python's executable names depending on
# the fs being case-insensitive (Mac OS X, Cygwin...) or
# case-sensitive (linux)...so this way we will have an unique name
# for our hostpython, regarding the used fs
for exe_name in ['python.exe', 'python']:
for exe_name in ["python.exe", "python"]:
exe = join(self.get_path_to_python(), exe_name)
if isfile(exe):
shprint(sh.cp, exe, self.python_exe)
Expand Down

0 comments on commit a28cdcb

Please sign in to comment.