Load parent package config (#150850)

Fixes #150196
This commit is contained in:
Sigurd Meldgaard
2024-08-20 09:34:35 +02:00
committed by GitHub
parent eef4a06e4e
commit 1a2e25c2d8
55 changed files with 615 additions and 393 deletions

View File

@@ -1083,15 +1083,19 @@ abstract class FlutterCommand extends Command<void> {
BuildMode defaultBuildMode = BuildMode.debug;
BuildMode getBuildMode() {
// No debug when _excludeDebug is true.
// If debug is not excluded, then take the command line flag.
final bool debugResult = !_excludeDebug && boolArg('debug');
final bool jitReleaseResult = !_excludeRelease && boolArg('jit-release');
final bool releaseResult = !_excludeRelease && boolArg('release');
// No debug when _excludeDebug is true. If debug is not excluded, then take
// the command line flag (if such exists for this command).
bool argIfDefined(String flagName, bool ifNotDefined) {
return argParser.options.containsKey(flagName) ? boolArg(flagName) : ifNotDefined;
}
final bool debugResult = !_excludeDebug && argIfDefined('debug', false);
final bool jitReleaseResult = !_excludeRelease && argIfDefined('jit-release', false);
final bool releaseResult = !_excludeRelease && argIfDefined('release', false);
final bool profileResult = argIfDefined('profile', false);
final List<bool> modeFlags = <bool>[
debugResult,
profileResult,
jitReleaseResult,
boolArg('profile'),
releaseResult,
];
if (modeFlags.where((bool flag) => flag).length > 1) {
@@ -1101,7 +1105,7 @@ abstract class FlutterCommand extends Command<void> {
if (debugResult) {
return BuildMode.debug;
}
if (boolArg('profile')) {
if (profileResult) {
return BuildMode.profile;
}
if (releaseResult) {
@@ -1184,6 +1188,19 @@ abstract class FlutterCommand extends Command<void> {
/// if `pubspec.yaml` or `example/pubspec.yaml` is invalid.
FlutterProject get project => FlutterProject.current();
/// The path to the package config for the current project.
///
/// If an explicit argument is given, that is returned. Otherwise the file
/// system is searched for the package config. For projects in pub workspaces
/// the package config might be located in a parent directory.
///
/// If none is found `.dart_tool/package_config.json` is returned.
String packageConfigPath() {
final String? packagesPath = this.packagesPath;
return packagesPath ??
findPackageConfigFileOrDefault(project.directory).path;
}
/// Compute the [BuildInfo] for the current flutter command.
///
/// Commands that build multiple build modes can pass in a [forcedBuildMode]
@@ -1203,7 +1220,8 @@ abstract class FlutterCommand extends Command<void> {
? stringArg('build-number')
: null;
final File packageConfigFile = globals.fs.file(packagesPath ?? project.packageConfigFile.path);
final File packageConfigFile = globals.fs.file(packageConfigPath());
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
packageConfigFile,
logger: globals.logger,
@@ -1750,21 +1768,22 @@ Run 'flutter -h' (or 'flutter <command> -h') for available flutter commands and
usage: globals.flutterUsage,
analytics: analytics,
projectDir: project.directory,
packageConfigPath: packageConfigPath(),
generateDartPluginRegistry: true,
);
await generateLocalizationsSyntheticPackage(
environment: environment,
buildSystem: globals.buildSystem,
buildTargets: globals.buildTargets,
);
await pub.get(
context: PubContext.getVerifyContext(name),
project: project,
checkUpToDate: cachePubGet,
);
await generateLocalizationsSyntheticPackage(
environment: environment,
buildSystem: globals.buildSystem,
buildTargets: globals.buildTargets,
);
// null implicitly means all plugins are allowed
List<String>? allowedPlugins;
if (stringArg(FlutterGlobalOptions.kDeviceIdOption, global: true) == 'preview') {

View File

@@ -125,8 +125,7 @@ class LocalEngineLocator {
Future<String?> _findEngineSourceByPackageConfig(String? packagePath) async {
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
_fileSystem.file(
// TODO(zanderso): update to package_config
packagePath ?? _fileSystem.path.join('.packages'),
packagePath ?? findPackageConfigFileOrDefault(_fileSystem.currentDirectory),
),
logger: _logger,
throwOnError: false,