def _unpack_aar(self, aar, arch): '''Unpack content of .aar bundle and copy to current dist dir.''' with temp_directory() as temp_dir: name = splitext(basename(aar))[0] jar_name = name + '.jar' info("unpack {} aar".format(name)) debug(" from {}".format(aar)) debug(" to {}".format(temp_dir)) shprint(sh.unzip, '-o', aar, '-d', temp_dir) jar_src = join(temp_dir, 'classes.jar') jar_tgt = join('libs', jar_name) debug("copy {} jar".format(name)) debug(" from {}".format(jar_src)) debug(" to {}".format(jar_tgt)) ensure_dir('libs') shprint(sh.cp, '-a', jar_src, jar_tgt) so_src_dir = join(temp_dir, 'jni', arch.arch) so_tgt_dir = join('libs', arch.arch) debug("copy {} .so".format(name)) debug(" from {}".format(so_src_dir)) debug(" to {}".format(so_tgt_dir)) ensure_dir(so_tgt_dir) so_files = glob.glob(join(so_src_dir, '*.so')) for f in so_files: shprint(sh.cp, '-a', f, so_tgt_dir)
def test_temp_directory(self, mock_mkdtemp, mock_shutil_rmtree): """ Basic test for method :meth:`~pythonforandroid.util.temp_directory`. We perform this test by `mocking` the command `mkdtemp` and `shutil.rmtree` and we make sure that those functions are called in the proper place. """ mock_mkdtemp.return_value = "/temp/any_directory" with util.temp_directory(): mock_mkdtemp.assert_called_once() mock_shutil_rmtree.assert_not_called() mock_shutil_rmtree.assert_called_once_with("/temp/any_directory")
def build_arch(self, arch): # We don't have to actually build anything as CrystaX comes # with the necessary modules. They are included by modifying # the Android.mk in the jni folder. # If the Python version to be used is not prebuilt with the CrystaX # NDK, we do have to download it. crystax_python_dir = join(self.ctx.ndk_dir, 'sources', 'python') if not exists(join(crystax_python_dir, self.version)): info(('The NDK does not have a prebuilt Python {}, trying ' 'to obtain one.').format(self.version)) if self.version not in prebuilt_download_locations: error(('No prebuilt version for Python {} could be found, ' 'the built cannot continue.')) exit(1) with temp_directory() as td: self.download_file(prebuilt_download_locations[self.version], join(td, 'downloaded_python')) shprint(sh.tar, 'xf', join(td, 'downloaded_python'), '--directory', crystax_python_dir) if not exists(join(crystax_python_dir, self.version)): error(('Something went wrong, the directory at {} should ' 'have been created but does not exist.').format( join(crystax_python_dir, self.version))) if not exists(join( crystax_python_dir, self.version, 'libs', arch.arch)): error(('The prebuilt Python for version {} does not contain ' 'binaries for your chosen architecture "{}".').format( self.version, arch.arch)) exit(1) # TODO: We should have an option to build a new Python. This # would also allow linking to openssl and sqlite from CrystaX. dirn = self.ctx.get_python_install_dir() ensure_dir(dirn) # Instead of using a locally built hostpython, we use the # user's Python for now. They must have the right version # available. Using e.g. pyenv makes this easy. self.ctx.hostpython = 'python{}'.format(self.version)
def build_arch(self, arch): # We don't have to actually build anything as CrystaX comes # with the necessary modules. They are included by modifying # the Android.mk in the jni folder. # If the Python version to be used is not prebuilt with the CrystaX # NDK, we do have to download it. crystax_python_dir = join(self.ctx.ndk_dir, 'sources', 'python') if not exists(join(crystax_python_dir, self.version)): info(('The NDK does not have a prebuilt Python {}, trying ' 'to obtain one.').format(self.version)) if self.version not in prebuilt_download_locations: error(('No prebuilt version for Python {} could be found, ' 'the built cannot continue.')) exit(1) with temp_directory() as td: self.download_file(prebuilt_download_locations[self.version], join(td, 'downloaded_python')) shprint(sh.tar, 'xf', join(td, 'downloaded_python'), '--directory', crystax_python_dir) if not exists(join(crystax_python_dir, self.version)): error(('Something went wrong, the directory at {} should ' 'have been created but does not exist.').format( join(crystax_python_dir, self.version))) if not exists(join(crystax_python_dir, self.version, 'libs', arch.arch)): error(('The prebuilt Python for version {} does not contain ' 'binaries for your chosen architecture "{}".').format( self.version, arch.arch)) exit(1) # TODO: We should have an option to build a new Python. This # would also allow linking to openssl and sqlite from CrystaX. dirn = self.ctx.get_python_install_dir() ensure_dir(dirn) # Instead of using a locally built hostpython, we use the # user's Python for now. They must have the right version # available. Using e.g. pyenv makes this easy. self.ctx.hostpython = 'python{}'.format(self.version)