Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pygame recipe #2019

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions pythonforandroid/bootstraps/common/build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,11 @@ def make_package(args):
assets_dir = "src/main/assets"

# Delete the old assets.
try_unlink(join(assets_dir, 'public.mp3'))
try_unlink(join(assets_dir, 'private.mp3'))
ensure_dir(assets_dir)

shutil.rmtree(assets_dir)
ensure_dir(assets_dir)
open(os.path.join(assets_dir, ".gitkeep"), 'a').close()

# In order to speedup import and initial depack,
# construct a python27.zip
make_python_zip()
Expand Down Expand Up @@ -357,6 +358,15 @@ def make_package(args):
tar_dirs.append(python_bundle_dir)
if get_bootstrap_name() == "webview":
tar_dirs.append('webview_includes')
if hasattr(args, "assets") and args.assets is not None:
for asset in args.assets:
asset_src, asset_dest = asset.split(":")
if isfile(realpath(asset_src)):
ensure_dir(dirname(join(assets_dir, asset_dest)))
shutil.copy(realpath(asset_src), join(assets_dir, asset_dest))
else:
shutil.copytree(realpath(asset_src), join(assets_dir, asset_dest))

if args.private or args.launcher:
make_tar(
join(assets_dir, 'private.mp3'), tar_dirs, args.ignore_path,
Expand Down Expand Up @@ -649,6 +659,9 @@ def parse_args(args=None):
help='Custom key=value to add in application metadata')
ap.add_argument('--uses-library', dest='android_used_libs', action='append', default=[],
help='Used shared libraries included using <uses-library> tag in AndroidManifest.xml')
ap.add_argument('--asset', dest='assets',
action="append",
help=('Put this in the assets folder'))
ap.add_argument('--icon', dest='icon',
help=('A png file to use as the icon for '
'the application.'))
Expand Down
3 changes: 2 additions & 1 deletion pythonforandroid/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,10 +578,11 @@ def build_recipes(build_order, python_modules, ctx, project_dir,
info_main('Building {} for {}'.format(recipe.name, arch.arch))
if recipe.should_build(arch):
recipe.build_arch(arch)
recipe.install_libraries(arch)
else:
info('{} said it is already built, skipping'
.format(recipe.name))
recipe.install_libraries(arch)


# 4) biglink everything
info_main('# Biglinking object files')
Expand Down
2 changes: 1 addition & 1 deletion pythonforandroid/recipes/openssl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class OpenSSLRecipe(Recipe):
version = '1.1'
'''the major minor version used to link our recipes'''

url_version = '1.1.1'
url_version = '1.1.1f'
'''the version used to download our libraries'''

url = 'https://www.openssl.org/source/openssl-{url_version}.tar.gz'
Expand Down
57 changes: 57 additions & 0 deletions pythonforandroid/recipes/pygame2/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from pythonforandroid.recipe import CompiledComponentsPythonRecipe
from os.path import join
from pythonforandroid.toolchain import current_directory


class Pygame2Recipe(CompiledComponentsPythonRecipe):

version = '2.0.0-dev7'
url = 'https://github.com/pygame/pygame/archive/android-2.0.0-dev7.tar.gz'

site_packages_name = 'pygame'
name = 'pygame2'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you going to officially make the new release pygame2, with e.g. a different name in pip? If so then fine, but if not it's probably more obvious to just call the recipe "pygame". Happy to go with your preference though.


depends = ['sdl2', 'sdl2_image', 'sdl2_mixer', 'sdl2_ttf', 'setuptools', 'jpeg', 'png']
call_hostpython_via_targetpython = False # Due to setuptools
install_in_hostpython = False

def prebuild_arch(self, arch):
super(Pygame2Recipe, self).prebuild_arch(arch)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
super(Pygame2Recipe, self).prebuild_arch(arch)
super().prebuild_arch(arch)

with current_directory(self.get_build_dir(arch.arch)):
setup_template = open(join("buildconfig", "Setup.Android.SDL2.in")).read()
env = self.get_recipe_env(arch)
env['ANDROID_ROOT'] = join(self.ctx.ndk_platform, 'usr')

ndk_lib_dir = join(self.ctx.ndk_platform, 'usr', 'lib')

png = self.get_recipe('png', self.ctx)
png_lib_dir = join(png.get_build_dir(arch.arch), '.libs')
png_inc_dir = png.get_build_dir(arch)

jpeg = self.get_recipe('jpeg', self.ctx)
jpeg_inc_dir = jpeg_lib_dir = jpeg.get_build_dir(arch.arch)

setup_file = setup_template.format(
sdl_includes=(
" -I" + join(self.ctx.bootstrap.build_dir, 'jni', 'SDL', 'include') +
" -L" + join(self.ctx.bootstrap.build_dir, "libs", str(arch)) +
" -L" + png_lib_dir + " -L" + jpeg_lib_dir + " -L" + ndk_lib_dir),
sdl_ttf_includes="-I"+join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_ttf'),
sdl_image_includes="-I"+join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_image'),
sdl_mixer_includes="-I"+join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_mixer'),
jpeg_includes="-I"+jpeg_inc_dir,
png_includes="-I"+png_inc_dir,
freetype_includes=""
)
open("Setup", "w").write(setup_file)

def get_recipe_env(self, arch):
env = super(Pygame2Recipe, self).get_recipe_env(arch)
if 'sdl2' in self.ctx.recipe_build_order:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this always be True, or in any case you always want to set the cross compile and android env vars?

env['USE_SDL2'] = '1'
env["PYGAME_CROSS_COMPILE"] = "TRUE"
env["PYGAME_ANDROID"] = "TRUE"
return env


recipe = Pygame2Recipe()
8 changes: 8 additions & 0 deletions pythonforandroid/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,10 @@ def add_parser(subparsers, *args, **kwargs):
# However, it is also needed before the distribution is finally
# assembled for locating the setup.py / other build systems, which
# is why we also add it here:
parser_apk.add_argument(
'--add-asset', dest='assets',
action="append",
help=('Put this in the assets folder'))
parser_apk.add_argument(
'--private', dest='private',
help='the directory with the app source code files' +
Expand Down Expand Up @@ -576,6 +580,10 @@ def add_parser(subparsers, *args, **kwargs):
if hasattr(args, "private") and args.private is not None:
# Pass this value on to the internal bootstrap build.py:
args.unknown_args += ["--private", args.private]
if hasattr(args, "assets") and args.assets is not None:
# Pass this value on to the internal bootstrap build.py:
for asset in args.assets:
args.unknown_args += ["--asset", os.path.abspath(asset)+":"+asset]
if hasattr(args, "ignore_setup_py") and args.ignore_setup_py:
args.use_setup_py = False

Expand Down