lucidsoftware / rules_twirl

Bazel rules for compiling Twirl templates
Apache License 2.0
3 stars 9 forks source link

Custom Encoding #27

Open olib963 opened 4 years ago

olib963 commented 4 years ago

Thanks for the work on creating a bazel wrapper for twirl!

It seems the default encoding used by bazel is US-ASCII, we are moving from SBT to bazel and the sbt plugin uses a default of UTF-8. This change is causing any UTF-8 special characters to be written as "??" in our compiled templates.

I have managed to get the default character set in the JVM to be UTF-8 by setting:

build --action_env JAVA_TOOL_OPTIONS="-Dfile.encoding=UTF-8"
test --test_env JAVA_TOOL_OPTIONS="-Dfile.encoding=UTF-8"

in .bazelrc but this does not seem to be passed on to the twirl compiler.

I was wondering if you had a suggested approach to solving this. I can do a little dive into the code and try to get it running locally but I thought I would check if you already had something in mind for this.

olib963 commented 4 years ago

After a brief look setting jvm_flags = ["-Dfile.encoding=UTF-8"] on the java binary seems to fix this. I have just redeclared this binary in my own project by adding the CLI to my maven dependencies and creating a new target.

If you feel this is a suitable work around please close the issue :D Personally I think it would be nice if this could be configured.

SrodriguezO commented 4 years ago

Hey @olib963, thanks for looking into this!

I think having this be configurable is a good idea. A simple select on the compiler-cli binary would probably do the trick. This could set jvm_flags = ["-Dfile.encoding=UTF-8"] if --action_env JAVA_TOOL_OPTIONS="-Dfile.encoding=UTF-8" is specified but default to the current behavior otherwise. Would you be interested in opening a PR?

olib963 commented 4 years ago

Thanks for the quick response :D I would be happy to look into a PR sometime next week. I am a little new to bazel so will try my best to get something up and running.

Would you prefer the approach that we

SrodriguezO commented 4 years ago

Using --action_env probably makes the most sense here :) That really is the expected behavior, but we decoupled the twirl templates compiler cli from the rule set (i.e. it's pre-built now) which means Bazel command args don't affect it.