Skip to content

Commit

Permalink
Merge pull request #40 from nikmolnar/setup-build
Browse files Browse the repository at this point in the history
Add `--build` and `--execute` options to the setup script
  • Loading branch information
therealphildini committed May 23, 2017
2 parents 126b9a9 + 287b4e2 commit 58ba018
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
26 changes: 26 additions & 0 deletions briefcase/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ class app(Command):
'URL for the support package to use'),
('download-dir=', None,
"Directory where the project support packages will be cached"),
('build', None,
"Build the project after generating"),
('execute', None,
"Run the application after building"),
('os-version=', None,
"Set the device OS version. Currently only iOS supported (e.g., iOS 10.2)"),
('device=', None,
"Set the device to run. Currently only iOS supported (e.g., iPhone 7 Plus)")
]

def initialize_options(self):
Expand All @@ -66,6 +74,10 @@ def initialize_options(self):
self.version_code = None
self.guid = None
self.secret_key = None
self.build = False
self.execute = False
self.os_version = None
self.device = None

def finalize_options(self):
if self.formal_name is None:
Expand Down Expand Up @@ -108,6 +120,9 @@ def finalize_options(self):

pip.utils.ensure_dir(self.download_dir)

if self.execute:
self.build = True

def find_support_pkg(self):
api_url = 'https://pybee.org/static/api/%s/releases.json' % self.support_project

Expand Down Expand Up @@ -268,6 +283,12 @@ def install_support_package(self):
def install_extras(self):
pass

def build_app(self):
pass

def run_app(self):
pass

def post_run(self):
print()
print("Installation complete.")
Expand Down Expand Up @@ -299,4 +320,9 @@ def run(self):
self.install_support_package()
self.install_extras()

if self.build:
self.build_app()
if self.execute:
self.run_app()

self.post_run()
63 changes: 63 additions & 0 deletions briefcase/ios.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import json
import os
import shutil

import subprocess

from .app import app


Expand All @@ -23,6 +26,12 @@ def finalize_options(self):

self.resource_dir = self.dir

if self.os_version is None:
self.os_version = 'iOS 10.2'

if self.device is None:
self.device = 'iPhone 7 Plus'

def install_icon(self):
last_size = None
for size in ['180', '167', '152', '120', '87', '80', '76', '58', '40', '29']:
Expand Down Expand Up @@ -55,3 +64,57 @@ def install_splash(self):
)
else:
print("WARNING: No %s splash file available." % size)

def build_app(self):
project_file = '%s.xcodeproj' % self.formal_name
build_settings = [
('AD_HOC_CODE_SIGNING_ALLOWED', 'YES'),
('CODE_SIGN_IDENTITY', '-'),
('VALID_ARCHS', '"i386 x86_64"'),
('ARCHS', 'x86_64'),
('ONLY_ACTIVE_ARCHS', 'NO')
]
build_settings_str = ['%s=%s' % x for x in build_settings]

print(' * Building XCode project...')

subprocess.Popen([
'xcodebuild', ' '.join(build_settings_str), '-project', project_file, '-destination',
'platform="iOS Simulator,name=%s,OS=%s"' %(self.device, self.os_version), '-quiet', '-configuration',
'Debug', '-arch', 'x86_64', '-sdk', 'iphonesimulator%s' % (self.os_version.split(' ')[-1],), 'build'
], cwd=os.path.abspath(self.dir)).wait()

def run_app(self):
working_dir = os.path.abspath(self.dir)

# Find an appropriate device
pipe = subprocess.Popen(['xcrun', 'simctl', 'list', '-j'], stdout=subprocess.PIPE)
pipe.wait()

data = json.loads(pipe.stdout.read().decode())

device_list = data['devices'].get(self.os_version, [])
device_list = [x for x in device_list if x['name'].lower() == self.device.lower()]

if not device_list:
print('WARNING: No devices found for OS %s and device name %s'.format(self.os_version, self.device))
return

device = device_list[0]

# Install app and launch simulator
print(' * Launching app...')

app_identifier = '.'.join([self.bundle, self.formal_name.replace(' ', '-')])

subprocess.Popen(['xcrun', 'instruments', '-w', device['udid']]).wait()

subprocess.Popen(['xcrun', 'simctl', 'uninstall', device['udid'], app_identifier], cwd=working_dir).wait()
subprocess.Popen([
'xcrun', 'simctl', 'install', device['udid'],
os.path.join('build', 'Debug-iphonesimulator', '%s.app' % self.formal_name)
], cwd=working_dir).wait()

subprocess.Popen([
'xcrun', 'simctl', 'launch', device['udid'], app_identifier
]).wait()

0 comments on commit 58ba018

Please sign in to comment.