Unverified Commit 78efd3eb authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] ensure desktop builds can run without flutter_tools' package_config (#62426)

parent 50828a13
......@@ -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<void> main(List<String> arguments) async {
......@@ -18,7 +18,7 @@ Future<void> main(List<String> 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(<String>['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(<String>[
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<String> segments) {
final String separator = Platform.isWindows ? r'\' : '/';
return segments.join(separator);
}
......@@ -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');
......
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