Skip to content

Commit 6a28c2e

Browse files
committed
add pyleveldb recipe;
1 parent 6ec6f11 commit 6a28c2e

File tree

2 files changed

+147
-0
lines changed

2 files changed

+147
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from pythonforandroid.toolchain import PythonRecipe, shprint, shutil, current_directory
2+
from os.path import join, exists
3+
import sh
4+
5+
class PyLevelDBRecipe(PythonRecipe):
6+
version = '0.193'
7+
url = 'https://pypi.python.org/packages/source/l/leveldb/leveldb-{version}.tar.gz'
8+
depends = ['leveldb', 'hostpython2', 'python2', 'setuptools']
9+
call_hostpython_via_targetpython = False
10+
patches = ['bindings-only.patch']
11+
12+
def should_build(self, arch):
13+
return not self.ctx.has_package('leveldb', arch.arch)
14+
15+
def build_arch(self, arch):
16+
env = self.get_recipe_env(arch)
17+
with current_directory(self.get_build_dir(arch.arch)):
18+
# Remove source in this pypi package
19+
sh.rm('-rf', './leveldb', './leveldb.egg-info', './snappy')
20+
# Use source from leveldb recipe
21+
sh.ln('-s', self.get_recipe('leveldb', self.ctx).get_build_dir(arch.arch), 'leveldb')
22+
# Build python bindings
23+
hostpython = sh.Command(self.hostpython_location)
24+
shprint(hostpython,
25+
'setup.py',
26+
'build'
27+
, _env=env)
28+
# Install python bindings
29+
super(PyLevelDBRecipe, self).build_arch(arch)
30+
31+
def get_recipe_env(self, arch):
32+
env = super(PyLevelDBRecipe, self).get_recipe_env(arch)
33+
# Copy environment from leveldb recipe
34+
env.update(self.get_recipe('leveldb', self.ctx).get_recipe_env(arch))
35+
env['PYTHON_ROOT'] = self.ctx.get_python_install_dir()
36+
env['CFLAGS'] += ' -I' + env['PYTHON_ROOT'] + '/include/python2.7'
37+
# Set linker to use the correct gcc
38+
env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions'
39+
env['LDFLAGS'] += ' -L' + env['PYTHON_ROOT'] + '/lib' + \
40+
' -lpython2.7' + \
41+
' -lleveldb'
42+
return env
43+
44+
recipe = PyLevelDBRecipe()
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
--- pyleveldb/setup.py 2014-03-28 02:51:24.000000000 +0100
2+
+++ pyleveldb-patch/setup.py 2016-03-02 11:52:13.780678586 +0100
3+
@@ -7,41 +7,22 @@
4+
#
5+
# See LICENSE for details.
6+
7+
-import glob
8+
-import platform
9+
-import sys
10+
-
11+
from setuptools import setup, Extension
12+
13+
-system,node,release,version,machine,processor = platform.uname()
14+
-common_flags = [
15+
+extra_compile_args = [
16+
'-I./leveldb/include',
17+
'-I./leveldb',
18+
- '-I./snappy',
19+
+ '-I./leveldb/snappy',
20+
'-I.',
21+
- '-fno-builtin-memcmp',
22+
'-O2',
23+
'-fPIC',
24+
'-DNDEBUG',
25+
'-DSNAPPY',
26+
-]
27+
-
28+
-if system == 'Darwin':
29+
- extra_compile_args = common_flags + [
30+
- '-DOS_MACOSX',
31+
+ '-Wall',
32+
'-DLEVELDB_PLATFORM_POSIX',
33+
- '-Wno-error=unused-command-line-argument-hard-error-in-future',
34+
- ]
35+
-elif system == 'Linux':
36+
- extra_compile_args = common_flags + [
37+
- '-pthread',
38+
- '-Wall',
39+
- '-DOS_LINUX',
40+
- '-DLEVELDB_PLATFORM_POSIX',
41+
- ]
42+
-else:
43+
- print >>sys.stderr, "Don't know how to compile leveldb for %s!" % system
44+
- sys.exit(0)
45+
+ '-D_REENTRANT',
46+
+ '-DOS_ANDROID',
47+
+]
48+
49+
setup(
50+
name = 'leveldb',
51+
@@ -75,52 +56,6 @@
52+
ext_modules = [
53+
Extension('leveldb',
54+
sources = [
55+
- # snappy
56+
- './snappy/snappy.cc',
57+
- './snappy/snappy-stubs-internal.cc',
58+
- './snappy/snappy-sinksource.cc',
59+
- './snappy/snappy-c.cc',
60+
-
61+
- #leveldb
62+
- 'leveldb/db/builder.cc',
63+
- 'leveldb/db/c.cc',
64+
- 'leveldb/db/db_impl.cc',
65+
- 'leveldb/db/db_iter.cc',
66+
- 'leveldb/db/dbformat.cc',
67+
- 'leveldb/db/filename.cc',
68+
- 'leveldb/db/log_reader.cc',
69+
- 'leveldb/db/log_writer.cc',
70+
- 'leveldb/db/memtable.cc',
71+
- 'leveldb/db/repair.cc',
72+
- 'leveldb/db/table_cache.cc',
73+
- 'leveldb/db/version_edit.cc',
74+
- 'leveldb/db/version_set.cc',
75+
- 'leveldb/db/write_batch.cc',
76+
- 'leveldb/table/block.cc',
77+
- 'leveldb/table/block_builder.cc',
78+
- 'leveldb/table/filter_block.cc',
79+
- 'leveldb/table/format.cc',
80+
- 'leveldb/table/iterator.cc',
81+
- 'leveldb/table/merger.cc',
82+
- 'leveldb/table/table.cc',
83+
- 'leveldb/table/table_builder.cc',
84+
- 'leveldb/table/two_level_iterator.cc',
85+
- 'leveldb/util/arena.cc',
86+
- 'leveldb/util/bloom.cc',
87+
- 'leveldb/util/cache.cc',
88+
- 'leveldb/util/coding.cc',
89+
- 'leveldb/util/comparator.cc',
90+
- 'leveldb/util/crc32c.cc',
91+
- 'leveldb/util/env.cc',
92+
- 'leveldb/util/env_posix.cc',
93+
- 'leveldb/util/filter_policy.cc',
94+
- 'leveldb/util/hash.cc',
95+
- 'leveldb/util/histogram.cc',
96+
- 'leveldb/util/logging.cc',
97+
- 'leveldb/util/options.cc',
98+
- 'leveldb/util/status.cc',
99+
- 'leveldb/port/port_posix.cc',
100+
-
101+
# python stuff
102+
'leveldb_ext.cc',
103+
'leveldb_object.cc',

0 commit comments

Comments
 (0)