-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Generate BuildConfig #16934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate BuildConfig #16934
Conversation
10178ed to
453c9bf
Compare
|
Can you elaborate on what this patch does? cc @tvolkert |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(minor nit: our syntax for TODOs is // TODO(username): description, https://link_to_issue)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm guessing this wasn't intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this presumably has to be generated at build time so shouldn't be in the template?
packages/flutter_tools/pubspec.yaml
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're actually trying to reduce our dependencies currently so we probably will want to avoid adding these if we can help it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can generate the code by hand but maybe it will not right formatted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't actually use exact dartfmt style either so technically it might not be right formatted either way. :-)
|
When I call On Android, I have the This path creates a So it will be more comfortable on Dart side to do something depending on the build. |
453c9bf to
452b3c3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
syntax for TODOs is // TODO(username): description, https://link-to-issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not so easy to write a TODO in the right syntax :D
|
I'll let @mravn-google or @tvolkert do the actual review, I'm not familiar the Android build system. |
|
I'm deferring to @mravn-google |
|
ping @mravn-google |
|
Sorry for the latency. Current behavior is that following |
|
This behaviour (build/run the project without Flutter tooling) isn't changed. But maybe the |
|
@the4thfloor Are you still looking into this? It's totally fine if not; we can take it over (though it might take longer). I'm just asking because I'm trying to clean out our review queue. |
de48f0d to
52b66dc
Compare
10bb598 to
20bd871
Compare
This commit adds a generator which generates a `BuildConfig` class located at `lib/build_config.g.dart`. The generator runs when `flutter run` or `flutter build` is called. The `BuildConfig` class holds some information about the current build.
20bd871 to
b0d7736
Compare
|
@Hixie @mravn-google this PR is ready to review :-) |
|
Seems to me Flutter tooling needs a design change to provide a good user experience for working with generated files. This PR makes generated files part of default operation, which worries me a bit. What is the intended status of the generated file? Is it supposed to be checked into version control?
Other questions:
I think we should come up with reasonable answers to such questions, or at least make the generation of |
|
This For now, I will add a flag to enable/disable this generation step. I would prefer to add this flag as an option in the Flutter part in the pubspec.yaml file to enable/disable this project-wide for all runs/builds. Are you fine with this? |
|
@devoncarew Any considerations on how the Flutter IDE plugins should handle codegen? This PR proposes to generate a |
|
My 2 cents is leaving lib/ alone, but as said above there's no built in way to add a gen folder. Maybe we add a new package to hold generated files as part of the build? The advantage is that devs will clearly know what code was typed (lib) and what was generated (myapp_gen). |
|
@fmatosqg all code-gen approaches (built_value, json_serializable, built_redux, ...) write to If this PR would be implemented as such a builder there could also be a part 'version.g.dart';
@versionInfo
class Version extends _$Version {}and only if that file with that annotation exists the |
|
@mravn-google How does this relate to the work you're doing? Is it compatible? |
|
Our work on add2app does not preclude code generation build steps. But for a seamless add2app experience, such steps should be executable via platform-specific build tooling (Gradle, CocoaPods and/or custom Xcode build scripts). We already call Maybe |
|
Hi, i implemented the changes on flutter folder files (Windows 10) in c:\flutter\packages\flutter_tools\lib\src\commands: |
|
@alexlovar I guess the best way to get is to check out this branch (and maybe rebase it with master) |
|
|
||
| dynamic _escape(dynamic value) { | ||
| if (value is String) { | ||
| return '\'$value\''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is value contains an apostrophe or backslash?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is an excellent question. Currently, I don't know what happens, but I will look into it.
| return output.toString(); | ||
| } | ||
|
|
||
| dynamic _escape(dynamic value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's hard for me to understand the range and domain of this method. It takes any type, and returns either an escaped string or the type unmodified? What if the type is an object whose toString isn't valid Dart, say?
| ]; | ||
| await checkGenerator(manifest: manifest, buildInfo: buildInfo, expectedLines: expected); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should probably also have a test that verifies that the generated file compiles and analyzes cleanly.
|
|
||
| await generateBuildConfigClassAtPath(buildInfo: buildInfo, projectPath: projectPath); | ||
|
|
||
| final String srcFile = fs.path.join(projectPath, 'lib', 'build_config.g.dart'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to put this in the build/ directory?
|
@the4thfloor Sorry that we are not being very responsive and helpful on this PR... the truth is that we don't really have any build system experts on the team, and so we're somewhat stumbling around in the dark on this topic. It doesn't help that we'd like to keep things consistent between iOS and Android, so ideally anyone who owns this area would be an expert it both. We're hoping to have a more coherent solution to codegen at some point in the future, something that works reliably with hot reload, for example, but we haven't yet started thinking about that much and so we're not really sure what we want this to look like. As @mravn-google points out above, this is also something that interacts with our existing-app integration (where the build is driven not from the It might be best to file a bug and list all the requirements (some of which are in comments on this PR), and then have a discussion about the overall architecture that will address all these requirements, before landing this PR. |
|
@Hixie For me, it is okay when it needs longer than other PRs because it is a topic with a significant impact on the build system. My lasts thoughts before I switch to iOS was to use the hidden .dart_tools folder to store the generated files. But Flutter doesn't use this folder. I have to look into it why Flutter doesn't use it. But if there is a more significant change in the build system in the pipe, it doesn't make sense to add other complicated things. Maybe it is better to discuss it first in a bug ticket. |
|
Hi, Is the file path possible to be the same with flutter i18n ? I think the4thfloor did a good job, thanks again. |
|
TL;DR I suggest using a convention where I like I believe 2 standards for generated files are needed, 1 for pre-build time such as autogenerated code that deals with json and people can argue whether they go in commits or note, and another for files that will be consistently overwritten during the build (as in C macros), meaning it's obvious nobody wants to commit them. |
|
fyi @matthew-carroll you may find this bug relevant to your interests. I think we should close this PR for now, because we don't have a complete handle on the problem space (as per my last comment). I think the next step is to file an issue that describes the problem we want solved, and to discuss a design there. |
|
I'm going to close this PR per the last comment. Please do file an issue to discuss the design if you still desire a change in this area. Thanks. |
|
Sounds good. My 2 cents is that we need to figure out how to integrate Android's real BuildConfig on the engine side. We probably shouldn't imitate something that already exists, and I think it's our own build system shortcoming that we can't offer this Class as it usually exists. |
|
I was a little disappointed this didn't get merged, as I wanted to be able to read the app's version data from within my app. I worked around it by adding |
This commit adds a generator which generates a
BuildConfigclass located atlib/build_config.g.dart.The generator runs when
flutter runorflutter buildis called (or its equivalent IDE methods).The
BuildConfigclass holds some information about the current build; it looks like this:If the project is executed or build with native tools the generator will not (re-)generate the
BuildConfigclass.