Skip to content

Commit 15590da

Browse files
committed
fixed rebase armageddon
1 parent cea61f5 commit 15590da

File tree

10 files changed

+64
-45
lines changed

10 files changed

+64
-45
lines changed

pythonforandroid/bdistapk.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ def argv_contains(t):
1414
return False
1515

1616

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

2019
user_options = []
20+
package_type = None
2121

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

26-
option_dict = self.distribution.get_option_dict('apk')
26+
option_dict = self.distribution.get_option_dict(self.package_type)
2727

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

3535
def finalize_options(self):
3636

37-
setup_options = self.distribution.get_option_dict('apk')
37+
setup_options = self.distribution.get_option_dict(self.package_type)
3838
for (option, (source, value)) in setup_options.items():
3939
if source == 'command line':
4040
continue
@@ -75,7 +75,7 @@ def run(self):
7575
self.prepare_build_dir()
7676

7777
from pythonforandroid.entrypoints import main
78-
sys.argv[1] = 'apk'
78+
sys.argv[1] = self.package_type
7979
main()
8080

8181
def prepare_build_dir(self):
@@ -127,6 +127,22 @@ def prepare_build_dir(self):
127127
)
128128

129129

130+
class BdistAPK(Bdist):
131+
"""
132+
distutil command handler for 'apk'
133+
"""
134+
description = 'Create an APK with python-for-android'
135+
package_type = 'apk'
136+
137+
138+
class BdistAAR(Bdist):
139+
"""
140+
distutil command handler for 'aar'
141+
"""
142+
description = 'Create an AAR with python-for-android'
143+
package_type = 'aar'
144+
145+
130146
def _set_user_options():
131147
# This seems like a silly way to do things, but not sure if there's a
132148
# better way to pass arbitrary options onwards to p4a

pythonforandroid/bootstrap.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from pythonforandroid.recipe import Recipe
1515

1616

17-
def copy_files(src_root, dest_root, override=True):
17+
def copy_files(src_root, dest_root, override=True, symlink=False):
1818
for root, dirnames, filenames in walk(src_root):
1919
for filename in filenames:
2020
subdir = normpath(root.replace(src_root, ""))
@@ -29,7 +29,10 @@ def copy_files(src_root, dest_root, override=True):
2929
if override and os.path.exists(dest_file):
3030
os.unlink(dest_file)
3131
if not os.path.exists(dest_file):
32-
shutil.copy(src_file, dest_file)
32+
if symlink:
33+
os.symlink(src_file, dest_file)
34+
else:
35+
shutil.copy(src_file, dest_file)
3336
else:
3437
os.makedirs(dest_file)
3538

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

143+
def get_bootstrap_dirs(self):
144+
"""get all bootstrap directories, following the MRO path"""
145+
146+
# get all bootstrap names along the __mro__, cutting off Bootstrap and object
147+
classes = self.__class__.__mro__[:-2]
148+
bootstrap_names = [cls.name for cls in classes] + ['common']
149+
bootstrap_dirs = [
150+
join(self.ctx.root_dir, 'bootstraps', bootstrap_name)
151+
for bootstrap_name in reversed(bootstrap_names)
152+
]
153+
return bootstrap_dirs
154+
140155
def prepare_build_dir(self):
141-
'''Ensure that a build dir exists for the recipe. This same single
142-
dir will be used for building all different archs.'''
156+
"""Ensure that a build dir exists for the recipe. This same single
157+
dir will be used for building all different archs."""
158+
bootstrap_dirs = self.get_bootstrap_dirs()
159+
# now do a cumulative copy of all bootstrap dirs
143160
self.build_dir = self.get_build_dir()
144-
self.common_dir = self.get_common_dir()
145-
copy_files(join(self.bootstrap_dir, 'build'), self.build_dir)
146-
copy_files(join(self.common_dir, 'build'), self.build_dir,
147-
override=False)
148-
if self.ctx.symlink_java_src:
149-
info('Symlinking java src instead of copying')
150-
shprint(sh.rm, '-r', join(self.build_dir, 'src'))
151-
shprint(sh.mkdir, join(self.build_dir, 'src'))
152-
for dirn in listdir(join(self.bootstrap_dir, 'build', 'src')):
153-
shprint(sh.ln, '-s', join(self.bootstrap_dir, 'build', 'src', dirn),
154-
join(self.build_dir, 'src'))
161+
for bootstrap_dir in bootstrap_dirs:
162+
copy_files(join(bootstrap_dir, 'build'), self.build_dir, symlink=self.ctx.symlink_bootstrap_files)
163+
155164
with current_directory(self.build_dir):
156165
with open('project.properties', 'w') as fileh:
157166
fileh.write('target=android-{}'.format(self.ctx.android_api))

pythonforandroid/bootstraps/common/build/build.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def compile_dir(dfn, optimize_python=True):
225225
def make_package(args):
226226
# If no launcher is specified, require a main.py/main.pyo:
227227
if (get_bootstrap_name() != "sdl" or args.launcher is None) and \
228-
get_bootstrap_name() != "webview":
228+
get_bootstrap_name() not in ["webview", "service_library"]:
229229
# (webview doesn't need an entrypoint, apparently)
230230
if args.private is None or (
231231
not exists(join(realpath(args.private), 'main.py')) and
@@ -479,6 +479,7 @@ def make_package(args):
479479
android_api=android_api,
480480
build_tools_version=build_tools_version,
481481
debug_build="debug" in args.build_mode,
482+
is_library=(get_bootstrap_name() == 'service_library'),
482483
)
483484

