Repository navigation
[flutter_tools] Add BuildService and flutter build support for tool extensions - #193748
Conversation
…xtensions Adds `BuildService`, `ExtensionBuildTarget`, `ExtensionBuildResult`, and `ExtensionBuildManager` to allow tool extensions to register custom `flutter build <target>` subcommands and execute builds over RPC. Part of flutter#190692
There was a problem hiding this comment.
Code Review
This pull request introduces support for custom build targets in Flutter tool extensions by adding an ExtensionBuildManager that queries active extensions for build targets and dynamically registers them as subcommands under flutter build. It also defines the core data models and service interfaces in flutter_tools_core and flutter_tools_extension, along with a prototype Linux implementation and integration tests. Feedback focuses on improving robustness and efficiency, including parallelizing target queries to prevent blocking, handling initialization errors gracefully during target retrieval and build execution, using collection-if for cleaner serialization of build results, and adding trace logging when custom subcommands conflict with existing ones.
…ldService - Simplify JSON-RPC map matching to use `Map<String, Object?>` directly in `ExtensionBuildManager.build` and `ExtensionBuildTarget.listFromJson`. - Wrap `_extensionManager.ensureInitialized()` in `try-catch` in `ExtensionBuildManager` and parallelize `build.getBuildTargets` RPC queries across connections via `Future.wait`. - Skip targets with empty names and log a trace message when skipping conflicting build subcommands. - Add Dartdoc comments to `ExtensionBuildSubCommand`.
…coverage for BuildService - Destructure `toolDependencies` in `executable.dart` and pass `toolDependencies.featureFlags` instead of the ambient `featureFlags` getter. - Return per-connection target lists from `Future.wait` in `ExtensionBuildManager.getBuildTargets` and iterate deterministically in connection order, skipping duplicate target names. - Use `_logger.printTrace` for initialization and RPC diagnostics in `ExtensionBuildManager` to avoid duplicate error output on `throwToolExit`. - Expand hermetic and RPC dispatch unit tests in `tool_extensions_build_test.dart` and `linux_build_test.dart`.
…se record in getBuildTargets - Move `initializeDynamicOptions()` from `ExtensionArgParserMixin` to `FlutterCommand` and remove `with ExtensionArgParserMixin` from `BuildCommand`. - Return `(ExtensionConnection, List<ExtensionBuildTarget>)` records from `Future.wait` in `ExtensionBuildManager.getBuildTargets` and destructure in a `for-in` loop.
loic-sharma
left a comment
There was a problem hiding this comment.
Overall this looks good to me 👍
…nd remove build timeout - Construct `ExtensionBuildManager` in `ToolDependencies.bootstrap` and pass `toolDependencies.extensionBuildManager` to `BuildCommand` in `generateCommands`. - Make `ExtensionConnection.sendRequest` accept a nullable `Duration? timeout` and pass `null` from `ExtensionBuildManager.build` so long-running custom builds do not time out.
…tests Adds `extensionBuildManager` to `FakeToolDependencies` in `args_test.dart` and `test/src/fakes.dart` so `generateCommands` does not throw `UnimplementedError: extensionBuildManager`.
…xtensions (flutter#193748) Adds `BuildService`, `ExtensionBuildTarget`, `ExtensionBuildResult`, and `ExtensionBuildManager` to allow tool extensions to register custom `flutter build <target>` subcommands and execute builds over RPC. Part of flutter#190692 ## 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.
Adds
BuildService,ExtensionBuildTarget,ExtensionBuildResult, andExtensionBuildManagerto allow tool extensions to register customflutter build <target>subcommands and execute builds over RPC.Part of #190692
Pre-launch Checklist
///).