Unverified Commit d46da3ae authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] remove PackageMap and finish PackageConfig migration (#55244)

parent d2572c8f
...@@ -111,7 +111,7 @@ Future<void> run(List<String> args) async { ...@@ -111,7 +111,7 @@ Future<void> run(List<String> args) async {
// TODO(tvolkert): Remove once flutter_tester no longer looks for this. // TODO(tvolkert): Remove once flutter_tester no longer looks for this.
globals.fs.link(sdkRootDest.childFile('platform.dill').path).createSync('platform_strong.dill'); globals.fs.link(sdkRootDest.childFile('platform.dill').path).createSync('platform_strong.dill');
PackageMap.globalPackagesPath = globalPackagesPath =
globals.fs.path.normalize(globals.fs.path.absolute(argResults[_kOptionPackages] as String)); globals.fs.path.normalize(globals.fs.path.absolute(argResults[_kOptionPackages] as String));
Directory testDirectory; Directory testDirectory;
......
...@@ -125,7 +125,7 @@ class _ManifestAssetBundle implements AssetBundle { ...@@ -125,7 +125,7 @@ class _ManifestAssetBundle implements AssetBundle {
bool reportLicensedPackages = false, bool reportLicensedPackages = false,
}) async { }) async {
assetDirPath ??= getAssetBuildDirectory(); assetDirPath ??= getAssetBuildDirectory();
packagesPath ??= globals.fs.path.absolute(PackageMap.globalPackagesPath); packagesPath ??= globals.fs.path.absolute(globalPackagesPath);
FlutterManifest flutterManifest; FlutterManifest flutterManifest;
try { try {
flutterManifest = FlutterManifest.createFromPath( flutterManifest = FlutterManifest.createFromPath(
...@@ -152,15 +152,9 @@ class _ManifestAssetBundle implements AssetBundle { ...@@ -152,15 +152,9 @@ 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 loadPackageConfigUri( final PackageConfig packageConfig = await loadPackageConfigOrFail(
globals.fs.file(packagesPath).absolute.uri, globals.fs.file(packagesPath),
loader: (Uri uri) { logger: globals.logger,
final File file = globals.fs.file(uri);
if (!file.existsSync()) {
return null;
}
return file.readAsBytes();
},
); );
final List<Uri> wildcardDirectories = <Uri>[]; final List<Uri> wildcardDirectories = <Uri>[];
......
...@@ -144,15 +144,9 @@ class WebAssetServer implements AssetReader { ...@@ -144,15 +144,9 @@ 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 loadPackageConfigUri( final PackageConfig packageConfig = await loadPackageConfigOrFail(
globals.fs.file(PackageMap.globalPackagesPath).absolute.uri, globals.fs.file(globalPackagesPath),
loader: (Uri uri) { logger: globals.logger,
final File file = globals.fs.file(uri);
if (!file.existsSync()) {
return null;
}
return file.readAsBytes();
}
); );
final Map<String, String> digests = <String, String>{}; final Map<String, String> digests = <String, String>{};
final Map<String, String> modules = <String, String>{}; final Map<String, String> modules = <String, String>{};
......
...@@ -551,7 +551,7 @@ class _ResidentWebRunner extends ResidentWebRunner { ...@@ -551,7 +551,7 @@ class _ResidentWebRunner extends ResidentWebRunner {
..createSync(); ..createSync();
result = _generatedEntrypointDirectory.childFile('web_entrypoint.dart'); result = _generatedEntrypointDirectory.childFile('web_entrypoint.dart');
final bool hasWebPlugins = findPlugins(flutterProject) final bool hasWebPlugins = (await findPlugins(flutterProject))
.any((Plugin p) => p.platforms.containsKey(WebPlugin.kConfigKey)); .any((Plugin p) => p.platforms.containsKey(WebPlugin.kConfigKey));
await injectPlugins(flutterProject, checkProjects: true); await injectPlugins(flutterProject, checkProjects: true);
......
...@@ -41,7 +41,7 @@ class BuildRunnerWebCompilationProxy extends WebCompilationProxy { ...@@ -41,7 +41,7 @@ class BuildRunnerWebCompilationProxy extends WebCompilationProxy {
.childDirectory('.dart_tool') .childDirectory('.dart_tool')
.createSync(); .createSync();
final FlutterProject flutterProject = FlutterProject.fromDirectory(projectDirectory); final FlutterProject flutterProject = FlutterProject.fromDirectory(projectDirectory);
final bool hasWebPlugins = findPlugins(flutterProject) final bool hasWebPlugins = (await findPlugins(flutterProject))
.any((Plugin p) => p.platforms.containsKey(WebPlugin.kConfigKey)); .any((Plugin p) => p.platforms.containsKey(WebPlugin.kConfigKey));
final BuildDaemonClient client = await const BuildDaemonCreator().startBuildDaemon( final BuildDaemonClient client = await const BuildDaemonCreator().startBuildDaemon(
projectDirectory.path, projectDirectory.path,
......
...@@ -9,6 +9,7 @@ import '../../base/build.dart'; ...@@ -9,6 +9,7 @@ import '../../base/build.dart';
import '../../base/file_system.dart'; import '../../base/file_system.dart';
import '../../build_info.dart'; import '../../build_info.dart';
import '../../compile.dart'; import '../../compile.dart';
import '../../dart/package_map.dart';
import '../../globals.dart' as globals; import '../../globals.dart' as globals;
import '../../project.dart'; import '../../project.dart';
import '../build_system.dart'; import '../build_system.dart';
...@@ -231,15 +232,9 @@ class KernelSnapshot extends Target { ...@@ -231,15 +232,9 @@ class KernelSnapshot extends Target {
forceLinkPlatform = false; forceLinkPlatform = false;
} }
final PackageConfig packageConfig = await loadPackageConfigUri( final PackageConfig packageConfig = await loadPackageConfigOrFail(
packagesFile.absolute.uri, environment.projectDir.childFile('.packages'),
loader: (Uri uri) { logger: environment.logger,
final File file = globals.fs.file(uri);
if (!file.existsSync()) {
return null;
}
return file.readAsBytes();
}
); );
final CompilerOutput output = await compiler.compile( final CompilerOutput output = await compiler.compile(
......
...@@ -57,15 +57,9 @@ class WebEntrypointTarget extends Target { ...@@ -57,15 +57,9 @@ 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 loadPackageConfigUri( final PackageConfig packageConfig = await loadPackageConfigOrFail(
environment.projectDir.childFile('.packages').absolute.uri, environment.projectDir.childFile('.packages'),
loader: (Uri uri) { logger: environment.logger,
final File file = environment.fileSystem.file(uri);
if (!file.existsSync()) {
return null;
}
return file.readAsBytes();
}
); );
// Use the PackageConfig to find the correct package-scheme import path // Use the PackageConfig to find the correct package-scheme import path
...@@ -159,7 +153,7 @@ class Dart2JSTarget extends Target { ...@@ -159,7 +153,7 @@ class Dart2JSTarget extends Target {
final bool csp = environment.defines[kCspMode] == 'true'; final bool csp = environment.defines[kCspMode] == 'true';
final BuildMode buildMode = getBuildModeForName(environment.defines[kBuildMode]); final BuildMode buildMode = getBuildModeForName(environment.defines[kBuildMode]);
final String specPath = globals.fs.path.join(globals.artifacts.getArtifactPath(Artifact.flutterWebSdk), 'libraries.json'); final String specPath = globals.fs.path.join(globals.artifacts.getArtifactPath(Artifact.flutterWebSdk), 'libraries.json');
final String packageFile = PackageMap.globalPackagesPath; final String packageFile = globalPackagesPath;
final File outputKernel = environment.buildDir.childFile('app.dill'); final File outputKernel = environment.buildDir.childFile('app.dill');
final File outputFile = environment.buildDir.childFile('main.dart.js'); final File outputFile = environment.buildDir.childFile('main.dart.js');
final List<String> dartDefines = parseDartDefines(environment); final List<String> dartDefines = parseDartDefines(environment);
......
...@@ -74,7 +74,7 @@ class BundleBuilder { ...@@ -74,7 +74,7 @@ class BundleBuilder {
mainPath ??= defaultMainPath; mainPath ??= defaultMainPath;
depfilePath ??= defaultDepfilePath; depfilePath ??= defaultDepfilePath;
assetDirPath ??= getAssetBuildDirectory(); assetDirPath ??= getAssetBuildDirectory();
packagesPath ??= globals.fs.path.absolute(PackageMap.globalPackagesPath); packagesPath ??= globals.fs.path.absolute(globalPackagesPath);
final FlutterProject flutterProject = FlutterProject.current(); final FlutterProject flutterProject = FlutterProject.current();
await buildWithAssemble( await buildWithAssemble(
buildMode: buildInfo.mode, buildMode: buildInfo.mode,
...@@ -177,7 +177,7 @@ Future<AssetBundle> buildAssets({ ...@@ -177,7 +177,7 @@ Future<AssetBundle> buildAssets({
bool reportLicensedPackages = false, bool reportLicensedPackages = false,
}) async { }) async {
assetDirPath ??= getAssetBuildDirectory(); assetDirPath ??= getAssetBuildDirectory();
packagesPath ??= globals.fs.path.absolute(PackageMap.globalPackagesPath); packagesPath ??= globals.fs.path.absolute(globalPackagesPath);
// Build the asset bundle. // Build the asset bundle.
final AssetBundle assetBundle = AssetBundleFactory.instance.createBundle(); final AssetBundle assetBundle = AssetBundleFactory.instance.createBundle();
......
...@@ -470,14 +470,14 @@ void restoreTestRunner() { ...@@ -470,14 +470,14 @@ void restoreTestRunner() {
Future<void> _runTests(List<String> testArgs, Map<String, String> environment) async { Future<void> _runTests(List<String> testArgs, Map<String, String> environment) async {
globals.printTrace('Running driver tests.'); globals.printTrace('Running driver tests.');
PackageMap.globalPackagesPath = globals.fs.path.normalize(globals.fs.path.absolute(PackageMap.globalPackagesPath)); globalPackagesPath = globals.fs.path.normalize(globals.fs.path.absolute(globalPackagesPath));
final String dartVmPath = globals.fs.path.join(dartSdkPath, 'bin', 'dart'); final String dartVmPath = globals.fs.path.join(dartSdkPath, 'bin', 'dart');
final int result = await processUtils.stream( final int result = await processUtils.stream(
<String>[ <String>[
dartVmPath, dartVmPath,
...dartVmFlags, ...dartVmFlags,
...testArgs, ...testArgs,
'--packages=${PackageMap.globalPackagesPath}', '--packages=$globalPackagesPath',
'-rexpanded', '-rexpanded',
], ],
environment: environment, environment: environment,
......
...@@ -29,7 +29,7 @@ class InjectPluginsCommand extends FlutterCommand { ...@@ -29,7 +29,7 @@ class InjectPluginsCommand extends FlutterCommand {
@override @override
Future<FlutterCommandResult> runCommand() async { Future<FlutterCommandResult> runCommand() async {
final FlutterProject project = FlutterProject.current(); final FlutterProject project = FlutterProject.current();
refreshPluginsList(project, checkProjects: true); await refreshPluginsList(project, checkProjects: true);
await injectPlugins(project, checkProjects: true); await injectPlugins(project, checkProjects: true);
final bool result = hasPlugins(project); final bool result = hasPlugins(project);
if (result) { if (result) {
......
...@@ -2,86 +2,53 @@ ...@@ -2,86 +2,53 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:typed_data';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
// TODO(bkonyi): remove deprecated member usage, https://github.com/flutter/flutter/issues/51951 import 'package:package_config/package_config.dart';
// ignore: deprecated_member_use
import 'package:package_config/packages_file.dart' as packages_file;
import '../base/common.dart';
import '../base/file_system.dart'; import '../base/file_system.dart';
import '../globals.dart' as globals hide fs; import '../base/logger.dart';
const String kPackagesFileName = '.packages'; const String kPackagesFileName = '.packages';
Map<String, Uri> _parse(String packagesPath, FileSystem fileSystem) { String get globalPackagesPath => _globalPackagesPath ?? kPackagesFileName;
final List<int> source = fileSystem.file(packagesPath).readAsBytesSync();
return packages_file.parse(source,
Uri.file(packagesPath, windows: globals.platform.isWindows));
}
class PackageMap {
PackageMap(this.packagesPath, {
@required FileSystem fileSystem,
}) : _fileSystem = fileSystem;
/// Create a [PackageMap] for testing.
PackageMap.test(Map<String, Uri> input, {
@required FileSystem fileSystem,
}) : packagesPath = '.packages',
_map = input,
_fileSystem = fileSystem;
final FileSystem _fileSystem;
static String get globalPackagesPath => _globalPackagesPath ?? kPackagesFileName; set globalPackagesPath(String value) {
static set globalPackagesPath(String value) {
_globalPackagesPath = value; _globalPackagesPath = value;
} }
static bool get isUsingCustomPackagesPath => _globalPackagesPath != null;
static String _globalPackagesPath;
final String packagesPath;
/// Load and parses the .packages file.
void load() {
_map ??= _parse(packagesPath, _fileSystem);
}
Map<String, Uri> get map {
load();
return _map;
}
Map<String, Uri> _map;
/// Returns the path to [packageUri].
String pathForPackage(Uri packageUri) => uriForPackage(packageUri).path;
/// Returns the path to [packageUri] as URL.
Uri uriForPackage(Uri packageUri) {
assert(packageUri.scheme == 'package');
final List<String> pathSegments = packageUri.pathSegments.toList();
final String packageName = pathSegments.removeAt(0);
final Uri packageBase = map[packageName];
if (packageBase == null) {
return null;
}
final String packageRelativePath = _fileSystem.path.joinAll(pathSegments);
return packageBase.resolveUri(_fileSystem.path.toUri(packageRelativePath));
}
String checkValid() { bool get isUsingCustomPackagesPath => _globalPackagesPath != null;
if (_fileSystem.isFileSync(packagesPath)) {
String _globalPackagesPath;
/// Load the package configuration from [file] or throws a [ToolExit]
/// if the operation would fail.
Future<PackageConfig> loadPackageConfigOrFail(File file, {
@required Logger logger,
}) {
final FileSystem fileSystem = file.fileSystem;
return loadPackageConfigUri(
file.absolute.uri,
loader: (Uri uri) {
final File configFile = fileSystem.file(uri);
if (!configFile.existsSync()) {
return null; return null;
} }
String message = '$packagesPath does not exist.'; return Future<Uint8List>.value(configFile.readAsBytesSync());
final String pubspecPath = _fileSystem.path.absolute(_fileSystem.path.dirname(packagesPath), 'pubspec.yaml'); },
if (_fileSystem.isFileSync(pubspecPath)) { onError: (dynamic error) {
logger.printTrace(error.toString());
String message = '${file.path} does not exist.';
final String pubspecPath = fileSystem.path.absolute(fileSystem.path.dirname(file.path), 'pubspec.yaml');
if (fileSystem.isFileSync(pubspecPath)) {
message += '\nDid you run "flutter pub get" in this directory?'; message += '\nDid you run "flutter pub get" in this directory?';
} else { } else {
message += '\nDid you run this command from the same directory as your pubspec.yaml file?'; message += '\nDid you run this command from the same directory as your pubspec.yaml file?';
} }
return message; logger.printError(message);
throwToolExit(null);
} }
);
} }
...@@ -16,7 +16,7 @@ import '../project.dart'; ...@@ -16,7 +16,7 @@ import '../project.dart';
Future<void> processPodsIfNeeded(XcodeBasedProject xcodeProject, String buildDirectory, BuildMode buildMode) async { Future<void> processPodsIfNeeded(XcodeBasedProject xcodeProject, String buildDirectory, BuildMode buildMode) async {
final FlutterProject project = xcodeProject.parent; final FlutterProject project = xcodeProject.parent;
// Ensure that the plugin list is up to date, since hasPlugins relies on it. // Ensure that the plugin list is up to date, since hasPlugins relies on it.
refreshPluginsList(project); await refreshPluginsList(project);
if (!(hasPlugins(project) || (project.isModule && xcodeProject.podfile.existsSync()))) { if (!(hasPlugins(project) || (project.isModule && xcodeProject.podfile.existsSync()))) {
return; return;
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import 'dart:async'; import 'dart:async';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:package_config/package_config.dart';
import 'package:yaml/yaml.dart'; import 'package:yaml/yaml.dart';
import 'android/gradle.dart'; import 'android/gradle.dart';
...@@ -298,26 +299,23 @@ Plugin _pluginFromPackage(String name, Uri packageRoot) { ...@@ -298,26 +299,23 @@ Plugin _pluginFromPackage(String name, Uri packageRoot) {
); );
} }
List<Plugin> findPlugins(FlutterProject project) { Future<List<Plugin>> findPlugins(FlutterProject project) async {
final List<Plugin> plugins = <Plugin>[]; final List<Plugin> plugins = <Plugin>[];
Map<String, Uri> packages;
try {
final String packagesFile = globals.fs.path.join( final String packagesFile = globals.fs.path.join(
project.directory.path, project.directory.path,
PackageMap.globalPackagesPath, globalPackagesPath,
); );
packages = PackageMap(packagesFile, fileSystem: globals.fs).map; final PackageConfig packageConfig = await loadPackageConfigOrFail(
} on FormatException catch (e) { globals.fs.file(packagesFile),
globals.printTrace('Invalid .packages file: $e'); logger: globals.logger,
return plugins; );
} for (final Package package in packageConfig.packages) {
packages.forEach((String name, Uri uri) { final Uri packageRoot = package.packageUriRoot.resolve('..');
final Uri packageRoot = uri.resolve('..'); final Plugin plugin = _pluginFromPackage(package.name, packageRoot);
final Plugin plugin = _pluginFromPackage(name, packageRoot);
if (plugin != null) { if (plugin != null) {
plugins.add(plugin); plugins.add(plugin);
} }
}); }
return plugins; return plugins;
} }
...@@ -1065,8 +1063,8 @@ void _createPlatformPluginSymlinks(Directory symlinkDirectory, List<dynamic> pla ...@@ -1065,8 +1063,8 @@ void _createPlatformPluginSymlinks(Directory symlinkDirectory, List<dynamic> pla
/// which already exist. /// which already exist.
/// ///
/// Assumes `pub get` has been executed since last change to `pubspec.yaml`. /// Assumes `pub get` has been executed since last change to `pubspec.yaml`.
void refreshPluginsList(FlutterProject project, {bool checkProjects = false}) { Future<void> refreshPluginsList(FlutterProject project, {bool checkProjects = false}) async {
final List<Plugin> plugins = findPlugins(project); final List<Plugin> plugins = await findPlugins(project);
// TODO(franciscojma): Remove once migration is complete. // TODO(franciscojma): Remove once migration is complete.
// Write the legacy plugin files to avoid breaking existing apps. // Write the legacy plugin files to avoid breaking existing apps.
...@@ -1093,7 +1091,7 @@ void refreshPluginsList(FlutterProject project, {bool checkProjects = false}) { ...@@ -1093,7 +1091,7 @@ void refreshPluginsList(FlutterProject project, {bool checkProjects = false}) {
/// ///
/// Assumes [refreshPluginsList] has been called since last change to `pubspec.yaml`. /// Assumes [refreshPluginsList] has been called since last change to `pubspec.yaml`.
Future<void> injectPlugins(FlutterProject project, {bool checkProjects = false}) async { Future<void> injectPlugins(FlutterProject project, {bool checkProjects = false}) async {
final List<Plugin> plugins = findPlugins(project); final List<Plugin> plugins = await findPlugins(project);
if ((checkProjects && project.android.existsSync()) || !checkProjects) { if ((checkProjects && project.android.existsSync()) || !checkProjects) {
await _writeAndroidPluginRegistrant(project, plugins); await _writeAndroidPluginRegistrant(project, plugins);
} }
......
...@@ -226,7 +226,7 @@ class FlutterProject { ...@@ -226,7 +226,7 @@ class FlutterProject {
if (!directory.existsSync() || hasExampleApp) { if (!directory.existsSync() || hasExampleApp) {
return; return;
} }
refreshPluginsList(this); await refreshPluginsList(this);
if ((android.existsSync() && checkProjects) || !checkProjects) { if ((android.existsSync() && checkProjects) || !checkProjects) {
await android.ensureReadyForPlatformSpecificTooling(); await android.ensureReadyForPlatformSpecificTooling();
} }
......
...@@ -59,7 +59,7 @@ class FlutterDevice { ...@@ -59,7 +59,7 @@ class FlutterDevice {
targetModel: targetModel, targetModel: targetModel,
experimentalFlags: experimentalFlags, experimentalFlags: experimentalFlags,
dartDefines: buildInfo.dartDefines, dartDefines: buildInfo.dartDefines,
packagesPath: PackageMap.globalPackagesPath, packagesPath: globalPackagesPath,
); );
/// Create a [FlutterDevice] with optional code generation enabled. /// Create a [FlutterDevice] with optional code generation enabled.
...@@ -107,7 +107,7 @@ class FlutterDevice { ...@@ -107,7 +107,7 @@ class FlutterDevice {
dartDefines: buildInfo.dartDefines, dartDefines: buildInfo.dartDefines,
librariesSpec: globals.fs.file(globals.artifacts librariesSpec: globals.fs.file(globals.artifacts
.getArtifactPath(Artifact.flutterWebLibrariesJson)).uri.toString(), .getArtifactPath(Artifact.flutterWebLibrariesJson)).uri.toString(),
packagesPath: PackageMap.globalPackagesPath, packagesPath: globalPackagesPath,
); );
} else { } else {
generator = ResidentCompiler( generator = ResidentCompiler(
...@@ -124,7 +124,7 @@ class FlutterDevice { ...@@ -124,7 +124,7 @@ class FlutterDevice {
experimentalFlags: experimentalFlags, experimentalFlags: experimentalFlags,
dartDefines: buildInfo.dartDefines, dartDefines: buildInfo.dartDefines,
initializeFromDill: globals.fs.path.join(getBuildDirectory(), 'cache.dill'), initializeFromDill: globals.fs.path.join(getBuildDirectory(), 'cache.dill'),
packagesPath: PackageMap.globalPackagesPath, packagesPath: globalPackagesPath,
); );
} }
...@@ -665,7 +665,7 @@ abstract class ResidentRunner { ...@@ -665,7 +665,7 @@ abstract class ResidentRunner {
String dillOutputPath, String dillOutputPath,
}) : mainPath = findMainDartFile(target), }) : mainPath = findMainDartFile(target),
projectRootPath = projectRootPath ?? globals.fs.currentDirectory.path, projectRootPath = projectRootPath ?? globals.fs.currentDirectory.path,
packagesFilePath = packagesFilePath ?? globals.fs.path.absolute(PackageMap.globalPackagesPath), packagesFilePath = packagesFilePath ?? globals.fs.path.absolute(globalPackagesPath),
_dillOutputPath = dillOutputPath, _dillOutputPath = dillOutputPath,
artifactDirectory = dillOutputPath == null artifactDirectory = dillOutputPath == null
? globals.fs.systemTempDirectory.createTempSync('flutter_tool.') ? globals.fs.systemTempDirectory.createTempSync('flutter_tool.')
......
...@@ -157,15 +157,9 @@ class HotRunner extends ResidentRunner { ...@@ -157,15 +157,9 @@ 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 loadPackageConfigUri( final PackageConfig packageConfig = await loadPackageConfigOrFail(
globals.fs.file(PackageMap.globalPackagesPath).absolute.uri, globals.fs.file(globalPackagesPath),
loader: (Uri uri) { logger: globals.logger,
final File file = globals.fs.file(uri);
if (!file.existsSync()) {
return null;
}
return file.readAsBytes();
}
); );
for (final FlutterDevice device in flutterDevices) { for (final FlutterDevice device in flutterDevices) {
results.incorporateResults(await device.updateDevFS( results.incorporateResults(await device.updateDevFS(
...@@ -361,15 +355,9 @@ class HotRunner extends ResidentRunner { ...@@ -361,15 +355,9 @@ 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 loadPackageConfigUri( final PackageConfig packageConfig = await loadPackageConfigOrFail(
globals.fs.file(PackageMap.globalPackagesPath).absolute.uri, globals.fs.file(globalPackagesPath),
loader: (Uri uri) { logger: globals.logger,
final File file = globals.fs.file(uri);
if (!file.existsSync()) {
return null;
}
return file.readAsBytes();
}
); );
for (final FlutterDevice device in flutterDevices) { for (final FlutterDevice device in flutterDevices) {
// Here we initialize the frontend_server concurrently with the platform // Here we initialize the frontend_server concurrently with the platform
...@@ -1301,15 +1289,9 @@ class ProjectFileInvalidator { ...@@ -1301,15 +1289,9 @@ class ProjectFileInvalidator {
} }
Future<PackageConfig> _createPackageConfig(String packagesPath) { Future<PackageConfig> _createPackageConfig(String packagesPath) {
return loadPackageConfigUri( return loadPackageConfigOrFail(
_fileSystem.file(packagesPath).absolute.uri, _fileSystem.file(globalPackagesPath),
loader: (Uri uri) { logger: _logger,
final File file = _fileSystem.file(uri);
if (!file.existsSync()) {
return null;
}
return file.readAsBytes();
}
); );
} }
} }
...@@ -818,7 +818,7 @@ abstract class FlutterCommand extends Command<void> { ...@@ -818,7 +818,7 @@ abstract class FlutterCommand extends Command<void> {
@protected @protected
@mustCallSuper @mustCallSuper
Future<void> validateCommand() async { Future<void> validateCommand() async {
if (_requiresPubspecYaml && !PackageMap.isUsingCustomPackagesPath) { if (_requiresPubspecYaml && !isUsingCustomPackagesPath) {
// Don't expect a pubspec.yaml file if the user passed in an explicit .packages file path. // Don't expect a pubspec.yaml file if the user passed in an explicit .packages file path.
// If there is no pubspec in the current directory, look in the parent // If there is no pubspec in the current directory, look in the parent
...@@ -835,14 +835,6 @@ abstract class FlutterCommand extends Command<void> { ...@@ -835,14 +835,6 @@ abstract class FlutterCommand extends Command<void> {
if (changedDirectory) { if (changedDirectory) {
globals.printStatus('Changing current working directory to: ${globals.fs.currentDirectory.path}'); globals.printStatus('Changing current working directory to: ${globals.fs.currentDirectory.path}');
} }
// Validate the current package map only if we will not be running "pub get" later.
if (parent?.name != 'pub' && !(_usesPubOption && boolArg('pub'))) {
final String error = PackageMap(PackageMap.globalPackagesPath, fileSystem: globals.fs).checkValid();
if (error != null) {
throw ToolExit(error);
}
}
} }
if (_usesTargetOption) { if (_usesTargetOption) {
......
...@@ -314,7 +314,7 @@ class FlutterCommandRunner extends CommandRunner<void> { ...@@ -314,7 +314,7 @@ class FlutterCommandRunner extends CommandRunner<void> {
} }
if (topLevelResults.wasParsed('packages')) { if (topLevelResults.wasParsed('packages')) {
PackageMap.globalPackagesPath = globals.fs.path.normalize(globals.fs.path.absolute(topLevelResults['packages'] as String)); globalPackagesPath = globals.fs.path.normalize(globals.fs.path.absolute(topLevelResults['packages'] as String));
} }
// See if the user specified a specific device. // See if the user specified a specific device.
...@@ -354,19 +354,9 @@ class FlutterCommandRunner extends CommandRunner<void> { ...@@ -354,19 +354,9 @@ 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 loadPackageConfigUri( final PackageConfig packageConfig = await loadPackageConfigOrFail(
globals.fs.file(PackageMap.globalPackagesPath).absolute.uri, globals.fs.file(globalPackagesPath),
onError: (dynamic error) { logger: globals.logger,
// Errors indicate the automatic detection will fail, but are not
// fatal.
},
loader: (Uri uri) {
final File file = globals.fs.file(uri);
if (!file.existsSync()) {
return null;
}
return file.readAsBytes();
},
); );
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.
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:package_config/package_config.dart';
import 'package:package_config/package_config_types.dart';
import 'base/common.dart'; import 'base/common.dart';
import 'base/file_system.dart'; import 'base/file_system.dart';
...@@ -247,8 +249,11 @@ Future<Directory> _templateImageDirectory(String name, FileSystem fileSystem) as ...@@ -247,8 +249,11 @@ 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 PackageMap packageConfig = PackageMap(packageFilePath, fileSystem: fileSystem); final PackageConfig packageConfig = await loadPackageConfigOrFail(
final Uri imagePackageLibDir = packageConfig.map['flutter_template_images']; fileSystem.file(packageFilePath),
logger: globals.logger,
);
final Uri imagePackageLibDir = packageConfig['flutter_template_images']?.packageUriRoot;
// Ensure that the template image package is present. // Ensure that the template image package is present.
if (imagePackageLibDir == null || !fileSystem.directory(imagePackageLibDir).existsSync()) { if (imagePackageLibDir == null || !fileSystem.directory(imagePackageLibDir).existsSync()) {
await _ensurePackageDependencies(toolPackagePath); await _ensurePackageDependencies(toolPackagePath);
......
...@@ -115,7 +115,7 @@ class CoverageCollector extends TestWatcher { ...@@ -115,7 +115,7 @@ class CoverageCollector extends TestWatcher {
return null; return null;
} }
if (formatter == null) { if (formatter == null) {
final coverage.Resolver resolver = coverage.Resolver(packagesPath: PackageMap.globalPackagesPath); final coverage.Resolver resolver = coverage.Resolver(packagesPath: globalPackagesPath);
final String packagePath = globals.fs.currentDirectory.path; final String packagePath = globals.fs.currentDirectory.path;
final List<String> reportOn = coverageDirectory == null final List<String> reportOn = coverageDirectory == null
? <String>[globals.fs.path.join(packagePath, 'lib')] ? <String>[globals.fs.path.join(packagePath, 'lib')]
......
...@@ -459,7 +459,7 @@ class FlutterPlatform extends PlatformPlugin { ...@@ -459,7 +459,7 @@ class FlutterPlatform extends PlatformPlugin {
final Process process = await _startProcess( final Process process = await _startProcess(
shellPath, shellPath,
mainDart, mainDart,
packages: PackageMap.globalPackagesPath, packages: globalPackagesPath,
enableObservatory: enableObservatory, enableObservatory: enableObservatory,
startPaused: startPaused, startPaused: startPaused,
disableServiceAuthCodes: disableServiceAuthCodes, disableServiceAuthCodes: disableServiceAuthCodes,
......
...@@ -97,31 +97,19 @@ class FlutterWebPlatform extends PlatformPlugin { ...@@ -97,31 +97,19 @@ class FlutterWebPlatform extends PlatformPlugin {
); );
} }
final Future<PackageConfig> _packagesFuture = loadPackageConfigUri( final Future<PackageConfig> _packagesFuture = loadPackageConfigOrFail(
Uri.base.resolve('.packages'), globals.fs.file(globalPackagesPath),
loader: (Uri uri) { logger: globals.logger,
final File file = globals.fs.file(uri);
if (!file.existsSync()) {
return null;
}
return file.readAsBytes();
}
); );
final Future<PackageConfig> _flutterToolsPackageMap = loadPackageConfigUri( final Future<PackageConfig> _flutterToolsPackageMap = loadPackageConfigOrFail(
globals.fs.file(globals.fs.path.join( globals.fs.file(globals.fs.path.join(
Cache.flutterRoot, Cache.flutterRoot,
'packages', 'packages',
'flutter_tools', 'flutter_tools',
'.packages', '.packages',
)).absolute.uri, )),
loader: (Uri uri) { logger: globals.logger,
final File file = globals.fs.file(uri);
if (!file.existsSync()) {
return null;
}
return file.readAsBytes();
}
); );
/// Uri of the test package. /// Uri of the test package.
...@@ -874,7 +862,7 @@ class TestGoldenComparator { ...@@ -874,7 +862,7 @@ class TestGoldenComparator {
shellPath, shellPath,
'--disable-observatory', '--disable-observatory',
'--non-interactive', '--non-interactive',
'--packages=${PackageMap.globalPackagesPath}', '--packages=$globalPackagesPath',
output, output,
]; ];
......
...@@ -179,8 +179,8 @@ class _FlutterTestRunnerImpl implements FlutterTestRunner { ...@@ -179,8 +179,8 @@ class _FlutterTestRunnerImpl implements FlutterTestRunner {
// Make the global packages path absolute. // Make the global packages path absolute.
// (Makes sure it still works after we change the current directory.) // (Makes sure it still works after we change the current directory.)
PackageMap.globalPackagesPath = globalPackagesPath =
globals.fs.path.normalize(globals.fs.path.absolute(PackageMap.globalPackagesPath)); globals.fs.path.normalize(globals.fs.path.absolute(globalPackagesPath));
// Call package:test's main method in the appropriate directory. // Call package:test's main method in the appropriate directory.
final Directory saved = globals.fs.currentDirectory; final Directory saved = globals.fs.currentDirectory;
......
...@@ -103,7 +103,7 @@ class TestCompiler { ...@@ -103,7 +103,7 @@ class TestCompiler {
initializeFromDill: testFilePath, initializeFromDill: testFilePath,
unsafePackageSerialization: false, unsafePackageSerialization: false,
dartDefines: const <String>[], dartDefines: const <String>[],
packagesPath: PackageMap.globalPackagesPath, packagesPath: globalPackagesPath,
); );
if (flutterProject.hasBuilders) { if (flutterProject.hasBuilders) {
return CodeGeneratingResidentCompiler.create( return CodeGeneratingResidentCompiler.create(
...@@ -126,15 +126,9 @@ class TestCompiler { ...@@ -126,15 +126,9 @@ class TestCompiler {
if (!isEmpty) { if (!isEmpty) {
return; return;
} }
_packageConfig ??= await loadPackageConfigUri( _packageConfig ??= await loadPackageConfigOrFail(
globals.fs.file(PackageMap.globalPackagesPath).absolute.uri, globals.fs.file(globalPackagesPath),
loader: (Uri uri) async { logger: globals.logger,
final File file = globals.fs.file(uri);
if (!file.existsSync()) {
return null;
}
return file.readAsBytes();
}
); );
while (compilationQueue.isNotEmpty) { while (compilationQueue.isNotEmpty) {
final _CompilationRequest request = compilationQueue.first; final _CompilationRequest request = compilationQueue.first;
......
...@@ -128,7 +128,7 @@ class FlutterTesterDevice extends Device { ...@@ -128,7 +128,7 @@ class FlutterTesterDevice extends Device {
'--run-forever', '--run-forever',
'--non-interactive', '--non-interactive',
'--enable-dart-profiling', '--enable-dart-profiling',
'--packages=${PackageMap.globalPackagesPath}', '--packages=$globalPackagesPath',
]; ];
if (debuggingOptions.debuggingEnabled) { if (debuggingOptions.debuggingEnabled) {
if (debuggingOptions.startPaused) { if (debuggingOptions.startPaused) {
......
...@@ -32,7 +32,7 @@ Future<void> buildWeb( ...@@ -32,7 +32,7 @@ Future<void> buildWeb(
if (!flutterProject.web.existsSync()) { if (!flutterProject.web.existsSync()) {
throwToolExit('Missing index.html.'); throwToolExit('Missing index.html.');
} }
final bool hasWebPlugins = findPlugins(flutterProject) final bool hasWebPlugins = (await findPlugins(flutterProject))
.any((Plugin p) => p.platforms.containsKey(WebPlugin.kConfigKey)); .any((Plugin p) => p.platforms.containsKey(WebPlugin.kConfigKey));
await injectPlugins(flutterProject, checkProjects: true); await injectPlugins(flutterProject, checkProjects: true);
final Status status = globals.logger.startProgress('Compiling $target for the Web...', timeout: null); final Status status = globals.logger.startProgress('Compiling $target for the Web...', timeout: null);
......
...@@ -46,7 +46,7 @@ void main() { ...@@ -46,7 +46,7 @@ void main() {
final File packagesFile = globals.fs.file(globals.fs.path.join('foo', '.packages')) final File packagesFile = globals.fs.file(globals.fs.path.join('foo', '.packages'))
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsStringSync('foo:lib/\n'); ..writeAsStringSync('foo:lib/\n');
PackageMap.globalPackagesPath = packagesFile.path; globalPackagesPath = packagesFile.path;
globals.fs.currentDirectory.childDirectory('bar').createSync(); globals.fs.currentDirectory.childDirectory('bar').createSync();
processManager = FakeProcessManager.list(<FakeCommand>[]); processManager = FakeProcessManager.list(<FakeCommand>[]);
......
...@@ -104,7 +104,7 @@ void main() { ...@@ -104,7 +104,7 @@ void main() {
// Set up a simple .packages file for all the tests to use, pointing to one package. // Set up a simple .packages file for all the tests to use, pointing to one package.
dummyPackageDirectory = fs.directory('/pubcache/apackage/lib/'); dummyPackageDirectory = fs.directory('/pubcache/apackage/lib/');
packagesFile = fs.file(fs.path.join(flutterProject.directory.path, PackageMap.globalPackagesPath)); packagesFile = fs.file(fs.path.join(flutterProject.directory.path, globalPackagesPath));
packagesFile..createSync(recursive: true) packagesFile..createSync(recursive: true)
..writeAsStringSync('apackage:file://${dummyPackageDirectory.path}\n'); ..writeAsStringSync('apackage:file://${dummyPackageDirectory.path}\n');
}); });
...@@ -359,8 +359,9 @@ EndGlobal'''); ...@@ -359,8 +359,9 @@ EndGlobal''');
} }
group('refreshPlugins', () { group('refreshPlugins', () {
testUsingContext('Refreshing the plugin list is a no-op when the plugins list stays empty', () { testUsingContext('Refreshing the plugin list is a no-op when the plugins list stays empty', () async {
refreshPluginsList(flutterProject); await refreshPluginsList(flutterProject);
expect(flutterProject.flutterPluginsFile.existsSync(), false); expect(flutterProject.flutterPluginsFile.existsSync(), false);
expect(flutterProject.flutterPluginsDependenciesFile.existsSync(), false); expect(flutterProject.flutterPluginsDependenciesFile.existsSync(), false);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
...@@ -368,11 +369,12 @@ EndGlobal'''); ...@@ -368,11 +369,12 @@ EndGlobal''');
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
}); });
testUsingContext('Refreshing the plugin list deletes the plugin file when there were plugins but no longer are', () { testUsingContext('Refreshing the plugin list deletes the plugin file when there were plugins but no longer are', () async {
flutterProject.flutterPluginsFile.createSync(); flutterProject.flutterPluginsFile.createSync();
flutterProject.flutterPluginsDependenciesFile.createSync(); flutterProject.flutterPluginsDependenciesFile.createSync();
refreshPluginsList(flutterProject); await refreshPluginsList(flutterProject);
expect(flutterProject.flutterPluginsFile.existsSync(), false); expect(flutterProject.flutterPluginsFile.existsSync(), false);
expect(flutterProject.flutterPluginsDependenciesFile.existsSync(), false); expect(flutterProject.flutterPluginsDependenciesFile.existsSync(), false);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
...@@ -380,11 +382,12 @@ EndGlobal'''); ...@@ -380,11 +382,12 @@ EndGlobal''');
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
}); });
testUsingContext('Refreshing the plugin list creates a plugin directory when there are plugins', () { testUsingContext('Refreshing the plugin list creates a plugin directory when there are plugins', () async {
configureDummyPackageAsPlugin(); configureDummyPackageAsPlugin();
when(iosProject.existsSync()).thenReturn(true); when(iosProject.existsSync()).thenReturn(true);
refreshPluginsList(flutterProject); await refreshPluginsList(flutterProject);
expect(flutterProject.flutterPluginsFile.existsSync(), true); expect(flutterProject.flutterPluginsFile.existsSync(), true);
expect(flutterProject.flutterPluginsDependenciesFile.existsSync(), true); expect(flutterProject.flutterPluginsDependenciesFile.existsSync(), true);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
...@@ -392,7 +395,9 @@ EndGlobal'''); ...@@ -392,7 +395,9 @@ EndGlobal''');
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
}); });
testUsingContext('Refreshing the plugin list modifies .flutter-plugins and .flutter-plugins-dependencies when there are plugins', () { testUsingContext(
'Refreshing the plugin list modifies .flutter-plugins '
'and .flutter-plugins-dependencies when there are plugins', () async {
final Directory pluginA = createPluginWithDependencies(name: 'plugin-a', dependencies: const <String>['plugin-b', 'plugin-c', 'random-package']); final Directory pluginA = createPluginWithDependencies(name: 'plugin-a', dependencies: const <String>['plugin-b', 'plugin-c', 'random-package']);
final Directory pluginB = createPluginWithDependencies(name: 'plugin-b', dependencies: const <String>['plugin-c']); final Directory pluginB = createPluginWithDependencies(name: 'plugin-b', dependencies: const <String>['plugin-c']);
final Directory pluginC = createPluginWithDependencies(name: 'plugin-c', dependencies: const <String>[]); final Directory pluginC = createPluginWithDependencies(name: 'plugin-c', dependencies: const <String>[]);
...@@ -407,7 +412,7 @@ EndGlobal'''); ...@@ -407,7 +412,7 @@ EndGlobal''');
(Invocation _) => version (Invocation _) => version
); );
refreshPluginsList(flutterProject); await refreshPluginsList(flutterProject);
// Verify .flutter-plugins-dependencies is configured correctly. // Verify .flutter-plugins-dependencies is configured correctly.
expect(flutterProject.flutterPluginsFile.existsSync(), true); expect(flutterProject.flutterPluginsFile.existsSync(), true);
...@@ -494,13 +499,14 @@ EndGlobal'''); ...@@ -494,13 +499,14 @@ EndGlobal''');
FlutterVersion: () => mockVersion FlutterVersion: () => mockVersion
}); });
testUsingContext('Changes to the plugin list invalidates the Cocoapod lockfiles', () { testUsingContext('Changes to the plugin list invalidates the Cocoapod lockfiles', () async {
simulatePodInstallRun(iosProject); simulatePodInstallRun(iosProject);
simulatePodInstallRun(macosProject); simulatePodInstallRun(macosProject);
configureDummyPackageAsPlugin(); configureDummyPackageAsPlugin();
when(iosProject.existsSync()).thenReturn(true); when(iosProject.existsSync()).thenReturn(true);
when(macosProject.existsSync()).thenReturn(true); when(macosProject.existsSync()).thenReturn(true);
refreshPluginsList(flutterProject);
await refreshPluginsList(flutterProject);
expect(iosProject.podManifestLock.existsSync(), false); expect(iosProject.podManifestLock.existsSync(), false);
expect(macosProject.podManifestLock.existsSync(), false); expect(macosProject.podManifestLock.existsSync(), false);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
...@@ -510,7 +516,7 @@ EndGlobal'''); ...@@ -510,7 +516,7 @@ EndGlobal''');
FlutterVersion: () => mockVersion FlutterVersion: () => mockVersion
}); });
testUsingContext('No changes to the plugin list does not invalidate the Cocoapod lockfiles', () { testUsingContext('No changes to the plugin list does not invalidate the Cocoapod lockfiles', () async {
configureDummyPackageAsPlugin(); configureDummyPackageAsPlugin();
when(iosProject.existsSync()).thenReturn(true); when(iosProject.existsSync()).thenReturn(true);
when(macosProject.existsSync()).thenReturn(true); when(macosProject.existsSync()).thenReturn(true);
...@@ -519,11 +525,11 @@ EndGlobal'''); ...@@ -519,11 +525,11 @@ EndGlobal''');
// Since there was no plugins list, the lock files will be invalidated. // Since there was no plugins list, the lock files will be invalidated.
// The second call is where the plugins list is compared to the existing one, and if there is no change, // The second call is where the plugins list is compared to the existing one, and if there is no change,
// the podfiles shouldn't be invalidated. // the podfiles shouldn't be invalidated.
refreshPluginsList(flutterProject); await refreshPluginsList(flutterProject);
simulatePodInstallRun(iosProject); simulatePodInstallRun(iosProject);
simulatePodInstallRun(macosProject); simulatePodInstallRun(macosProject);
refreshPluginsList(flutterProject); await refreshPluginsList(flutterProject);
expect(iosProject.podManifestLock.existsSync(), true); expect(iosProject.podManifestLock.existsSync(), true);
expect(macosProject.podManifestLock.existsSync(), true); expect(macosProject.podManifestLock.existsSync(), true);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
...@@ -1081,11 +1087,11 @@ flutter: ...@@ -1081,11 +1087,11 @@ flutter:
when(featureFlags.isWindowsEnabled).thenReturn(true); when(featureFlags.isWindowsEnabled).thenReturn(true);
}); });
testUsingContext('Symlinks are created for Linux plugins', () { testUsingContext('Symlinks are created for Linux plugins', () async {
when(linuxProject.existsSync()).thenReturn(true); when(linuxProject.existsSync()).thenReturn(true);
configureDummyPackageAsPlugin(); configureDummyPackageAsPlugin();
// refreshPluginsList should call createPluginSymlinks. // refreshPluginsList should call createPluginSymlinks.
refreshPluginsList(flutterProject); await refreshPluginsList(flutterProject);
expect(linuxProject.pluginSymlinkDirectory.childLink('apackage').existsSync(), true); expect(linuxProject.pluginSymlinkDirectory.childLink('apackage').existsSync(), true);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
...@@ -1094,11 +1100,11 @@ flutter: ...@@ -1094,11 +1100,11 @@ flutter:
FeatureFlags: () => featureFlags, FeatureFlags: () => featureFlags,
}); });
testUsingContext('Symlinks are created for Windows plugins', () { testUsingContext('Symlinks are created for Windows plugins', () async {
when(windowsProject.existsSync()).thenReturn(true); when(windowsProject.existsSync()).thenReturn(true);
configureDummyPackageAsPlugin(); configureDummyPackageAsPlugin();
// refreshPluginsList should call createPluginSymlinks. // refreshPluginsList should call createPluginSymlinks.
refreshPluginsList(flutterProject); await refreshPluginsList(flutterProject);
expect(windowsProject.pluginSymlinkDirectory.childLink('apackage').existsSync(), true); expect(windowsProject.pluginSymlinkDirectory.childLink('apackage').existsSync(), true);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
...@@ -1130,7 +1136,7 @@ flutter: ...@@ -1130,7 +1136,7 @@ flutter:
FeatureFlags: () => featureFlags, FeatureFlags: () => featureFlags,
}); });
testUsingContext('Existing symlinks are removed automatically on refresh when no longer in use', () { testUsingContext('Existing symlinks are removed automatically on refresh when no longer in use', () async {
when(linuxProject.existsSync()).thenReturn(true); when(linuxProject.existsSync()).thenReturn(true);
when(windowsProject.existsSync()).thenReturn(true); when(windowsProject.existsSync()).thenReturn(true);
...@@ -1144,7 +1150,7 @@ flutter: ...@@ -1144,7 +1150,7 @@ flutter:
// refreshPluginsList should remove existing links and recreate on changes. // refreshPluginsList should remove existing links and recreate on changes.
configureDummyPackageAsPlugin(); configureDummyPackageAsPlugin();
refreshPluginsList(flutterProject); await refreshPluginsList(flutterProject);
for (final File file in dummyFiles) { for (final File file in dummyFiles) {
expect(file.existsSync(), false); expect(file.existsSync(), false);
...@@ -1179,11 +1185,11 @@ flutter: ...@@ -1179,11 +1185,11 @@ flutter:
FeatureFlags: () => featureFlags, FeatureFlags: () => featureFlags,
}); });
testUsingContext('createPluginSymlinks repairs missing links', () { testUsingContext('createPluginSymlinks repairs missing links', () async {
when(linuxProject.existsSync()).thenReturn(true); when(linuxProject.existsSync()).thenReturn(true);
when(windowsProject.existsSync()).thenReturn(true); when(windowsProject.existsSync()).thenReturn(true);
configureDummyPackageAsPlugin(); configureDummyPackageAsPlugin();
refreshPluginsList(flutterProject); await refreshPluginsList(flutterProject);
final List<Link> links = <Link>[ final List<Link> links = <Link>[
linuxProject.pluginSymlinkDirectory.childLink('apackage'), linuxProject.pluginSymlinkDirectory.childLink('apackage'),
......
...@@ -116,11 +116,13 @@ void main() { ...@@ -116,11 +116,13 @@ void main() {
fs.directory('$_kArbitraryEngineRoot/src/out/ios_debug/gen/dart-pkg/sky_engine/lib/').createSync(recursive: true); fs.directory('$_kArbitraryEngineRoot/src/out/ios_debug/gen/dart-pkg/sky_engine/lib/').createSync(recursive: true);
fs.directory('$_kArbitraryEngineRoot/src/out/host_debug').createSync(recursive: true); fs.directory('$_kArbitraryEngineRoot/src/out/host_debug').createSync(recursive: true);
fs.file(_kDotPackages).writeAsStringSync('sky_engine:file://$_kArbitraryEngineRoot/src/out/ios_debug/gen/dart-pkg/sky_engine/lib/'); fs.file(_kDotPackages).writeAsStringSync('sky_engine:file://$_kArbitraryEngineRoot/src/out/ios_debug/gen/dart-pkg/sky_engine/lib/');
await runner.run(<String>['dummy', '--local-engine=ios_debug']); await runner.run(<String>['dummy', '--local-engine=ios_debug']);
// Verify that this also works if the sky_engine path is a symlink to the engine root. // Verify that this also works if the sky_engine path is a symlink to the engine root.
fs.link('/symlink').createSync(_kArbitraryEngineRoot); fs.link('/symlink').createSync(_kArbitraryEngineRoot);
fs.file(_kDotPackages).writeAsStringSync('sky_engine:file:///symlink/src/out/ios_debug/gen/dart-pkg/sky_engine/lib/'); fs.file(_kDotPackages).writeAsStringSync('sky_engine:file:///symlink/src/out/ios_debug/gen/dart-pkg/sky_engine/lib/');
await runner.run(<String>['dummy', '--local-engine=ios_debug']); await runner.run(<String>['dummy', '--local-engine=ios_debug']);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FileSystem: () => fs, FileSystem: () => fs,
...@@ -129,8 +131,10 @@ void main() { ...@@ -129,8 +131,10 @@ 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');
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);
await runner.run(<String>['dummy', '--local-engine-src-path=$_kArbitraryEngineRoot/src', '--local-engine=ios_debug']); await runner.run(<String>['dummy', '--local-engine-src-path=$_kArbitraryEngineRoot/src', '--local-engine=ios_debug']);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FileSystem: () => fs, FileSystem: () => fs,
...@@ -139,8 +143,10 @@ void main() { ...@@ -139,8 +143,10 @@ void main() {
}, initializeFlutterRoot: false); }, initializeFlutterRoot: false);
testUsingContext('works if --local-engine is specified and --local-engine-src-path is determined by flutter root', () async { testUsingContext('works if --local-engine is specified and --local-engine-src-path is determined by flutter root', () async {
fs.file(_kDotPackages).writeAsStringSync('\n');
fs.directory('$_kEngineRoot/src/out/ios_debug').createSync(recursive: true); fs.directory('$_kEngineRoot/src/out/ios_debug').createSync(recursive: true);
fs.directory('$_kEngineRoot/src/out/host_debug').createSync(recursive: true); fs.directory('$_kEngineRoot/src/out/host_debug').createSync(recursive: true);
await runner.run(<String>['dummy', '--local-engine=ios_debug']); await runner.run(<String>['dummy', '--local-engine=ios_debug']);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FileSystem: () => fs, FileSystem: () => fs,
......
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