Merge pull request #82 from iansf/ios_listen

Get iOS devices working on Mac if you specify sky-src-path.
This commit is contained in:
Ian Fischer 2015-10-09 16:51:03 -07:00
commit 51f1eb3581
3 changed files with 74 additions and 12 deletions

View file

@ -92,6 +92,9 @@ class IOSDevice extends _Device {
String _loggerPath;
String get loggerPath => _loggerPath;
String _pusherPath;
String get pusherPath => _pusherPath;
String _name;
String get name => _name;
@ -107,6 +110,13 @@ class IOSDevice extends _Device {
_informerPath = _checkForCommand('ideviceinfo');
_debuggerPath = _checkForCommand('idevicedebug');
_loggerPath = _checkForCommand('idevicesyslog');
_pusherPath = _checkForCommand(
'ios-deploy',
'To copy files to iOS devices, please install ios-deploy. '
'You can do this using homebrew as follows:\n'
'\$ brew tap flutter/flutter\n'
'\$ brew install ios-deploy',
'Copying files to iOS devices is not currently supported on Linux.');
}
static List<IOSDevice> getAttachedDevices([IOSDevice mockIOS]) {
@ -208,6 +218,33 @@ class IOSDevice extends _Device {
return false;
}
Future<bool> pushFile(
ApplicationPackage app, String localFile, String targetFile) async {
if (Platform.isMacOS) {
runSync([
pusherPath,
'-t',
'1',
'--bundle_id',
app.appPackageID,
'--upload',
localFile,
'--to',
targetFile
]);
return true;
} else {
// TODO(iansf): It may be possible to make this work on Linux. Since this
// functionality appears to be the only that prevents us from
// supporting iOS on Linux, it may be worth putting some time
// into investigating this.
// See https://bbs.archlinux.org/viewtopic.php?id=192655
return false;
}
return false;
}
/// Note that clear is not supported on iOS at this time.
Future<int> logs({bool clear: false}) {
return runCommandAndStreamOutput([loggerPath],
prefix: 'IOS DEV: ', filter: new RegExp(r'.*SkyShell.*'));

View file

@ -19,22 +19,14 @@ class ListenCommand extends Command {
final name = 'listen';
final description = 'Listen for changes to files and reload the running app '
'on all connected devices.';
AndroidDevice android = null;
AndroidDevice android;
IOSDevice ios;
List<String> watchCommand;
/// Only run once. Used for testing.
bool singleRun;
ListenCommand({this.android, this.singleRun: false}) {
argParser.addFlag('checked',
negatable: true,
defaultsTo: true,
help: 'Toggle Dart\'s checked mode.');
argParser.addOption('target',
defaultsTo: '.',
abbr: 't',
help: 'Target app path or filename to start.');
}
ListenCommand({this.android, this.ios, this.singleRun: false}) {}
@override
Future<int> run() async {
@ -42,6 +34,10 @@ class ListenCommand extends Command {
android = new AndroidDevice();
}
if (ios == null) {
ios = new IOSDevice();
}
if (argResults.rest.length > 0) {
watchCommand = _initWatchCommand(argResults.rest);
} else {
@ -51,10 +47,37 @@ class ListenCommand extends Command {
Map<BuildPlatform, ApplicationPackage> packages =
ApplicationPackageFactory.getAvailableApplicationPackages();
ApplicationPackage androidApp = packages[BuildPlatform.android];
ApplicationPackage iosApp = packages[BuildPlatform.iOS];
while (true) {
_logging.info('Updating running Sky apps...');
// TODO(iansf): refactor build command so that this doesn't have
// to call out like this.
List<String> command = ['pub', 'run', 'sky_tools', 'build',];
try {
// In testing, sky-src-path isn't added to the options, and
// the ArgParser module throws an exception, so we have to
// catch and ignore the error in order to test.
if (globalResults.wasParsed('sky-src-path')) {
command.addAll([
// TODO(iansf): Don't rely on sky-src-path for the snapshotter.
'--compiler',
'${globalResults['sky-src-path']}'
'/out/ios_Debug/clang_x64/sky_snapshot'
]);
}
} catch (e) {}
runSync(command);
String localFLXPath = 'app.flx';
String remoteFLXPath = 'Documents/app.flx';
if (ios.isConnected()) {
await ios.pushFile(iosApp, localFLXPath, remoteFLXPath);
}
if (android.isConnected()) {
await android.startServer(
argResults['target'], true, argResults['checked'], androidApp);

View file

@ -20,8 +20,10 @@ defineTests() {
MockAndroidDevice android = new MockAndroidDevice();
when(android.isConnected()).thenReturn(false);
MockIOSDevice ios = new MockIOSDevice();
when(ios.isConnected()).thenReturn(false);
ListenCommand command =
new ListenCommand(android: android, singleRun: true);
new ListenCommand(android: android, ios: ios, singleRun: true);
CommandRunner runner = new CommandRunner('test_flutter', '')
..addCommand(command);