Skip to content

Commit e72d87d

Browse files
committed
Added hostpython recipe build
1 parent d5acffd commit e72d87d

File tree

2 files changed

+164
-103
lines changed

2 files changed

+164
-103
lines changed

recipes/hostpython2/__init__.py

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

2-
from toolchain import Recipe, shprint, get_directory
3-
from os.path import join
2+
from toolchain import Recipe, shprint, get_directory, current_directory
3+
from os.path import join, exists
4+
from os import chdir
45
import sh
56

67

@@ -17,5 +18,47 @@ def prebuild_armeabi(self):
1718
get_directory(self.versioned_url),
1819
'Modules', 'Setup'))
1920

21+
def build_armeabi(self):
22+
# AND: Should use an i386 recipe system
23+
print('Running hostpython build. Arch is armeabi! '
24+
'This is naughty, need to fix the Arch system!')
25+
26+
# AND: Fix armeabi again
27+
with current_directory(join(self.get_build_dir('armeabi'),
28+
get_directory(self.versioned_url))):
29+
30+
if exists('hostpython'):
31+
print('hostpython already exists, skipping build')
32+
return
33+
34+
configure = sh.Command('./configure')
35+
print('Configuring hostpython2')
36+
37+
shprint(configure)
38+
shprint(sh.make, '-j5')
39+
40+
shprint(sh.mv, join('Parser', 'pgen'), 'hostpgen')
41+
42+
if exists('python.exe'):
43+
shprint(sh.mv, 'python.exe', 'hostpython')
44+
elif exists('python'):
45+
shprint(sh.mv, 'python', 'hostpython')
46+
else:
47+
print('Unable to find the python executable after '
48+
'hostpython build!')
49+
exit(1)
50+
51+
self.ctx.hostpython = join(self.get_build_dir('armeabi'),
52+
get_directory(self.versioned_url),
53+
'hostpython')
54+
self.ctx.hostpgen = join(self.get_build_dir('armeabi'),
55+
get_directory(self.versioned_url),
56+
'hostpgen')
57+
58+
59+
60+
61+
62+
2063

2164
recipe = Hostpython2Recipe()

toolchain.py

Lines changed: 119 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ def get_directory(filename):
6161
exit(1)
6262

6363

64+
import contextlib
65+
@contextlib.contextmanager
66+
def current_directory(new_dir):
67+
cur_dir = getcwd()
68+
print('Switching current directory to', new_dir)
69+
chdir(new_dir)
70+
yield
71+
print('Directory context ended, switching to', cur_dir)
72+
chdir(cur_dir)
73+
6474

6575

6676
# def cache_execution(f):
@@ -198,7 +208,7 @@ def get_env(self):
198208
toolchain_prefix = 'arm-linux-androideabi'
199209
toolchain_version = '4.4.3'
200210
elif self.ctx.ndk_ver[:2] == 'r9':
201-
toolchain_prefix == 'arm-linux-androideabi'
211+
toolchain_prefix = 'arm-linux-androideabi'
202212
toolchain_version = '4.9'
203213
else:
204214
print('Error: NDK not supported by these tools?')
@@ -207,7 +217,7 @@ def get_env(self):
207217
env['TOOLCHAIN_PREFIX'] = toolchain_prefix
208218
env['TOOLCHAIN_VERSION'] = toolchain_version
209219

210-
env['PATH'] = "{sdk_dir}/toolchains/{toolchain_prefix}-{toolchain_version}/prebuilt/{py_platform}-x86/bin/:{ndk_dir}/toolchains/{toolchain_prefix}-{toolchain_version}/prebuilt/{py_platform}-x86_64/bin/:{ndk_dir}:{sdk_dir}/tools:{path}".format(sdk_dir=sdk_dir, ndk_dir=ndk_dir, toolchain_prefix=toolchain_prefix, toolchain_version=toolchain_version, py_platform=py_platform, path=environ.get('PATH'))
220+
env['PATH'] = "{sdk_dir}/toolchains/{toolchain_prefix}-{toolchain_version}/prebuilt/{py_platform}-x86/bin/:{ndk_dir}/toolchains/{toolchain_prefix}-{toolchain_version}/prebuilt/{py_platform}-x86_64/bin/:{ndk_dir}:{sdk_dir}/tools:{path}".format(sdk_dir=self.ctx.sdk_dir, ndk_dir=self.ctx.ndk_dir, toolchain_prefix=toolchain_prefix, toolchain_version=toolchain_version, py_platform=py_platform, path=environ.get('PATH'))
211221

