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
Allow the library builder to work with non-dart (json, xml, yaml, etc...) based on allow build extension #500
Conversation
…If build extension does not support dart and is to generate code from yaml or json or xml then allow source generator
…If build extension does not support dart and is to generate code from yaml or json or xml then allow source generator
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
@googlebot I signed it! |
This library is really not intended for use on non-Dart files - see the core Builder class from the build system which is probably what you want. I think we likely want to make the |
@jakemac53 can you please explain the correct use case for LibraryBuilder as it stands today? It seems to be useless, not a single example of LibraryBuilder. Why limit to Dart files? It be nice if you can explain the need for limitation of such nicely defined abstraction? |
LibraryBuilder, PartBuilder, and SharedPartBuilder all were built specifically for the case of consuming some Dart code and outputting more Dart code. This is baked into the apis at several levels. For instance, The majority of the functionality the package provides is based around consuming dart code - it doesn't really do anything for you as far as emitting it (other than the shared part stuff). It might be helpful to understand more what it is you want to use this package for, as opposed to the vanilla |
@jakemac53 thank you for your reply. For my use case I have some generator that use PartBuilder and SharedPartBuilder which take benefit of annotation processing. Using the same codebase I want create a version resilient code generator that will read json specification versions as input and output dart code library for the set of specification and its version. i.e. we have a domain called ITSM and it has v1, v2, and v3. The generator will generate a dart library that will be version resilient. So if i use the the builder then i can't elegantly reuse the code write for other generator. |
You should be able to re-use code here by creating shared functions here? Ultimately they both should just be building up output String objects, there shouldn't be any incompatible concepts between the two? |
@jakemac53, yes should be able to re-use code, but is it only me or does it not make sense to not block non dart input? |
The question is really "why does it make sense to allow non-Dart input"? I don't see a compelling case for that today, and I do see some arguments against it. We don't want to broaden the scope of the package unnecessarily, narrowly targeted packages are easier to maintain. We wouldn't want to be hampered from making some design decision we would like to later on because of this choice. I will give a very concrete example. Soon we will want to migrate this package to null safety. Today, the types on the generate would all be able to stay unchanged - you are always given a non-null library reader and build step. With the change you propose here, the library reader would have to change to be So for that reason alone, I would need a very strong counter argument to allow non-dart files here. |
I am going to go ahead and close this pr - that doesn't mean the discussion has to end but I am pretty convinced that we shouldn't allow this for the reasons listed above. |
@jakemac53 cuz there are real use cases for non-Dart inputs*. You are not broadening the scope of the package, you are making sure that the package is not more widely usable. What design decision are going to be hampered? if the package handles it correctly then nullsafety can be achieved correctly. I agree LibraryReader could be null and the package could easily handle that appropriately in _generateForLibrary. Look it seems you have made up your mind and you want to limit the scope and you have the right to do that. But there are very real use cases that would require non-dart inputs. You can search the gitter and you will find people who have mentioned them, in any case I am not going to discuss this. I will maintain my fork until I find a better abstraction that handles more comprehensive use cases and move on. |
Those use cases can use I don't understand how using The most relevant use case I can see for using builders:
my_builder:
target: "my_builder"
import: "package:my_builder/builder.dart"
builder_factories: ["myBuilder"]
build_extensions: {".json": [".my_output.g.part"]}
auto_apply: dependents
build_to: cache
applies_builders: ["source_gen|combining_builder"] |
The current source generator only works with dart code even for LibraryBuilder, which kind not does not make sense. This change will support to generate code for non-dart extension.