Commit bb1da703 authored by Devon Carew's avatar Devon Carew

return exit codes on failures

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