diff --git a/pythonforandroid/toolchain.py b/pythonforandroid/toolchain.py index 7e19aef2b7..7589dfaa5e 100644 --- a/pythonforandroid/toolchain.py +++ b/pythonforandroid/toolchain.py @@ -720,7 +720,7 @@ def add_parser(subparsers, *args, **kwargs): self._archs = args.arch - self.ctx.local_recipes = args.local_recipes + self.ctx.local_recipes = realpath(args.local_recipes) self.ctx.copy_libs = args.copy_libs self.ctx.activity_class_name = args.activity_class_name diff --git a/tests/test_toolchain.py b/tests/test_toolchain.py index 23d0d3ff9e..0cc2b1a7f5 100644 --- a/tests/test_toolchain.py +++ b/tests/test_toolchain.py @@ -1,4 +1,5 @@ import io +import os import sys import pytest from unittest import mock @@ -136,3 +137,34 @@ def test_recipes(self): assert expected_string in m_stdout.getvalue() # deletes static attribute to not mess with other tests del Recipe.recipes + + def test_local_recipes_dir(self): + """ + Checks the `local_recipes` attribute in the Context is absolute. + """ + cwd = os.path.realpath(os.getcwd()) + common_args = [ + 'toolchain.py', + 'recommendations', + ] + + # Check the default ./p4a-recipes becomes absolute. + argv = common_args + with patch_sys_argv(argv): + toolchain = ToolchainCL() + expected_local_recipes = os.path.join(cwd, 'p4a-recipes') + assert toolchain.ctx.local_recipes == expected_local_recipes + + # Check a supplied relative directory becomes absolute. + argv = common_args + ['--local-recipes=foo'] + with patch_sys_argv(argv): + toolchain = ToolchainCL() + expected_local_recipes = os.path.join(cwd, 'foo') + assert toolchain.ctx.local_recipes == expected_local_recipes + + # An absolute directory should remain unchanged. + local_recipes = os.path.join(cwd, 'foo') + argv = common_args + ['--local-recipes={}'.format(local_recipes)] + with patch_sys_argv(argv): + toolchain = ToolchainCL() + assert toolchain.ctx.local_recipes == local_recipes