Skip to content
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

Custom Encoding #27

Open
olib963 opened this issue Feb 10, 2020 · 4 comments
Open

Custom Encoding #27

olib963 opened this issue Feb 10, 2020 · 4 comments

Comments

@olib963
Copy link

olib963 commented Feb 10, 2020

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
Copy link
Author

olib963 commented Feb 10, 2020

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
Copy link
Contributor

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
Copy link
Author

olib963 commented Feb 10, 2020

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

  • use --action_env
  • use a new parameter
  • allow both with the latter overriding the former?

@SrodriguezO
Copy link
Contributor

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.

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