Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pythonforandroid/bdistapk.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def _set_user_options():
for i, arg in enumerate(sys.argv):
if arg.startswith('--'):
if ('=' in arg or
(i < (len(sys.argv) - 1) and not sys.argv[i+1].startswith('-'))):
(i < (len(sys.argv) - 1) and not sys.argv[i+1].startswith('-'))):
user_options.append((arg[2:].split('=')[0] + '=', None, None))
else:
user_options.append((arg[2:], None, None))
Expand Down
8 changes: 4 additions & 4 deletions pythonforandroid/bootstraps/pygame/build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ def select(fn):
fn = realpath(fn)
assert(fn.startswith(d))
fn = fn[len(d):]
if (fn.startswith('/site-packages/') or
fn.startswith('/config/') or
fn.startswith('/lib-dynload/') or
fn.startswith('/libpymodules.so')):
if (fn.startswith('/site-packages/')
or fn.startswith('/config/')
or fn.startswith('/lib-dynload/')
or fn.startswith('/libpymodules.so')):
return False
return fn

Expand Down
8 changes: 4 additions & 4 deletions pythonforandroid/bootstraps/pygame/build/buildlib/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,8 @@ def _split_lines(self, text, width):

def _fill_text(self, text, width, indent):
text = self._whitespace_matcher.sub(' ', text).strip()
return _textwrap.fill(text, width, initial_indent=indent,
subsequent_indent=indent)
return _textwrap.fill(
text, width, initial_indent=indent, subsequent_indent=indent)

def _get_help_string(self, action):
return action.help
Expand Down Expand Up @@ -2070,8 +2070,8 @@ def _parse_optional(self, arg_string):

# if multiple actions match, the option string was ambiguous
if len(option_tuples) > 1:
options = ', '.join([option_string
for action, option_string, explicit_arg in option_tuples])
options = ', '.join(
[option_string for action, option_string, explicit_arg in option_tuples])
tup = arg_string, options
self.error(_('ambiguous option: %s could match %s') % tup)

Expand Down
8 changes: 4 additions & 4 deletions pythonforandroid/bootstraps/sdl2/build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ def select(fn):
fn = realpath(fn)
assert(fn.startswith(d))
fn = fn[len(d):]
if (fn.startswith('/site-packages/') or
fn.startswith('/config/') or
fn.startswith('/lib-dynload/') or
fn.startswith('/libpymodules.so')):
if (fn.startswith('/site-packages/')
or fn.startswith('/config/')
or fn.startswith('/lib-dynload/')
or fn.startswith('/libpymodules.so')):
return False
return fn

Expand Down
8 changes: 4 additions & 4 deletions pythonforandroid/bootstraps/service_only/build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ def select(fn):
fn = realpath(fn)
assert(fn.startswith(d))
fn = fn[len(d):]
if (fn.startswith('/site-packages/') or
fn.startswith('/config/') or
fn.startswith('/lib-dynload/') or
fn.startswith('/libpymodules.so')):
if (fn.startswith('/site-packages/')
or fn.startswith('/config/')
or fn.startswith('/lib-dynload/')
or fn.startswith('/libpymodules.so')):
return False
return fn

Expand Down
8 changes: 4 additions & 4 deletions pythonforandroid/bootstraps/webview/build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ def select(fn):
fn = realpath(fn)
assert(fn.startswith(d))
fn = fn[len(d):]
if (fn.startswith('/site-packages/') or
fn.startswith('/config/') or
fn.startswith('/lib-dynload/') or
fn.startswith('/libpymodules.so')):
if (fn.startswith('/site-packages/')
or fn.startswith('/config/')
or fn.startswith('/lib-dynload/')
or fn.startswith('/libpymodules.so')):
return False
return fn

