Commit 133a9c35 authored by Dan Rubel's avatar Dan Rubel Committed by GitHub

extract flutter watch from flutter analyze (#6012)

parent c1a29674
......@@ -45,7 +45,7 @@ SRC_ROOT=$PWD
# generate and analyze our large sample app
dart dev/tools/mega_gallery.dart
(cd dev/benchmarks/mega_gallery; flutter analyze --watch --benchmark)
(cd dev/benchmarks/mega_gallery; flutter watch --benchmark)
if [ -n "$COVERAGE_FLAG" ]; then
GSUTIL=$HOME/google-cloud-sdk/bin/gsutil
......
......@@ -38,6 +38,7 @@ import 'src/commands/test.dart';
import 'src/commands/trace.dart';
import 'src/commands/update_packages.dart';
import 'src/commands/upgrade.dart';
import 'src/commands/watch.dart';
import 'src/device.dart';
import 'src/doctor.dart';
import 'src/globals.dart';
......@@ -84,7 +85,8 @@ Future<Null> main(List<String> args) async {
..addCommand(new TestCommand())
..addCommand(new TraceCommand())
..addCommand(new UpdatePackagesCommand(hidden: !verboseHelp))
..addCommand(new UpgradeCommand());
..addCommand(new UpgradeCommand())
..addCommand(new WatchCommand(verboseHelp: verboseHelp));
return Chain.capture/*<Future<Null>>*/(() async {
// Initialize globals.
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:io';
import '../base/utils.dart';
import '../globals.dart';
import '../runner/flutter_command.dart';
/// Common behavior for `flutter analyze` and `flutter watch`
abstract class AnalysisCommand extends FlutterCommand {
AnalysisCommand({bool verboseHelp: false}) {
argParser.addFlag('flutter-repo', help: 'Include all the examples and tests from the Flutter repository.', defaultsTo: false);
argParser.addFlag('current-directory', help: 'Include all the Dart files in the current directory, if any.', defaultsTo: true);
argParser.addFlag('current-package', help: 'Include the lib/main.dart file from the current directory, if any.', defaultsTo: true);
argParser.addFlag('dartdocs', help: 'List every public member that is lacking documentation (only examines files in the Flutter repository).', defaultsTo: false);
argParser.addOption('write', valueHelp: 'file', help: 'Also output the results to a file.');
argParser.addOption('dart-sdk', valueHelp: 'path-to-sdk', help: 'The path to the Dart SDK.', hide: !verboseHelp);
// Hidden option to enable a benchmarking mode.
argParser.addFlag('benchmark', negatable: false, hide: !verboseHelp, help: 'Also output the analysis time');
usesPubOption();
}
@override
bool get shouldRunPub {
// If they're not analyzing the current project.
if (!argResults['current-package'])
return false;
// Or we're not in a project directory.
if (!new File('pubspec.yaml').existsSync())
return false;
return super.shouldRunPub;
}
void dumpErrors(Iterable<String> errors) {
if (argResults['write'] != null) {
try {
final RandomAccessFile resultsFile = new File(argResults['write']).openSync(mode: FileMode.WRITE);
try {
resultsFile.lockSync();
resultsFile.writeStringSync(errors.join('\n'));
} finally {
resultsFile.close();
}
} catch (e) {
printError('Failed to save output to "${argResults['write']}": $e');
}
}
}
void writeBenchmark(Stopwatch stopwatch, int errorCount, int membersMissingDocumentation) {
final String benchmarkOut = 'analysis_benchmark.json';
Map<String, dynamic> data = <String, dynamic>{
'time': (stopwatch.elapsedMilliseconds / 1000.0),
'issues': errorCount,
'missingDartDocs': membersMissingDocumentation
};
new File(benchmarkOut).writeAsStringSync(toPrettyJson(data));
printStatus('Analysis benchmark written to $benchmarkOut ($data).');
}
bool get isBenchmarking => argResults['benchmark'];
}
\ No newline at end of file
This diff is collapsed.
......@@ -2,14 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:io';
import 'package:flutter_tools/src/base/os.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/analyze.dart';
import 'package:flutter_tools/src/dart/pub.dart';
import 'package:flutter_tools/src/dart/sdk.dart';
import 'package:flutter_tools/src/runner/flutter_command_runner.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';
......@@ -17,7 +13,6 @@ import 'package:test/test.dart';
import 'src/context.dart';
void main() {
AnalysisServer server;
Directory tempDir;
setUp(() {
......@@ -27,47 +22,9 @@ void main() {
tearDown(() {
tempDir?.deleteSync(recursive: true);
return server?.dispose();
});
group('analyze', () {
testUsingContext('AnalysisServer success', () async {
_createSampleProject(tempDir);
await pubGet(directory: tempDir.path);
server = new AnalysisServer(dartSdkPath, <String>[tempDir.path]);
int errorCount = 0;
Future<bool> onDone = server.onAnalyzing.where((bool analyzing) => analyzing == false).first;
server.onErrors.listen((FileAnalysisErrors errors) => errorCount += errors.errors.length);
await server.start();
await onDone;
expect(errorCount, 0);
}, overrides: <Type, dynamic>{
OperatingSystemUtils: os
});
testUsingContext('AnalysisServer errors', () async {
_createSampleProject(tempDir, brokenCode: true);
await pubGet(directory: tempDir.path);
server = new AnalysisServer(dartSdkPath, <String>[tempDir.path]);
int errorCount = 0;
Future<bool> onDone = server.onAnalyzing.where((bool analyzing) => analyzing == false).first;
server.onErrors.listen((FileAnalysisErrors errors) => errorCount += errors.errors.length);
await server.start();
await onDone;
expect(errorCount, 2);
}, overrides: <Type, dynamic>{
OperatingSystemUtils: os
});
testUsingContext('inRepo', () {
AnalyzeCommand cmd = new AnalyzeCommand();
......@@ -94,19 +51,3 @@ void main() {
});
});
}
void _createSampleProject(Directory directory, { bool brokenCode: false }) {
File pubspecFile = new File(path.join(directory.path, 'pubspec.yaml'));
pubspecFile.writeAsStringSync('''
name: foo_project
''');
File dartFile = new File(path.join(directory.path, 'lib', 'main.dart'));
dartFile.parent.createSync();
dartFile.writeAsStringSync('''
void main() {
print('hello world');
${brokenCode ? 'prints("hello world");' : ''}
}
''');
}
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:io';
import 'package:flutter_tools/src/base/os.dart';
import 'package:flutter_tools/src/commands/watch.dart';
import 'package:flutter_tools/src/dart/pub.dart';
import 'package:flutter_tools/src/dart/sdk.dart';
import 'package:flutter_tools/src/runner/flutter_command_runner.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';
import 'src/context.dart';
void main() {
AnalysisServer server;
Directory tempDir;
setUp(() {
FlutterCommandRunner.initFlutterRoot();
tempDir = Directory.systemTemp.createTempSync('analysis_test');
});
tearDown(() {
tempDir?.deleteSync(recursive: true);
return server?.dispose();
});
group('watch', () {
testUsingContext('AnalysisServer success', () async {
_createSampleProject(tempDir);
await pubGet(directory: tempDir.path);
server = new AnalysisServer(dartSdkPath, <String>[tempDir.path]);
int errorCount = 0;
Future<bool> onDone = server.onAnalyzing.where((bool analyzing) => analyzing == false).first;
server.onErrors.listen((FileAnalysisErrors errors) => errorCount += errors.errors.length);
await server.start();
await onDone;
expect(errorCount, 0);
}, overrides: <Type, dynamic>{
OperatingSystemUtils: os
});
});
testUsingContext('AnalysisServer errors', () async {
_createSampleProject(tempDir, brokenCode: true);
await pubGet(directory: tempDir.path);
server = new AnalysisServer(dartSdkPath, <String>[tempDir.path]);
int errorCount = 0;
Future<bool> onDone = server.onAnalyzing.where((bool analyzing) => analyzing == false).first;
server.onErrors.listen((FileAnalysisErrors errors) => errorCount += errors.errors.length);
await server.start();
await onDone;
expect(errorCount, 2);
}, overrides: <Type, dynamic>{
OperatingSystemUtils: os
});
}
void _createSampleProject(Directory directory, { bool brokenCode: false }) {
File pubspecFile = new File(path.join(directory.path, 'pubspec.yaml'));
pubspecFile.writeAsStringSync('''
name: foo_project
''');
File dartFile = new File(path.join(directory.path, 'lib', 'main.dart'));
dartFile.parent.createSync();
dartFile.writeAsStringSync('''
void main() {
print('hello world');
${brokenCode ? 'prints("hello world");' : ''}
}
''');
}
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