kivy-ios/recipes/kivent_core/__init__.py

103 lines
3.6 KiB
Python
Raw Normal View History

"""
Author: Lawrence Du
E-mail: larrydu88@gmail.com
"""
from toolchain import CythonRecipe, shprint
import sh
2019-01-11 18:22:49 +01:00
from os.path import join
from os import chdir
import logging
logger = logging.getLogger(__name__)
class KiventCoreRecipe(CythonRecipe):
version = 'master'
url = 'https://github.com/kivy/kivent/archive/{version}.zip'
name = 'kivent_core'
depends = ['libffi', 'kivy'] # note: unsure if libffi is necessary here
pre_build_ext = False
subbuilddir = False
cythonize = True
pbx_frameworks = ["OpenGLES"] # note: This line may be unnecessary
2019-01-11 18:22:49 +01:00
def get_recipe_env(self, arch):
env = super(KiventCoreRecipe, self).get_recipe_env(arch)
env['CYTHONPATH'] = self.get_recipe(
'kivy', self.ctx).get_build_dir(arch.arch)
return env
def get_build_dir(self, arch, sub=False):
"""
2019-01-11 18:22:49 +01:00
Call this to get the correct build_dir, where setup.py is located which is
actually under modules/core/setup.py
"""
builddir = super(KiventCoreRecipe, self).get_build_dir(str(arch))
if sub or self.subbuilddir:
core_build_dir = join(builddir, 'modules', 'core')
logger.info("Core build directory is located at {}".format(core_build_dir))
return core_build_dir
else:
logger.info("Building in {}".format(builddir))
return builddir
def build_arch(self, arch):
"""
2019-01-11 18:22:49 +01:00
Override build.arch to avoid calling setup.py here (Call it in
install() instead).
"""
self.subbuildir = True
self.cythonize_build()
self.biglink()
self.subbuilddir = False
2019-01-11 18:22:49 +01:00
def install(self):
"""
2019-01-11 18:22:49 +01:00
This method simply builds the command line call for calling
kivent_core/modules/core/setup.py
2019-01-11 18:22:49 +01:00
This constructs the equivalent of the command
"$python2.7 setup.py build_ext install"
only with the environment variables altered for each different architecture
The appropriate version of kivy also needs to be added to the path, and this
differs for each architecture (i386, x86_64, armv7, etc)
Note: This method is called by build_all() in toolchain.py
"""
arch = list(self.filtered_archs)[0]
build_dir = self.get_build_dir(arch.arch, sub=True)
logger.info("Building kivent_core {} in {}".format(arch.arch, build_dir))
chdir(build_dir)
hostpython = sh.Command(self.ctx.hostpython)
# Get the appropriate environment for this recipe (including CYTHONPATH)
# build_env = arch.get_env()
build_env = self.get_recipe_env(arch)
dest_dir = join(self.ctx.dist_dir, "root", "python")
build_env['PYTHONPATH'] = join(dest_dir, 'lib', 'python2.7', 'site-packages')
2019-01-11 18:22:49 +01:00
# Add Architecture specific kivy path for 'import kivy' to PYTHONPATH
arch_kivy_path = self.get_recipe('kivy', self.ctx).get_build_dir(arch.arch)
build_env['PYTHONPATH'] = join(build_env['PYTHONPATH'], ':', arch_kivy_path)
# Make sure you call kivent_core/modules/core/setup.py
subdir_path = self.get_build_dir(str(arch), sub=True)
setup_path = join(subdir_path, "setup.py")
# Print out directories for sanity check
logger.info("ENVS", build_env)
logger.info("ROOT", self.ctx.root_dir)
logger.info("BUILD", self.ctx.build_dir)
logger.info("INCLUDE", self.ctx.include_dir)
logger.info("DISTDIR", self.ctx.dist_dir)
logger.info("ARCH KIVY LOC", self.get_recipe('kivy', self.ctx).get_build_dir(arch.arch))
2019-01-11 18:22:49 +01:00
shprint(hostpython, setup_path, "build_ext", "install", _env=build_env)
2019-01-11 18:22:49 +01:00
recipe = KiventCoreRecipe()