Skip to content

Commit 2812d46

Browse files
authored
Stop reading .packages from flutter_tools. (#154912)
1 parent 15c0ae0 commit 2812d46

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+503
-333
lines changed

packages/flutter_tools/lib/src/cache.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,9 @@ class Cache {
215215
/// 1. FLUTTER_ROOT environment variable contains the path.
216216
/// 2. Platform script is a data URI scheme, returning `../..` to support
217217
/// tests run from `packages/flutter_tools`.
218-
/// 3. Platform script is package URI scheme, returning the grandparent directory
219-
/// of the package config file location from `packages/flutter_tools/.packages`.
218+
/// 3. Platform script is package URI scheme, returning the grandgrandparent
219+
/// directory of the package config file location from
220+
/// `packages/flutter_tools/.dart_tool/package_config.json`.
220221
/// 4. Platform script file path is the snapshot path generated by `bin/flutter`,
221222
/// returning the grandparent directory from `bin/cache`.
222223
/// 5. Platform script file name is the entrypoint in `packages/flutter_tools/bin/flutter_tools.dart`,
@@ -246,7 +247,7 @@ class Cache {
246247
final String packageConfigPath = Uri.parse(platform.packageConfig!).toFilePath(
247248
windows: platform.isWindows,
248249
);
249-
return normalize(dirname(dirname(dirname(packageConfigPath))));
250+
return normalize(dirname(dirname(dirname(dirname(packageConfigPath)))));
250251
}
251252

252253
if (platform.script.scheme == 'file') {

packages/flutter_tools/lib/src/dart/package_map.dart

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ File? findPackageConfigFile(Directory dir) {
3333
if (candidatePackageConfigFile.existsSync()) {
3434
return candidatePackageConfigFile;
3535
}
36-
// TODO(sigurdm): we should not need to check this file, it is obsolete,
37-
// https://github.com/flutter/flutter/issues/150908.
38-
final File candidatePackagesFile = candidateDir.childFile('.packages');
39-
if (candidatePackagesFile.existsSync()) {
40-
return candidatePackagesFile;
41-
}
4236
final Directory parentDir = candidateDir.parent;
4337
if (fileSystem.identicalSync(parentDir.path, candidateDir.path)) {
4438
return null;

packages/flutter_tools/test/commands.shard/hermetic/build_ios_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void main() {
9898
// Sets up the minimal mock project files necessary to look like a Flutter project.
9999
void createCoreMockProjectFiles() {
100100
fileSystem.file('pubspec.yaml').createSync();
101-
fileSystem.file('.packages').createSync();
101+
fileSystem.directory('.dart_tool').childFile('package_config.json').createSync(recursive: true);
102102
fileSystem.file(fileSystem.path.join('lib', 'main.dart')).createSync(recursive: true);
103103
}
104104

@@ -264,7 +264,7 @@ void main() {
264264
osUtils: FakeOperatingSystemUtils(),
265265
);
266266
fileSystem.file('pubspec.yaml').createSync();
267-
fileSystem.file('.packages').createSync();
267+
fileSystem.directory('.dart_tool').childFile('package_config.json').createSync(recursive: true);
268268
fileSystem.file(fileSystem.path.join('lib', 'main.dart'))
269269
.createSync(recursive: true);
270270

packages/flutter_tools/test/commands.shard/hermetic/build_ipa_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void main() {
108108
// Sets up the minimal mock project files necessary to look like a Flutter project.
109109
void createCoreMockProjectFiles() {
110110
fileSystem.file('pubspec.yaml').createSync();
111-
fileSystem.file('.packages').createSync();
111+
fileSystem.directory('.dart_tool').childFile('package_config.json').createSync(recursive: true);
112112
fileSystem.file(fileSystem.path.join('lib', 'main.dart')).createSync(recursive: true);
113113
}
114114

@@ -277,7 +277,7 @@ void main() {
277277
osUtils: FakeOperatingSystemUtils(),
278278
);
279279
fileSystem.file('pubspec.yaml').createSync();
280-
fileSystem.file('.packages').createSync();
280+
fileSystem.directory('.dart_tool').childFile('package_config.json').createSync(recursive: true);
281281
fileSystem.file(fileSystem.path.join('lib', 'main.dart'))
282282
.createSync(recursive: true);
283283

packages/flutter_tools/test/commands.shard/hermetic/build_linux_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void main() {
7474
// Creates the mock files necessary to look like a Flutter project.
7575
void setUpMockCoreProjectFiles() {
7676
fileSystem.file('pubspec.yaml').createSync();
77-
fileSystem.file('.packages').createSync();
77+
fileSystem.directory('.dart_tool').childFile('package_config.json').createSync(recursive: true);
7878
fileSystem.file(fileSystem.path.join('lib', 'main.dart')).createSync(recursive: true);
7979
}
8080

@@ -664,7 +664,7 @@ project(runner LANGUAGES CXX)
664664
set(BINARY_NAME "fizz_bar")
665665
''');
666666
fileSystem.file('pubspec.yaml').createSync();
667-
fileSystem.file('.packages').createSync();
667+
fileSystem.directory('.dart_tool').childFile('package_config.json').createSync(recursive: true);
668668
final FlutterProject flutterProject = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
669669

670670
expect(getCmakeExecutableName(flutterProject.linux), 'fizz_bar');

packages/flutter_tools/test/commands.shard/hermetic/build_web_test.dart

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void main() {
4747
fileSystem.file('pubspec.yaml')
4848
..createSync()
4949
..writeAsStringSync('name: foo\n');
50-
fileSystem.file('.packages').createSync();
50+
fileSystem.directory('.dart_tool').childFile('package_config.json').createSync(recursive: true);
5151
fileSystem.file(fileSystem.path.join('web', 'index.html')).createSync(recursive: true);
5252
fileSystem.file(fileSystem.path.join('lib', 'main.dart')).createSync(recursive: true);
5353
artifacts = Artifacts.test(fileSystem: fileSystem);
@@ -430,10 +430,28 @@ void setupFileSystemForEndToEndTest(FileSystem fileSystem) {
430430
}
431431

432432
// Project files.
433-
fileSystem.file('.packages')
434-
.writeAsStringSync('''
435-
foo:lib/
436-
fizz:bar/lib/
433+
fileSystem
434+
.directory('.dart_tool')
435+
.childFile('package_config.json')
436+
..createSync(recursive: true)
437+
..writeAsStringSync('''
438+
{
439+
"packages": [
440+
{
441+
"name": "foo",
442+
"rootUri": "../",
443+
"packageUri": "lib/",
444+
"languageVersion": "3.2"
445+
},
446+
{
447+
"name": "fizz",
448+
"rootUri": "../bar",
449+
"packageUri": "lib/",
450+
"languageVersion": "3.2"
451+
}
452+
],
453+
"configVersion": 2
454+
}
437455
''');
438456
fileSystem.file('pubspec.yaml')
439457
.writeAsStringSync('''

packages/flutter_tools/test/commands.shard/hermetic/build_windows_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void main() {
6565
// Creates the mock files necessary to look like a Flutter project.
6666
void setUpMockCoreProjectFiles() {
6767
fileSystem.file('pubspec.yaml').createSync();
68-
fileSystem.file('.packages').createSync();
68+
fileSystem.directory('.dart_tool').childFile('package_config.json').createSync(recursive: true);
6969
fileSystem.file(fileSystem.path.join('lib', 'main.dart')).createSync(recursive: true);
7070
}
7171

packages/flutter_tools/test/commands.shard/hermetic/clean_test.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,13 @@ void main() {
7575

7676
expect(projectUnderTest.flutterPluginsFile, isNot(exists));
7777
expect(projectUnderTest.flutterPluginsDependenciesFile, isNot(exists));
78-
expect(projectUnderTest.directory.childFile('.packages'), isNot(exists));
78+
expect(
79+
projectUnderTest
80+
.directory
81+
.childDirectory('.dart_tool')
82+
.childFile('package_config.json'),
83+
isNot(exists),
84+
);
7985

8086
expect(xcodeProjectInterpreter.workspaces, const <CleanWorkspaceCall>[
8187
CleanWorkspaceCall('/ios/Runner.xcworkspace', 'Runner', false),
@@ -231,7 +237,7 @@ FlutterProject setupProjectUnderTest(Directory currentDirectory, bool setupXcode
231237
projectUnderTest.macos.hostAppRoot.childDirectory('Runner.xcworkspace').createSync(recursive: true);
232238
}
233239
projectUnderTest.dartTool.createSync(recursive: true);
234-
projectUnderTest.directory.childFile('.packages').createSync(recursive: true);
240+
projectUnderTest.directory.childDirectory('.dart_tool').childFile('package_config.jon').createSync(recursive: true);
235241
projectUnderTest.android.ephemeralDirectory.createSync(recursive: true);
236242

237243
projectUnderTest.ios.ephemeralDirectory.createSync(recursive: true);

packages/flutter_tools/test/commands.shard/hermetic/create_usage_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class FakePub extends Fake implements Pub {
4040
bool shouldSkipThirdPartyGenerator = true,
4141
PubOutputMode outputMode = PubOutputMode.all,
4242
}) async {
43-
project.directory.childFile('.packages').createSync();
43+
project.directory.childDirectory('.dart_tool').childFile('package_config.json').createSync(recursive: true);
4444
if (offline) {
4545
calledGetOffline += 1;
4646
} else {

packages/flutter_tools/test/commands.shard/hermetic/pub_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ void main() {
8383
fileSystem.currentDirectory.childFile('pubspec.yaml').createSync();
8484
fileSystem.currentDirectory.childFile('.flutter-plugins').createSync();
8585
fileSystem.currentDirectory.childFile('.flutter-plugins-dependencies').createSync();
86-
fileSystem.currentDirectory.childFile('.packages').writeAsBytesSync(<int>[0]);
8786
fileSystem.currentDirectory.childFile('.dart_tool/package_config.json')
8887
..createSync(recursive: true)
8988
..writeAsBytesSync(<int>[0]);

packages/flutter_tools/test/commands.shard/permeable/build_bundle_test.dart

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ void main() {
122122
testUsingContext('bundle fails to build for Windows if feature is disabled', () async {
123123
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
124124
globals.fs.file('pubspec.yaml').createSync(recursive: true);
125-
globals.fs.file('.packages').createSync(recursive: true);
126125
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(
127126
logger: BufferLogger.test(),
128127
));
@@ -142,7 +141,6 @@ void main() {
142141
testUsingContext('bundle fails to build for Linux if feature is disabled', () async {
143142
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
144143
globals.fs.file('pubspec.yaml').createSync();
145-
globals.fs.file('.packages').createSync();
146144
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(
147145
logger: BufferLogger.test(),
148146
));
@@ -162,7 +160,6 @@ void main() {
162160
testUsingContext('bundle fails to build for macOS if feature is disabled', () async {
163161
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
164162
globals.fs.file('pubspec.yaml').createSync();
165-
globals.fs.file('.packages').createSync();
166163
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(
167164
logger: BufferLogger.test(),
168165
));
@@ -182,7 +179,6 @@ void main() {
182179
testUsingContext('bundle --tree-shake-icons fails', () async {
183180
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
184181
globals.fs.file('pubspec.yaml').createSync();
185-
globals.fs.file('.packages').createSync();
186182
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(
187183
logger: BufferLogger.test(),
188184
));
@@ -201,7 +197,6 @@ void main() {
201197
testUsingContext('bundle can build for Windows if feature is enabled', () async {
202198
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
203199
globals.fs.file('pubspec.yaml').createSync();
204-
globals.fs.file('.packages').createSync();
205200
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(
206201
logger: BufferLogger.test(),
207202
));
@@ -221,7 +216,6 @@ void main() {
221216
testUsingContext('bundle can build for Linux if feature is enabled', () async {
222217
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
223218
globals.fs.file('pubspec.yaml').createSync();
224-
globals.fs.file('.packages').createSync();
225219
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(
226220
logger: BufferLogger.test(),
227221
));
@@ -241,7 +235,6 @@ void main() {
241235
testUsingContext('bundle can build for macOS if feature is enabled', () async {
242236
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
243237
globals.fs.file('pubspec.yaml').createSync();
244-
globals.fs.file('.packages').createSync();
245238
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(
246239
logger: BufferLogger.test(),
247240
));
@@ -261,7 +254,7 @@ void main() {
261254
testUsingContext('passes track widget creation through', () async {
262255
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
263256
globals.fs.file('pubspec.yaml').createSync();
264-
globals.fs.file('.packages').createSync();
257+
265258
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(
266259
logger: BufferLogger.test(),
267260
));
@@ -294,7 +287,6 @@ void main() {
294287
testUsingContext('passes dart-define through', () async {
295288
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
296289
globals.fs.file('pubspec.yaml').createSync();
297-
globals.fs.file('.packages').createSync();
298290
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(
299291
logger: BufferLogger.test(),
300292
));
@@ -328,7 +320,6 @@ void main() {
328320
testUsingContext('passes filesystem-scheme through', () async {
329321
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
330322
globals.fs.file('pubspec.yaml').createSync();
331-
globals.fs.file('.packages').createSync();
332323
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(
333324
logger: BufferLogger.test(),
334325
));
@@ -361,7 +352,6 @@ void main() {
361352
testUsingContext('passes filesystem-roots through', () async {
362353
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
363354
globals.fs.file('pubspec.yaml').createSync();
364-
globals.fs.file('.packages').createSync();
365355
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(
366356
logger: BufferLogger.test(),
367357
));
@@ -395,7 +385,6 @@ void main() {
395385
testUsingContext('passes extra frontend-options through', () async {
396386
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
397387
globals.fs.file('pubspec.yaml').createSync();
398-
globals.fs.file('.packages').createSync();
399388
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(
400389
logger: BufferLogger.test(),
401390
));
@@ -429,7 +418,6 @@ void main() {
429418
testUsingContext('passes extra gen_snapshot-options through', () async {
430419
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
431420
globals.fs.file('pubspec.yaml').createSync();
432-
globals.fs.file('.packages').createSync();
433421
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(
434422
logger: BufferLogger.test(),
435423
));
@@ -463,7 +451,6 @@ void main() {
463451
testUsingContext('passes profile options through', () async {
464452
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
465453
globals.fs.file('pubspec.yaml').createSync();
466-
globals.fs.file('.packages').createSync();
467454
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(
468455
logger: BufferLogger.test(),
469456
));
@@ -505,7 +492,6 @@ void main() {
505492
testUsingContext('passes release options through', () async {
506493
globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true);
507494
globals.fs.file('pubspec.yaml').createSync();
508-
globals.fs.file('.packages').createSync();
509495
final CommandRunner<void> runner = createTestCommandRunner(BuildBundleCommand(
510496
logger: BufferLogger.test(),
511497
));

packages/flutter_tools/test/general.shard/android/android_device_test.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ name: example
189189
flutter:
190190
module: {}
191191
''');
192-
fileSystem.file('.packages').createSync();
193192
final FlutterProject flutterProject = FlutterProjectFactory(
194193
fileSystem: fileSystem,
195194
logger: BufferLogger.test(),
@@ -202,7 +201,6 @@ flutter:
202201
testWithoutContext('isSupportedForProject is true with editable host app', () async {
203202
final FileSystem fileSystem = MemoryFileSystem.test();
204203
fileSystem.file('pubspec.yaml').createSync();
205-
fileSystem.file('.packages').createSync();
206204
fileSystem.directory('android').createSync();
207205
final FlutterProject flutterProject = FlutterProjectFactory(
208206
fileSystem: fileSystem,
@@ -217,7 +215,6 @@ flutter:
217215
testWithoutContext('isSupportedForProject is false with no host app and no module', () async {
218216
final FileSystem fileSystem = MemoryFileSystem.test();
219217
fileSystem.file('pubspec.yaml').createSync();
220-
fileSystem.file('.packages').createSync();
221218
final FlutterProject flutterProject = FlutterProjectFactory(
222219
fileSystem: fileSystem,
223220
logger: BufferLogger.test(),

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,6 @@ void main() {
424424

425425
testUsingContext('returns null when there is no ios or .ios directory', () async {
426426
globals.fs.file('pubspec.yaml').createSync();
427-
globals.fs.file('.packages').createSync();
428427
final BuildableIOSApp? iosApp = await IOSApp.fromIosProject(
429428
FlutterProject.fromDirectory(globals.fs.currentDirectory).ios, null) as BuildableIOSApp?;
430429

@@ -433,7 +432,6 @@ void main() {
433432

434433
testUsingContext('returns null when there is no Runner.xcodeproj', () async {
435434
globals.fs.file('pubspec.yaml').createSync();
436-
globals.fs.file('.packages').createSync();
437435
globals.fs.file('ios/FooBar.xcodeproj').createSync(recursive: true);
438436
final BuildableIOSApp? iosApp = await IOSApp.fromIosProject(
439437
FlutterProject.fromDirectory(globals.fs.currentDirectory).ios, null) as BuildableIOSApp?;
@@ -443,7 +441,6 @@ void main() {
443441

444442
testUsingContext('returns null when there is no Runner.xcodeproj/project.pbxproj', () async {
445443
globals.fs.file('pubspec.yaml').createSync();
446-
globals.fs.file('.packages').createSync();
447444
globals.fs.file('ios/Runner.xcodeproj').createSync(recursive: true);
448445
final BuildableIOSApp? iosApp = await IOSApp.fromIosProject(
449446
FlutterProject.fromDirectory(globals.fs.currentDirectory).ios, null) as BuildableIOSApp?;
@@ -453,7 +450,6 @@ void main() {
453450

454451
testUsingContext('returns null when there with no product identifier', () async {
455452
globals.fs.file('pubspec.yaml').createSync();
456-
globals.fs.file('.packages').createSync();
457453
final Directory project = globals.fs.directory('ios/Runner.xcodeproj')..createSync(recursive: true);
458454
project.childFile('project.pbxproj').createSync();
459455
final BuildableIOSApp? iosApp = await IOSApp.fromIosProject(

0 commit comments

Comments
 (0)