def __init__(self): super(Context, self).__init__() self.include_dirs = [] self._build_env_prepared = False self._sdk_dir = None self._ndk_dir = None self._android_api = None self._ndk_api = None self.ndk = None self.toolchain_prefix = None self.toolchain_version = None self.local_recipes = None self.copy_libs = False # this list should contain all Archs, it is pruned later self.archs = ( ArchARM(self), ArchARMv7_a(self), Archx86(self), Archx86_64(self), ArchAarch_64(self), ) self.root_dir = realpath(dirname(__file__)) # remove the most obvious flags that can break the compilation self.env.pop("LDFLAGS", None) self.env.pop("ARCHFLAGS", None) self.env.pop("CFLAGS", None) self.python_recipe = None # Set by TargetPythonRecipe
def test_arch_x86_64(self, mock_ensure_dir, mock_find_executable, mock_glob): """ Test that class :class:`~pythonforandroid.archs.Archx86_64` returns some expected attributes and environment variables. .. note:: Here we mock the same functions than :meth:`TestArchARM.test_arch_arm` plus `glob`, so we make sure that the glob result is the expected even if the folder doesn't exist, which is probably the case. This has to be done because here we tests the `get_env` with clang """ mock_find_executable.return_value = self.expected_compiler mock_ensure_dir.return_value = True mock_glob.return_value = ["llvm"] arch = Archx86_64(self.ctx) self.assertEqual(arch.arch, "x86_64") self.assertEqual(arch.__str__(), "x86_64") self.assertEqual(arch.toolchain_prefix, "x86_64") self.assertEqual(arch.command_prefix, "x86_64-linux-android") self.assertEqual(arch.target, "x86_64-linux-android21") self.assertEqual(arch.platform_dir, "arch-x86_64") env = arch.get_env() # check glob and find_executable calls self.assertEqual(mock_glob.call_count, 4) for glob_call, kw in mock_glob.call_args_list: self.assertEqual( glob_call[0], "{ndk_dir}/toolchains/llvm*".format(ndk_dir=self.ctx._ndk_dir), ) mock_find_executable.assert_called_once_with(self.expected_compiler, path=environ["PATH"]) # For x86_64 we expect some extra cflags in our `environment` mock_find_executable.assert_called_once() self.assertIn(" -march=x86-64 -msse4.2 -mpopcnt -m64 -mtune=intel", env["CFLAGS"])
def test_arch_x86_64(self, mock_ensure_dir, mock_find_executable): """ Test that class :class:`~pythonforandroid.archs.Archx86_64` returns some expected attributes and environment variables. .. note:: Here we mock the same functions than :meth:`TestArchARM.test_arch_arm` """ mock_find_executable.return_value = "arm-linux-androideabi-gcc" mock_ensure_dir.return_value = True arch = Archx86_64(self.ctx) self.assertEqual(arch.arch, "x86_64") self.assertEqual(arch.__str__(), "x86_64") self.assertEqual(arch.toolchain_prefix, "x86_64") self.assertEqual(arch.command_prefix, "x86_64-linux-android") self.assertEqual(arch.target, "x86_64-none-linux-android") self.assertEqual(arch.platform_dir, "arch-x86_64") # For x86_64 we expect some extra cflags in our `environment` env = arch.get_env() self.assertIn(" -march=x86-64 -msse4.2 -mpopcnt -m64 -mtune=intel", env["CFLAGS"])