Skip to content

Enable code generation features in tool (via opt-in) - #29399

Merged
jonahwilliams merged 8 commits into
flutter:masterfrom
jonahwilliams:unflag_codegen
Mar 21, 2019
Merged

jonahwilliams merged 8 commits into
flutter:masterfrom
jonahwilliams:unflag_codegen

Conversation

@jonahwilliams

@jonahwilliams jonahwilliams commented Mar 15, 2019 •

Copy link
Copy Markdown
Contributor

Description

Allows usage of build_runner builders as an integrated part of flutter's test, hot reload, and build workflows. This feature is a developer preview, I expect that there will be follow up fixes and bugs required, and their may need to be changes to configuration or versions accepted.

Example: to use json_serializable in a project:

pubspec.yaml

name: example_project

dependencies:
  json_annotation:  ^2.0.0

builders:
  json_serializable: ^2.0.3

After flutter run or flutter generate, the generated code will appear in the build cache. The editor may need to be restarted if this is the first run of code generation.

Currently we only support building to cache for the sake of our hot reload integration. We'll need to revisit this and provide guidance for package publishing.

Related Issues

#27141

Requires #28152

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes tests for all changed/updated/fixed behaviors (See Test Coverage).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require Flutter developers to manually update their apps to accommodate your change?

@goderbauer goderbauer added the tool Affects the "flutter" command-line tool. See also t: labels. label Mar 15, 2019
@jonahwilliams
jonahwilliams marked this pull request as ready for review March 19, 2019 00:34
@jonahwilliams
jonahwilliams requested a review from yjbanov March 19, 2019 00:34
@jonahwilliams

Copy link
Copy Markdown
Contributor Author

cc @yjbanov

@yjbanov yjbanov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

const KernelCompilerFactory();

Future<KernelCompiler> create(FlutterProject flutterProject) async {
if (flutterProject == null || !flutterProject.hasBuilders) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible for a project to go from not having builders to having some while a flutter command is running? If so, is this case handled? IOW, would the factory be rerun to get the code-generating compiler?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we won't be able to switch them currently. This does fall under the umbrella for "hot reload literally everything" that I am working on.

The solution is to: 1) always run with build_runner enabled and 2) use manifest invalidation as triggers to update the build script

However, that is a much bigger change. I don't think it should block letting people use the feature

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

Comment thread packages/flutter_tools/lib/src/run_hot.dart Outdated
Comment thread packages/flutter_tools/lib/src/run_hot.dart Outdated
@yjbanov yjbanov mentioned this pull request Mar 20, 2019
9 of 10 tasks
const KernelCompilerFactory();

Future<KernelCompiler> create(FlutterProject flutterProject) async {
if (flutterProject == null || !flutterProject.hasBuilders) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

Comment thread packages/flutter_tools/test/tester/flutter_tester_test.dart Outdated
@jonahwilliams
jonahwilliams merged commit 469a859 into flutter:master Mar 21, 2019
@jonahwilliams
jonahwilliams deleted the unflag_codegen branch March 21, 2019 20:13
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants