From ae324109956d5a9acf41812054eba57305bf67c5 Mon Sep 17 00:00:00 2001 From: Ian Fischer Date: Fri, 9 Oct 2015 16:10:36 -0700 Subject: [PATCH] Get iOS devices working on Mac if you specify sky-src-path. --- packages/flutter_tools/lib/src/device.dart | 37 ++++++++++++++++ packages/flutter_tools/lib/src/listen.dart | 45 +++++++++++++++----- packages/flutter_tools/test/listen_test.dart | 4 +- 3 files changed, 74 insertions(+), 12 deletions(-) diff --git a/packages/flutter_tools/lib/src/device.dart b/packages/flutter_tools/lib/src/device.dart index e51d27d076..36c9d0d9b5 100644 --- a/packages/flutter_tools/lib/src/device.dart +++ b/packages/flutter_tools/lib/src/device.dart @@ -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 getAttachedDevices([IOSDevice mockIOS]) { @@ -208,6 +218,33 @@ class IOSDevice extends _Device { return false; } + Future 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 logs({bool clear: false}) { return runCommandAndStreamOutput([loggerPath], prefix: 'IOS DEV: ', filter: new RegExp(r'.*SkyShell.*')); diff --git a/packages/flutter_tools/lib/src/listen.dart b/packages/flutter_tools/lib/src/listen.dart index 31b00cf898..7dc0cf39b2 100644 --- a/packages/flutter_tools/lib/src/listen.dart +++ b/packages/flutter_tools/lib/src/listen.dart @@ -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 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 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 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 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); diff --git a/packages/flutter_tools/test/listen_test.dart b/packages/flutter_tools/test/listen_test.dart index 6a96ed8c99..b2d40a1f59 100644 --- a/packages/flutter_tools/test/listen_test.dart +++ b/packages/flutter_tools/test/listen_test.dart @@ -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);