Skip to content

Commit 0610d20

Browse files
authored
📦 Split logic for build modes & debug symbols (kivy#2213)
If we want to **keep** debug symbols from `.so` files we will use: `--with-debug-symbols` Also: - enable debug builds for all bootstraps (AndroidManifest.tmpl.xml) - add log message to make it clear what kind of build we will get
1 parent d96d71e commit 0610d20

File tree

11 files changed

+38
-12
lines changed

11 files changed

+38
-12
lines changed

pythonforandroid/bootstraps/common/build/build.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,9 @@ def parse_args_and_make_package(args=None):
680680
const='release', default='debug',
681681
help='Build your app as a non-debug release build. '
682682
'(Disables gdb debugging among other things)')
683+
ap.add_argument('--with-debug-symbols', dest='with_debug_symbols',
684+
action='store_const', const=True, default=False,
685+
help='Will keep debug symbols from `.so` files.')
683686
ap.add_argument('--add-jar', dest='add_jar', action='append',
684687
help=('Add a Java .jar to the libs, so you can access its '
685688
'classes with pyjnius. You can specify this '

pythonforandroid/bootstraps/sdl2/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def assemble_distribution(self):
4747
with open('blacklist.txt', 'a') as fileh:
4848
fileh.write('\nsqlite3/*\nlib-dynload/_sqlite3.so\n')
4949

50-
if not self.ctx.build_as_debuggable:
50+
if not self.ctx.with_debug_symbols:
5151
self.strip_libraries(arch)
5252
self.fry_eggs(site_packages_dir)
5353
super().assemble_distribution()

pythonforandroid/bootstraps/service_library/build/templates/AndroidManifest.tmpl.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<!-- Android 2.3.3 -->
88
<uses-sdk android:minSdkVersion="{{ args.min_sdk_version }}" android:targetSdkVersion="{{ android_api }}" />
99

10-
<application>
10+
<application {% if debug %}android:debuggable="true"{% endif %} >
1111
{% for name in service_names %}
1212
<service android:name="{{ args.package }}.Service{{ name|capitalize }}"
1313
android:process=":service_{{ name }}"

pythonforandroid/bootstraps/service_only/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def assemble_distribution(self):
4646
with open('blacklist.txt', 'a') as fileh:
4747
fileh.write('\nsqlite3/*\nlib-dynload/_sqlite3.so\n')
4848

49-
if not self.ctx.build_as_debuggable:
49+
if not self.ctx.with_debug_symbols:
5050
self.strip_libraries(arch)
5151
self.fry_eggs(site_packages_dir)
5252
super().assemble_distribution()

pythonforandroid/bootstraps/service_only/build/templates/AndroidManifest.tmpl.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
An example Java class can be found in README-android.txt
4646
-->
4747
<application android:label="@string/app_name"
48+
{% if debug %}android:debuggable="true"{% endif %}
4849
android:icon="@drawable/icon"
4950
android:allowBackup="true"
5051
android:theme="{{args.android_apptheme}}{% if not args.window %}.Fullscreen{% endif %}"

pythonforandroid/bootstraps/webview/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def assemble_distribution(self):
4343
with open('blacklist.txt', 'a') as fileh:
4444
fileh.write('\nsqlite3/*\nlib-dynload/_sqlite3.so\n')
4545

46-
if not self.ctx.build_as_debuggable:
46+
if not self.ctx.with_debug_symbols:
4747
self.strip_libraries(arch)
4848
self.fry_eggs(site_packages_dir)
4949
super().assemble_distribution()

pythonforandroid/bootstraps/webview/build/templates/AndroidManifest.tmpl.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
android:theme="{{args.android_apptheme}}{% if not args.window %}.Fullscreen{% endif %}"
5252
android:hardwareAccelerated="true"
5353
android:usesCleartextTraffic="true"
54+
{% if debug %}android:debuggable="true"{% endif %}
5455
>
5556
{% for l in args.android_used_libs %}
5657
<uses-library android:name="{{ l }}" />

pythonforandroid/build.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,12 @@ class Context:
8282
'''A build context. If anything will be built, an instance this class
8383
will be instantiated and used to hold all the build state.'''
8484

85-
# Whether to build with debugging symbols
85+
# Whether to make a debug or release build
8686
build_as_debuggable = False
8787

88+
# Whether to strip debug symbols in `.so` files
89+
with_debug_symbols = False
90+
8891
env = environ.copy()
8992
# the filepath of toolchain.py
9093
root_dir = None
@@ -831,7 +834,7 @@ def run_pymodules_install(ctx, modules, project_dir=None,
831834
)
832835

833836
# Strip object files after potential Cython or native code builds:
834-
if not ctx.build_as_debuggable:
837+
if not ctx.with_debug_symbols:
835838
standard_recipe.strip_object_files(
836839
ctx.archs[0], env, build_dir=ctx.build_dir
837840
)

pythonforandroid/recipe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ def build_cython_components(self, arch):
10721072
info('First build appeared to complete correctly, skipping manual'
10731073
'cythonising.')
10741074

1075-
if not self.ctx.build_as_debuggable:
1075+
if not self.ctx.with_debug_symbols:
10761076
self.strip_object_files(arch, env)
10771077

10781078
def strip_object_files(self, arch, env, build_dir=None):

pythonforandroid/toolchain.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,14 @@ def build_dist_from_args(ctx, dist, args):
196196
ctx.recipe_build_order))
197197
info('Dist will also contain modules ({}) installed from pip'.format(
198198
', '.join(ctx.python_modules)))
199+
info(
200+
'Dist will be build in mode {build_mode}{with_debug_symbols}'.format(
201+
build_mode='debug' if ctx.build_as_debuggable else 'release',
202+
with_debug_symbols=' (with debug symbols)'
203+
if ctx.with_debug_symbols
204+
else '',
205+
)
206+
)
199207