484485
# ant build templates

pythonforandroid/bootstraps/common/build/src/main/java/org/kivy/android/PythonUtil.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ protected static ArrayList<String> getLibraries(File libsDir) {
3939
libsList.add("python3.5m");
4040
libsList.add("python3.6m");
4141
libsList.add("python3.7m");
42+
libsList.add("python3.8m");
4243
libsList.add("main");
4344
return libsList;
4445
}
@@ -59,7 +60,7 @@ public static void loadLibraries(File filesDir, File libsDir) {
5960
// load, and it has failed, give a more
6061
// general error
6162
Log.v(TAG, "Library loading error: " + e.getMessage());
62-
if (lib.startsWith("python3.7") && !foundPython) {
63+
if (lib.startsWith("python3.8") && !foundPython) {
6364
throw new java.lang.RuntimeException("Could not load any libpythonXXX.so");
6465
} else if (lib.startsWith("python")) {
6566
continue;

pythonforandroid/bootstraps/common/build/templates/build.tmpl.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ allprojects {
2222
}
2323
}
2424

25+
{% if is_library %}
26+
apply plugin: 'com.android.library'
27+
{% else %}
2528
apply plugin: 'com.android.application'
29+
{% endif %}
2630

2731
android {
2832
compileSdkVersion {{ android_api }}

pythonforandroid/build.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class Context:
117117

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

120-
symlink_java_src = False # If True, will symlink instead of copying during build
120+
symlink_bootstrap_files = False # If True, will symlink instead of copying during build
121121

122122
java_build_tool = 'auto'
123123

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

484-
def prepare_bootstrap(self, bs):
485-
bs.ctx = self
486-
self.bootstrap = bs
484+
def prepare_bootstrap(self, bootstrap):
485+
if not bootstrap:
486+
raise TypeError("None is not allowed for bootstrap")
487+
bootstrap.ctx = self
488+
self.bootstrap = bootstrap
487489
self.bootstrap.prepare_build_dir()
488490
self.bootstrap_build_dir = self.bootstrap.build_dir
489491

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def recursively_include(results, directory, patterns):
100100
],
101101
'distutils.commands': [
102102
'apk = pythonforandroid.bdistapk:BdistAPK',
103+
'aar = pythonforandroid.bdistapk:BdistAAR',
103104
],
104105
},
105106
classifiers = [

testapps/setup_testapp_python3_sqlite_openssl.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
options = {'apk': {'requirements': 'requests,peewee,sdl2,pyjnius,kivy,python3',
66
'android-api': 27,
77
'ndk-api': 21,
8+
'bootstrap': 'sdl2',
89
'dist-name': 'bdisttest_python3_sqlite_openssl_googlendk',
910
'ndk-version': '10.3.2',
1011
'arch': 'armeabi-v7a',

testapps/setup_vispy.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
'blacklist-requirements': 'openssl,sqlite3',
88
'android-api': 27,
99
'ndk-api': 21,
10+
'bootstrap': 'empty',
1011
'ndk-dir': '/home/asandy/android/android-ndk-r17c',
1112
'dist-name': 'bdisttest',
1213
'ndk-version': '10.3.2',

tests/test_bootstrap.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -288,16 +288,10 @@ def test_bootstrap_prepare_build_dir(
288288
@mock.patch("pythonforandroid.bootstrap.os.unlink")
289289
@mock.patch("pythonforandroid.bootstrap.open", create=True)
290290
@mock.patch("pythonforandroid.util.chdir")
291-
@mock.patch("pythonforandroid.bootstrap.sh.ln")
292291
@mock.patch("pythonforandroid.bootstrap.listdir")
293-
@mock.patch("pythonforandroid.bootstrap.sh.mkdir")
294-
@mock.patch("pythonforandroid.bootstrap.sh.rm")
295292
def test_bootstrap_prepare_build_dir_with_java_src(
296293
self,
297-
mock_sh_rm,
298-
mock_sh_mkdir,
299294
mock_listdir,
300-
mock_sh_ln,
301295
mock_chdir,
302296
mock_open,
303297
mock_os_unlink,
@@ -309,7 +303,7 @@ def test_bootstrap_prepare_build_dir_with_java_src(
309303
:meth:`~pythonforandroid.bootstrap.Bootstrap.prepare_build_dir`. In
310304
here we will simulate that we have `with_java_src` set to some value.
311305
"""
312-
self.ctx.symlink_java_src = ["some_java_src"]
306+
self.ctx.symlink_bootstrap_files = True
313307
mock_listdir.return_value = [
314308
"jnius",
315309
"kivy",
@@ -327,18 +321,7 @@ def test_bootstrap_prepare_build_dir_with_java_src(
327321
# make sure that the open command has been called only once
328322
mock_open.assert_called_with("project.properties", "w")
329323

330-
# check that the symlink was made 4 times and that
331-
self.assertEqual(
332-
len(mock_sh_ln.call_args_list), len(mock_listdir.return_value)
333-
)
334-
for i, directory in enumerate(mock_listdir.return_value):
335-
self.assertTrue(
336-
mock_sh_ln.call_args_list[i][0][1].endswith(directory)
337-
)
338-
339324
# check that the other mocks we made are actually called
340-
mock_sh_rm.assert_called()
341-
mock_sh_mkdir.assert_called()
342325
mock_chdir.assert_called()
343326
mock_os_unlink.assert_called()
344327
mock_os_path_exists.assert_called()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy