Skip to content

Commit f11e8e0

Browse files
authored
Attempt on optimizing the builds (#3383)
Attempt on optimizing the builds. A couple of changes done to the recipe.
1 parent e772ad9 commit f11e8e0

3 files changed

Lines changed: 37 additions & 28 deletions

File tree

‎pythonforandroid/recipe.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -531,11 +531,10 @@ def unpack(self, arch):
531531
def get_recipe_env(self, arch=None, with_flags_in_cc=True):
532532
"""Return the env specialized for the recipe
533533
"""
534-
if arch is None:
535-
arch = self.filtered_archs[0]
534+
arch = arch or self.filtered_archs[0]
536535
env = arch.get_env(with_flags_in_cc=with_flags_in_cc)
537536

538-
for proxy_key in ['HTTP_PROXY', 'http_proxy', 'HTTPS_PROXY', 'https_proxy']:
537+
for proxy_key in ('HTTP_PROXY', 'http_proxy', 'HTTPS_PROXY', 'https_proxy'):
539538
if proxy_key in environ:
540539
env[proxy_key] = environ[proxy_key]
541540

‎pythonforandroid/recipes/python3/__init__.py‎

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,28 @@ class Python3Recipe(TargetPythonRecipe):
7373
configure_args = [
7474
'--host={android_host}',
7575
'--build={android_build}',
76-
'--enable-shared',
7776
'--enable-ipv6',
7877
'--enable-loadable-sqlite-extensions',
79-
'--without-static-libpython',
80-
'--without-readline',
78+
'--enable-shared',
79+
80+
# Attempt on making the builds lighter
81+
'--disable-test-modules',
82+
'--without-doc-strings',
8183
'--without-ensurepip',
84+
'--without-readline',
85+
'--without-static-libpython',
8286

8387
# Android prefix
8488
'--prefix={prefix}',
85-
'--enable-loadable-sqlite-extensions',
8689

8790
# Special cross compile args
88-
'ac_cv_file__dev_ptmx=yes',
8991
'ac_cv_file__dev_ptc=no',
90-
'ac_cv_header_sys_eventfd_h=no',
91-
'ac_cv_little_endian_double=yes',
92+
'ac_cv_file__dev_ptmx=yes',
9293
'ac_cv_header_bzlib_h=no',
94+
'ac_cv_header_sys_eventfd_h=no',
95+
'py_cv_module__curses=n/a',
96+
'py_cv_module__curses_panel=n/a',
97+
'py_cv_module__tkinter=n/a'
9398
]
9499

95100
'''The configure arguments needed to build the python recipe. Those are
@@ -107,19 +112,24 @@ class Python3Recipe(TargetPythonRecipe):
107112

108113
stdlib_dir_blacklist = {
109114
'__pycache__',
110-
'test',
111-
'tests',
112-
'lib2to3',
115+
'curses',
113116
'ensurepip',
114117
'idlelib',
118+
'lib2to3',
119+
'pydoc_data',
120+
'test',
121+
'tests',
115122
'tkinter',
123+
'turtledemo',
124+
'venv'
116125
}
117126
'''The directories that we want to omit for our python bundle'''
118127

119128
stdlib_filen_blacklist = [
120-
'*.py',
121129
'*.exe',
130+
'*.py',
122131
'*.whl',
132+
'turtle.pyc'
123133
]
124134
'''The file extensions that we want to blacklist for our python bundle'''
125135

@@ -139,7 +149,8 @@ class Python3Recipe(TargetPythonRecipe):
139149
if the full path contains any of these exceptions.'''
140150

141151
site_packages_filen_blacklist = [
142-
'*.py'
152+
'*.py',
153+
'*.pyx'
143154
]
144155
'''The file extensions from site packages dir that we don't want to be
145156
included in our python bundle.'''
@@ -235,19 +246,18 @@ def prebuild_arch(self, arch):
235246
def get_recipe_env(self, arch=None, with_flags_in_cc=True):
236247
env = super().get_recipe_env(arch)
237248
env['HOSTARCH'] = arch.command_prefix
238-
239249
env['CC'] = arch.get_clang_exe(with_target=True)
240-
241-
env['PATH'] = (
242-
'{hostpython_dir}:{old_path}').format(
243-
hostpython_dir=self.get_recipe(
244-
'host' + self.name, self.ctx).get_path_to_python(),
245-
old_path=env['PATH'])
246-
250+
env['PATH'] = '{hostpython_dir}:{old_path}'.format(
251+
hostpython_dir=self.get_recipe(
252+
'host' + self.name, self.ctx
253+
).get_path_to_python(),
254+
old_path=env['PATH']
255+
)
247256
env['CFLAGS'] = ' '.join(
248257
[
249-
'-fPIC',
250-
'-DANDROID'
258+
'-ffunction-sections',
259+
'-fdata-sections',
260+
'-fPIC'
251261
]
252262
)
253263

@@ -402,7 +412,7 @@ def compile_python_files(self, dir):
402412
longer used...uses .pyc (https://www.python.org/dev/peps/pep-0488)
403413
'''
404414
args = [self.ctx.hostpython]
405-
args += ['-OO', '-m', 'compileall', '-b', '-f', dir]
415+
args += ['-OO', '-m', 'compileall', '-b', '-f', '-q', dir]
406416
subprocess.call(args)
407417

408418
def create_python_bundle(self, dirn, arch):

‎tests/recipes/test_python3.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_compile_python_files(self, mock_subprocess):
4040
hostpy = self.recipe.ctx.hostpython = '/fake/hostpython3'
4141
self.recipe.compile_python_files(fake_compile_dir)
4242
mock_subprocess.assert_called_once_with(
43-
[hostpy, '-OO', '-m', 'compileall', '-b', '-f', fake_compile_dir],
43+
[hostpy, '-OO', '-m', 'compileall', '-b', '-f', '-q', fake_compile_dir],
4444
)
4545

4646
@mock.patch("pythonforandroid.recipe.Recipe.check_recipe_choices")
@@ -61,7 +61,7 @@ def test_get_recipe_env(
6161
)
6262
env = self.recipe.get_recipe_env(self.arch)
6363

64-
self.assertIn('-fPIC -DANDROID', env["CFLAGS"])
64+
self.assertIn('-fPIC', env["CFLAGS"])
6565
self.assertEqual(env["CC"], self.arch.get_clang_exe(with_target=True))
6666

6767
# make sure that the mocked methods are actually called

0 commit comments

Comments
 (0)