200208
ctx.distribution = dist
201209
ctx.prepare_bootstrap(bs)
@@ -518,6 +526,10 @@ def add_parser(subparsers, *args, **kwargs):
518526
const='release', default='debug',
519527
help='Build your app as a non-debug release build. '
520528
'(Disables gdb debugging among other things)')
529+
parser_packaging.add_argument(
530+
'--with-debug-symbols', dest='with_debug_symbols',
531+
action='store_const', const=True, default=False,
532+
help='Will keep debug symbols from `.so` files.')
521533
parser_packaging.add_argument(
522534
'--keystore', dest='keystore', action='store', default=None,
523535
help=('Keystore for JAR signing key, will use jarsigner '
@@ -593,6 +605,8 @@ def add_parser(subparsers, *args, **kwargs):
593605
args.unknown_args += ["--private", args.private]
594606
if hasattr(args, "build_mode") and args.build_mode == "release":
595607
args.unknown_args += ["--release"]
608+
if hasattr(args, "with_debug_symbols") and args.with_debug_symbols:
609+
args.unknown_args += ["--with-debug-symbols"]
596610
if hasattr(args, "ignore_setup_py") and args.ignore_setup_py:
597611
args.use_setup_py = False
598612

@@ -612,6 +626,9 @@ def add_parser(subparsers, *args, **kwargs):
612626
self.ctx.build_as_debuggable = getattr(
613627
args, "build_mode", "debug"
614628
) == "debug"
629+
self.ctx.with_debug_symbols = getattr(
630+
args, "with_debug_symbols", False
631+
)
615632

616633
have_setup_py_or_similar = False
617634
if getattr(args, "private", None) is not None:

tests/test_build.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_run_pymodules_install_optional_project_dir(self):
1919
assert m_info.call_args_list[-1] == mock.call(
2020
'No Python modules and no setup.py to process, skipping')
2121

22-
def test_strip_if_debuggable(self):
22+
def test_strip_if_with_debug_symbols(self):
2323
ctx = mock.Mock()
2424
ctx.python_recipe.major_minor_version_string = "python3.6"
2525
ctx.get_site_packages_dir.return_value = "test-doesntexist"
@@ -38,12 +38,13 @@ def test_strip_if_debuggable(self):
3838
mock.patch('pythonforandroid.build.run_setuppy_install'):
3939
m_project_has_setup_py.return_value = False
4040

41-
# Make sure it is NOT called when debug build:
42-
ctx.build_as_debuggable = True
41+
# Make sure it is NOT called when `with_debug_symbols` is true:
42+
ctx.with_debug_symbols = True
4343
assert run_pymodules_install(ctx, modules, project_dir) is None
4444
assert m_CythonRecipe().strip_object_files.called is False
4545

46-
# Make sure strip object files IS called when release build:
47-
ctx.build_as_debuggable = False
46+
# Make sure strip object files IS called when
47+
# `with_debug_symbols` is fasle:
48+
ctx.with_debug_symbols = False
4849
assert run_pymodules_install(ctx, modules, project_dir) is None
4950
assert m_CythonRecipe().strip_object_files.called is True

0 commit comments

Comments
 (0)