Skip to content

Convoluted codegen build process #58

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

Open
fabienrenaud opened this issue May 22, 2017 · 3 comments
Open

Convoluted codegen build process #58

fabienrenaud opened this issue May 22, 2017 · 3 comments

Comments

@fabienrenaud
Copy link

I can not wrap my head around how the codegen build process is supposed to work smoothly...
I did get it to work (with gradle), but steps were convoluted.

The StaticCodeGenerator expects to find .java file from the current directory and yet have the .class file of the same class available in its classpath. When both conditions are satisfied, it generates sources (encoder+decoder packages) and puts them in the source directory (src/main/java) which then needs to be compiled again.

In gradle language, the series of tasks are: clean compileJava jsoniterCodegen clean build
Note: I have to run clean after the 'jsoniterCodegen' otherwise gradle doesn't run compileJava task again.

Although it can work. Compiling the entire project twice, or running the custom jsoniterCodegen task manually every time it may be needed isn't nice (and is slow).

There are a couple of ways of fixing this:

  • don't build java sources, write bytecode .class directly. this opens to the possibility of running the custom jsoniter task after :compileJava, during the :classes task (which is part of the build lifecycle for the java gradle plugin). I understand this is a v0.x though so the java sources may be kept around for as long as easy debugging of generated code may be necessary.
  • don't create any dependency between DemoCodegenConfig and jsoniter lib (just use reflection at build time to check whether it implements both methods). This way, it would be possible run a simple javac on the java file and move it to the right place (which StaticCodeGenerator could do too).

In addition, it would be nice if I could specify where to put the new files; I like to put my generated sources in a specific directory. I could do that if this if check was dropped:

if (!new File(configJavaFile).exists()) {
or if there was an option for the target source directory where StaticCodeGenerator should write java files.

Let me know if anything is unclear.

@taowen
Copy link
Contributor

taowen commented May 23, 2017

  • generating the .class is not option. static codegen is not there for performance reason, but to support platform like Android. Will gradle pickup the .class, and include them into the apk? I am familiar with android development. If that is true, I can codegen .class file.
  • don't create any dependency between DemoCodegenConfig and jsoniter lib (just use reflection at build time to check whether it implements both methods). Can you elaborate on this? javac => static codegen => javac again, This process is convoluted because I need to use reflection api to read your model classes. I don't see any other way to simplify these. Unless rewrite everything without reflection api.
  • The argument to specify codegen target directory will be added

taowen added a commit that referenced this issue May 23, 2017
@fabienrenaud
Copy link
Author

What about generating bytecode directly (form class files and using reflection) instead of java code? Just like annotation processors usually do...

@taowen
Copy link
Contributor

taowen commented May 23, 2017

I can provide that as an option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants