Skip to content

Commit

Permalink
fixed rebase armageddon
Browse files Browse the repository at this point in the history
  • Loading branch information
zworkb committed Apr 15, 2020
1 parent cea61f5 commit 15590da
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 45 deletions.
26 changes: 21 additions & 5 deletions pythonforandroid/bdistapk.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ def argv_contains(t):
return False


class BdistAPK(Command):
description = 'Create an APK with python-for-android'
class Bdist(Command):

user_options = []
package_type = None

def initialize_options(self):
for option in self.user_options:
setattr(self, option[0].strip('=').replace('-', '_'), None)

option_dict = self.distribution.get_option_dict('apk')
option_dict = self.distribution.get_option_dict(self.package_type)

# This is a hack, we probably aren't supposed to loop through
# the option_dict so early because distutils does exactly the
Expand All @@ -34,7 +34,7 @@ def initialize_options(self):

def finalize_options(self):

setup_options = self.distribution.get_option_dict('apk')
setup_options = self.distribution.get_option_dict(self.package_type)
for (option, (source, value)) in setup_options.items():
if source == 'command line':
continue
Expand Down Expand Up @@ -75,7 +75,7 @@ def run(self):
self.prepare_build_dir()

from pythonforandroid.entrypoints import main
sys.argv[1] = 'apk'
sys.argv[1] = self.package_type
main()

def prepare_build_dir(self):
Expand Down Expand Up @@ -127,6 +127,22 @@ def prepare_build_dir(self):
)


class BdistAPK(Bdist):
"""
distutil command handler for 'apk'
"""
description = 'Create an APK with python-for-android'
package_type = 'apk'


class BdistAAR(Bdist):
"""
distutil command handler for 'aar'
"""
description = 'Create an AAR with python-for-android'
package_type = 'aar'


def _set_user_options():
# This seems like a silly way to do things, but not sure if there's a
# better way to pass arbitrary options onwards to p4a
Expand Down
41 changes: 25 additions & 16 deletions pythonforandroid/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from pythonforandroid.recipe import Recipe


def copy_files(src_root, dest_root, override=True):
def copy_files(src_root, dest_root, override=True, symlink=False):
for root, dirnames, filenames in walk(src_root):
for filename in filenames:
subdir = normpath(root.replace(src_root, ""))
Expand All @@ -29,7 +29,10 @@ def copy_files(src_root, dest_root, override=True):
if override and os.path.exists(dest_file):
os.unlink(dest_file)
if not os.path.exists(dest_file):
shutil.copy(src_file, dest_file)
if symlink:
os.symlink(src_file, dest_file)
else:
shutil.copy(src_file, dest_file)
else:
os.makedirs(dest_file)

