From a28cdcb57d01d534fc793a01447139733cc856fd Mon Sep 17 00:00:00 2001 From: Ruben Di Battista Date: Fri, 10 Apr 2020 03:08:28 +0200 Subject: [PATCH] Add CFLAGS env var to hostpython3 to fix pyconfig.h error --- .../recipes/hostpython3/__init__.py | 74 +++++++++++-------- 1 file changed, 45 insertions(+), 29 deletions(-) diff --git a/pythonforandroid/recipes/hostpython3/__init__.py b/pythonforandroid/recipes/hostpython3/__init__.py index 651fb019aa..490a6ae282 100644 --- a/pythonforandroid/recipes/hostpython3/__init__.py +++ b/pythonforandroid/recipes/hostpython3/__init__.py @@ -1,4 +1,5 @@ import sh +import os from multiprocessing import cpu_count from os.path import exists, join, isfile @@ -13,7 +14,7 @@ class Hostpython3Recipe(Recipe): - ''' + """ The hostpython3's recipe. .. versionchanged:: 2019.10.06.post0 @@ -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): @@ -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): @@ -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)