[flutter_tools] migrate .packages to package_config, partial (#70200)

This commit is contained in:
Jonah Williams
2020-11-11 13:50:41 -08:00
committed by GitHub
parent 5b19328ff0
commit a40ee8a3fb
26 changed files with 95 additions and 91 deletions

View File

@@ -21,7 +21,6 @@ import '../build_system/targets/icon_tree_shaker.dart' show kIconTreeShakerEnabl
import '../bundle.dart' as bundle;
import '../cache.dart';
import '../dart/generate_synthetic_packages.dart';
import '../dart/package_map.dart';
import '../dart/pub.dart';
import '../device.dart';
import '../features.dart';
@@ -882,7 +881,8 @@ abstract class FlutterCommand extends Command<void> {
bundleSkSLPath: bundleSkSLPath,
dartExperiments: experiments,
performanceMeasurementFile: performanceMeasurementFile,
packagesPath: globalResults['packages'] as String ?? '.packages',
packagesPath: globalResults['packages'] as String
?? globals.fs.path.absolute('.dart_tool', 'package_config.json'),
nullSafetyMode: nullSafetyMode,
codeSizeDirectory: codeSizeDirectory,
androidGradleDaemon: androidGradleDaemon,
@@ -1174,7 +1174,7 @@ abstract class FlutterCommand extends Command<void> {
@protected
@mustCallSuper
Future<void> validateCommand() async {
if (_requiresPubspecYaml && !isUsingCustomPackagesPath) {
if (_requiresPubspecYaml && !globalResults.wasParsed('packages')) {
// 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

View File

@@ -16,7 +16,6 @@ import '../base/user_messages.dart';
import '../base/utils.dart';
import '../cache.dart';
import '../convert.dart';
import '../dart/package_map.dart';
import '../globals.dart' as globals;
import '../tester/flutter_tester.dart';
@@ -82,19 +81,9 @@ class FlutterCommandRunner extends CommandRunner<void> {
argParser.addFlag('suppress-analytics',
negatable: false,
help: 'Suppress analytics reporting when this command runs.');
String packagesHelp;
bool showPackagesCommand;
if (globals.fs.isFileSync(kPackagesFileName)) {
packagesHelp = '(defaults to "$kPackagesFileName")';
showPackagesCommand = verboseHelp;
} else {
packagesHelp = '(required, since the current directory does not contain a "$kPackagesFileName" file)';
showPackagesCommand = true;
}
argParser.addOption('packages',
hide: !showPackagesCommand,
help: 'Path to your ".packages" file.\n$packagesHelp');
hide: !verboseHelp,
help: 'Path to your "package_config.json" file.');
if (verboseHelp) {
argParser.addSeparator('Local build selection options (not normally required):');
}
@@ -219,7 +208,8 @@ class FlutterCommandRunner extends CommandRunner<void> {
// Set up the tooling configuration.
final EngineBuildPaths engineBuildPaths = await globals.localEngineLocator.findEnginePath(
topLevelResults['local-engine-src-path'] as String,
topLevelResults['local-engine'] as String
topLevelResults['local-engine'] as String,
topLevelResults['packages'] as String,
);
if (engineBuildPaths != null) {
contextOverrides.addAll(<Type, dynamic>{
@@ -254,10 +244,6 @@ class FlutterCommandRunner extends CommandRunner<void> {
await globals.flutterVersion.checkFlutterVersionFreshness();
}
if (topLevelResults.wasParsed('packages')) {
globalPackagesPath = globals.fs.path.normalize(globals.fs.path.absolute(topLevelResults['packages'] as String));
}
// See if the user specified a specific device.
globals.deviceManager.specifiedDeviceId = topLevelResults['device-id'] as String;

View File

@@ -47,13 +47,16 @@ class LocalEngineLocator {
final UserMessages _userMessages;
/// Returns the engine build path of a local engine if one is located, otherwise `null`.
Future<EngineBuildPaths> findEnginePath(String engineSourcePath, String localEngine) async {
Future<EngineBuildPaths> findEnginePath(String engineSourcePath, String localEngine, String packagePath) async {
engineSourcePath ??= _platform.environment[kFlutterEngineEnvironmentVariableName];
if (engineSourcePath == null && localEngine != null) {
try {
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
_fileSystem.file(globalPackagesPath),
_fileSystem.file(
// TODO(jonahwilliams): update to package_config
packagePath ?? _fileSystem.path.join('.packages'),
),
logger: _logger,
throwOnError: false,
);