Fix import statements in flutter_tools (#13911)

This commit is contained in:
Ian Hickson 2018-01-17 10:17:52 -08:00 committed by GitHub
parent 7b6af52c92
commit 18c60d3301
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 53 additions and 15 deletions

View file

@ -171,7 +171,7 @@ dependencies:
errors.removeLast();
int errorCount = 0;
for (String error in errors) {
const String kBullet = '';
final String kBullet = Platform.isWindows ? ' - ' : '';
const String kColon = ':';
final RegExp atRegExp = new RegExp(r' at .*main.dart:');
final int start = error.indexOf(kBullet);

View file

@ -45,10 +45,17 @@ const Map<String, ShardRunner> _kShards = const <String, ShardRunner>{
Future<Null> main(List<String> args) async {
flutterTestArgs.addAll(args);
final String shard = Platform.environment['SHARD'] ?? 'tests';
if (!_kShards.containsKey(shard))
throw new ArgumentError('Invalid shard: $shard');
await _kShards[shard]();
final String shard = Platform.environment['SHARD'];
if (shard != null) {
if (!_kShards.containsKey(shard))
throw new ArgumentError('Invalid shard: $shard');
await _kShards[shard]();
} else {
for (String currentShard in _kShards.keys) {
print('${bold}SHARD=$currentShard$reset');
await _kShards[currentShard]();
}
}
}
Future<Null> _generateDocs() async {
@ -88,7 +95,8 @@ Future<Null> _verifyInternationalizations() async {
Future<Null> _analyzeRepo() async {
await _verifyGeneratedPluginRegistrants(flutterRoot);
await _verifyNoBadImports(flutterRoot);
await _verifyNoBadImportsInFlutter(flutterRoot);
await _verifyNoBadImportsInFlutterTools(flutterRoot);
await _verifyInternationalizations();
// Analyze all the Dart code in the repo.
@ -181,6 +189,10 @@ Future<Null> _runCoverage() async {
print('${bold}DONE: test.dart does not run coverage in Travis$reset');
return;
}
if (Platform.isWindows) {
print('${bold}DONE: test.dart does not run coverage on Windows$reset');
return;
}
final File coverageFile = new File(path.join(flutterRoot, 'packages', 'flutter', 'coverage', 'lcov.info'));
if (!coverageFile.existsSync()) {
@ -214,8 +226,11 @@ Future<Null> _pubRunTest(
if (new Directory(pubCache).existsSync()) {
pubEnvironment['PUB_CACHE'] = pubCache;
}
return _runCommand(pub, args, workingDirectory: workingDirectory,
environment: pubEnvironment);
return _runCommand(
pub, args,
workingDirectory: workingDirectory,
environment: pubEnvironment,
);
}
class EvalResult {
@ -329,7 +344,7 @@ Future<Null> _runFlutterTest(String workingDirectory, {
workingDirectory: workingDirectory,
expectFailure: expectFailure,
printOutput: printOutput,
skip: skip || Platform.isWindows, // TODO(goderbauer): run on Windows when sky_shell is available
skip: skip,
);
}
@ -351,7 +366,7 @@ Future<Null> _runFlutterAnalyze(String workingDirectory, {
);
}
Future<Null> _verifyNoBadImports(String workingDirectory) async {
Future<Null> _verifyNoBadImportsInFlutter(String workingDirectory) async {
final List<String> errors = <String>[];
final String libPath = path.join(workingDirectory, 'packages', 'flutter', 'lib');
final String srcPath = path.join(workingDirectory, 'packages', 'flutter', 'lib', 'src');
@ -424,7 +439,7 @@ final RegExp _importPattern = new RegExp(r"import 'package:flutter/([^.]+)\.dart
final RegExp _importMetaPattern = new RegExp(r"import 'package:meta/meta.dart'");
Set<String> _findDependencies(String srcPath, List<String> errors, { bool checkForMeta: false }) {
return new Directory(srcPath).listSync().where((FileSystemEntity entity) {
return new Directory(srcPath).listSync(recursive: true).where((FileSystemEntity entity) {
return entity is File && path.extension(entity.path) == '.dart';
}).map<Set<String>>((FileSystemEntity entity) {
final Set<String> result = new Set<String>();
@ -475,6 +490,30 @@ List<T> _deepSearch<T>(Map<T, Set<T>> map, T start, [ Set<T> seen ]) {
return null;
}
Future<Null> _verifyNoBadImportsInFlutterTools(String workingDirectory) async {
final List<String> errors = <String>[];
for (FileSystemEntity entity in new Directory(path.join(workingDirectory, 'packages', 'flutter_tools', 'lib'))
.listSync(recursive: true)
.where((FileSystemEntity entity) => entity is File && path.extension(entity.path) == '.dart')) {
final File file = entity;
if (file.readAsStringSync().contains('package:flutter_tools/')) {
errors.add('$yellow${file.path}$reset imports flutter_tools.');
}
}
// Fail if any errors
if (errors.isNotEmpty) {
print('$red━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━$reset');
if (errors.length == 1) {
print('${bold}An error was detected when looking at import dependencies within the flutter_tools package:$reset\n');
} else {
print('${bold}Multiple errors were detected when looking at import dependencies within the flutter_tools package:$reset\n');
}
print(errors.join('\n\n'));
print('$red━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━$reset\n');
exit(1);
}
}
void _printProgress(String action, String workingDir, String command) {
const String arrow = '';
print('$arrow $action: cd $cyan$workingDir$reset; $yellow$command$reset');

View file

@ -5,9 +5,9 @@
import 'dart:async';
import 'dart:collection';
import 'package:flutter_tools/src/base/common.dart';
import 'package:meta/meta.dart';
import '../base/common.dart';
import '../base/file_system.dart';
import '../base/logger.dart';
import '../base/net.dart';

View file

@ -5,11 +5,10 @@
import 'dart:async';
import 'dart:convert';
import 'package:flutter_tools/src/base/common.dart';
import 'package:flutter_tools/src/base/process_manager.dart';
import 'package:usage/uuid/uuid.dart';
import 'artifacts.dart';
import 'base/common.dart';
import 'base/file_system.dart';
import 'base/io.dart';
import 'base/process_manager.dart';

View file

@ -4,12 +4,12 @@
import 'dart:async';
import 'package:flutter_tools/src/globals.dart';
import 'package:json_schema/json_schema.dart';
import 'package:yaml/yaml.dart';
import 'base/file_system.dart';
import 'cache.dart';
import 'globals.dart';
/// A wrapper around the `flutter` section in the `pubspec.yaml` file.
class FlutterManifest {