[flutter_tools] use initially parsed package config for language version, sound mode determination (#70323)
This commit is contained in:
@@ -6,6 +6,7 @@ import 'package:args/args.dart';
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:file/file.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:package_config/package_config_types.dart';
|
||||
|
||||
import '../application_package.dart';
|
||||
import '../base/common.dart';
|
||||
@@ -21,6 +22,8 @@ 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/language_version.dart';
|
||||
import '../dart/package_map.dart';
|
||||
import '../dart/pub.dart';
|
||||
import '../device.dart';
|
||||
import '../features.dart';
|
||||
@@ -758,6 +761,11 @@ abstract class FlutterCommand extends Command<void> {
|
||||
? stringArg('build-number')
|
||||
: null;
|
||||
|
||||
final File packagesFile = globals.fs.file(
|
||||
globalResults['packages'] as String ?? globals.fs.path.absolute('.dart_tool', 'package_config.json'));
|
||||
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
|
||||
packagesFile, logger: globals.logger, throwOnError: false);
|
||||
|
||||
final List<String> experiments =
|
||||
argParser.options.containsKey(FlutterOptions.kEnableExperiment)
|
||||
? stringsArg(FlutterOptions.kEnableExperiment).toList()
|
||||
@@ -789,12 +797,28 @@ abstract class FlutterCommand extends Command<void> {
|
||||
codeSizeDirectory = directory.path;
|
||||
}
|
||||
|
||||
NullSafetyMode nullSafetyMode = NullSafetyMode.unsound;
|
||||
NullSafetyMode nullSafetyMode = NullSafetyMode.sound;
|
||||
if (argParser.options.containsKey(FlutterOptions.kNullSafety)) {
|
||||
// Explicitly check for `true` and `false` so that `null` results in not
|
||||
// passing a flag. This will use the automatically detected null-safety
|
||||
// value based on the entrypoint
|
||||
if (!argResults.wasParsed(FlutterOptions.kNullSafety)) {
|
||||
// passing a flag. Examine the entrypoint file to determine if it
|
||||
// is opted in or out.
|
||||
final bool wasNullSafetyFlagParsed = argResults.wasParsed(FlutterOptions.kNullSafety);
|
||||
if (!wasNullSafetyFlagParsed && argParser.options.containsKey('target')) {
|
||||
final File entrypointFile = globals.fs.file(targetFile);
|
||||
final LanguageVersion languageVersion = determineLanguageVersion(
|
||||
entrypointFile,
|
||||
packageConfig.packageOf(entrypointFile.absolute.uri),
|
||||
);
|
||||
// Extra frontend options are only provided if explicitly
|
||||
// requested.
|
||||
if (languageVersion.major >= nullSafeVersion.major && languageVersion.minor >= nullSafeVersion.minor) {
|
||||
nullSafetyMode = NullSafetyMode.sound;
|
||||
} else {
|
||||
nullSafetyMode = NullSafetyMode.unsound;
|
||||
}
|
||||
} else if (!wasNullSafetyFlagParsed) {
|
||||
// This mode is only used for commands which do not build a single target like
|
||||
// 'flutter test'.
|
||||
nullSafetyMode = NullSafetyMode.autodetect;
|
||||
} else if (boolArg(FlutterOptions.kNullSafety)) {
|
||||
nullSafetyMode = NullSafetyMode.sound;
|
||||
@@ -886,6 +910,7 @@ abstract class FlutterCommand extends Command<void> {
|
||||
nullSafetyMode: nullSafetyMode,
|
||||
codeSizeDirectory: codeSizeDirectory,
|
||||
androidGradleDaemon: androidGradleDaemon,
|
||||
packageConfig: packageConfig,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user