Skip to content

Commit

Permalink
Merge pull request #1160 from AndreMiras/feature/ios_build
Browse files Browse the repository at this point in the history
🍏 Improves iOS support
  • Loading branch information
AndreMiras authored Jun 21, 2020
2 parents af577b6 + 020a550 commit a967c09
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Setup environment
run: |
pip install -e .
pip install Cython==0.29.19
pip install Cython
- run: buildozer --help
- run: buildozer init
- name: SDK, NDK and p4a download
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/ios.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
on: [push, pull_request]
name: iOS
jobs:
Integration:
runs-on: macOS-latest
steps:
- name: Setup python
uses: actions/setup-python@v2
with:
python-version: 3.8
- uses: actions/checkout@v2
- name: Setup environment
run: |
pip install -e .
pip install Cython cookiecutter pbxproj
- run: buildozer --help
- run: buildozer init
- name: Install dependencies
run: |
brew install autoconf automake libtool pkg-config
- name: buildozer ios debug
run: |
touch main.py
buildozer ios debug
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Buildozer
=========

[![Build](https://github.com/kivy/buildozer/workflows/Tests/badge.svg)](https://github.com/kivy/buildozer/actions?query=workflow%3ATests)
[![Build](https://github.com/kivy/buildozer/workflows/Android/badge.svg)](https://github.com/kivy/buildozer/actions?query=workflow%3AAndroid)
[![Tests](https://github.com/kivy/buildozer/workflows/Tests/badge.svg)](https://github.com/kivy/buildozer/actions?query=workflow%3ATests)
[![Android](https://github.com/kivy/buildozer/workflows/Android/badge.svg)](https://github.com/kivy/buildozer/actions?query=workflow%3AAndroid)
[![iOS](https://github.com/kivy/buildozer/workflows/iOS/badge.svg)](https://github.com/kivy/buildozer/actions?query=workflow%3AiOS)
[![Coverage Status](https://coveralls.io/repos/github/kivy/buildozer/badge.svg)](https://coveralls.io/github/kivy/buildozer)
[![Backers on Open Collective](https://opencollective.com/kivy/backers/badge.svg)](#backers)
[![Sponsors on Open Collective](https://opencollective.com/kivy/sponsors/badge.svg)](#sponsors)
Expand Down
7 changes: 5 additions & 2 deletions buildozer/default.spec
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ source.include_exts = py,png,jpg,kv,atlas
#source.exclude_exts = spec

# (list) List of directory to exclude (let empty to not exclude anything)
#source.exclude_dirs = tests, bin
#source.exclude_dirs = tests, bin, venv

# (list) List of exclusions using pattern matching
#source.exclude_patterns = license,images/*/*.jpg
Expand Down Expand Up @@ -263,7 +263,10 @@ ios.kivy_ios_branch = master
#ios.ios_deploy_dir = ../ios_deploy
# Or specify URL and branch
ios.ios_deploy_url = https://github.com/phonegap/ios-deploy
ios.ios_deploy_branch = 1.7.0
ios.ios_deploy_branch = 1.10.0

# (bool) Whether or not to sign the code
ios.codesign.allowed = false

# (str) Name of the certificate to use for signing the debug version
# Get a list of available identities: buildozer ios list_identities
Expand Down
52 changes: 31 additions & 21 deletions buildozer/targets/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ class TargetIos(Target):
def check_requirements(self):
checkbin = self.buildozer.checkbin
cmd = self.buildozer.cmd
executable = sys.executable or 'python'
self._toolchain_cmd = f"{executable} toolchain.py "
self._xcodebuild_cmd = "xcodebuild "

checkbin('Xcode xcodebuild', 'xcodebuild')
checkbin('Xcode xcode-select', 'xcode-select')
Expand Down Expand Up @@ -99,10 +102,21 @@ def install_platform(self):
branch='1.7.0',
owner='phonegap')

def toolchain(self, cmd, **kwargs):
kwargs.setdefault('cwd', self.ios_dir)
return self.buildozer.cmd(self._toolchain_cmd + cmd, **kwargs)

def xcodebuild(self, cmd='', **kwargs):
return self.buildozer.cmd(self._xcodebuild_cmd + cmd, **kwargs)

@property
def code_signing_allowed(self):
allowed = self.buildozer.config.getboolean("app", "ios.codesign.allowed")
allowed = "YES" if allowed else "NO"
return f"CODE_SIGNING_ALLOWED={allowed}"

def get_available_packages(self):
available_modules = self.buildozer.cmd(
'./toolchain.py recipes --compact',
cwd=self.ios_dir, get_stdout=True)[0]
available_modules = self.toolchain("recipes --compact", get_stdout=True)[0]
return available_modules.splitlines()[0].split()

def compile_platform(self):
Expand Down Expand Up @@ -139,11 +153,10 @@ def compile_platform(self):
return

modules_str = ' '.join(ios_requirements)
self.buildozer.cmd('./toolchain.py build {}'.format(modules_str),
cwd=self.ios_dir)
self.toolchain(f"build {modules_str}")

if not self.buildozer.file_exists(self.ios_deploy_dir, 'ios-deploy'):
self.buildozer.cmd('make ios-deploy', cwd=self.ios_deploy_dir)
self.xcodebuild(cwd=self.ios_deploy_dir)

self.buildozer.state['ios.requirements'] = ios_requirements
self.buildozer.state.sync()
Expand All @@ -170,12 +183,10 @@ def build_package(self):

self.app_project_dir = join(self.ios_dir, '{0}-ios'.format(app_name.lower()))
if not self.buildozer.file_exists(self.app_project_dir):
create_cmd = './toolchain.py create {0}{1} {2}'.format(frameworks_cmd, app_name,
self.buildozer.app_dir)
self.buildozer.cmd(create_cmd, cwd=self.ios_dir)
cmd = f"create {frameworks_cmd}{app_name} {self.buildozer.app_dir}"
else:
update_cmd = './toolchain.py update {0}{1}-ios'.format(frameworks_cmd, app_name)
self.buildozer.cmd(update_cmd, cwd=self.ios_dir)
cmd = f"update {frameworks_cmd}{app_name}-ios"
self.toolchain(cmd)

# fix the plist
plist_fn = '{}-Info.plist'.format(app_name.lower())
Expand All @@ -194,9 +205,10 @@ def build_package(self):
# ok, write the modified plist.
plistlib.writePlist(plist, plist_rfn)

mode = 'Debug' if self.build_mode == 'debug' else 'Release'
self.buildozer.cmd('xcodebuild -configuration {} ENABLE_BITCODE=NO clean build'.format(mode),
cwd=self.app_project_dir)
mode = self.build_mode.capitalize()
self.xcodebuild(
f"-configuration {mode} ENABLE_BITCODE=NO {self.code_signing_allowed} clean build",
cwd=self.app_project_dir)
ios_app_dir = '{app_lower}-ios/build/{mode}-iphoneos/{app_lower}.app'.format(
app_lower=app_name.lower(), mode=mode)
self.buildozer.state['ios:latestappdir'] = ios_app_dir
Expand All @@ -221,8 +233,7 @@ def build_package(self):
self.buildozer.rmdir(intermediate_dir)

self.buildozer.info('Creating archive...')
self.buildozer.cmd((
'/usr/bin/xcodebuild'
self.xcodebuild((
' -alltargets'
' -configuration {mode}'
' -scheme {scheme}'
Expand All @@ -233,8 +244,7 @@ def build_package(self):
cwd=build_dir)

self.buildozer.info('Creating IPA...')
self.buildozer.cmd((
'/usr/bin/xcodebuild'
self.xcodebuild((
' -exportArchive'
' -exportFormat IPA'
' -archivePath "{xcarchive}"'
Expand Down Expand Up @@ -301,13 +311,13 @@ def _create_icons(self):
self.buildozer.error('Icon {} does not exists'.format(icon_fn))
return

self.buildozer.cmd('./toolchain.py icon {} {}'.format(
self.app_project_dir, icon_fn),
cwd=self.ios_dir)
self.toolchain(f"icon {self.app_project_dir} {icon_fn}")

def check_configuration_tokens(self):
errors = []
config = self.buildozer.config
if not config.getboolean('app', 'ios.codesign.allowed'):
return
identity_debug = config.getdefault('app', 'ios.codesign.debug', '')
identity_release = config.getdefault('app', 'ios.codesign.release',
identity_debug)
Expand Down

0 comments on commit a967c09

Please sign in to comment.