Expand Down
35 changes: 21 additions & 14 deletions pythonforandroid/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@ class Context(object):
will be instantiated and used to hold all the build state.'''

env = environ.copy()
root_dir = None # the filepath of toolchain.py
storage_dir = None # the root dir where builds and dists will be stored

build_dir = None # in which bootstraps are copied for building
# and recipes are built
dist_dir = None # the Android project folder where everything ends up
libs_dir = None # where Android libs are cached after build but
# before being placed in dists
# the filepath of toolchain.py
root_dir = None
# the root dir where builds and dists will be stored
storage_dir = None

# in which bootstraps are copied for building
# and recipes are built
build_dir = None
# the Android project folder where everything ends up
dist_dir = None
# where Android libs are cached after build
# but before being placed in dists
libs_dir = None
aars_dir = None

ccache = None # whether to use ccache
Expand Down Expand Up @@ -178,12 +183,14 @@ def prepare_build_environment(self, user_sdk_dir, user_ndk_dir,
sdk_dir = None
if user_sdk_dir:
sdk_dir = user_sdk_dir
if sdk_dir is None: # This is the old P4A-specific var
# This is the old P4A-specific var
if sdk_dir is None:
sdk_dir = environ.get('ANDROIDSDK', None)
if sdk_dir is None: # This seems used more conventionally
# This seems used more conventionally
if sdk_dir is None:
sdk_dir = environ.get('ANDROID_HOME', None)
if sdk_dir is None: # Checks in the buildozer SDK dir, useful
# for debug tests of p4a
# Checks in the buildozer SDK dir, useful for debug tests of p4a
if sdk_dir is None:
possible_dirs = glob.glob(expanduser(join(
'~', '.buildozer', 'android', 'platform', 'android-sdk-*')))
possible_dirs = [d for d in possible_dirs if not
Expand Down Expand Up @@ -842,8 +849,8 @@ def copylibs_function(soname, objs_paths, extra_link_dirs=[], env=None):
if needso:
lib = needso.group(1)
if (lib not in needed_libs
and lib not in found_libs
and lib not in blacklist_libs):
and lib not in found_libs
and lib not in blacklist_libs):
needed_libs.append(needso.group(1))

sofiles += found_sofiles
Expand Down
33 changes: 18 additions & 15 deletions pythonforandroid/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def download(self):
debug('* Expected md5sum: {}'.format(expected_md5))
raise ValueError(
('Generated md5sum does not match expected md5sum '
'for {} recipe').format(self.name))
'for {} recipe').format(self.name))
else:
info('{} download already cached, skipping'.format(self.name))

Expand Down Expand Up @@ -410,10 +410,11 @@ def unpack(self, arch):
try:
sh.unzip(extraction_filename)
except (sh.ErrorReturnCode_1, sh.ErrorReturnCode_2):
pass # return code 1 means unzipping had
# warnings but did complete,
# apparently happens sometimes with
# github zips
# return code 1 means unzipping had
# warnings but did complete,
# apparently happens sometimes with
# github zips
pass
import zipfile
fileh = zipfile.ZipFile(extraction_filename, 'r')
root_directory = fileh.filelist[0].filename.split('/')[0]
Expand Down Expand Up @@ -765,8 +766,8 @@ def get_recipe_env(self, arch=None, with_flags_in_cc=True):
env['PYTHON_ROOT'] = self.ctx.get_python_install_dir()
env['CFLAGS'] += ' -I' + env[
'PYTHON_ROOT'] + '/include/python2.7'
env['LDFLAGS'] += ' -L' + env['PYTHON_ROOT'] + '/lib' + \
' -lpython2.7'
env['LDFLAGS'] += (
' -L' + env['PYTHON_ROOT'] + '/lib' + ' -lpython2.7')
elif self.ctx.python_recipe.from_crystax:
ndk_dir_python = join(self.ctx.ndk_dir, 'sources',
'python', python_version)
Expand All @@ -783,9 +784,9 @@ def get_recipe_env(self, arch=None, with_flags_in_cc=True):
env['CFLAGS'] += ' -I' + env[
'PYTHON_ROOT'] + '/include/python{}m'.format(
python_short_version)
env['LDFLAGS'] += ' -L' + env['PYTHON_ROOT'] + '/lib' + \
' -lpython{}m'.format(
python_short_version)
env['LDFLAGS'] += (
' -L' + env['PYTHON_ROOT'] + '/lib' +
' -lpython{}m'.format(python_short_version))
hppath = []
hppath.append(join(dirname(self.hostpython_location), 'Lib'))
hppath.append(join(hppath[0], 'site-packages'))
Expand Down Expand Up @@ -920,12 +921,14 @@ def get_recipe_env(self, arch):
arch_noeabi=arch.arch.replace('eabi', '')
)
env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions'
env['CFLAGS'] += " -I{ctx.ndk_dir}/platforms/android-{ctx.android_api}/arch-{arch_noeabi}/usr/include" \
" -I{ctx.ndk_dir}/sources/cxx-stl/gnu-libstdc++/{ctx.toolchain_version}/include" \
" -I{ctx.ndk_dir}/sources/cxx-stl/gnu-libstdc++/{ctx.toolchain_version}/libs/{arch.arch}/include".format(**keys)
env['CFLAGS'] += (
" -I{ctx.ndk_dir}/platforms/android-{ctx.android_api}/arch-{arch_noeabi}/usr/include" +
" -I{ctx.ndk_dir}/sources/cxx-stl/gnu-libstdc++/{ctx.toolchain_version}/include" +
" -I{ctx.ndk_dir}/sources/cxx-stl/gnu-libstdc++/{ctx.toolchain_version}/libs/{arch.arch}/include".format(**keys))
env['CXXFLAGS'] = env['CFLAGS'] + ' -frtti -fexceptions'
env['LDFLAGS'] += " -L{ctx.ndk_dir}/sources/cxx-stl/gnu-libstdc++/{ctx.toolchain_version}/libs/{arch.arch}" \
" -lgnustl_shared".format(**keys)
env['LDFLAGS'] += (
" -L{ctx.ndk_dir}/sources/cxx-stl/gnu-libstdc++/{ctx.toolchain_version}/libs/{arch.arch}" +
" -lgnustl_shared".format(**keys))

return env

Expand Down
18 changes: 10 additions & 8 deletions pythonforandroid/recipes/Pillow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def get_recipe_env(self, arch=None):

ndk_dir = self.ctx.ndk_platform
ndk_lib_dir = join(ndk_dir, 'usr', 'lib')
ndk_include_dir = (join(self.ctx.ndk_dir, 'sysroot', 'usr', 'include')
ndk_include_dir = (
join(self.ctx.ndk_dir, 'sysroot', 'usr', 'include')
if py_ver == '2.7' else join(ndk_dir, 'usr', 'include'))

png = self.get_recipe('png', self.ctx)
Expand All @@ -48,23 +49,24 @@ def get_recipe_env(self, arch=None):
cflags += ' -I{} -L{}'.format(jpeg_jni_dir, jpeg_lib_dir)
cflags += ' -I{} -L{}'.format(ndk_include_dir, ndk_lib_dir)

gcc_lib = (shprint(sh.gcc, '-print-libgcc-file-name')
.stdout.decode('utf-8').split('\n')[0])
gcc_lib = shprint(
sh.gcc, '-print-libgcc-file-name').stdout.decode('utf-8').split('\n')[0]
gcc_include = join(dirname(gcc_lib), 'include')
cflags += ' -I{}'.format(gcc_include)

if self.ctx.ndk == 'crystax':
py_inc_dir = join(self.ctx.ndk_dir, 'sources', 'python', py_ver,
'include', 'python')
py_lib_dir = join(self.ctx.ndk_dir, 'sources', 'python', py_ver,
'libs', arch.arch)
py_inc_dir = join(
self.ctx.ndk_dir, 'sources', 'python', py_ver, 'include', 'python')
py_lib_dir = join(
self.ctx.ndk_dir, 'sources', 'python', py_ver, 'libs', arch.arch)
cflags += ' -I{}'.format(py_inc_dir)
env['LDFLAGS'] += ' -L{} -lpython{}m'.format(py_lib_dir, py_ver)

env['LDFLAGS'] += ' {} -L{}'.format(env['CFLAGS'], self.ctx.libs_dir)
if cflags not in env['CFLAGS']:
env['CFLAGS'] += cflags
env['LDSHARED'] = '{} {}'.format(env['CC'],
env['LDSHARED'] = '{} {}'.format(
env['CC'],
'-pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions')
return env

Expand Down
34 changes: 18 additions & 16 deletions pythonforandroid/recipes/android/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,24 @@ def prebuild_arch(self, arch):
'JNI_NAMESPACE': jni_ns,
}

with current_directory(self.get_build_dir(arch.arch)):
with open(join('android', 'config.pxi'), 'w') as fpxi:
with open(join('android', 'config.h'), 'w') as fh:
with open(join('android', 'config.py'), 'w') as fpy:
for key, value in config.items():
fpxi.write(tpxi.format(key, repr(value)))
fpy.write(tpy.format(key, repr(value)))
fh.write(th.format(key, value if isinstance(value, int)
else '"{}"'.format(value)))
self.config_env[key] = str(value)

if is_sdl2:
fh.write('JNIEnv *SDL_AndroidGetJNIEnv(void);\n')
fh.write('#define SDL_ANDROID_GetJNIEnv SDL_AndroidGetJNIEnv\n')
elif is_pygame:
fh.write('JNIEnv *SDL_ANDROID_GetJNIEnv(void);\n')
with (
current_directory(self.get_build_dir(arch.arch))), (
open(join('android', 'config.pxi'), 'w')) as fpxi, (
open(join('android', 'config.h'), 'w')) as fh, (
open(join('android', 'config.py'), 'w')) as fpy:
for key, value in config.items():
fpxi.write(tpxi.format(key, repr(value)))
fpy.write(tpy.format(key, repr(value)))
fh.write(th.format(key,
value if isinstance(value, int)
else '"{}"'.format(value)))
self.config_env[key] = str(value)

if is_sdl2:
fh.write('JNIEnv *SDL_AndroidGetJNIEnv(void);\n')
fh.write('#define SDL_ANDROID_GetJNIEnv SDL_AndroidGetJNIEnv\n')
elif is_pygame:
fh.write('JNIEnv *SDL_ANDROID_GetJNIEnv(void);\n')


recipe = AndroidRecipe()
4 changes: 2 additions & 2 deletions pythonforandroid/recipes/android/src/android/broadcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ def start(self):
Handler = autoclass('android.os.Handler')
self.handlerthread.start()
self.handler = Handler(self.handlerthread.getLooper())
self.context.registerReceiver(self.receiver, self.receiver_filter, None,
self.handler)
self.context.registerReceiver(
self.receiver, self.receiver_filter, None, self.handler)

def stop(self):
self.context.unregisterReceiver(self.receiver)
Expand Down
6 changes: 2 additions & 4 deletions pythonforandroid/recipes/hostpython2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ def build_arch(self, arch):

if exists('hostpython'):
info('hostpython already exists, skipping build')
self.ctx.hostpython = join(self.get_build_dir(),
'hostpython')
self.ctx.hostpgen = join(self.get_build_dir(),
'hostpgen')
self.ctx.hostpython = join(self.get_build_dir(), 'hostpython')
self.ctx.hostpgen = join(self.get_build_dir(), 'hostpgen')
return

if 'LIBS' in os.environ:
Expand Down
27 changes: 13 additions & 14 deletions pythonforandroid/recipes/ifaddrs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ class IFAddrRecipe(CompiledComponentsPythonRecipe):

def should_build(self, arch):
"""It's faster to build than check"""
return not (exists(join(self.ctx.libs_dir, arch.arch, 'libifaddrs.so'))
and exists(join(self.ctx.get_python_install_dir(), 'lib'
"libifaddrs.so"))
)
return not (
exists(join(self.ctx.libs_dir, arch.arch, 'libifaddrs.so'))
and exists(join(self.ctx.get_python_install_dir(), 'lib' "libifaddrs.so")))

def prebuild_arch(self, arch):
"""Make the build and target directories"""
Expand All @@ -33,10 +32,10 @@ def prebuild_arch(self, arch):
def build_arch(self, arch):
"""simple shared compile"""
env = self.get_recipe_env(arch, with_flags_in_cc=False)
for path in (self.get_build_dir(arch.arch),
join(self.ctx.python_recipe.get_build_dir(arch.arch), 'Lib'),
join(self.ctx.python_recipe.get_build_dir(arch.arch), 'Include'),
):
for path in (
self.get_build_dir(arch.arch),
join(self.ctx.python_recipe.get_build_dir(arch.arch), 'Lib'),
join(self.ctx.python_recipe.get_build_dir(arch.arch), 'Include')):
if not exists(path):
info("creating {}".format(path))
shprint(sh.mkdir, '-p', path)
Expand All @@ -56,12 +55,12 @@ def build_arch(self, arch):
shprint(sh.cp, 'libifaddrs.so', self.ctx.get_libs_dir(arch.arch))
shprint(sh.cp, "libifaddrs.so", join(self.ctx.get_python_install_dir(), 'lib'))
# drop header in to the Python include directory
shprint(sh.cp, "ifaddrs.h", join(self.ctx.get_python_install_dir(),
'include/python{}'.format(
self.ctx.python_recipe.version[0:3]
)
)
)
python_version = self.ctx.python_recipe.version[0:3]
shprint(sh.cp, "ifaddrs.h",
join(
self.ctx.get_python_install_dir(),
'include/python{}'.format(python_version))
)
include_path = join(self.ctx.python_recipe.get_build_dir(arch.arch), 'Include')
shprint(sh.cp, "ifaddrs.h", include_path)

Expand Down
8 changes: 4 additions & 4 deletions pythonforandroid/recipes/libglob/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ def prebuild_arch(self, arch):
def build_arch(self, arch):
"""simple shared compile"""
env = self.get_recipe_env(arch, with_flags_in_cc=False)
for path in (self.get_build_dir(arch.arch),
join(self.ctx.python_recipe.get_build_dir(arch.arch), 'Lib'),
join(self.ctx.python_recipe.get_build_dir(arch.arch), 'Include'),
):
for path in (
self.get_build_dir(arch.arch),
join(self.ctx.python_recipe.get_build_dir(arch.arch), 'Lib'),
join(self.ctx.python_recipe.get_build_dir(arch.arch), 'Include')):
if not exists(path):
info("creating {}".format(path))
shprint(sh.mkdir, '-p', path)
Expand Down
Loading