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