Repository navigation
Revert: [flutter_tools] Remove globals from macOS build, migration, and Xcode project - #195535
Conversation
…nd Xcode project (flutter#193652)" This reverts commit 6da6a9b.
|
Detected the If you add the The "Merge" button is also unlocked. To bypass presubmits as well as the tree status, press the GitHub "Add to Merge Queue". |
There was a problem hiding this comment.
Code Review
This pull request refactors the flutter_tools package to remove the AppleContext dependency from several classes, including BuildMacosCommand, MacOSDevice, and SwiftPackageManagerIntegrationMigration. It introduces a more direct usage of globals for dependencies like logger, fileSystem, and plistParser to simplify dependency injection. Additionally, it updates the FlutterProjectFactory constructor and its usage across the codebase. Several critical issues were identified regarding constructor parameter naming and inconsistent use of local variables versus global accessors.
| /// A wrapper around the `flutter` section in the `pubspec.yaml` file. | ||
| class FlutterManifest { | ||
| FlutterManifest._({required this.logger}); | ||
| FlutterManifest._({required this._logger}); |
There was a problem hiding this comment.
Changing the constructor parameter to this._logger makes the named parameter _logger instead of logger. This causes a compile-time error in the redirecting factory constructor FlutterManifest.empty (which expects logger) and in the constructor invocation at line 86 (FlutterManifest._(logger: _logger)). To fix this, define the constructor parameter as logger and initialize the private field _logger in the initializer list.
FlutterManifest._({required Logger logger}) : _logger = logger;| this._xcodeProjectInterpreter, | ||
| this._xcodeProjectInterpreterBuilder, | ||
| }); | ||
| FlutterProjectFactory({required this._logger, required this._fileSystem, this._config}); |
There was a problem hiding this comment.
Changing the constructor parameters to this._logger and this._fileSystem makes the named parameters _logger and _fileSystem instead of logger and fileSystem. This breaks every single instantiation of FlutterProjectFactory across the codebase (including in globals.dart, tool_dependencies.dart, and numerous tests) with compile-time errors. To fix this, define the constructor with public parameter names logger and fileSystem, and initialize the private fields in the initializer list.
| FlutterProjectFactory({required this._logger, required this._fileSystem, this._config}); | |
| FlutterProjectFactory({ | |
| required Logger logger, | |
| required FileSystem fileSystem, | |
| Config? config, | |
| }) : _logger = logger, | |
| _fileSystem = fileSystem, | |
| _config = config; |
| fileSystem: globals.fs, | ||
| plistParser: globals.plistParser, | ||
| config: globals.config, |
There was a problem hiding this comment.
Since fs and config are already destructured from toolContext at the beginning of buildMacOS (line 93), we should consistently use these local variables instead of falling back to globals.fs and globals.config.
| fileSystem: globals.fs, | |
| plistParser: globals.plistParser, | |
| config: globals.config, | |
| fileSystem: fs, | |
| plistParser: globals.plistParser, | |
| config: config, |
| logger: logger, | ||
| cocoapods: cocoaPods, | ||
| analytics: analytics, | ||
| fileSystem: globals.fs, |
| // regardless of the project name so long as there is exactly one project. | ||
| final String? xcodeProjectName = xcodeProject.existsSync() ? xcodeProject.basename : null; | ||
| final XcodeProjectInfo? projectInfo = await xcodeProjectInterpreter.getInfo( | ||
| final XcodeProjectInfo? projectInfo = await globals.xcodeProjectInterpreter?.getInfo( |
There was a problem hiding this comment.
Since globals.xcodeProjectInterpreter is checked for null and guaranteed to be non-null at line 103, use ! instead of ?. to be consistent with other usages in this file.
| final XcodeProjectInfo? projectInfo = await globals.xcodeProjectInterpreter?.getInfo( | |
| final XcodeProjectInfo? projectInfo = await globals.xcodeProjectInterpreter!.getInfo( |
| .fetchDependenciesAndGenerateXcodebuildArgs( | ||
| flutterProject.macos, | ||
| fs.directory(buildDirectoryPath), | ||
| globals.fs.directory(buildDirectoryPath), |
| 'OBJROOT=${globals.fs.path.join(flutterBuildDir.absolute.path, 'Build', 'Intermediates.noindex')}', | ||
| 'SYMROOT=${globals.fs.path.join(flutterBuildDir.absolute.path, 'Build', 'Products')}', |
There was a problem hiding this comment.
Use the destructured local variable fs instead of globals.fs for consistency.
| 'OBJROOT=${globals.fs.path.join(flutterBuildDir.absolute.path, 'Build', 'Intermediates.noindex')}', | |
| 'SYMROOT=${globals.fs.path.join(flutterBuildDir.absolute.path, 'Build', 'Products')}', | |
| 'OBJROOT=${fs.path.join(flutterBuildDir.absolute.path, 'Build', 'Intermediates.noindex')}', | |
| 'SYMROOT=${fs.path.join(flutterBuildDir.absolute.path, 'Build', 'Products')}', |
| final File? aotSnapshot = const <CpuArch>[CpuArch.armv7, CpuArch.arm64, CpuArch.x64] | ||
| .map<File?>((CpuArch arch) { | ||
| return fileSystem | ||
| return globals.fs |
| final File? precompilerTrace = const <CpuArch>[CpuArch.armv7, CpuArch.arm64, CpuArch.x64] | ||
| .map<File?>((CpuArch arch) { | ||
| return fileSystem | ||
| return globals.fs |
| Directory directory, | ||
| ) { | ||
| return fileSystem.path.extension(directory.path) == '.app'; | ||
| return globals.fs.path.extension(directory.path) == '.app'; |
…nd Xcode project" (flutter#195552) Relands flutter#193652, which was reverted in flutter#195535 due to a semantic merge conflict with flutter#194052: `runMacOSPodInstall` in `build_macos.dart` referenced `globals.cocoaPods` and `globals.templateRenderer` after the `globals.dart` import was removed. This reland fixes the conflict by passing the injected `cocoaPods` and threading `required TemplateRenderer templateRenderer` into `buildMacOS`, `BuildMacosCommand`, `MacOSDevice`, `MacOSDevices`, and `FlutterDeviceManager`. Part of flutter#47161 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [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 [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/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
Reverts: [flutter_tools] Remove globals from macOS build, migration, and Xcode project
Initiated by: @hellohuanlin
Reason for reverting: ```
Original PR Author: @bkonyi
Reviewed By: @chingjun
The original PR description is provided below:
Migrates macOS build utilities,
XcodeProjectInterpreter,IosProject,MacOSProject, andXcodeProjectMigrationaway fromglobals.dartto explicit dependency injection viaToolContext.Part of #47161
Pre-launch Checklist
///).