212222
env['CC'] = '{toolchain_prefix}-gcc {cflags}'.format(
213223
toolchain_prefix=toolchain_prefix,
@@ -885,30 +895,30 @@ def extract(self):
885895
# self.extract_file(self.archive_fn, build_dir)
886896

887897
# @cache_execution
888-
def build(self, arch):
889-
self.build_dir = self.get_build_dir(arch.arch)
890-
if self.has_marker("building"):
891-
print("Warning: {} build for {} has been incomplete".format(
892-
self.name, arch.arch))
893-
print("Warning: deleting the build and restarting.")
894-
shutil.rmtree(self.build_dir)
895-
self.extract_arch(arch.arch)
896-
897-
if self.has_marker("build_done"):
898-
print("Build python for {} already done.".format(arch.arch))
899-
return
900-
901-
self.set_marker("building")
902-
903-
chdir(self.build_dir)
904-
print("Prebuild {} for {}".format(self.name, arch.arch))
905-
self.prebuild_arch(arch)
906-
print("Build {} for {}".format(self.name, arch.arch))
907-
self.build_arch(arch)
908-
print("Postbuild {} for {}".format(self.name, arch.arch))
909-
self.postbuild_arch(arch)
910-
self.delete_marker("building")
911-
self.set_marker("build_done")
898+
# def build(self, arch):
899+
# self.build_dir = self.get_build_dir(arch.arch)
900+
# if self.has_marker("building"):
901+
# print("Warning: {} build for {} has been incomplete".format(
902+
# self.name, arch.arch))
903+
# print("Warning: deleting the build and restarting.")
904+
# shutil.rmtree(self.build_dir)
905+
# self.extract_arch(arch.arch)
906+
907+
# if self.has_marker("build_done"):
908+
# print("Build python for {} already done.".format(arch.arch))
909+
# return
910+
911+
# self.set_marker("building")
912+
913+
# chdir(self.build_dir)
914+
# print("Prebuild {} for {}".format(self.name, arch.arch))
915+
# self.prebuild_arch(arch)
916+
# print("Build {} for {}".format(self.name, arch.arch))
917+
# self.build_arch(arch)
918+
# print("Postbuild {} for {}".format(self.name, arch.arch))
919+
# self.postbuild_arch(arch)
920+
# self.delete_marker("building")
921+
# self.set_marker("build_done")
912922

913923
# @cache_execution
914924
def build_all(self):
@@ -949,6 +959,9 @@ def prebuild(self):
949959
# this to support
950960
# multiple archs
951961

962+
def build(self):
963+
self.build_arch(self.ctx.archs[0]) # Same here!
964+
952965
def prebuild_arch(self, arch):
953966
prebuild = "prebuild_{}".format(arch.arch)
954967
if hasattr(self, prebuild):
@@ -1097,68 +1110,69 @@ def prepare_build_dir(self, ctx):
10971110

10981111

10991112
class PythonRecipe(Recipe):
1113+
pass
11001114
# @cache_execution
1101-
def install(self):
1102-
self.install_python_package()
1103-
self.reduce_python_package()
1115+
# def install(self):
1116+
# self.install_python_package()
1117+
# self.reduce_python_package()
11041118

1105-
def install_python_package(self, name=None, env=None, is_dir=True):
1106-
"""Automate the installation of a Python package into the target
1107-
site-packages.
1119+
# def install_python_package(self, name=None, env=None, is_dir=True):
1120+
# """Automate the installation of a Python package into the target
1121+
# site-packages.
11081122

1109-
It will works with the first filtered_archs, and the name of the recipe.
1110-
"""
1111-
arch = self.filtered_archs[0]
1112-
if name is None:
1113-
name = self.name
1114-
if env is None:
1115-
env = self.get_recipe_env(arch)
1116-
1117-
print("Install {} into the site-packages".format(name))
1118-
build_dir = self.get_build_dir(arch.arch)
1119-
chdir(build_dir)
1120-
hostpython = sh.Command(self.ctx.hostpython)
1121-
iosbuild = join(build_dir, "iosbuild")
1122-
shprint(hostpython, "setup.py", "install", "-O2",
1123-
"--prefix", iosbuild,
1124-
_env=env)
1125-
dest_dir = join(self.ctx.site_packages_dir, name)
1126-
if is_dir:
1127-
if exists(dest_dir):
1128-
shutil.rmtree(dest_dir)
1129-
func = shutil.copytree
1130-
else:
1131-
func = shutil.copy
1132-
func(
1133-
join(iosbuild, "lib",
1134-
self.ctx.python_ver_dir, "site-packages", name),
1135-
dest_dir)
1136-
1137-
def reduce_python_package(self):
1138-
"""Feel free to remove things you don't want in the final
1139-
site-packages.
1140-
"""
1141-
pass
1123+
# It will works with the first filtered_archs, and the name of the recipe.
1124+
# """
1125+
# arch = self.filtered_archs[0]
1126+
# if name is None:
1127+
# name = self.name
1128+
# if env is None:
1129+
# env = self.get_recipe_env(arch)
1130+
1131+
# print("Install {} into the site-packages".format(name))
1132+
# build_dir = self.get_build_dir(arch.arch)
1133+
# chdir(build_dir)
1134+
# hostpython = sh.Command(self.ctx.hostpython)
1135+
# iosbuild = join(build_dir, "iosbuild")
1136+
# shprint(hostpython, "setup.py", "install", "-O2",
1137+
# "--prefix", iosbuild,
1138+
# _env=env)
1139+
# dest_dir = join(self.ctx.site_packages_dir, name)
1140+
# if is_dir:
1141+
# if exists(dest_dir):
1142+
# shutil.rmtree(dest_dir)
1143+
# func = shutil.copytree
1144+
# else:
1145+
# func = shutil.copy
1146+
# func(
1147+
# join(iosbuild, "lib",
1148+
# self.ctx.python_ver_dir, "site-packages", name),
1149+
# dest_dir)
1150+
1151+
# def reduce_python_package(self):
1152+
# """Feel free to remove things you don't want in the final
1153+
# site-packages.
1154+
# """
1155+
# pass
11421156

11431157

11441158
class CythonRecipe(PythonRecipe):
11451159
pre_build_ext = False
11461160
cythonize = True
11471161

1148-
def cythonize_file(self, filename):
1149-
if filename.startswith(self.build_dir):
1150-
filename = filename[len(self.build_dir) + 1:]
1151-
print("Cythonize {}".format(filename))
1152-
cmd = sh.Command(join(self.ctx.root_dir, "tools", "cythonize.py"))
1153-
shprint(cmd, filename)
1154-
1155-
def cythonize_build(self):
1156-
if not self.cythonize:
1157-
return
1158-
root_dir = self.build_dir
1159-
for root, dirnames, filenames in walk(root_dir):
1160-
for filename in fnmatch.filter(filenames, "*.pyx"):
1161-
self.cythonize_file(join(root, filename))
1162+
# def cythonize_file(self, filename):
1163+
# if filename.startswith(self.build_dir):
1164+
# filename = filename[len(self.build_dir) + 1:]
1165+
# print("Cythonize {}".format(filename))
1166+
# cmd = sh.Command(join(self.ctx.root_dir, "tools", "cythonize.py"))
1167+
# shprint(cmd, filename)
1168+
1169+
# def cythonize_build(self):
1170+
# if not self.cythonize:
1171+
# return
1172+
# root_dir = self.build_dir
1173+
# for root, dirnames, filenames in walk(root_dir):
1174+
# for filename in fnmatch.filter(filenames, "*.pyx"):
1175+
# self.cythonize_file(join(root, filename))
11621176

11631177
def biglink(self):
11641178
dirs = []
@@ -1168,28 +1182,28 @@ def biglink(self):
11681182
cmd = sh.Command(join(self.ctx.root_dir, "tools", "biglink"))
11691183
shprint(cmd, join(self.build_dir, "lib{}.a".format(self.name)), *dirs)
11701184

1171-
def get_recipe_env(self, arch):
1172-
env = super(CythonRecipe, self).get_recipe_env(arch)
1173-
env["KIVYIOSROOT"] = self.ctx.root_dir
1174-
env["IOSSDKROOT"] = arch.sysroot
1175-
env["LDSHARED"] = join(self.ctx.root_dir, "tools", "liblink")
1176-
env["ARM_LD"] = env["LD"]
1177-
env["ARCH"] = arch.arch
1178-
return env
1179-
1180-
def build_arch(self, arch):
1181-
build_env = self.get_recipe_env(arch)
1182-
hostpython = sh.Command(self.ctx.hostpython)
1183-
if self.pre_build_ext:
1184-
try:
1185-
shprint(hostpython, "setup.py", "build_ext", "-g",
1186-
_env=build_env)
1187-
except:
1188-
pass
1189-
self.cythonize_build()
1190-
shprint(hostpython, "setup.py", "build_ext", "-g",
1191-
_env=build_env)
1192-
self.biglink()
1185+
# def get_recipe_env(self, arch):
1186+
# env = super(CythonRecipe, self).get_recipe_env(arch)
1187+
# env["KIVYIOSROOT"] = self.ctx.root_dir
1188+
# env["IOSSDKROOT"] = arch.sysroot
1189+
# env["LDSHARED"] = join(self.ctx.root_dir, "tools", "liblink")
1190+
# env["ARM_LD"] = env["LD"]
1191+
# env["ARCH"] = arch.arch
1192+
# return env
1193+
1194+
# def build_arch(self, arch):
1195+
# build_env = self.get_recipe_env(arch)
1196+
# hostpython = sh.Command(self.ctx.hostpython)
1197+
# if self.pre_build_ext:
1198+
# try:
1199+
# shprint(hostpython, "setup.py", "build_ext", "-g",
1200+
# _env=build_env)
1201+
# except:
1202+
# pass
1203+
# self.cythonize_build()
1204+
# shprint(hostpython, "setup.py", "build_ext", "-g",
1205+
# _env=build_env)
1206+
# self.biglink()
11931207

11941208

11951209
def build_recipes(names, ctx):
@@ -1221,6 +1235,7 @@ def build_recipes(names, ctx):
12211235
recipe_loaded.append(name)
12221236
build_order = list(graph.find_order())
12231237
print("Build order is {}".format(build_order))
1238+
ctx.recipe_build_order = build_order
12241239

12251240
recipes = [Recipe.get_recipe(name, ctx) for name in build_order]
12261241

@@ -1236,6 +1251,9 @@ def build_recipes(names, ctx):
12361251
recipe.prebuild()
12371252

12381253
# 3) build packages
1254+
for recipe in recipes:
1255+
recipe.build()
1256+
12391257

12401258
return
12411259
for recipe in recipes:

0 commit comments

Comments
 (0)