Skip to content

Commit

Permalink
Cleanup build/start targets.
Browse files Browse the repository at this point in the history
  • Loading branch information
freakboy3742 committed Jul 27, 2017
1 parent a127811 commit f6d2040
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 32 deletions.
37 changes: 22 additions & 15 deletions briefcase/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@ class app(Command):
"Name of the splash screen file."),
('app-requires', None,
'List of platform-specific requirements for this app.'),
('support-pkg=', 's',
('support-pkg=', None,
'URL for the support package to use'),
('download-dir=', None,
"Directory where the project support packages will be cached"),
('build', None,
('build', 'b',
"Build the project after generating"),
('execute', None,
"Run the application after building"),
('start', 's',
"Start 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)")
"Set the device OS version. (e.g., iOS 10.2)"),
('device-name=', None,
"Set the device to run. (e.g., iPhone 7 Plus)")
]

def initialize_options(self):
Expand All @@ -77,9 +77,9 @@ def initialize_options(self):
self.guid = None
self.secret_key = None
self.build = False
self.execute = False
self.start = False
self.os_version = None
self.device = None
self.device_name = None

def finalize_options(self):
if self.formal_name is None:
Expand Down Expand Up @@ -122,7 +122,7 @@ def finalize_options(self):

pip.utils.ensure_dir(self.download_dir)

if self.execute:
if self.start:
self.build = True

def find_support_pkg(self):
Expand Down Expand Up @@ -298,9 +298,15 @@ def build_app(self):
def run_app(self):
pass

def post_run(self):
def post_build(self):
print()
print("Installation complete.")
print("Build complete.")

def start_app(self):
print("Don't know how to start %s applications." % self.platform)

def post_start(self):
pass

def run(self):
full_generation = True
Expand Down Expand Up @@ -331,6 +337,7 @@ def run(self):
self.install_extras()
if self.build:
self.build_app()
if self.execute:
self.run_app()
self.post_run()
self.post_build()
if self.start:
self.start_app()
self.post_start()
34 changes: 17 additions & 17 deletions briefcase/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def finalize_options(self):
self.platform = 'iOS'
self.support_project = "Python-Apple-support"

self.device = None

if self.dir is None:
self.dir = self.platform

Expand Down Expand Up @@ -63,7 +65,7 @@ def install_splash(self):
print("WARNING: No %s splash file available." % size)

def set_device_target(self):
if self.device is None or self.os_version is None:
if self.os_version is None or self.device_name is None or self.device is None:
# Find an appropriate device
pipe = subprocess.Popen(['xcrun', 'simctl', 'list', '-j'], stdout=subprocess.PIPE)
pipe.wait()
Expand Down Expand Up @@ -91,34 +93,32 @@ def set_device_target(self):
print("Invalid selection.")
print

if self.device is None:
if self.device_name is None:
device_list = data['devices'].get(self.os_version, [])
if len(device_list) == 0:
print('No %s devices found', file=sys.stderr)
sys.exit(2)
elif len(device_list) == 1:
print('Device ID is %s...' % device_list[0])
device = device_list[0]
self.device = device['name']
self.device = device_list[0]
self.device_name = device['name']
else:
print()
while self.device is None:
while self.device_name is None:
print('Available devices:')
for i, device in enumerate(device_list):
print(' [%s] %s' % (i+1, device['name']))
index = int(input('Which device do you want to target: '))
try:
device = device_list[int(index) - 1]
self.device = device['name']
self.device = device_list[int(index) - 1]
self.device_name = device['name']
except:
print("Invalid selection.")
print

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

return device
if self.device is None:
device_list = data['devices'].get(self.os_version, [])
self.device = [x for x in device_list if x['name'].lower() == self.device_name.lower()][0]

def has_required_xcode_version(self):
pipe = subprocess.Popen(['xcrun', 'xcodebuild', '-version'], stdout=subprocess.PIPE)
Expand Down Expand Up @@ -151,24 +151,24 @@ def build_app(self):

self.set_device_target()

print(' * Building XCode project for %s %s...' % (self.device, self.os_version))
print(' * Building XCode project for %s %s...' % (self.device_name, self.os_version))

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',
'platform="iOS Simulator,name=%s,OS=%s"' % (self.device_name, 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):
def start_app(self):
if not self.has_required_xcode_version():
return

working_dir = os.path.abspath(self.dir)

device = self.set_device_target()
self.set_device_target()

# Install app and launch simulator
print(' * Launching app on %s %s...' % (self.device, self.os_version))
print(' * Launching app on %s %s...' % (self.device_name, self.os_version))
app_identifier = '.'.join([self.bundle, self.formal_name.replace(' ', '-')])

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

0 comments on commit f6d2040

Please sign in to comment.