Merge pull request #761 from iansf/fix_linux

Fix sky_tool listen on linux.
This commit is contained in:
Ian Fischer 2015-08-24 15:53:09 -07:00
commit a41825619b

View File

@ -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,6 +291,7 @@ 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
try:
cmd = [ cmd = [
'which', 'which',
'ios-deploy' 'ios-deploy'
@ -297,6 +299,8 @@ class IOSDevice(object):
out = subprocess.check_output(cmd) out = subprocess.check_output(cmd)
match = re.search(r'ios-deploy', out) match = re.search(r'ios-deploy', out)
cls._has_ios_deploy = match is not None 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):
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):
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):
if self.watch_cmd is None:
name = platform.system()
if name == 'Linux':
try:
cmd = [
'which',
'inotifywait'
]
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 = [ cmd = [
'which', 'which',
'fswatch' 'fswatch'
] ]
out = subprocess.check_output(cmd) out = subprocess.check_output(cmd)
match = re.search(r'fswatch', out) except subprocess.CalledProcessError:
if match is None: logging.error('"listen" command is only useful if you have installed fswatch on Mac. Run "brew install fswatch" to install it with homebrew.')
logging.error('"listen" command is only useful if you have installed fswatch. Run "brew install fswatch" to install it with homebrew.') return False
return
tempdir = None self.watch_cmd = [
currdir = None
while True:
# Watch filesystem for changes
cmd = [
'fswatch', 'fswatch',
'-r', '-r',
'-v', '-v',
'-1', '-1',
'.' directory
] ]
subprocess.check_call(cmd) else:
logging.error('"listen" command is only available on Mac and Linux.')
return False
subprocess.check_call(self.watch_cmd)
return True
def run(self, args, pids):
tempdir = tempfile.mkdtemp()
currdir = os.getcwd()
while True:
# Watch filesystem for changes
if not self.watch_dir(currdir):
return
logging.info('Updating running Sky apps...') logging.info('Updating running Sky apps...')
@ -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 = [