Commit 494d1e01 authored by Devon Carew's avatar Devon Carew

verify that we're running from the root of a project

remove an unused import

review comments

rename st --> stack
parent 678af9c0
...@@ -20,6 +20,7 @@ import 'src/commands/run_mojo.dart'; ...@@ -20,6 +20,7 @@ import 'src/commands/run_mojo.dart';
import 'src/commands/start.dart'; import 'src/commands/start.dart';
import 'src/commands/stop.dart'; import 'src/commands/stop.dart';
import 'src/commands/trace.dart'; import 'src/commands/trace.dart';
import 'src/process.dart';
/// Main entry point for commands. /// Main entry point for commands.
/// ///
...@@ -58,6 +59,16 @@ Future main(List<String> args) async { ...@@ -58,6 +59,16 @@ Future main(List<String> args) async {
exit(result); exit(result);
} on UsageException catch (e) { } on UsageException catch (e) {
stderr.writeln(e); stderr.writeln(e);
exit(4); // Args error exit code.
exit(64);
} catch (e, stack) {
if (e is ProcessExit) {
// We've caught an exit code.
exit(e.exitCode);
}
stderr.writeln(e);
Logger.root.log(Level.SEVERE, '\nException:', null, stack);
exit(1);
} }
} }
...@@ -127,7 +127,7 @@ class BuildCommand extends FlutterCommand { ...@@ -127,7 +127,7 @@ class BuildCommand extends FlutterCommand {
} }
@override @override
Future<int> run() async { Future<int> runInProject() async {
String compilerPath = argResults['compiler']; String compilerPath = argResults['compiler'];
if (compilerPath == null) if (compilerPath == null)
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:async'; import 'dart:async';
import 'dart:io';
import 'package:args/command_runner.dart'; import 'package:args/command_runner.dart';
...@@ -14,6 +15,9 @@ import 'flutter_command_runner.dart'; ...@@ -14,6 +15,9 @@ import 'flutter_command_runner.dart';
abstract class FlutterCommand extends Command { abstract class FlutterCommand extends Command {
FlutterCommandRunner get runner => super.runner; FlutterCommandRunner get runner => super.runner;
/// Whether this command needs to be run from the root of a project.
bool get requiresProjectRoot => true;
Future downloadApplicationPackages() async { Future downloadApplicationPackages() async {
if (applicationPackages == null) if (applicationPackages == null)
applicationPackages = await ApplicationPackageStore.forConfigs(runner.buildConfigurations); applicationPackages = await ApplicationPackageStore.forConfigs(runner.buildConfigurations);
...@@ -40,6 +44,20 @@ abstract class FlutterCommand extends Command { ...@@ -40,6 +44,20 @@ abstract class FlutterCommand extends Command {
devices = other.devices; devices = other.devices;
} }
Future<int> run() async {
if (requiresProjectRoot) {
if (!FileSystemEntity.isFileSync('pubspec.yaml')) {
stderr.writeln('No pubspec.yaml file found. '
'This command should be run from the root of a project.');
return 1;
}
}
return runInProject();
}
Future<int> runInProject();
ApplicationPackageStore applicationPackages; ApplicationPackageStore applicationPackages;
Toolchain toolchain; Toolchain toolchain;
DeviceStore devices; DeviceStore devices;
......
...@@ -12,6 +12,7 @@ import 'package:path/path.dart' as path; ...@@ -12,6 +12,7 @@ import 'package:path/path.dart' as path;
import '../artifacts.dart'; import '../artifacts.dart';
import '../build_configuration.dart'; import '../build_configuration.dart';
import '../process.dart';
final Logger _logging = new Logger('sky_tools.flutter_command_runner'); final Logger _logging = new Logger('sky_tools.flutter_command_runner');
...@@ -116,8 +117,8 @@ class FlutterCommandRunner extends CommandRunner { ...@@ -116,8 +117,8 @@ class FlutterCommandRunner extends CommandRunner {
else else
message += '\nDid you run this command from the same directory as your pubspec.yaml file?'; message += '\nDid you run this command from the same directory as your pubspec.yaml file?';
} }
_logging.severe(message); stderr.writeln(message);
exit(2); throw new ProcessExit(2);
} }
String enginePath = globalResults['engine-src-path']; String enginePath = globalResults['engine-src-path'];
...@@ -129,9 +130,11 @@ class FlutterCommandRunner extends CommandRunner { ...@@ -129,9 +130,11 @@ class FlutterCommandRunner extends CommandRunner {
String realFlutterPath = flutterDir.resolveSymbolicLinksSync(); String realFlutterPath = flutterDir.resolveSymbolicLinksSync();
enginePath = path.dirname(path.dirname(path.dirname(path.dirname(realFlutterPath)))); enginePath = path.dirname(path.dirname(path.dirname(path.dirname(realFlutterPath))));
if (enginePath == '/' || enginePath.isEmpty || !FileSystemEntity.isDirectorySync(path.join(enginePath, 'out'))) { bool dirExists = FileSystemEntity.isDirectorySync(path.join(enginePath, 'out'));
_logging.severe('Unable to detect local build in $enginePath.\nDo you have a dependency override for the flutter package?'); if (enginePath == '/' || enginePath.isEmpty || !dirExists) {
exit(2); stderr.writeln('Unable to detect local build in $enginePath.\n'
'Do you have a dependency override for the flutter package?');
throw new ProcessExit(2);
} }
} }
......
...@@ -160,8 +160,7 @@ class FlutterDemo extends StatelessComponent { ...@@ -160,8 +160,7 @@ class FlutterDemo extends StatelessComponent {
), ),
floatingActionButton: new FloatingActionButton( floatingActionButton: new FloatingActionButton(
child: new Icon( child: new Icon(
type: 'content/add', type: 'content/add'
size: 24
) )
) )
); );
......
...@@ -18,7 +18,7 @@ class InstallCommand extends FlutterCommand { ...@@ -18,7 +18,7 @@ class InstallCommand extends FlutterCommand {
} }
@override @override
Future<int> run() async { Future<int> runInProject() async {
await downloadApplicationPackagesAndConnectToDevices(); await downloadApplicationPackagesAndConnectToDevices();
return install(boot: argResults['boot']) ? 0 : 2; return install(boot: argResults['boot']) ? 0 : 2;
} }
......
...@@ -23,7 +23,7 @@ class ListCommand extends FlutterCommand { ...@@ -23,7 +23,7 @@ class ListCommand extends FlutterCommand {
} }
@override @override
Future<int> run() async { Future<int> runInProject() async {
connectToDevices(); connectToDevices();
bool details = argResults['details']; bool details = argResults['details'];
......
...@@ -38,7 +38,7 @@ class ListenCommand extends FlutterCommand { ...@@ -38,7 +38,7 @@ class ListenCommand extends FlutterCommand {
static const String _remoteFlutterBundle = 'Documents/app.flx'; static const String _remoteFlutterBundle = 'Documents/app.flx';
@override @override
Future<int> run() async { Future<int> runInProject() async {
await downloadApplicationPackagesAndConnectToDevices(); await downloadApplicationPackagesAndConnectToDevices();
await downloadToolchain(); await downloadToolchain();
......
...@@ -22,7 +22,7 @@ class LogsCommand extends FlutterCommand { ...@@ -22,7 +22,7 @@ class LogsCommand extends FlutterCommand {
} }
@override @override
Future<int> run() async { Future<int> runInProject() async {
connectToDevices(); connectToDevices();
bool clear = argResults['clear']; bool clear = argResults['clear'];
......
...@@ -36,7 +36,7 @@ class StartCommand extends FlutterCommand { ...@@ -36,7 +36,7 @@ class StartCommand extends FlutterCommand {
} }
@override @override
Future<int> run() async { Future<int> runInProject() async {
await downloadApplicationPackagesAndConnectToDevices(); await downloadApplicationPackagesAndConnectToDevices();
bool poke = argResults['poke']; bool poke = argResults['poke'];
......
...@@ -17,7 +17,7 @@ class StopCommand extends FlutterCommand { ...@@ -17,7 +17,7 @@ class StopCommand extends FlutterCommand {
final String description = 'Stop your Flutter app on all attached devices.'; final String description = 'Stop your Flutter app on all attached devices.';
@override @override
Future<int> run() async { Future<int> runInProject() async {
await downloadApplicationPackagesAndConnectToDevices(); await downloadApplicationPackagesAndConnectToDevices();
return await stop() ? 0 : 2; return await stop() ? 0 : 2;
} }
......
...@@ -28,7 +28,7 @@ class TraceCommand extends FlutterCommand { ...@@ -28,7 +28,7 @@ class TraceCommand extends FlutterCommand {
} }
@override @override
Future<int> run() async { Future<int> runInProject() async {
await downloadApplicationPackagesAndConnectToDevices(); await downloadApplicationPackagesAndConnectToDevices();
if (!devices.android.isConnected()) { if (!devices.android.isConnected()) {
......
...@@ -89,3 +89,10 @@ String _runWithLoggingSync(List<String> cmd, {bool checked: false}) { ...@@ -89,3 +89,10 @@ String _runWithLoggingSync(List<String> cmd, {bool checked: false}) {
_logging.fine(results.stdout.trim()); _logging.fine(results.stdout.trim());
return results.stdout; return results.stdout;
} }
class ProcessExit implements Exception {
final int exitCode;
ProcessExit(this.exitCode);
String get message => 'ProcessExit: ${exitCode}';
String toString() => message;
}
...@@ -19,7 +19,7 @@ dependencies: ...@@ -19,7 +19,7 @@ dependencies:
shelf_route: ^0.13.4 shelf_route: ^0.13.4
shelf_static: ^0.2.3 shelf_static: ^0.2.3
shelf: ^0.6.2 shelf: ^0.6.2
test: ^0.12.5 test: 0.12.4+9
yaml: ^2.1.3 yaml: ^2.1.3
dev_dependencies: dev_dependencies:
......
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