Skip to content

Commit 0206746

Browse files
UditDewanbkonyi
andauthored
Skip platform tooling regeneration for non-Flutter pub workspace packages (flutter#189705)
`flutter pub get` post-processing iterates every workspace root package listed in `.dart_tool/package_graph.json` and unconditionally regenerates platform-specific tooling for each of them. Since `regeneratePlatformSpecificTooling` gates only on whether platform directories exist on disk, a pub workspace root that is a plain Dart package (no dependency on Flutter) with a stray `ios/` or `android/` directory got that directory populated with Flutter project files (`GeneratedPluginRegistrant.*`, `Generated.xcconfig`, `flutter_export_environment.sh`, ...). This PR skips platform tooling regeneration for workspace packages that do not depend on the `flutter` package, directly or transitively, according to the resolved package graph. Checking the transitive closure (rather than just the direct dependencies of the pubspec) keeps workspace members that only depend on Flutter through another package (e.g. an app that only declares a dependency on a plugin) working exactly as before, which is covered by the existing test `get creates plugin registrants for each app in workspace`. Adds a regression test that sets up a workspace whose root is a plain Dart package with empty `ios/` and `android/` directories, and verifies that `flutter pub get` leaves them empty while still processing the Flutter app member of the workspace. The test fails before this change (`ios/` gains `Runner/` and `Flutter/` directories) and passes after it. Fixes flutter#189550 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --------- Co-authored-by: Ben Konyi <[email protected]>
1 parent 4adca2f commit 0206746

2 files changed

Lines changed: 83 additions & 6 deletions

File tree

‎packages/flutter_tools/lib/src/commands/packages.dart‎

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'dart:collection';
6+
57
import 'package:args/args.dart';
68
import 'package:package_config/package_config.dart';
79
import 'package:pool/pool.dart';
@@ -397,12 +399,20 @@ class PackagesGetCommand extends FlutterCommand {
397399
const ignoreReleaseModeSinceItsNotABuildAndHopeItWorks = false;
398400
// We need to regenerate the platform specific tooling for both the
399401
// project itself and example (if present).
400-
await project.regeneratePlatformSpecificTooling(
401-
releaseMode: ignoreReleaseModeSinceItsNotABuildAndHopeItWorks,
402-
pubspecCache: pubspecCache,
403-
packageGraph: graph,
404-
packageConfig: packageConfig,
405-
);
402+
//
403+
// Workspace packages that do not depend on Flutter (such as a pub
404+
// workspace root that is a plain Dart package) are skipped, so that a
405+
// stray ios/ or android/ directory in one of them is not populated
406+
// with Flutter project files.
407+
// See https://github.com/flutter/flutter/issues/189550.
408+
if (_dependsOnFlutter(graph, workspaceRootName)) {
409+
await project.regeneratePlatformSpecificTooling(
410+
releaseMode: ignoreReleaseModeSinceItsNotABuildAndHopeItWorks,
411+
pubspecCache: pubspecCache,
412+
packageGraph: graph,
413+
packageConfig: packageConfig,
414+
);
415+
}
406416
if (example && project.hasExampleApp && project.example.pubspecFile.existsSync()) {
407417
final FlutterProject exampleProject = project.example;
408418
// Skip if the example is already a workspace root — it will be
@@ -423,6 +433,27 @@ class PackagesGetCommand extends FlutterCommand {
423433
return FlutterCommandResult.success();
424434
}
425435

436+
/// Whether [packageName] depends on the `flutter` package, directly or
437+
/// transitively, according to the resolved package [graph].
438+
static bool _dependsOnFlutter(PackageGraph graph, String packageName) {
439+
final visited = <String>{};
440+
final toVisit = Queue<String>.of(<String>[packageName]);
441+
while (toVisit.isNotEmpty) {
442+
final String current = toVisit.removeFirst();
443+
if (!visited.add(current)) {
444+
continue;
445+
}
446+
if (current == 'flutter') {
447+
return true;
448+
}
449+
final List<String>? dependencies = graph.dependencies[current];
450+
if (dependencies != null) {
451+
toVisit.addAll(dependencies);
452+
}
453+
}
454+
return false;
455+
}
456+
426457
late final Future<List<Plugin>> _pluginsFound = (() async {
427458
final FlutterProject? rootProject = _rootProject;
428459
if (rootProject == null) {

‎packages/flutter_tools/test/commands.shard/permeable/packages_test.dart‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,52 @@ workspace:
458458
},
459459
);
460460

461+
testUsingContext(
462+
'get does not generate platform tooling for a non-Flutter workspace root',
463+
// Regression test for https://github.com/flutter/flutter/issues/189550.
464+
() async {
465+
tempDir.childFile('pubspec.yaml').writeAsStringSync('''
466+
name: workspace
467+
environment:
468+
sdk: ^3.7.0-0
469+
workspace:
470+
- flutter_project
471+
''');
472+
// A stray platform directory in the plain Dart workspace root must not
473+
// be populated with Flutter project files.
474+
tempDir.childDirectory('ios').createSync();
475+
tempDir.childDirectory('android').createSync();
476+
final String projectPath = await createProject(tempDir, arguments: <String>['--no-pub']);
477+
final File pubspecFile = fileSystem.file(fileSystem.path.join(projectPath, 'pubspec.yaml'));
478+
final pubspecYaml = loadYaml(pubspecFile.readAsStringSync()) as YamlMap;
479+
final pubspec = <String, Object?>{
480+
...pubspecYaml.value.cast<String, Object?>(),
481+
'resolution': 'workspace',
482+
'environment': <String, Object?>{'sdk': '^3.5.0-0'},
483+
};
484+
pubspecFile.writeAsStringSync(jsonEncode(pubspec));
485+
await runCommandIn(tempDir.path, 'get');
486+
487+
expectDependenciesResolved(tempDir.path);
488+
expect(tempDir.childDirectory('ios').listSync(), isEmpty);
489+
expect(tempDir.childDirectory('android').listSync(), isEmpty);
490+
// The Flutter app member of the workspace is still processed.
491+
expectExists(projectPath, 'ios/Flutter/Generated.xcconfig');
492+
},
493+
overrides: <Type, Generator>{
494+
Stdio: () => mockStdio,
495+
Pub: () => Pub.test(
496+
fileSystem: globals.fs,
497+
logger: globals.logger,
498+
processManager: globals.processManager,
499+
botDetector: globals.botDetector,
500+
platform: globals.platform,
501+
stdio: mockStdio,
502+
),
503+
Analytics: () => fakeAnalytics,
504+
},
505+
);
506+
461507
testUsingContext(
462508
'get generates files into lib/l10n',
463509
() async {

0 commit comments

Comments
 (0)