From 18c60d33011c7e7c56ac33a1749cc8c8be488e13 Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Wed, 17 Jan 2018 10:17:52 -0800 Subject: [PATCH] Fix import statements in flutter_tools (#13911) --- dev/bots/analyze-sample-code.dart | 2 +- dev/bots/test.dart | 59 +++++++++++++++---- .../lib/src/commands/update_packages.dart | 2 +- packages/flutter_tools/lib/src/compile.dart | 3 +- .../lib/src/flutter_manifest.dart | 2 +- 5 files changed, 53 insertions(+), 15 deletions(-) diff --git a/dev/bots/analyze-sample-code.dart b/dev/bots/analyze-sample-code.dart index 58fd2b72faf..4ff92104682 100644 --- a/dev/bots/analyze-sample-code.dart +++ b/dev/bots/analyze-sample-code.dart @@ -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); diff --git a/dev/bots/test.dart b/dev/bots/test.dart index 839e08024f0..cb26429ae35 100644 --- a/dev/bots/test.dart +++ b/dev/bots/test.dart @@ -45,10 +45,17 @@ const Map _kShards = const { Future main(List 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 _generateDocs() async { @@ -88,7 +95,8 @@ Future _verifyInternationalizations() async { Future _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 _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 _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 _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 _runFlutterAnalyze(String workingDirectory, { ); } -Future _verifyNoBadImports(String workingDirectory) async { +Future _verifyNoBadImportsInFlutter(String workingDirectory) async { final List errors = []; 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 _findDependencies(String srcPath, List 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>((FileSystemEntity entity) { final Set result = new Set(); @@ -475,6 +490,30 @@ List _deepSearch(Map> map, T start, [ Set seen ]) { return null; } +Future _verifyNoBadImportsInFlutterTools(String workingDirectory) async { + final List errors = []; + 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'); diff --git a/packages/flutter_tools/lib/src/commands/update_packages.dart b/packages/flutter_tools/lib/src/commands/update_packages.dart index 825e4f70ae0..0eb4cf8e416 100644 --- a/packages/flutter_tools/lib/src/commands/update_packages.dart +++ b/packages/flutter_tools/lib/src/commands/update_packages.dart @@ -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'; diff --git a/packages/flutter_tools/lib/src/compile.dart b/packages/flutter_tools/lib/src/compile.dart index 70ece1016f0..74b7af32ef0 100644 --- a/packages/flutter_tools/lib/src/compile.dart +++ b/packages/flutter_tools/lib/src/compile.dart @@ -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'; diff --git a/packages/flutter_tools/lib/src/flutter_manifest.dart b/packages/flutter_tools/lib/src/flutter_manifest.dart index c909ee675b0..e26d9f1efac 100644 --- a/packages/flutter_tools/lib/src/flutter_manifest.dart +++ b/packages/flutter_tools/lib/src/flutter_manifest.dart @@ -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 {