Skip to content

Commit 058fc8f

Browse files
kochelmonsterbobatsar
authored andcommitted
various recipes
1 parent ac25fab commit 058fc8f

File tree

11 files changed

+320
-0
lines changed

11 files changed

+320
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from pythonforandroid.toolchain import PythonRecipe
2+
3+
4+
class GeventWebsocketRecipe(PythonRecipe):
5+
version = '0.9.5'
6+
url = 'https://pypi.python.org/packages/source/g/gevent-websocket/gevent-websocket-{version}.tar.gz'
7+
depends = [('python2', 'python3crystax'), 'setuptools']
8+
site_packages_name = 'geventwebsocket'
9+
call_hostpython_via_targetpython = False
10+
11+
recipe = GeventWebsocketRecipe()
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
import sh
2+
import os
3+
from os.path import join, isdir
4+
from pythonforandroid.recipe import NDKRecipe
5+
from pythonforandroid.toolchain import shprint, info
6+
from pythonforandroid.util import current_directory, ensure_dir
7+
8+
9+
class ICURecipe(NDKRecipe):
10+
name = 'icu4c'
11+
version = '57.1'
12+
url = 'http://download.icu-project.org/files/icu4c/57.1/icu4c-57_1-src.tgz'
13+
14+
depends = [('python2', 'python3crystax')] # installs in python
15+
generated_libraries = [
16+
'libicui18n.so', 'libicuuc.so', 'libicudata.so', 'libicule.so']
17+
18+
def get_lib_dir(self, arch):
19+
lib_dir = join(self.ctx.get_python_install_dir(), "lib")
20+
ensure_dir(lib_dir)
21+
return lib_dir
22+
23+
def prepare_build_dir(self, arch):
24+
if self.ctx.android_api > 19:
25+
# greater versions do not have /usr/include/sys/exec_elf.h
26+
raise RuntimeError("icu needs an android api <= 19")
27+
28+
super(ICURecipe, self).prepare_build_dir(arch)
29+
30+
def build_arch(self, arch, *extra_args):
31+
env = self.get_recipe_env(arch).copy()
32+
build_root = self.get_build_dir(arch.arch)
33+
34+
def make_build_dest(dest):
35+
build_dest = join(build_root, dest)
36+
if not isdir(build_dest):
37+
ensure_dir(build_dest)
38+
return build_dest, False
39+
40+
return build_dest, True
41+
42+
icu_build = join(build_root, "icu_build")
43+
build_linux, exists = make_build_dest("build_icu_linux")
44+
45+
host_env = os.environ.copy()
46+
# reduce the function set
47+
host_env["CPPFLAGS"] = (
48+
"-O3 -fno-short-wchar -DU_USING_ICU_NAMESPACE=1 -fno-short-enums "
49+
"-DU_HAVE_NL_LANGINFO_CODESET=0 -D__STDC_INT64__ -DU_TIMEZONE=0 "
50+
"-DUCONFIG_NO_LEGACY_CONVERSION=1 "
51+
"-DUCONFIG_NO_TRANSLITERATION=0 ")
52+
53+
if not exists:
54+
configure = sh.Command(
55+
join(build_root, "source", "runConfigureICU"))
56+
with current_directory(build_linux):
57+
shprint(
58+
configure,
59+
"Linux",
60+
"--prefix="+icu_build,
61+
"--enable-extras=no",
62+
"--enable-strict=no",
63+
"--enable-static",
64+
"--enable-tests=no",
65+
"--enable-samples=no",
66+
_env=host_env)
67+
shprint(sh.make, "-j5", _env=host_env)
68+
shprint(sh.make, "install", _env=host_env)
69+
70+
build_android, exists = make_build_dest("build_icu_android")
71+
if exists:
72+
return
73+
74+
configure = sh.Command(join(build_root, "source", "configure"))
75+
76+
include = (
77+
" -I{ndk}/sources/cxx-stl/gnu-libstdc++/{version}/include/"
78+
" -I{ndk}/sources/cxx-stl/gnu-libstdc++/{version}/libs/"
79+
"{arch}/include")
80+
include = include.format(ndk=self.ctx.ndk_dir,
81+
version=env["TOOLCHAIN_VERSION"],
82+
arch=arch.arch)
83+
env["CPPFLAGS"] = env["CXXFLAGS"] + " "
84+
env["CPPFLAGS"] += host_env["CPPFLAGS"]
85+
env["CPPFLAGS"] += include
86+
87+
lib = "{ndk}/sources/cxx-stl/gnu-libstdc++/{version}/libs/{arch}"
88+
lib = lib.format(ndk=self.ctx.ndk_dir,
89+
version=env["TOOLCHAIN_VERSION"],
90+
arch=arch.arch)
91+
env["LDFLAGS"] += " -lgnustl_shared -L"+lib
92+
93+
env.pop("CFLAGS", None)
94+
env.pop("CXXFLAGS", None)
95+
96+
with current_directory(build_android):
97+
shprint(
98+
configure,
99+
"--with-cross-build="+build_linux,
100+
"--enable-extras=no",
101+
"--enable-strict=no",
102+
"--enable-static",
103+
"--enable-tests=no",
104+
"--enable-samples=no",
105+
"--host="+env["TOOLCHAIN_PREFIX"],
106+
"--prefix="+icu_build,
107+
_env=env)
108+
shprint(sh.make, "-j5", _env=env)
109+
shprint(sh.make, "install", _env=env)
110+
111+
self.copy_files(arch)
112+
113+
def copy_files(self, arch):
114+
ndk = self.ctx.ndk_dir
115+
env = self.get_recipe_env(arch)
116+
117+
lib = "{ndk}/sources/cxx-stl/gnu-libstdc++/{version}/libs/{arch}"
118+
lib = lib.format(ndk=self.ctx.ndk_dir,
119+
version=env["TOOLCHAIN_VERSION"],
120+
arch=arch.arch)
121+
stl_lib = join(lib, "libgnustl_shared.so")
122+
dst_dir = join(self.ctx.get_site_packages_dir(), "..", "lib-dynload")
123+
shprint(sh.cp, stl_lib, dst_dir)
124+
125+
src_lib = join(self.get_build_dir(arch.arch), "icu_build", "lib")
126+
dst_lib = self.get_lib_dir(arch)
127+
128+
src_suffix = "." + self.version
129+
dst_suffix = "." + self.version.split(".")[0] # main version
130+
for lib in self.generated_libraries:
131+
shprint(sh.cp, join(src_lib, lib+src_suffix),
132+
join(dst_lib, lib+dst_suffix))
133+
134+
src_include = join(
135+
self.get_build_dir(arch.arch), "icu_build", "include")
136+
dst_include = join(
137+
self.ctx.get_python_install_dir(), "include", "icu")
138+
ensure_dir(dst_include)
139+
shprint(sh.cp, "-r", join(src_include, "layout"), dst_include)
140+
shprint(sh.cp, "-r", join(src_include, "unicode"), dst_include)
141+
142+
# copy stl library
143+
lib = "{ndk}/sources/cxx-stl/gnu-libstdc++/{version}/libs/{arch}"
144+
lib = lib.format(ndk=self.ctx.ndk_dir,
145+
version=env["TOOLCHAIN_VERSION"],
146+
arch=arch.arch)
147+
stl_lib = join(lib, "libgnustl_shared.so")
148+
149+
dst_dir = join(self.ctx.get_python_install_dir(), "lib")
150+
ensure_dir(dst_dir)
151+
shprint(sh.cp, stl_lib, dst_dir)
152+
153+
154+
recipe = ICURecipe()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import os
2+
import sh
3+
from pythonforandroid.recipe import CythonRecipe
4+
5+
6+
class MsgPackRecipe(CythonRecipe):
7+
version = '0.4.7'
8+
url = 'https://pypi.python.org/packages/source/m/msgpack-python/msgpack-python-{version}.tar.gz'
9+
depends = [('python2', 'python3crystax'), "setuptools"]
10+
call_hostpython_via_targetpython = False
11+
12+
recipe = MsgPackRecipe()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from pythonforandroid.toolchain import PythonRecipe
2+
3+
4+
class PyamlRecipe(PythonRecipe):
5+
version = "15.8.2"
6+
url = 'https://pypi.python.org/packages/source/p/pyaml/pyaml-{version}.tar.gz'
7+
depends = [('python2', 'python3crystax'), "setuptools"]
8+
site_packages_name = 'yaml'
9+
call_hostpython_via_targetpython = False
10+
11+
recipe = PyamlRecipe()
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import os
2+
import sh
3+
from os.path import join
4+
from pythonforandroid.recipe import CompiledComponentsPythonRecipe
5+
from pythonforandroid.util import current_directory
6+
from pythonforandroid.toolchain import shprint, info
7+
8+
9+
class PyICURecipe(CompiledComponentsPythonRecipe):
10+
version = '1.9.2'
11+
url = 'https://pypi.python.org/packages/source/P/PyICU/PyICU-{version}.tar.gz'
12+
depends = [('python2', 'python3crystax'), "icu"]
13+
patches = ['locale.patch', 'icu.patch']
14+
15+
def get_recipe_env(self, arch):
16+
env = super(PyICURecipe, self).get_recipe_env(arch)
17+
18+
icu_include = join(
19+
self.ctx.get_python_install_dir(), "include", "icu")
20+
21+
env["CC"] += " -I"+icu_include
22+
23+
include = (
24+
" -I{ndk}/sources/cxx-stl/gnu-libstdc++/{version}/include/"
25+
" -I{ndk}/sources/cxx-stl/gnu-libstdc++/{version}/libs/"
26+
"{arch}/include")
27+
include = include.format(ndk=self.ctx.ndk_dir,
28+
version=env["TOOLCHAIN_VERSION"],
29+
arch=arch.arch)
30+
env["CC"] += include
31+
32+
lib = "{ndk}/sources/cxx-stl/gnu-libstdc++/{version}/libs/{arch}"
33+
lib = lib.format(ndk=self.ctx.ndk_dir,
34+
version=env["TOOLCHAIN_VERSION"],
35+
arch=arch.arch)
36+
env["LDFLAGS"] += " -lgnustl_shared -L"+lib
37+
38+
build_dir = self.get_build_dir(arch.arch)
39+
env["LDFLAGS"] += " -L"+build_dir
40+
return env
41+
42+
def build_arch(self, arch):
43+
build_dir = self.get_build_dir(arch.arch)
44+
45+
info("create links to icu libs")
46+
lib_dir = join(self.ctx.get_python_install_dir(), "lib")
47+
icu_libs = [f for f in os.listdir(lib_dir) if f.startswith("libicu")]
48+
49+
for l in icu_libs:
50+
raw = l.rsplit(".", 1)[0]
51+
try:
52+
shprint(sh.ln, "-s", join(lib_dir, l), join(build_dir, raw))
53+
except Exception:
54+
pass
55+
56+
super(PyICURecipe, self).build_arch(arch)
57+
58+
59+
recipe = PyICURecipe()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
diff -Naur icu.py icu1.py
2+
--- pyicu/icu.py 2012-11-23 21:28:55.000000000 +0100
3+
+++ icu1.py 2016-05-14 14:45:44.160023949 +0200
4+
@@ -34,4 +34,15 @@
5+
class InvalidArgsError(Exception):
6+
pass
7+
8+
+import ctypes
9+
+import os
10+
+root = os.environ["ANDROID_APP_PATH"]
11+
+ctypes.cdll.LoadLibrary(os.path.join(root, "lib", "libgnustl_shared.so"))
12+
+ctypes.cdll.LoadLibrary(os.path.join(root, "lib", "libicudata.so.57"))
13+
+ctypes.cdll.LoadLibrary(os.path.join(root, "lib", "libicuuc.so.57"))
14+
+ctypes.cdll.LoadLibrary(os.path.join(root, "lib", "libicui18n.so.57"))
15+
+ctypes.cdll.LoadLibrary(os.path.join(root, "lib", "libicule.so.57"))
16+
+del root
17+
+del os
18+
+
19+
from docs import *
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
diff -Naur locale.cpp locale1.cpp
2+
--- pyicu/locale.cpp 2015-04-29 07:32:39.000000000 +0200
3+
+++ locale1.cpp 2016-05-12 17:13:08.990059346 +0200
4+
@@ -27,7 +27,7 @@
5+
#if defined(_MSC_VER) || defined(__WIN32)
6+
#include <windows.h>
7+
#else
8+
-#include <sys/fcntl.h>
9+
+#include <fcntl.h>
10+
#include <sys/stat.h>
11+
#include <sys/mman.h>
12+
#endif
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from pythonforandroid.toolchain import PythonRecipe
2+
3+
4+
class PyYamlRecipe(PythonRecipe):
5+
version = "3.11"
6+
url = 'http://pyyaml.org/download/pyyaml/PyYAML-{version}.tar.gz'
7+
depends = [('python2', 'python3crystax'), "setuptools"]
8+
site_packages_name = 'pyyaml'
9+
call_hostpython_via_targetpython = False
10+
11+
recipe = PyYamlRecipe()
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from pythonforandroid.toolchain import PythonRecipe
2+
3+
4+
class SimpleCryptRecipe(PythonRecipe):
5+
version = '4.1.7'
6+
url = 'https://pypi.python.org/packages/source/s/simple-crypt/simple-crypt-{version}.tar.gz'
7+
depends = [('python2', 'python3crystax'), 'pycrypto']
8+
site_packages_name = 'simplecrypt'
9+
10+
recipe = SimpleCryptRecipe()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from pythonforandroid.toolchain import CompiledComponentsPythonRecipe
2+
3+
4+
class UJsonRecipe(CompiledComponentsPythonRecipe):
5+
version = '1.35'
6+
url = 'https://pypi.python.org/packages/source/u/ujson/ujson-{version}.tar.gz'
7+
depends = [('python2', 'python3crystax')]
8+
9+
recipe = UJsonRecipe()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import os
2+
import sh
3+
from pythonforandroid.recipe import CythonRecipe
4+
5+
6+
class WSAccellRecipe(CythonRecipe):
7+
version = '0.6.2'
8+
url = 'https://pypi.python.org/packages/source/w/wsaccel/wsaccel-{version}.tar.gz'
9+
depends = [('python2', 'python3crystax')]
10+
call_hostpython_via_targetpython = False
11+
12+
recipe = WSAccellRecipe()

0 commit comments

Comments
 (0)