diff --git a/packages/flutter_tools/bin/tool_backend.dart b/packages/flutter_tools/bin/tool_backend.dart index bc651302802..c024c0e662e 100644 --- a/packages/flutter_tools/bin/tool_backend.dart +++ b/packages/flutter_tools/bin/tool_backend.dart @@ -2,9 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// Do not add package imports to this file. import 'dart:convert'; // ignore: dart_convert_import. import 'dart:io'; // ignore: dart_io_import. -import 'package:path/path.dart' as path; // ignore: package_path_import. /// Executes the required flutter tasks for a desktop build. Future main(List arguments) async { @@ -18,7 +18,7 @@ Future main(List arguments) async { final String flutterEngine = Platform.environment['FLUTTER_ENGINE']; final String flutterRoot = Platform.environment['FLUTTER_ROOT']; final String flutterTarget = Platform.environment['FLUTTER_TARGET'] - ?? path.join('lib', 'main.dart'); + ?? pathJoin(['lib', 'main.dart']); final String localEngine = Platform.environment['LOCAL_ENGINE']; final String projectDirectory = Platform.environment['PROJECT_DIR']; final String splitDebugInfo = Platform.environment['SPLIT_DEBUG_INFO']; @@ -42,9 +42,14 @@ or '''); exit(1); } - - final String flutterExecutable = path.join( - flutterRoot, 'bin', Platform.isWindows ? 'flutter.bat' : 'flutter'); + final String flutterExecutable = pathJoin([ + flutterRoot, + 'bin', + if (Platform.isWindows) + 'flutter.bat' + else + 'flutter' + ]); final String bundlePlatform = targetPlatform == 'windows-x64' ? 'windows' : 'linux'; final String target = '${buildMode}_bundle_${bundlePlatform}_assets'; @@ -89,3 +94,11 @@ or exit(1); } } + +/// Perform a simple path join on the segments based on the current platform. +/// +/// Does not normalize paths that have repeated separators. +String pathJoin(List segments) { + final String separator = Platform.isWindows ? r'\' : '/'; + return segments.join(separator); +} diff --git a/packages/flutter_tools/test/general.shard/forbidden_imports_test.dart b/packages/flutter_tools/test/general.shard/forbidden_imports_test.dart index ef93f747c2c..fdeb0aa6f68 100644 --- a/packages/flutter_tools/test/general.shard/forbidden_imports_test.dart +++ b/packages/flutter_tools/test/general.shard/forbidden_imports_test.dart @@ -210,6 +210,16 @@ void main() { } } }); + + test('no import of packages in tool_backend.dart', () { + final File file = globals.fs.file(globals.fs.path.join(flutterTools, 'bin', 'tool_backend.dart')); + for (final String line in file.readAsLinesSync()) { + if (line.startsWith(RegExp(r'import.*package:.*'))) { + final String relativePath = globals.fs.path.relative(file.path, from:flutterTools); + fail('$relativePath imports a package'); + } + } + }); } bool _isDartFile(FileSystemEntity entity) => entity is File && entity.path.endsWith('.dart');