コード例 #1
0
ファイル: build.py プロジェクト: xoriole/python-for-android
    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
コード例 #2
0
ファイル: build.py プロジェクト: ssi379/python-for-android
    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_ver = None

        self.toolchain_prefix = None
        self.toolchain_version = None

        self.local_recipes = None

        # root of the toolchain
        self.setup_dirs()

        # this list should contain all Archs, it is pruned later
        self.archs = (ArchARM(self), ArchARMv7_a(self), Archx86(self))

        ensure_dir(join(self.build_dir, 'bootstrap_builds'))
        ensure_dir(join(self.build_dir, 'other_builds'))
        # other_builds: where everything else is built

        # 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)
コード例 #3
0
    def test_arch_arm(self, mock_ensure_dir, mock_find_executable, mock_glob):
        """
        Test that class :class:`~pythonforandroid.archs.ArchARM` returns some
        expected attributes and environment variables.

        .. note::
            Here we mock two methods:

                - `ensure_dir` because we don't want to create any directory
                - `find_executable` because otherwise we will
                  get an error when trying to find the compiler (we are setting
                  some fake paths for our android sdk and ndk so probably will
                  not exist)

        """
        mock_find_executable.return_value = self.expected_compiler
        mock_ensure_dir.return_value = True
        mock_glob.return_value = ["llvm"]

        arch = ArchARM(self.ctx)
        self.assertEqual(arch.arch, "armeabi")
        self.assertEqual(arch.__str__(), "armeabi")
        self.assertEqual(arch.toolchain_prefix, "arm-linux-androideabi")
        self.assertEqual(arch.command_prefix, "arm-linux-androideabi")
        self.assertEqual(arch.target, "armv7a-linux-androideabi21")
        self.assertEqual(arch.platform_dir, "arch-arm")
        arch = ArchARM(self.ctx)

        # Check environment flags
        env = arch.get_env()
        self.assertIsInstance(env, dict)
        self.assertEqual(expected_env_gcc_keys,
                         set(env.keys()) & expected_env_gcc_keys)

        # 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"])

        # check gcc compilers
        self.assertEqual(env["CC"].split()[0], self.expected_compiler)
        self.assertEqual(env["CXX"].split()[0], self.expected_compiler + "++")
        # check android binaries
        self.assertEqual(env["AR"], "arm-linux-androideabi-ar")
        self.assertEqual(env["LD"], "arm-linux-androideabi-ld")
        self.assertEqual(env["RANLIB"], "arm-linux-androideabi-ranlib")
        self.assertEqual(env["STRIP"].split()[0],
                         "arm-linux-androideabi-strip")
        self.assertEqual(env["READELF"].split()[0],
                         "arm-linux-androideabi-readelf")
        self.assertEqual(env["NM"].split()[0], "arm-linux-androideabi-nm")

        # check that cflags are in gcc
        self.assertIn(env["CFLAGS"], env["CC"])

        # check that flags aren't in gcc and also check ccache
        self.ctx.ccache = "/usr/bin/ccache"
        env = arch.get_env(with_flags_in_cc=False)
        self.assertNotIn(env["CFLAGS"], env["CC"])
        self.assertEqual(env["USE_CCACHE"], "1")
        self.assertEqual(env["NDK_CCACHE"], "/usr/bin/ccache")

        # Check exception in case that CC is not found
        mock_find_executable.return_value = None
        with self.assertRaises(BuildInterruptingException) as e:
            arch.get_env()
        self.assertEqual(
            e.exception.args[0],
            "Couldn't find executable for CC. This indicates a problem "
            "locating the {expected_compiler} executable in the Android "
            "NDK, not that you don't have a normal compiler installed. "
            "Exiting.".format(expected_compiler=self.expected_compiler),
        )