Skip to content

Commit e529d32

Browse files
authored
Remove patching of package_config.json from Flutter Pub wrapper. (#169306)
This PR removes the mechanics around `generateSyntheticPackage` from Flutter's `pub` wrapper (`DefaultPub`). The feature it supported (`package:flutter_gen`) was deprecated (opt-in 3.29, opt-out 3.32) and is now being removed: https://docs.flutter.dev/release/breaking-changes/flutter-generate-i10n-source --- One integration test (`flutter_gen_test.dart`) will fail at this PR until it is deleted in (pending) flutter/flutter#169283. /cc @sigurdm yay!
1 parent 92abd4c commit e529d32

File tree

2 files changed

+25
-184
lines changed

2 files changed

+25
-184
lines changed

packages/flutter_tools/lib/src/dart/pub.dart

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import '../base/process.dart';
2222
import '../cache.dart';
2323
import '../convert.dart';
2424
import '../dart/package_map.dart';
25-
import '../features.dart';
2625
import '../project.dart';
2726
import '../version.dart';
2827

@@ -192,7 +191,6 @@ abstract class Pub {
192191
required PubContext context,
193192
required String command,
194193
bool touchesPackageConfig = false,
195-
bool generateSyntheticPackage = false,
196194
PubOutputMode outputMode = PubOutputMode.all,
197195
});
198196
}
@@ -242,8 +240,6 @@ class _DefaultPub implements Pub {
242240
required FlutterProject project,
243241
bool upgrade = false,
244242
bool offline = false,
245-
bool generateSyntheticPackage = false,
246-
bool generateSyntheticPackageForExample = false,
247243
String? flutterRootOverride,
248244
bool checkUpToDate = false,
249245
bool shouldSkipThirdPartyGenerator = true,
@@ -700,15 +696,6 @@ class _DefaultPub implements Pub {
700696
///
701697
/// Creates a corresponding `package_config_subset` file that is used by the
702698
/// build system to avoid rebuilds caused by an updated pub timestamp.
703-
///
704-
/// if `project.generateSyntheticPackage` is `true` then insert flutter_gen
705-
/// synthetic package into the package configuration. This is used by the l10n
706-
/// localization tooling to insert a new reference into the package_config
707-
/// file, allowing the import of a package URI that is not specified in the
708-
/// pubspec.yaml
709-
///
710-
/// For more information, see:
711-
/// * [generateLocalizations]
712699
Future<void> _updatePackageConfig(FlutterProject project, File packageConfigFile) async {
713700
final PackageConfig packageConfig = await loadPackageConfigWithLogging(
714701
packageConfigFile,
@@ -718,47 +705,6 @@ class _DefaultPub implements Pub {
718705
packageConfigFile.parent
719706
.childFile('package_config_subset')
720707
.writeAsStringSync(_computePackageConfigSubset(packageConfig, _fileSystem));
721-
722-
// If we aren't generating localizations, short-circuit.
723-
if (!project.manifest.generateLocalizations) {
724-
return;
725-
}
726-
727-
// Workaround for https://github.com/flutter/flutter/issues/164864.
728-
// If this flag is set, synthetic packages cannot be used, so we short-circut.
729-
if (featureFlags.isExplicitPackageDependenciesEnabled) {
730-
return;
731-
}
732-
733-
if (!_fileSystem.path.equals(packageConfigFile.parent.parent.path, project.directory.path)) {
734-
throwToolExit(
735-
'`generate: true` is not supported within workspaces unless flutter config '
736-
'--explicit-package-dependencies is set.',
737-
);
738-
}
739-
740-
if (packageConfig.packages.any((Package package) => package.name == 'flutter_gen')) {
741-
return;
742-
}
743-
744-
// TODO(jonahwillams): Using raw json manipulation here because
745-
// savePackageConfig always writes to local io, and it changes absolute
746-
// paths to relative on round trip.
747-
// See: https://github.com/dart-lang/package_config/issues/99,
748-
// and: https://github.com/dart-lang/package_config/issues/100.
749-
750-
// Because [loadPackageConfigWithLogging] succeeded [packageConfigFile]
751-
// we can rely on the file to exist and be correctly formatted.
752-
final Map<String, dynamic> jsonContents =
753-
json.decode(packageConfigFile.readAsStringSync()) as Map<String, dynamic>;
754-
755-
(jsonContents['packages'] as List<dynamic>).add(<String, dynamic>{
756-
'name': 'flutter_gen',
757-
'rootUri': 'flutter_gen',
758-
'languageVersion': '2.12',
759-
});
760-
761-
packageConfigFile.writeAsStringSync(json.encode(jsonContents));
762708
}
763709

764710
// Subset the package config file to only the parts that are relevant for

packages/flutter_tools/test/general.shard/dart/pub_get_test.dart

Lines changed: 25 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import 'package:flutter_tools/src/base/platform.dart';
1212
import 'package:flutter_tools/src/cache.dart';
1313
import 'package:flutter_tools/src/convert.dart';
1414
import 'package:flutter_tools/src/dart/pub.dart';
15-
import 'package:flutter_tools/src/features.dart';
1615
import 'package:flutter_tools/src/project.dart';
1716

1817
import '../../src/common.dart';
@@ -988,133 +987,30 @@ exit code: 66
988987
expect(processManager, hasNoRemainingExpectations);
989988
});
990989

991-
testUsingContext(
992-
'package_config_subset file is generated from packages and not timestamp',
993-
() async {
994-
final FileSystem fileSystem = MemoryFileSystem.test();
995-
final Pub pub = Pub.test(
996-
fileSystem: fileSystem,
997-
logger: BufferLogger.test(),
998-
processManager: FakeProcessManager.any(),
999-
botDetector: const FakeBotDetector(false),
1000-
stdio: FakeStdio(),
1001-
platform: FakePlatform(
1002-
environment: const <String, String>{'PUB_CACHE': 'custom/pub-cache/path'},
1003-
),
1004-
);
1005-
fileSystem.file('version').createSync();
1006-
fileSystem.file('pubspec.yaml')
1007-
..createSync()
1008-
..writeAsStringSync('''
1009-
flutter:
1010-
generate: true
1011-
''');
1012-
fileSystem.file('.dart_tool/package_config.json')
1013-
..createSync(recursive: true)
1014-
..writeAsStringSync('''
1015-
{"configVersion": 2,"packages": [
1016-
{
1017-
"name": "flutter_tools",
1018-
"rootUri": "../",
1019-
"packageUri": "lib/",
1020-
"languageVersion": "2.7"
1021-
}
1022-
],"generated":"some-time"}
1023-
''');
1024-
1025-
await pub.get(
1026-
project: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
1027-
context: PubContext.flutterTests,
1028-
);
1029-
1030-
expect(
1031-
fileSystem.file('.dart_tool/package_config_subset').readAsStringSync(),
1032-
'flutter_tools\n'
1033-
'2.7\n'
1034-
'file:///\n'
1035-
'file:///lib/\n'
1036-
'2\n',
1037-
);
1038-
},
1039-
overrides: <Type, Generator>{
1040-
// ignore: avoid_redundant_argument_values
1041-
FeatureFlags: () => TestFeatureFlags(isExplicitPackageDependenciesEnabled: false),
1042-
},
1043-
);
1044-
1045-
testUsingContext(
1046-
'cannot use `generate: true` with a workspace without --explicit-package-dependencies',
1047-
() async {
1048-
final FileSystem fileSystem = MemoryFileSystem.test();
1049-
final Pub pub = Pub.test(
1050-
fileSystem: fileSystem,
1051-
logger: BufferLogger.test(),
1052-
processManager: FakeProcessManager.any(),
1053-
botDetector: const FakeBotDetector(false),
1054-
stdio: FakeStdio(),
1055-
platform: FakePlatform(
1056-
environment: const <String, String>{'PUB_CACHE': 'custom/pub-cache/path'},
1057-
),
1058-
);
1059-
1060-
final Directory pkg = fileSystem.directory('workspace_pkg')..createSync(recursive: true);
1061-
fileSystem.file('version').createSync();
1062-
pkg.childFile('pubspec.yaml')
1063-
..createSync()
1064-
..writeAsStringSync('''
1065-
flutter:
1066-
generate: true
1067-
''');
1068-
fileSystem.file('.dart_tool/package_config.json')
1069-
..createSync(recursive: true)
1070-
..writeAsStringSync('''
1071-
{"configVersion": 2,"packages": [
1072-
{
1073-
"name": "flutter_tools",
1074-
"rootUri": "../",
1075-
"packageUri": "lib/",
1076-
"languageVersion": "2.7"
1077-
}
1078-
],"generated":"some-time"}
1079-
''');
1080-
1081-
await expectLater(
1082-
pub.get(project: FlutterProject.fromDirectoryTest(pkg), context: PubContext.flutterTests),
1083-
throwsToolExit(message: '`generate: true` is not supported within workspaces unless'),
1084-
);
1085-
},
1086-
overrides: <Type, Generator>{
1087-
// ignore: avoid_redundant_argument_values
1088-
FeatureFlags: () => TestFeatureFlags(isExplicitPackageDependenciesEnabled: false),
1089-
},
1090-
);
1091-
1092-
testUsingContext(
1093-
'can use `generate: true` with a workspace with --explicit-package-dependencies',
1094-
() async {
1095-
final FileSystem fileSystem = MemoryFileSystem.test();
1096-
final Pub pub = Pub.test(
1097-
fileSystem: fileSystem,
1098-
logger: BufferLogger.test(),
1099-
processManager: FakeProcessManager.any(),
1100-
botDetector: const FakeBotDetector(false),
1101-
stdio: FakeStdio(),
1102-
platform: FakePlatform(
1103-
environment: const <String, String>{'PUB_CACHE': 'custom/pub-cache/path'},
1104-
),
1105-
);
990+
testUsingContext('can use generate: true within a workspace', () async {
991+
final FileSystem fileSystem = MemoryFileSystem.test();
992+
final Pub pub = Pub.test(
993+
fileSystem: fileSystem,
994+
logger: BufferLogger.test(),
995+
processManager: FakeProcessManager.any(),
996+
botDetector: const FakeBotDetector(false),
997+
stdio: FakeStdio(),
998+
platform: FakePlatform(
999+
environment: const <String, String>{'PUB_CACHE': 'custom/pub-cache/path'},
1000+
),
1001+
);
11061002

1107-
final Directory pkg = fileSystem.directory('workspace_pkg')..createSync(recursive: true);
1108-
fileSystem.file('version').createSync();
1109-
pkg.childFile('pubspec.yaml')
1110-
..createSync()
1111-
..writeAsStringSync('''
1003+
final Directory pkg = fileSystem.directory('workspace_pkg')..createSync(recursive: true);
1004+
fileSystem.file('version').createSync();
1005+
pkg.childFile('pubspec.yaml')
1006+
..createSync()
1007+
..writeAsStringSync('''
11121008
flutter:
11131009
generate: true
11141010
''');
1115-
fileSystem.file('.dart_tool/package_config.json')
1116-
..createSync(recursive: true)
1117-
..writeAsStringSync('''
1011+
fileSystem.file('.dart_tool/package_config.json')
1012+
..createSync(recursive: true)
1013+
..writeAsStringSync('''
11181014
{"configVersion": 2,"packages": [
11191015
{
11201016
"name": "flutter_tools",
@@ -1125,12 +1021,11 @@ exit code: 66
11251021
],"generated":"some-time"}
11261022
''');
11271023

1128-
await expectLater(
1129-
pub.get(project: FlutterProject.fromDirectoryTest(pkg), context: PubContext.flutterTests),
1130-
completes,
1131-
);
1132-
},
1133-
);
1024+
await expectLater(
1025+
pub.get(project: FlutterProject.fromDirectoryTest(pkg), context: PubContext.flutterTests),
1026+
completes,
1027+
);
1028+
});
11341029

11351030
testWithoutContext('Pub error handling', () async {
11361031
final BufferLogger logger = BufferLogger.test();

0 commit comments

Comments
 (0)