Commit d8c97c46 authored by Ian Fischer's avatar Ian Fischer

Make sky_tool listen work on Linux.

parent ce877f09
...@@ -9,6 +9,7 @@ import errno ...@@ -9,6 +9,7 @@ import errno
import json import json
import logging import logging
import os import os
import platform
import random import random
import re import re
import signal import signal
...@@ -290,13 +291,16 @@ class IOSDevice(object): ...@@ -290,13 +291,16 @@ class IOSDevice(object):
def has_ios_deploy(cls): def has_ios_deploy(cls):
if cls._has_ios_deploy is not None: if cls._has_ios_deploy is not None:
return cls._has_ios_deploy return cls._has_ios_deploy
cmd = [ try:
'which', cmd = [
'ios-deploy' 'which',
] 'ios-deploy'
out = subprocess.check_output(cmd) ]
match = re.search(r'ios-deploy', out) out = subprocess.check_output(cmd)
cls._has_ios_deploy = match is not None match = re.search(r'ios-deploy', out)
cls._has_ios_deploy = match is not None
except subprocess.CalledProcessError:
cls._has_ios_deploy = False
return cls._has_ios_deploy return cls._has_ios_deploy
_is_connected = False _is_connected = False
...@@ -352,6 +356,8 @@ class IOSDevice(object): ...@@ -352,6 +356,8 @@ class IOSDevice(object):
class IOSSimulator(object): class IOSSimulator(object):
@classmethod @classmethod
def is_booted(cls): def is_booted(cls):
if platform.system() != 'Darwin':
return False
return cls.get_simulator_device_id() is not None return cls.get_simulator_device_id() is not None
_device_id = None _device_id = None
...@@ -545,34 +551,67 @@ class IOSSimulator(object): ...@@ -545,34 +551,67 @@ class IOSSimulator(object):
class StartListening(object): class StartListening(object):
def __init__(self):
self.watch_cmd = None
def add_subparser(self, subparsers): def add_subparser(self, subparsers):
listen_parser = subparsers.add_parser('listen', listen_parser = subparsers.add_parser('listen',
help=('Listen for changes to files and reload the running app on all connected devices')) help=('Listen for changes to files and reload the running app on all connected devices'))
listen_parser.set_defaults(func=self.run) listen_parser.set_defaults(func=self.run)
def run(self, args, pids): def watch_dir(self, directory):
cmd = [ if self.watch_cmd is None:
'which', name = platform.system()
'fswatch' if name == 'Linux':
] try:
out = subprocess.check_output(cmd) cmd = [
match = re.search(r'fswatch', out) 'which',
if match is None: 'inotifywait'
logging.error('"listen" command is only useful if you have installed fswatch. Run "brew install fswatch" to install it with homebrew.') ]
return out = subprocess.check_output(cmd)
except subprocess.CalledProcessError:
logging.error('"listen" command is only useful if you have installed inotifywait on Linux. Run "apt-get install inotify-tools" or equivalent to install it.')
return False
self.watch_cmd = [
'inotifywait',
'-r',
'-e',
'modify,close_write,move,create,delete', # Only listen for events that matter, to avoid triggering constantly from the editor watching files
directory
]
elif name == 'Darwin':
try:
cmd = [
'which',
'fswatch'
]
out = subprocess.check_output(cmd)
except subprocess.CalledProcessError:
logging.error('"listen" command is only useful if you have installed fswatch on Mac. Run "brew install fswatch" to install it with homebrew.')
return False
self.watch_cmd = [
'fswatch',
'-r',
'-v',
'-1',
directory
]
else:
logging.error('"listen" command is only available on Mac and Linux.')
return False
subprocess.check_call(self.watch_cmd)
return True
tempdir = None def run(self, args, pids):
currdir = None tempdir = tempfile.mkdtemp()
currdir = os.getcwd()
while True: while True:
# Watch filesystem for changes # Watch filesystem for changes
cmd = [ if not self.watch_dir(currdir):
'fswatch', return
'-r',
'-v',
'-1',
'.'
]
subprocess.check_call(cmd)
logging.info('Updating running Sky apps...') logging.info('Updating running Sky apps...')
...@@ -590,10 +629,6 @@ class StartListening(object): ...@@ -590,10 +629,6 @@ class StartListening(object):
# since we aren't shipping the sky_snapshot binary yet. # since we aren't shipping the sky_snapshot binary yet.
continue continue
if tempdir is None:
tempdir = tempfile.mkdtemp()
currdir = os.getcwd()
# Build the snapshot # Build the snapshot
sky_snapshot_path = os.path.join(args.sky_src_path, args.ios_sim_debug_build_path, 'clang_x64', 'sky_snapshot') sky_snapshot_path = os.path.join(args.sky_src_path, args.ios_sim_debug_build_path, 'clang_x64', 'sky_snapshot')
cmd = [ cmd = [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment