Skip to content

Commit 4f07337

Browse files
authored
Merge pull request #672 from brussee/python2-sqlite3
sqlite3 for python2
2 parents 4939dac + bd319fe commit 4f07337

File tree

3 files changed

+55
-4
lines changed

3 files changed

+55
-4
lines changed

pythonforandroid/recipes/python2/__init__.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Python2Recipe(TargetPythonRecipe):
1414

1515
depends = ['hostpython2']
1616
conflicts = ['python3crystax', 'python3']
17-
opt_depends = ['openssl']
17+
opt_depends = ['openssl','sqlite3']
1818

1919
patches = ['patches/Python-{version}-xcompile.patch',
2020
'patches/Python-{version}-ctypes-disable-wchar.patch',
@@ -68,9 +68,6 @@ def build_arch(self, arch):
6868
# return
6969

7070
def do_python_build(self, arch):
71-
if 'sqlite' in self.ctx.recipe_build_order:
72-
print('sqlite support not yet enabled in python recipe')
73-
exit(1)
7471

7572
hostpython_recipe = Recipe.get_recipe('hostpython2', self.ctx)
7673
shprint(sh.cp, self.ctx.hostpython, self.get_build_dir(arch.arch))
@@ -101,6 +98,17 @@ def do_python_build(self, arch):
10198
shprint(sh.cp, join(self.get_recipe_dir(), 'Setup.local-ssl'), setuplocal)
10299
shprint(sh.sed, '-i', 's#^SSL=.*#SSL={}#'.format(openssl_build_dir), setuplocal)
103100

101+
if 'sqlite3' in self.ctx.recipe_build_order:
102+
# Include sqlite3 in python2 build
103+
r = Recipe.get_recipe('sqlite3', self.ctx)
104+
i = ' -I' + r.get_build_dir(arch.arch)
105+
l = ' -L' + r.get_lib_dir(arch) + ' -lsqlite3'
106+
# Insert or append to env
107+
f = 'CPPFLAGS'
108+
env[f] = env[f] + i if f in env else i
109+
f = 'LDFLAGS'
110+
env[f] = env[f] + l if f in env else l
111+
104112
configure = sh.Command('./configure')
105113
# AND: OFLAG isn't actually set, should it be?
106114
shprint(configure,
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
LOCAL_PATH := $(call my-dir)/..
2+
3+
include $(CLEAR_VARS)
4+
5+
LOCAL_SRC_FILES := sqlite3.c
6+
7+
LOCAL_MODULE := sqlite3
8+
9+
LOCAL_CFLAGS := -DSQLITE_ENABLE_FTS3
10+
11+
include $(BUILD_SHARED_LIBRARY)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from pythonforandroid.toolchain import NDKRecipe, shprint, shutil, current_directory
2+
from os.path import join, exists
3+
import sh
4+
5+
class Sqlite3Recipe(NDKRecipe):
6+
version = '3.12.2'
7+
# Don't forget to change the URL when changing the version
8+
url = 'https://www.sqlite.org/2016/sqlite-amalgamation-3120200.zip'
9+
generated_libraries = ['sqlite3']
10+
11+
def should_build(self, arch):
12+
return not self.has_libs(arch, 'libsqlite3.so')
13+
14+
def prebuild_arch(self, arch):
15+
super(Sqlite3Recipe, self).prebuild_arch(arch)
16+
# Copy the Android make file
17+
sh.mkdir('-p', join(self.get_build_dir(arch.arch), 'jni'))
18+
shutil.copyfile(join(self.get_recipe_dir(), 'Android.mk'),
19+
join(self.get_build_dir(arch.arch), 'jni/Android.mk'))
20+
21+
def build_arch(self, arch, *extra_args):
22+
super(Sqlite3Recipe, self).build_arch(arch)
23+
# Copy the shared library
24+
shutil.copyfile(join(self.get_build_dir(arch.arch), 'libs', arch.arch, 'libsqlite3.so'),
25+
join(self.ctx.get_libs_dir(arch.arch), 'libsqlite3.so'))
26+
27+
def get_recipe_env(self, arch):
28+
env = super(Sqlite3Recipe, self).get_recipe_env(arch)
29+
env['NDK_PROJECT_PATH'] = self.get_build_dir(arch.arch)
30+
return env
31+
32+
recipe = Sqlite3Recipe()

0 commit comments

Comments
 (0)