Unverified Commit 7b1d2421 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] Make packages not required for local engine (#55882)

parent 1ac09088
...@@ -152,7 +152,7 @@ class _ManifestAssetBundle implements AssetBundle { ...@@ -152,7 +152,7 @@ class _ManifestAssetBundle implements AssetBundle {
} }
final String assetBasePath = globals.fs.path.dirname(globals.fs.path.absolute(manifestPath)); final String assetBasePath = globals.fs.path.dirname(globals.fs.path.absolute(manifestPath));
final PackageConfig packageConfig = await loadPackageConfigOrFail( final PackageConfig packageConfig = await loadPackageConfigWithLogging(
globals.fs.file(packagesPath), globals.fs.file(packagesPath),
logger: globals.logger, logger: globals.logger,
); );
......
...@@ -154,7 +154,7 @@ class WebAssetServer implements AssetReader { ...@@ -154,7 +154,7 @@ class WebAssetServer implements AssetReader {
address = (await InternetAddress.lookup(hostname)).first; address = (await InternetAddress.lookup(hostname)).first;
} }
final HttpServer httpServer = await HttpServer.bind(address, port); final HttpServer httpServer = await HttpServer.bind(address, port);
final PackageConfig packageConfig = await loadPackageConfigOrFail( final PackageConfig packageConfig = await loadPackageConfigWithLogging(
globals.fs.file(globalPackagesPath), globals.fs.file(globalPackagesPath),
logger: globals.logger, logger: globals.logger,
); );
......
...@@ -231,7 +231,7 @@ class KernelSnapshot extends Target { ...@@ -231,7 +231,7 @@ class KernelSnapshot extends Target {
forceLinkPlatform = false; forceLinkPlatform = false;
} }
final PackageConfig packageConfig = await loadPackageConfigOrFail( final PackageConfig packageConfig = await loadPackageConfigWithLogging(
environment.projectDir.childFile('.packages'), environment.projectDir.childFile('.packages'),
logger: environment.logger, logger: environment.logger,
); );
......
...@@ -62,7 +62,7 @@ class WebEntrypointTarget extends Target { ...@@ -62,7 +62,7 @@ class WebEntrypointTarget extends Target {
final bool shouldInitializePlatform = environment.defines[kInitializePlatform] == 'true'; final bool shouldInitializePlatform = environment.defines[kInitializePlatform] == 'true';
final bool hasPlugins = environment.defines[kHasWebPlugins] == 'true'; final bool hasPlugins = environment.defines[kHasWebPlugins] == 'true';
final Uri importUri = environment.fileSystem.file(targetFile).absolute.uri; final Uri importUri = environment.fileSystem.file(targetFile).absolute.uri;
final PackageConfig packageConfig = await loadPackageConfigOrFail( final PackageConfig packageConfig = await loadPackageConfigWithLogging(
environment.projectDir.childFile('.packages'), environment.projectDir.childFile('.packages'),
logger: environment.logger, logger: environment.logger,
); );
......
...@@ -25,8 +25,12 @@ String _globalPackagesPath; ...@@ -25,8 +25,12 @@ String _globalPackagesPath;
/// Load the package configuration from [file] or throws a [ToolExit] /// Load the package configuration from [file] or throws a [ToolExit]
/// if the operation would fail. /// if the operation would fail.
Future<PackageConfig> loadPackageConfigOrFail(File file, { ///
/// If [nonFatal] is true, in the event of an error an empty package
/// config is returned.
Future<PackageConfig> loadPackageConfigWithLogging(File file, {
@required Logger logger, @required Logger logger,
bool throwOnError = true,
}) { }) {
final FileSystem fileSystem = file.fileSystem; final FileSystem fileSystem = file.fileSystem;
return loadPackageConfigUri( return loadPackageConfigUri(
...@@ -39,6 +43,9 @@ Future<PackageConfig> loadPackageConfigOrFail(File file, { ...@@ -39,6 +43,9 @@ Future<PackageConfig> loadPackageConfigOrFail(File file, {
return Future<Uint8List>.value(configFile.readAsBytesSync()); return Future<Uint8List>.value(configFile.readAsBytesSync());
}, },
onError: (dynamic error) { onError: (dynamic error) {
if (!throwOnError) {
return;
}
logger.printTrace(error.toString()); logger.printTrace(error.toString());
String message = '${file.path} does not exist.'; String message = '${file.path} does not exist.';
final String pubspecPath = fileSystem.path.absolute(fileSystem.path.dirname(file.path), 'pubspec.yaml'); final String pubspecPath = fileSystem.path.absolute(fileSystem.path.dirname(file.path), 'pubspec.yaml');
......
...@@ -305,7 +305,7 @@ Future<List<Plugin>> findPlugins(FlutterProject project) async { ...@@ -305,7 +305,7 @@ Future<List<Plugin>> findPlugins(FlutterProject project) async {
project.directory.path, project.directory.path,
globalPackagesPath, globalPackagesPath,
); );
final PackageConfig packageConfig = await loadPackageConfigOrFail( final PackageConfig packageConfig = await loadPackageConfigWithLogging(
globals.fs.file(packagesFile), globals.fs.file(packagesFile),
logger: globals.logger, logger: globals.logger,
); );
......
...@@ -157,7 +157,7 @@ class HotRunner extends ResidentRunner { ...@@ -157,7 +157,7 @@ class HotRunner extends ResidentRunner {
final Stopwatch stopwatch = Stopwatch()..start(); final Stopwatch stopwatch = Stopwatch()..start();
final UpdateFSReport results = UpdateFSReport(success: true); final UpdateFSReport results = UpdateFSReport(success: true);
final List<Uri> invalidated = <Uri>[Uri.parse(libraryId)]; final List<Uri> invalidated = <Uri>[Uri.parse(libraryId)];
final PackageConfig packageConfig = await loadPackageConfigOrFail( final PackageConfig packageConfig = await loadPackageConfigWithLogging(
globals.fs.file(globalPackagesPath), globals.fs.file(globalPackagesPath),
logger: globals.logger, logger: globals.logger,
); );
...@@ -355,7 +355,7 @@ class HotRunner extends ResidentRunner { ...@@ -355,7 +355,7 @@ class HotRunner extends ResidentRunner {
firstBuildTime = DateTime.now(); firstBuildTime = DateTime.now();
final List<Future<bool>> startupTasks = <Future<bool>>[]; final List<Future<bool>> startupTasks = <Future<bool>>[];
final PackageConfig packageConfig = await loadPackageConfigOrFail( final PackageConfig packageConfig = await loadPackageConfigWithLogging(
globals.fs.file(globalPackagesPath), globals.fs.file(globalPackagesPath),
logger: globals.logger, logger: globals.logger,
); );
...@@ -1300,7 +1300,7 @@ class ProjectFileInvalidator { ...@@ -1300,7 +1300,7 @@ class ProjectFileInvalidator {
} }
Future<PackageConfig> _createPackageConfig(String packagesPath) { Future<PackageConfig> _createPackageConfig(String packagesPath) {
return loadPackageConfigOrFail( return loadPackageConfigWithLogging(
_fileSystem.file(globalPackagesPath), _fileSystem.file(globalPackagesPath),
logger: _logger, logger: _logger,
); );
......
...@@ -354,9 +354,10 @@ class FlutterCommandRunner extends CommandRunner<void> { ...@@ -354,9 +354,10 @@ class FlutterCommandRunner extends CommandRunner<void> {
if (engineSourcePath == null && globalResults['local-engine'] != null) { if (engineSourcePath == null && globalResults['local-engine'] != null) {
try { try {
final PackageConfig packageConfig = await loadPackageConfigOrFail( final PackageConfig packageConfig = await loadPackageConfigWithLogging(
globals.fs.file(globalPackagesPath), globals.fs.file(globalPackagesPath),
logger: globals.logger, logger: globals.logger,
throwOnError: false,
); );
Uri engineUri = packageConfig[kFlutterEnginePackageName]?.packageUriRoot; Uri engineUri = packageConfig[kFlutterEnginePackageName]?.packageUriRoot;
// Skip if sky_engine is the self-contained one. // Skip if sky_engine is the self-contained one.
......
...@@ -249,7 +249,7 @@ Future<Directory> _templateImageDirectory(String name, FileSystem fileSystem) as ...@@ -249,7 +249,7 @@ Future<Directory> _templateImageDirectory(String name, FileSystem fileSystem) as
if (!fileSystem.file(packageFilePath).existsSync()) { if (!fileSystem.file(packageFilePath).existsSync()) {
await _ensurePackageDependencies(toolPackagePath); await _ensurePackageDependencies(toolPackagePath);
} }
final PackageConfig packageConfig = await loadPackageConfigOrFail( final PackageConfig packageConfig = await loadPackageConfigWithLogging(
fileSystem.file(packageFilePath), fileSystem.file(packageFilePath),
logger: globals.logger, logger: globals.logger,
); );
......
...@@ -97,12 +97,12 @@ class FlutterWebPlatform extends PlatformPlugin { ...@@ -97,12 +97,12 @@ class FlutterWebPlatform extends PlatformPlugin {
); );
} }
final Future<PackageConfig> _packagesFuture = loadPackageConfigOrFail( final Future<PackageConfig> _packagesFuture = loadPackageConfigWithLogging(
globals.fs.file(globalPackagesPath), globals.fs.file(globalPackagesPath),
logger: globals.logger, logger: globals.logger,
); );
final Future<PackageConfig> _flutterToolsPackageMap = loadPackageConfigOrFail( final Future<PackageConfig> _flutterToolsPackageMap = loadPackageConfigWithLogging(
globals.fs.file(globals.fs.path.join( globals.fs.file(globals.fs.path.join(
Cache.flutterRoot, Cache.flutterRoot,
'packages', 'packages',
......
...@@ -129,7 +129,7 @@ class TestCompiler { ...@@ -129,7 +129,7 @@ class TestCompiler {
if (!isEmpty) { if (!isEmpty) {
return; return;
} }
_packageConfig ??= await loadPackageConfigOrFail( _packageConfig ??= await loadPackageConfigWithLogging(
globals.fs.file(globalPackagesPath), globals.fs.file(globalPackagesPath),
logger: globals.logger, logger: globals.logger,
); );
......
...@@ -131,7 +131,7 @@ void main() { ...@@ -131,7 +131,7 @@ void main() {
}, initializeFlutterRoot: false); }, initializeFlutterRoot: false);
testUsingContext('works if --local-engine is specified and --local-engine-src-path is specified', () async { testUsingContext('works if --local-engine is specified and --local-engine-src-path is specified', () async {
fs.file(_kDotPackages).writeAsStringSync('\n'); // Intentionally do not create a package_config to verify that it is not required.
fs.directory('$_kArbitraryEngineRoot/src/out/ios_debug').createSync(recursive: true); fs.directory('$_kArbitraryEngineRoot/src/out/ios_debug').createSync(recursive: true);
fs.directory('$_kArbitraryEngineRoot/src/out/host_debug').createSync(recursive: true); fs.directory('$_kArbitraryEngineRoot/src/out/host_debug').createSync(recursive: true);
......
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