Skip to content

Commit 310048d

Browse files
committed
hostpython: first pass to be able to invoke hostpython from p4a command line
1 parent e5302af commit 310048d

File tree

2 files changed

+73
-7
lines changed

2 files changed

+73
-7
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
from pythonforandroid.toolchain import (
3+
PythonRecipe,
4+
Recipe,
5+
current_directory,
6+
info,
7+
shprint,
8+
)
9+
from os.path import join
10+
import sh
11+
12+
13+
class HostCythonRecipe(PythonRecipe):
14+
version = '0.23.4'
15+
url = 'https://pypi.python.org/packages/source/C/Cython/Cython-{version}.tar.gz'
16+
depends = ['python2']
17+
call_hostpython_via_targetpython = False
18+
install_in_hostpython = True
19+
install_in_targetpython = False
20+
21+
def get_recipe_env(self, arch=None):
22+
env = super(HostCythonRecipe, self).get_recipe_env(arch)
23+
from pprint import pprint
24+
pprint(env)
25+
cenv = {
26+
"PATH": env["PATH"],
27+
"BUILDLIB_PATH": env["BUILDLIB_PATH"]
28+
}
29+
return cenv
30+
31+
recipe = HostCythonRecipe()

pythonforandroid/toolchain.py

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,6 +1927,10 @@ class PythonRecipe(Recipe):
19271927
call_hostpython_via_targetpython is False.
19281928
'''
19291929

1930+
install_in_targetpython = True
1931+
'''If True (default), install the module in the target python build.
1932+
'''
1933+
19301934
@property
19311935
def hostpython_location(self):
19321936
if not self.call_hostpython_via_targetpython:
@@ -1974,13 +1978,14 @@ def install_python_package(self, name=None, env=None, is_dir=True):
19741978
# hostpython = sh.Command(self.ctx.hostpython)
19751979
hostpython = sh.Command(self.hostpython_location)
19761980

1977-
if self.call_hostpython_via_targetpython:
1978-
shprint(hostpython, 'setup.py', 'install', '-O2', _env=env)
1979-
else:
1980-
shprint(hostpython, 'setup.py', 'install', '-O2',
1981-
'--root={}'.format(self.ctx.get_python_install_dir()),
1982-
'--install-lib=lib/python2.7/site-packages',
1983-
_env=env) # AND: Hardcoded python2.7 needs fixing
1981+
if self.install_in_targetpython:
1982+
if self.call_hostpython_via_targetpython:
1983+
shprint(hostpython, 'setup.py', 'install', '-O2', _env=env)
1984+
else:
1985+
shprint(hostpython, 'setup.py', 'install', '-O2',
1986+
'--root={}'.format(self.ctx.get_python_install_dir()),
1987+
'--install-lib=lib/python2.7/site-packages',
1988+
_env=env) # AND: Hardcoded python2.7 needs fixing
19841989

19851990
# If asked, also install in the hostpython build dir
19861991
if self.install_in_hostpython:
@@ -2935,6 +2940,36 @@ def build_status(self, args):
29352940
recipe_str += '{Style.RESET_ALL}'.format(Style=Style)
29362941
print(recipe_str)
29372942

2943+
def hostpython(self, args):
2944+
'''Get an hostpython shell for the default arch
2945+
'''
2946+
ctx = self.ctx
2947+
ctx.prepare_build_environment(user_sdk_dir=self.sdk_dir,
2948+
user_ndk_dir=self.ndk_dir,
2949+
user_android_api=self.android_api,
2950+
user_ndk_ver=self.ndk_version)
2951+
2952+
recipe = Recipe.get_recipe('hostpython2', self.ctx)
2953+
hostpython = join(recipe.get_build_dir('armeabi'), 'hostpython')
2954+
env = recipe.get_recipe_env()
2955+
env["PYTHONPATH"] = ":".join([
2956+
join(recipe.get_build_dir('armeabi'), 'Lib', 'site-packages')
2957+
])
2958+
env["CFLAGS"] = "-I/home/tito/.local/share/python-for-android/build/other_builds/numpy/armeabi/numpy/numpy/core/include {}".format(env["CFLAGS"])
2959+
env["CFLAGS"] = "-I/home/tito/.local/share/python-for-android/build/other_builds/numpy/armeabi/numpy/build/src.linux-x86_64-2.7/numpy/core/include/numpy {}".format(env["CFLAGS"])
2960+
env["CFLAGS"] = "-I/home/tito/.local/share/python-for-android/build/other_builds/python2/armeabi/python2/Include {}".format(env["CFLAGS"])
2961+
env["CFLAGS"] = "-I/home/tito/.local/share/python-for-android/build/other_builds/python2/armeabi/python2 {}".format(env["CFLAGS"])
2962+
# env["LDFLAGS"] = "-lpython2.7 -lc"
2963+
env["LDFLAGS"] = "-lpython2.7"
2964+
env["LDFLAGS"] = "-L/home/tito/.local/share/python-for-android/build/other_builds/python2/armeabi/python2 {}".format(env["LDFLAGS"])
2965+
# env["LDSHARED"] = "{} -shared".format(env["LD"])
2966+
env["LDSHARED"] = "{} -shared".format(env["CC"])
2967+
env["CFLAGS"] = env["CFLAGS"].replace("-DANDROID", "")
2968+
env["CXXFLAGS"] = env["CXXFLAGS"].replace("-DANDROID", "")
2969+
from pprint import pprint
2970+
pprint(env)
2971+
pprint(ctx.include_dirs)
2972+
os.execve(hostpython, [hostpython] + args, env)
29382973

29392974
def main():
29402975
ToolchainCL()

0 commit comments

Comments
 (0)