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

New feature: allow to use a p4a fork #940

Merged
merged 4 commits into from
Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 6 additions & 3 deletions buildozer/default.spec
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,6 @@ fullscreen = 0
# (list) Java classes to add as activities to the manifest.
#android.add_activites = com.example.ExampleActivity

# (str) python-for-android branch to use, defaults to master
#p4a.branch = master

# (str) OUYA Console category. Should be one of GAME or APP
# If you leave this blank, OUYA support will not be enabled
#android.ouya.category = GAME
Expand Down Expand Up @@ -208,6 +205,12 @@ android.arch = armeabi-v7a
# Python for android (p4a) specific
#

# (str) python-for-android fork to use, defaults to upstream (kivy)
#p4a.fork = kivy
Copy link
Member

Choose a reason for hiding this comment

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

Minor remark: so for now, we're assuming the fork is on github only right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, and also we assume that the name of the fork has not changed 😉

Copy link
Member

Choose a reason for hiding this comment

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

That's more than enough for a first iteration and that probably covers more than 80% of the cases


# (str) python-for-android branch to use, defaults to master
#p4a.branch = master

# (str) python-for-android git clone directory (if empty, it will be automatically cloned from github)
#p4a.source_dir =

Expand Down
51 changes: 41 additions & 10 deletions buildozer/targets/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from os import environ
from os.path import exists, join, realpath, expanduser, basename, relpath
from platform import architecture
from shutil import copyfile
from shutil import copyfile, rmtree
from glob import glob

from buildozer.libs.version import parse
Expand All @@ -47,9 +47,11 @@
# does.
DEFAULT_SDK_TAG = '4333796'


class TargetAndroid(Target):
targetname = 'android'
p4a_directory = "python-for-android"
p4a_fork = 'kivy'
p4a_branch = 'master'
p4a_apk_cmd = "apk --debug --bootstrap="
extra_p4a_args = ''
Expand Down Expand Up @@ -614,8 +616,12 @@ def install_platform(self):

def _install_p4a(self):
cmd = self.buildozer.cmd
source = self.buildozer.config.getdefault('app', 'p4a.branch',
self.p4a_branch)
p4a_fork = self.buildozer.config.getdefault(
'app', 'p4a.fork', self.p4a_fork
)
p4a_branch = self.buildozer.config.getdefault(
'app', 'p4a.branch', self.p4a_branch
)
self.pa_dir = pa_dir = join(self.buildozer.platform_dir,
self.p4a_directory)
system_p4a_dir = self.buildozer.config.getdefault('app',
Expand All @@ -628,22 +634,47 @@ def _install_p4a(self):
self.buildozer.error('')
raise BuildozerException()
else:
# check that fork/branch has not been changed
if self.buildozer.file_exists(pa_dir):
cur_fork = cmd(
'git config --get remote.origin.url',
get_stdout=True,
cwd=pa_dir,
)[0].split('/')[3]
cur_branch = cmd(
'git branch -vv', get_stdout=True, cwd=pa_dir
)[0].split()[1]
if any([cur_fork != p4a_fork, cur_branch != p4a_branch]):
self.buildozer.info(
"Detected old fork/branch ({}/{}), deleting...".format(
cur_fork, cur_branch
)
)
rmtree(pa_dir)

if not self.buildozer.file_exists(pa_dir):
cmd(
('git clone -b {} --single-branch '
'https://github.com/kivy/python-for-android.git '
'{}').format(source, self.p4a_directory),
cwd=self.buildozer.platform_dir)
(
'git clone -b {p4a_branch} --single-branch '
'https://github.com/{p4a_fork}/python-for-android.git '
'{p4a_dir}'
).format(
p4a_branch=p4a_branch,
p4a_fork=p4a_fork,
p4a_dir=self.p4a_directory,
),
cwd=self.buildozer.platform_dir,
)
elif self.platform_update:
cmd('git clean -dxf', cwd=pa_dir)
current_branch = cmd('git rev-parse --abbrev-ref HEAD',
get_stdout=True, cwd=pa_dir)[0].strip()
if current_branch == source:
if current_branch == p4a_branch:
cmd('git pull', cwd=pa_dir)
else:
cmd('git fetch --tags origin {0}:{0}'.format(source),
cmd('git fetch --tags origin {0}:{0}'.format(p4a_branch),
cwd=pa_dir)
cmd('git checkout {}'.format(source), cwd=pa_dir)
cmd('git checkout {}'.format(p4a_branch), cwd=pa_dir)

# also install dependencies (currently, only setup.py knows about it)
# let's extract them.
Expand Down