Skip to content

Commit 361201b

Browse files
[stable] Skip platform tooling regeneration for non-Flutter pub workspace packages (#191270)
This pull request is created by [automatic cherry pick workflow](https://github.com/flutter/flutter/blob/main/docs/releases/Flutter-Cherrypick-Process.md#automatically-creates-a-cherry-pick-request) Please fill in the form below, and a flutter domain expert will evaluate this cherry pick request. ### Issue Link: #189550 ### Impact Description: In Dart workspaces containing both Flutter and non-Flutter packages, running `flutter pub get` post-processing unconditionally regenerated platform-specific tooling for all workspace packages. This caused non-Flutter packages to have their `analysis_options.yaml` modified (adding platform exclusions) and stray `ios/` or `android/` directories populated with generated Flutter project files (`GeneratedPluginRegistrant.*`, `Generated.xcconfig`, etc.). ### Changelog Description: [flutter/189550] When running `flutter pub get` in a Dart workspace, platform tooling regeneration and analysis options migration are skipped for packages that do not depend on Flutter. ### Workaround: Manually revert generated files and `analysis_options.yaml` changes in non-Flutter packages after running `flutter pub get`. ### Risk: ### Test Coverage: ### Validation Steps: 1. Create a Dart workspace containing a plain Dart package and a Flutter app package. 2. Run `flutter pub get` from the workspace root. 3. Verify that the plain Dart package's `analysis_options.yaml` remains unmodified and no platform files are created in its directory. 4. Verify that the Flutter app package is still properly processed.
1 parent e5b61cd commit 361201b

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)