Skip to content

Commit

Permalink
Merge pull request #940 from opacam/feature-allow-p4a-forks
Browse files Browse the repository at this point in the history
New feature: allow to use a p4a fork
  • Loading branch information
opacam authored Jul 26, 2019
2 parents 1d1b0b7 + 3583bb2 commit 7a0ef4f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 13 deletions.
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

# (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

0 comments on commit 7a0ef4f

Please sign in to comment.