Commit bb1da703 authored by Devon Carew's avatar Devon Carew

return exit codes on failures

parent 3c9c3133
...@@ -5,10 +5,10 @@ ...@@ -5,10 +5,10 @@
import 'dart:io'; import 'dart:io';
import 'package:args/args.dart'; import 'package:args/args.dart';
import 'package:shelf_static/shelf_static.dart';
import 'package:shelf/shelf_io.dart' as io;
import 'package:shelf/shelf.dart'; import 'package:shelf/shelf.dart';
import 'package:shelf/shelf_io.dart' as io;
import 'package:shelf_route/shelf_route.dart' as shelf_route; import 'package:shelf_route/shelf_route.dart' as shelf_route;
import 'package:shelf_static/shelf_static.dart';
void printUsage(parser) { void printUsage(parser) {
print('Usage: sky_server [-v] PORT'); print('Usage: sky_server [-v] PORT');
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:test/src/executable.dart' as executable;
import 'package:sky_tools/src/test/loader.dart' as loader; import 'package:sky_tools/src/test/loader.dart' as loader;
import 'package:test/src/executable.dart' as executable;
main(List<String> args) { main(List<String> args) {
loader.installHook(); loader.installHook();
......
...@@ -8,9 +8,9 @@ import 'dart:io'; ...@@ -8,9 +8,9 @@ import 'dart:io';
import 'package:args/command_runner.dart'; import 'package:args/command_runner.dart';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'src/commands/flutter_command_runner.dart';
import 'src/commands/build.dart'; import 'src/commands/build.dart';
import 'src/commands/cache.dart'; import 'src/commands/cache.dart';
import 'src/commands/flutter_command_runner.dart';
import 'src/commands/init.dart'; import 'src/commands/init.dart';
import 'src/commands/install.dart'; import 'src/commands/install.dart';
import 'src/commands/list.dart'; import 'src/commands/list.dart';
...@@ -25,13 +25,18 @@ import 'src/commands/trace.dart'; ...@@ -25,13 +25,18 @@ import 'src/commands/trace.dart';
/// ///
/// This function is intended to be used from the [flutter] command line tool. /// This function is intended to be used from the [flutter] command line tool.
Future main(List<String> args) async { Future main(List<String> args) async {
Logger.root.level = Level.WARNING; // This level can be adjusted by users through the `--verbose` option.
Logger.root.level = Level.SEVERE;
Logger.root.onRecord.listen((LogRecord record) { Logger.root.onRecord.listen((LogRecord record) {
print('${record.level.name}: ${record.message}'); if (record.level >= Level.WARNING) {
stderr.writeln(record.message);
} else {
print(record.message);
}
if (record.error != null) if (record.error != null)
print(record.error); stderr.writeln(record.error);
if (record.stackTrace != null) if (record.stackTrace != null)
print(record.stackTrace); stderr.writeln(record.stackTrace);
}); });
FlutterCommandRunner runner = new FlutterCommandRunner() FlutterCommandRunner runner = new FlutterCommandRunner()
...@@ -48,9 +53,11 @@ Future main(List<String> args) async { ...@@ -48,9 +53,11 @@ Future main(List<String> args) async {
..addCommand(new TraceCommand()); ..addCommand(new TraceCommand());
try { try {
await runner.run(args); dynamic result = await runner.run(args);
if (result is int)
exit(result);
} on UsageException catch (e) { } on UsageException catch (e) {
print(e); stderr.writeln(e);
exit(1); exit(4);
} }
} }
...@@ -81,24 +81,24 @@ Iterable<_MaterialAsset> _parseMaterialAssets(Map manifestDescriptor) sync* { ...@@ -81,24 +81,24 @@ Iterable<_MaterialAsset> _parseMaterialAssets(Map manifestDescriptor) sync* {
} }
} }
Future _loadManifest(String manifestPath) async { dynamic _loadManifest(String manifestPath) {
if (manifestPath == null) if (manifestPath == null)
return null; return null;
String manifestDescriptor = await new File(manifestPath).readAsString(); String manifestDescriptor = new File(manifestPath).readAsStringSync();
return loadYaml(manifestDescriptor); return loadYaml(manifestDescriptor);
} }
Future<ArchiveFile> _createFile(String key, String assetBase) async { ArchiveFile _createFile(String key, String assetBase) {
File file = new File('${assetBase}/${key}'); File file = new File('${assetBase}/${key}');
if (!await file.exists()) if (!file.existsSync())
return null; return null;
List<int> content = await file.readAsBytes(); List<int> content = file.readAsBytesSync();
return new ArchiveFile.noCompress(key, content.length, content); return new ArchiveFile.noCompress(key, content.length, content);
} }
Future<ArchiveFile> _createSnapshotFile(String snapshotPath) async { ArchiveFile _createSnapshotFile(String snapshotPath) {
File file = new File(snapshotPath); File file = new File(snapshotPath);
List<int> content = await file.readAsBytes(); List<int> content = file.readAsBytesSync();
return new ArchiveFile(_kSnapshotKey, content.length, content); return new ArchiveFile(_kSnapshotKey, content.length, content);
} }
...@@ -145,7 +145,7 @@ class BuildCommand extends FlutterCommand { ...@@ -145,7 +145,7 @@ class BuildCommand extends FlutterCommand {
String outputPath: _kDefaultOutputPath, String outputPath: _kDefaultOutputPath,
String snapshotPath: _kDefaultSnapshotPath String snapshotPath: _kDefaultSnapshotPath
}) async { }) async {
Map manifestDescriptor = await _loadManifest(manifestPath); Map manifestDescriptor = _loadManifest(manifestPath);
Iterable<_Asset> assets = _parseAssets(manifestDescriptor, manifestPath); Iterable<_Asset> assets = _parseAssets(manifestDescriptor, manifestPath);
Iterable<_MaterialAsset> materialAssets = _parseMaterialAssets(manifestDescriptor); Iterable<_MaterialAsset> materialAssets = _parseMaterialAssets(manifestDescriptor);
...@@ -156,20 +156,21 @@ class BuildCommand extends FlutterCommand { ...@@ -156,20 +156,21 @@ class BuildCommand extends FlutterCommand {
if (result != 0) if (result != 0)
return result; return result;
archive.addFile(await _createSnapshotFile(snapshotPath)); archive.addFile(_createSnapshotFile(snapshotPath));
for (_Asset asset in assets) for (_Asset asset in assets)
archive.addFile(await _createFile(asset.key, asset.base)); archive.addFile(_createFile(asset.key, asset.base));
for (_MaterialAsset asset in materialAssets) { for (_MaterialAsset asset in materialAssets) {
ArchiveFile file = await _createFile(asset.key, assetBase); ArchiveFile file = _createFile(asset.key, assetBase);
if (file != null) if (file != null)
archive.addFile(file); archive.addFile(file);
} }
File outputFile = new File(outputPath); File outputFile = new File(outputPath);
await outputFile.writeAsString('#!mojo mojo:sky_viewer\n'); outputFile.writeAsStringSync('#!mojo mojo:sky_viewer\n');
await outputFile.writeAsBytes(new ZipEncoder().encode(archive), mode: FileMode.APPEND, flush: true); outputFile.writeAsBytesSync(
new ZipEncoder().encode(archive), mode: FileMode.APPEND, flush: true);
return 0; return 0;
} }
} }
...@@ -94,7 +94,7 @@ class FlutterCommandRunner extends CommandRunner { ...@@ -94,7 +94,7 @@ class FlutterCommandRunner extends CommandRunner {
ArgResults _globalResults; ArgResults _globalResults;
Future<int> runCommand(ArgResults globalResults) async { Future<int> runCommand(ArgResults globalResults) {
if (globalResults['verbose']) if (globalResults['verbose'])
Logger.root.level = Level.INFO; Logger.root.level = Level.INFO;
......
...@@ -6,8 +6,8 @@ import 'dart:async'; ...@@ -6,8 +6,8 @@ import 'dart:async';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'flutter_command.dart';
import '../device.dart'; import '../device.dart';
import 'flutter_command.dart';
final Logger _logging = new Logger('sky_tools.list'); final Logger _logging = new Logger('sky_tools.list');
......
...@@ -6,8 +6,8 @@ import 'dart:async'; ...@@ -6,8 +6,8 @@ import 'dart:async';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'flutter_command.dart';
import '../device.dart'; import '../device.dart';
import 'flutter_command.dart';
final Logger _logging = new Logger('sky_tools.logs'); final Logger _logging = new Logger('sky_tools.logs');
......
...@@ -31,17 +31,17 @@ class RunMojoCommand extends Command { ...@@ -31,17 +31,17 @@ class RunMojoCommand extends Command {
} }
// TODO(abarth): Why not use path.absolute? // TODO(abarth): Why not use path.absolute?
Future<String> _makePathAbsolute(String relativePath) async { String _makePathAbsolute(String relativePath) {
File file = new File(relativePath); File file = new File(relativePath);
if (!await file.exists()) { if (!file.existsSync()) {
throw new Exception("Path \"${relativePath}\" does not exist"); throw new Exception("Path \"${relativePath}\" does not exist");
} }
return file.absolute.path; return file.absolute.path;
} }
Future<int> _runAndroid(String mojoPath, _MojoConfig mojoConfig, String appPath, List<String> additionalArgs) async { Future<int> _runAndroid(String mojoPath, _MojoConfig mojoConfig, String appPath, List<String> additionalArgs) {
String skyViewerUrl = ArtifactStore.googleStorageUrl('viewer', 'android-arm'); String skyViewerUrl = ArtifactStore.googleStorageUrl('viewer', 'android-arm');
String command = await _makePathAbsolute(path.join(mojoPath, 'mojo', 'devtools', 'common', 'mojo_run')); String command = _makePathAbsolute(path.join(mojoPath, 'mojo', 'devtools', 'common', 'mojo_run'));
String appName = path.basename(appPath); String appName = path.basename(appPath);
String appDir = path.dirname(appPath); String appDir = path.dirname(appPath);
String buildFlag = mojoConfig == _MojoConfig.Debug ? '--debug' : '--release'; String buildFlag = mojoConfig == _MojoConfig.Debug ? '--debug' : '--release';
...@@ -65,9 +65,9 @@ class RunMojoCommand extends Command { ...@@ -65,9 +65,9 @@ class RunMojoCommand extends Command {
} }
Future<int> _runLinux(String mojoPath, _MojoConfig mojoConfig, String appPath, List<String> additionalArgs) async { Future<int> _runLinux(String mojoPath, _MojoConfig mojoConfig, String appPath, List<String> additionalArgs) async {
String viewerPath = await _makePathAbsolute(await ArtifactStore.getPath(Artifact.skyViewerMojo)); String viewerPath = _makePathAbsolute(await ArtifactStore.getPath(Artifact.skyViewerMojo));
String mojoBuildType = mojoConfig == _MojoConfig.Debug ? 'Debug' : 'Release'; String mojoBuildType = mojoConfig == _MojoConfig.Debug ? 'Debug' : 'Release';
String mojoShellPath = await _makePathAbsolute(path.join(mojoPath, 'out', mojoBuildType, 'mojo_shell')); String mojoShellPath = _makePathAbsolute(path.join(mojoPath, 'out', mojoBuildType, 'mojo_shell'));
List<String> cmd = [ List<String> cmd = [
mojoShellPath, mojoShellPath,
'file://${appPath}', 'file://${appPath}',
...@@ -93,7 +93,7 @@ class RunMojoCommand extends Command { ...@@ -93,7 +93,7 @@ class RunMojoCommand extends Command {
} }
String mojoPath = argResults['mojo-path']; String mojoPath = argResults['mojo-path'];
_MojoConfig mojoConfig = argResults['mojo-debug'] ? _MojoConfig.Debug : _MojoConfig.Release; _MojoConfig mojoConfig = argResults['mojo-debug'] ? _MojoConfig.Debug : _MojoConfig.Release;
String appPath = await _makePathAbsolute(argResults['app']); String appPath = _makePathAbsolute(argResults['app']);
args.addAll(argResults.rest); args.addAll(argResults.rest);
if (argResults['android']) { if (argResults['android']) {
......
...@@ -67,6 +67,14 @@ class StartCommand extends FlutterCommand { ...@@ -67,6 +67,14 @@ class StartCommand extends FlutterCommand {
} }
} }
if (!startedSomething) {
if (!devices.all.any((device) => device.isConnected())) {
_logging.severe('Unable to run application - no connected devices.');
} else {
_logging.severe('Unable to run application.');
}
}
return startedSomething ? 0 : 2; return startedSomething ? 0 : 2;
} }
} }
...@@ -6,9 +6,9 @@ import 'dart:async'; ...@@ -6,9 +6,9 @@ import 'dart:async';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'flutter_command.dart';
import '../application_package.dart'; import '../application_package.dart';
import '../device.dart'; import '../device.dart';
import 'flutter_command.dart';
final Logger _logging = new Logger('sky_tools.trace'); final Logger _logging = new Logger('sky_tools.trace');
......
...@@ -277,7 +277,7 @@ class IOSDevice extends Device { ...@@ -277,7 +277,7 @@ class IOSDevice extends Device {
return 2; return 2;
} }
return runCommandAndStreamOutput([loggerPath], return runCommandAndStreamOutput([loggerPath],
prefix: 'IOS DEV: ', filter: new RegExp(r'.*SkyShell.*')); prefix: 'iOS dev: ', filter: new RegExp(r'.*SkyShell.*'));
} }
} }
...@@ -499,7 +499,7 @@ class IOSSimulator extends Device { ...@@ -499,7 +499,7 @@ class IOSSimulator extends Device {
runSync(['rm', logFilePath]); runSync(['rm', logFilePath]);
} }
return runCommandAndStreamOutput(['tail', '-f', logFilePath], return runCommandAndStreamOutput(['tail', '-f', logFilePath],
prefix: 'IOS SIM: ', filter: new RegExp(r'.*SkyShell.*')); prefix: 'iOS sim: ', filter: new RegExp(r'.*SkyShell.*'));
} }
} }
...@@ -575,7 +575,7 @@ class AndroidDevice extends Device { ...@@ -575,7 +575,7 @@ class AndroidDevice extends Device {
_hasValidAndroid = _checkForLollipopOrLater(); _hasValidAndroid = _checkForLollipopOrLater();
if (!_hasAdb || !_hasValidAndroid) { if (!_hasAdb || !_hasValidAndroid) {
_logging.severe('Unable to run on Android.'); _logging.warning('Unable to run on Android.');
} }
} }
...@@ -855,7 +855,7 @@ class AndroidDevice extends Device { ...@@ -855,7 +855,7 @@ class AndroidDevice extends Device {
'-s', '-s',
'sky', 'sky',
'chromium', 'chromium',
], prefix: 'ANDROID: '); ], prefix: 'android: ');
} }
void startTracing(AndroidApk apk) { void startTracing(AndroidApk apk) {
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
library stop_test;
import 'package:args/command_runner.dart'; import 'package:args/command_runner.dart';
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
import 'package:sky_tools/src/commands/stop.dart'; import 'package:sky_tools/src/commands/stop.dart';
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
library trace_test;
import 'package:args/command_runner.dart'; import 'package:args/command_runner.dart';
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
import 'package:sky_tools/src/commands/trace.dart'; import 'package:sky_tools/src/commands/trace.dart';
......
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