Skip to content

Commit 77579c3

Browse files
committed
Fixes dist lookup + some tests
1 parent e06db1b commit 77579c3

File tree

8 files changed

+32
-21
lines changed

8 files changed

+32
-21
lines changed

pythonforandroid/build.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ def get_ndk_standalone(ndk_dir):
3333

3434
def get_ndk_sysroot(ndk_dir):
3535
sysroot = join(get_ndk_standalone(ndk_dir), 'sysroot')
36+
sysroot_exists = True
3637
if not exists(sysroot):
3738
warning("sysroot doesn't exist: {}".format(sysroot))
38-
return sysroot
39+
sysroot_exists = False
40+
return sysroot, sysroot_exists
3941

4042

4143
def get_toolchain_versions(ndk_dir, arch):
@@ -382,8 +384,8 @@ def prepare_build_environment(self,
382384
py_platform = 'linux'
383385

384386
self.ndk_standalone = get_ndk_standalone(self.ndk_dir)
385-
self.ndk_sysroot = get_ndk_sysroot(self.ndk_dir)
386-
ok = ok and exists(self.ndk_sysroot)
387+
self.ndk_sysroot, ndk_sysroot_exists = get_ndk_sysroot(self.ndk_dir)
388+
ok = ok and ndk_sysroot_exists
387389
self.ndk_include_dir = join(self.ndk_sysroot, 'usr', 'include')
388390

389391
for arch in self.archs:

pythonforandroid/distribution.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def get_distribution(
4646
cls,
4747
ctx,
4848
*,
49-
arch_name, # required keyword argument: there is no sensible default
49+
archs, # required keyword argument: there is no sensible default
5050
name=None,
5151
recipes=[],
5252
ndk_api=None,
@@ -70,8 +70,8 @@ def get_distribution(
7070
ndk_api : int
7171
The NDK API to compile against, included in the dist because it cannot
7272
be changed later during APK packaging.
73-
arch_name : str
74-
The target architecture name to compile against, included in the dist because
73+
archs : list
74+
The target architectures list to compile against, included in the dist because
7575
it cannot be changed later during APK packaging.
7676
recipes : list
7777
The recipes that the distribution must contain.
@@ -99,7 +99,7 @@ def get_distribution(
9999
if name is not None and name:
100100
possible_dists = [
101101
d for d in possible_dists if
102-
(d.name == name) and (arch_name in d.archs)]
102+
(d.name == name) and all(arch_name in d.archs for arch_name in archs)]
103103

104104
if possible_dists:
105105
# There should only be one folder with a given dist name *and* arch.
@@ -136,7 +136,7 @@ def get_distribution(
136136
continue
137137
if ndk_api is not None and dist.ndk_api != ndk_api:
138138
continue
139-
if arch_name is not None and arch_name not in dist.archs:
139+
if not all(arch_name in dist.archs for arch_name in archs):
140140
continue
141141
if (set(dist.recipes) == set(recipes) or
142142
(set(recipes).issubset(set(dist.recipes)) and
@@ -179,7 +179,7 @@ def get_distribution(
179179
name)
180180
dist.recipes = recipes
181181
dist.ndk_api = ctx.ndk_api
182-
dist.archs = [arch_name]
182+
dist.archs = archs
183183

184184
return dist
185185

pythonforandroid/toolchain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def dist_from_args(ctx, args):
161161
ctx,
162162
name=args.dist_name,
163163
recipes=split_argument_list(args.requirements),
164-
arch_name=args.arch,
164+
archs=args.arch,
165165
ndk_api=args.ndk_api,
166166
force_build=args.force_build,
167167
require_perfect_match=args.require_perfect_match,

tests/recipes/recipe_ctx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def setUp(self):
3939
self.ctx.setup_dirs(os.getcwd())
4040
self.ctx.bootstrap = Bootstrap().get_bootstrap("sdl2", self.ctx)
4141
self.ctx.bootstrap.distribution = Distribution.get_distribution(
42-
self.ctx, name="sdl2", recipes=self.recipes, arch_name=self.TEST_ARCH,
42+
self.ctx, name="sdl2", recipes=self.recipes, archs=[self.TEST_ARCH],
4343
)
4444
self.ctx.recipe_build_order = self.recipe_build_order
4545
self.ctx.python_recipe = Recipe.get_recipe("python3", self.ctx)

tests/test_archs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def setUp(self):
6464
self.ctx,
6565
name="sdl2",
6666
recipes=["python3", "kivy"],
67-
arch_name=self.TEST_ARCH,
67+
archs=[self.TEST_ARCH],
6868
)
6969
self.ctx.python_recipe = Recipe.get_recipe("python3", self.ctx)
7070
# Here we define the expected compiler, which, as per ndk >= r19,

tests/test_bootstrap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def setUp_distribution_with_bootstrap(self, bs):
5050
self.ctx.bootstrap.distribution = Distribution.get_distribution(
5151
self.ctx, name="test_prj",
5252
recipes=["python3", "kivy"],
53-
arch_name=self.TEST_ARCH,
53+
archs=[self.TEST_ARCH],
5454
)
5555

5656
def tearDown(self):

tests/test_distribution.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def setUp_distribution_with_bootstrap(self, bs, **kwargs):
5353
self.ctx,
5454
name=kwargs.pop("name", "test_prj"),
5555
recipes=kwargs.pop("recipes", ["python3", "kivy"]),
56-
arch_name=self.TEST_ARCH,
56+
archs=[self.TEST_ARCH],
5757
**kwargs
5858
)
5959

@@ -111,7 +111,7 @@ def test_get_distribution_no_name(self, mock_exists):
111111
returns the proper result which should `unnamed_dist_1`."""
112112
mock_exists.return_value = False
113113
self.ctx.bootstrap = Bootstrap().get_bootstrap("sdl2", self.ctx)
114-
dist = Distribution.get_distribution(self.ctx, arch_name=self.TEST_ARCH)
114+
dist = Distribution.get_distribution(self.ctx, archs=[self.TEST_ARCH])
115115
self.assertEqual(dist.name, "unnamed_dist_1")
116116

117117
@mock.patch("pythonforandroid.util.chdir")
@@ -213,7 +213,7 @@ def test_get_distributions_error_ndk_api_mismatch(
213213
self.ctx,
214214
name="test_prj",
215215
recipes=["python3", "kivy"],
216-
arch_name=self.TEST_ARCH,
216+
archs=[self.TEST_ARCH],
217217
)
218218
mock_get_dists.return_value = [expected_dist]
219219
mock_glob.return_value = ["sdl2-python3"]
@@ -264,7 +264,7 @@ def test_get_distributions_possible_dists(self, mock_get_dists):
264264
self.ctx,
265265
name="test_prj",
266266
recipes=["python3", "kivy"],
267-
arch_name=self.TEST_ARCH,
267+
archs=[self.TEST_ARCH],
268268
)
269269
mock_get_dists.return_value = [expected_dist]
270270
self.setUp_distribution_with_bootstrap(

tests/test_toolchain.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import io
22
import sys
3+
from os.path import join
34
import pytest
45
from unittest import mock
56
from pythonforandroid.recipe import Recipe
67
from pythonforandroid.toolchain import ToolchainCL
78
from pythonforandroid.util import BuildInterruptingException
9+
from pythonforandroid.build import get_ndk_standalone
810

911

1012
def patch_sys_argv(argv):
@@ -70,24 +72,31 @@ def test_create(self):
7072
) as m_get_available_apis, mock.patch(
7173
'pythonforandroid.build.get_toolchain_versions'
7274
) as m_get_toolchain_versions, mock.patch(
75+
'pythonforandroid.build.get_ndk_sysroot'
76+
) as m_get_ndk_sysroot, mock.patch(
7377
'pythonforandroid.toolchain.build_recipes'
7478
) as m_build_recipes, mock.patch(
7579
'pythonforandroid.bootstraps.service_only.'
7680
'ServiceOnlyBootstrap.assemble_distribution'
7781
) as m_run_distribute:
7882
m_get_available_apis.return_value = [27]
7983
m_get_toolchain_versions.return_value = (['4.9'], True)
84+
m_get_ndk_sysroot.return_value = (
85+
join(get_ndk_standalone("/tmp/android-ndk"), "sysroot"),
86+
True,
87+
)
8088
tchain = ToolchainCL()
8189
assert tchain.ctx.activity_class_name == 'abc.myapp.android.CustomPythonActivity'
8290
assert tchain.ctx.service_class_name == 'xyz.myapp.android.CustomPythonService'
8391
assert m_get_available_apis.call_args_list in [
8492
[mock.call('/tmp/android-sdk')], # linux case
8593
[mock.call('/private/tmp/android-sdk')] # macos case
8694
]
87-
assert m_get_toolchain_versions.call_args_list in [
88-
[mock.call('/tmp/android-ndk', mock.ANY)], # linux case
89-
[mock.call('/private/tmp/android-ndk', mock.ANY)], # macos case
90-
]
95+
for callargs in m_get_toolchain_versions.call_args_list:
96+
assert callargs in [
97+
mock.call("/tmp/android-ndk", mock.ANY), # linux case
98+
mock.call("/private/tmp/android-ndk", mock.ANY), # macos case
99+
]
91100
build_order = [
92101
'hostpython3', 'libffi', 'openssl', 'sqlite3', 'python3',
93102
'genericndkbuild', 'setuptools', 'six', 'pyjnius', 'android',

0 commit comments

Comments
 (0)