Skip to content

Commit b3e8c03

Browse files
authored
Resolve absolute path to local recipes (kivy#2640)
This is necessary when using patches in a local recipe since `Recipe.apply_patch` assumes the recipe directory is absolute and uses `patch -d` to change directories. It could just be fixed there, but this ensures that recipe directories are always absolute. Closes: kivy#2623
1 parent 93c7bab commit b3e8c03

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

pythonforandroid/toolchain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ def add_parser(subparsers, *args, **kwargs):
720720

721721
self._archs = args.arch
722722

723-
self.ctx.local_recipes = args.local_recipes
723+
self.ctx.local_recipes = realpath(args.local_recipes)
724724
self.ctx.copy_libs = args.copy_libs
725725

726726
self.ctx.activity_class_name = args.activity_class_name

tests/test_toolchain.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import io
2+
import os
23
import sys
34
import pytest
45
from unittest import mock
@@ -136,3 +137,34 @@ def test_recipes(self):
136137
assert expected_string in m_stdout.getvalue()
137138
# deletes static attribute to not mess with other tests
138139
del Recipe.recipes
140+
141+
def test_local_recipes_dir(self):
142+
"""
143+
Checks the `local_recipes` attribute in the Context is absolute.
144+
"""
145+
cwd = os.path.realpath(os.getcwd())
146+
common_args = [
147+
'toolchain.py',
148+
'recommendations',
149+
]
150+
151+
# Check the default ./p4a-recipes becomes absolute.
152+
argv = common_args
153+
with patch_sys_argv(argv):
154+
toolchain = ToolchainCL()
155+
expected_local_recipes = os.path.join(cwd, 'p4a-recipes')
156+
assert toolchain.ctx.local_recipes == expected_local_recipes
157+
158+
# Check a supplied relative directory becomes absolute.
159+
argv = common_args + ['--local-recipes=foo']
160+
with patch_sys_argv(argv):
161+
toolchain = ToolchainCL()
162+
expected_local_recipes = os.path.join(cwd, 'foo')
163+
assert toolchain.ctx.local_recipes == expected_local_recipes
164+
165+
# An absolute directory should remain unchanged.
166+
local_recipes = os.path.join(cwd, 'foo')
167+
argv = common_args + ['--local-recipes={}'.format(local_recipes)]
168+
with patch_sys_argv(argv):
169+
toolchain = ToolchainCL()
170+
assert toolchain.ctx.local_recipes == local_recipes

0 commit comments

Comments
 (0)