Expand Down Expand Up @@ -109,7 +112,7 @@ def check_recipe_choices(self):
and optional dependencies are being used,
and returns a list of these.'''
recipes = []
built_recipes = self.ctx.recipe_build_order
built_recipes = self.ctx.recipe_build_order or []
for recipe in self.recipe_depends:
if isinstance(recipe, (tuple, list)):
for alternative in recipe:
Expand Down Expand Up @@ -137,21 +140,27 @@ def name(self):
modname = self.__class__.__module__
return modname.split(".", 2)[-1]

def get_bootstrap_dirs(self):
"""get all bootstrap directories, following the MRO path"""

# get all bootstrap names along the __mro__, cutting off Bootstrap and object
classes = self.__class__.__mro__[:-2]
bootstrap_names = [cls.name for cls in classes] + ['common']
bootstrap_dirs = [
join(self.ctx.root_dir, 'bootstraps', bootstrap_name)
for bootstrap_name in reversed(bootstrap_names)
]
return bootstrap_dirs

def prepare_build_dir(self):
'''Ensure that a build dir exists for the recipe. This same single
dir will be used for building all different archs.'''
"""Ensure that a build dir exists for the recipe. This same single
dir will be used for building all different archs."""
bootstrap_dirs = self.get_bootstrap_dirs()
# now do a cumulative copy of all bootstrap dirs
self.build_dir = self.get_build_dir()
self.common_dir = self.get_common_dir()
copy_files(join(self.bootstrap_dir, 'build'), self.build_dir)
copy_files(join(self.common_dir, 'build'), self.build_dir,
override=False)
if self.ctx.symlink_java_src:
info('Symlinking java src instead of copying')
shprint(sh.rm, '-r', join(self.build_dir, 'src'))
shprint(sh.mkdir, join(self.build_dir, 'src'))
for dirn in listdir(join(self.bootstrap_dir, 'build', 'src')):
shprint(sh.ln, '-s', join(self.bootstrap_dir, 'build', 'src', dirn),
join(self.build_dir, 'src'))
for bootstrap_dir in bootstrap_dirs:
copy_files(join(bootstrap_dir, 'build'), self.build_dir, symlink=self.ctx.symlink_bootstrap_files)

with current_directory(self.build_dir):
with open('project.properties', 'w') as fileh:
fileh.write('target=android-{}'.format(self.ctx.android_api))
Expand Down
3 changes: 2 additions & 1 deletion pythonforandroid/bootstraps/common/build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def compile_dir(dfn, optimize_python=True):
def make_package(args):
# If no launcher is specified, require a main.py/main.pyo:
if (get_bootstrap_name() != "sdl" or args.launcher is None) and \
get_bootstrap_name() != "webview":
get_bootstrap_name() not in ["webview", "service_library"]:
# (webview doesn't need an entrypoint, apparently)
if args.private is None or (
not exists(join(realpath(args.private), 'main.py')) and
Expand Down Expand Up @@ -479,6 +479,7 @@ def make_package(args):
android_api=android_api,
build_tools_version=build_tools_version,
debug_build="debug" in args.build_mode,
is_library=(get_bootstrap_name() == 'service_library'),
)

# ant build templates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ protected static ArrayList<String> getLibraries(File libsDir) {
libsList.add("python3.5m");
libsList.add("python3.6m");
libsList.add("python3.7m");
libsList.add("python3.8m");
libsList.add("main");
return libsList;
}
Expand All @@ -59,7 +60,7 @@ public static void loadLibraries(File filesDir, File libsDir) {
// load, and it has failed, give a more
// general error
Log.v(TAG, "Library loading error: " + e.getMessage());
if (lib.startsWith("python3.7") && !foundPython) {
if (lib.startsWith("python3.8") && !foundPython) {
throw new java.lang.RuntimeException("Could not load any libpythonXXX.so");
} else if (lib.startsWith("python")) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ allprojects {
}
}

{% if is_library %}
apply plugin: 'com.android.library'
{% else %}
apply plugin: 'com.android.application'
{% endif %}

android {
compileSdkVersion {{ android_api }}
Expand Down
10 changes: 6 additions & 4 deletions pythonforandroid/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class Context:

recipe_build_order = None # Will hold the list of all built recipes

symlink_java_src = False # If True, will symlink instead of copying during build
symlink_bootstrap_files = False # If True, will symlink instead of copying during build

java_build_tool = 'auto'

Expand Down Expand Up @@ -481,9 +481,11 @@ def set_archs(self, arch_names):
info('Will compile for the following archs: {}'.format(
', '.join([arch.arch for arch in self.archs])))

def prepare_bootstrap(self, bs):
bs.ctx = self
self.bootstrap = bs
def prepare_bootstrap(self, bootstrap):
if not bootstrap:
raise TypeError("None is not allowed for bootstrap")
bootstrap.ctx = self
self.bootstrap = bootstrap
self.bootstrap.prepare_build_dir()
self.bootstrap_build_dir = self.bootstrap.build_dir

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def recursively_include(results, directory, patterns):
],
'distutils.commands': [
'apk = pythonforandroid.bdistapk:BdistAPK',
'aar = pythonforandroid.bdistapk:BdistAAR',
],
},
classifiers = [
Expand Down
1 change: 1 addition & 0 deletions testapps/setup_testapp_python3_sqlite_openssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
options = {'apk': {'requirements': 'requests,peewee,sdl2,pyjnius,kivy,python3',
'android-api': 27,
'ndk-api': 21,
'bootstrap': 'sdl2',
'dist-name': 'bdisttest_python3_sqlite_openssl_googlendk',
'ndk-version': '10.3.2',
'arch': 'armeabi-v7a',
Expand Down
1 change: 1 addition & 0 deletions testapps/setup_vispy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'blacklist-requirements': 'openssl,sqlite3',
'android-api': 27,
'ndk-api': 21,
'bootstrap': 'empty',
'ndk-dir': '/home/asandy/android/android-ndk-r17c',
'dist-name': 'bdisttest',
'ndk-version': '10.3.2',
Expand Down
19 changes: 1 addition & 18 deletions tests/test_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,16 +288,10 @@ def test_bootstrap_prepare_build_dir(
@mock.patch("pythonforandroid.bootstrap.os.unlink")
@mock.patch("pythonforandroid.bootstrap.open", create=True)
@mock.patch("pythonforandroid.util.chdir")
@mock.patch("pythonforandroid.bootstrap.sh.ln")
@mock.patch("pythonforandroid.bootstrap.listdir")
@mock.patch("pythonforandroid.bootstrap.sh.mkdir")
@mock.patch("pythonforandroid.bootstrap.sh.rm")
def test_bootstrap_prepare_build_dir_with_java_src(
self,
mock_sh_rm,
mock_sh_mkdir,
mock_listdir,
mock_sh_ln,
mock_chdir,
mock_open,
mock_os_unlink,
Expand All @@ -309,7 +303,7 @@ def test_bootstrap_prepare_build_dir_with_java_src(
:meth:`~pythonforandroid.bootstrap.Bootstrap.prepare_build_dir`. In
here we will simulate that we have `with_java_src` set to some value.
"""
self.ctx.symlink_java_src = ["some_java_src"]
self.ctx.symlink_bootstrap_files = True
mock_listdir.return_value = [
"jnius",
"kivy",
Expand All @@ -327,18 +321,7 @@ def test_bootstrap_prepare_build_dir_with_java_src(
# make sure that the open command has been called only once
mock_open.assert_called_with("project.properties", "w")

# check that the symlink was made 4 times and that
self.assertEqual(
len(mock_sh_ln.call_args_list), len(mock_listdir.return_value)
)
for i, directory in enumerate(mock_listdir.return_value):
self.assertTrue(
mock_sh_ln.call_args_list[i][0][1].endswith(directory)
)

# check that the other mocks we made are actually called
mock_sh_rm.assert_called()
mock_sh_mkdir.assert_called()
mock_chdir.assert_called()
mock_os_unlink.assert_called()
mock_os_path_exists.assert_called()
Expand Down

0 comments on commit 15590da

Please sign in to comment.