-
Notifications
You must be signed in to change notification settings - Fork 126
javaextensiontask.rb - check javac path using JAVA_HOME
#247
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
Conversation
|
Sorry for the ping. You and Pavel have the two most recent commits here. I'm somewhat java challenged. Does this look ok? JFYI, started with Puma failing on jruby-head... |
7ba0151 to
da7dea5
Compare
lib/rake/javaextensiontask.rb
Outdated
| EOF | ||
| warn_once(not_jruby_compile_msg) unless defined?(JRUBY_VERSION) | ||
|
|
||
| javac_path = File.exist?(t = File.join(ENV["JAVA_HOME"], "bin", "javac")) ? |
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 seems that ENV["JAVA_HOME"] may not exist:
rake-compiler/lib/rake/javaextensiontask.rb
Lines 267 to 268 in 150c8e3
| jruby_home = ENV['JRUBY_HOME'] | |
| if jruby_home |
Can we reuse the checked ENV["JAVA_HOME"] 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.
Not sure if ENV["JAVA_HOME"] is used anywhere?
Can we use:
ENV.fetch("JAVA_HOME", "/")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 just pushed a change to using ENV.fetch. Used "/" for the default so it's an absolute path...
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.
Oh, sorry. It's JRUBY_HOME not JAVE_HOME...
lib/rake/javaextensiontask.rb
Outdated
| javac_path = File.exist?(t = File.join(ENV.fetch("JAVA_HOME", "/"), "bin", "javac")) ? | ||
| t : "javac" |
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.
Using / as the default JAVA_HOME will not work when javac exists in both of /usr/bin/javac and /usr/local/bin/javac, and PATH is /usr/local/bin:/usr/bin:/bin.
We may need to check ENV["JAVA_HOME"] explicitly:
| javac_path = File.exist?(t = File.join(ENV.fetch("JAVA_HOME", "/"), "bin", "javac")) ? | |
| t : "javac" | |
| java_home = ENV["JAVA_HOME"] | |
| if java_home | |
| javac_path = File.join(java_home, "bin", "javac") | |
| javac_path = nil unless File.exist?(javac_path) | |
| end | |
| javac_path ||= "javac" |
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.
Thanks for the review. I'm not sure about your example, it seems a rather extreme and odd edge case. Also, I'm not familiar with all of the *nix distributions.
"/" was a bad choice for default, as File.join('/', 'bin', 'javac')" and File.join('', 'bin', 'javac') both equal "/bin/javac".
The previous code worked correctly when used with GHA. But your changes also work.
Updated with your suggested code.
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.
Oh, sorry. I considered the following case:
ENV["PATH"]is"/usr/local/bin:/usr/binENV["JAVA_HOME"]isn't set/usr/local/bin/javacexists/usr/bin/javacexists
In the case, javac uses /usr/local/bin/javac but File.join(ENV.fetch("JAVA_HOME", "/"), "bin", "javac") uses /usr/bin/javac not /usr/local/bin/javac.
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.
Sorry, I need to try this.
If ENV["JAVA_HOME"] isn't set, then ENV.fetch("JAVA_HOME", "/"), "bin", "javac") yields /bin/javac, I thought File.exist?("/bin/javac") would be false, and then javac would be used, and the file would be resolved by PATH?
Again, I need to try it.
Regardless, thanks for your help and the new release.
|
Some background on this issue. At present, GitHub Actions (GHA) runners provide at least three Java versions (11, 17, 21). Some provide version 8. Version 17 is the default. JRuby 10/head requires version 21. This PR finishes the work by using |
|
@headius I'll merge this and release a new version. If you have any problem with this, please share it. |
|
Thanks for this PR. It works fine on UNIX but not Windows: I'm unsure if it's a bug of |
|
It seems So I guess we should just hack it with File.join(java_home.tr('\\', '/'), "bin", "javac")then, or seeing that File.join is beyond useless here, just: "#{java_home.tr('\\', '/')}/bin/javac" |
|
Oof even that doesn't work, Windows is truly cursed IMO: At this point I'll let others investigate/fix it. |
|
Ah, it's my mistake on Windows there is no bin/javac, it's bin/javac.exe. Sanity has returned. |
|
@kou so there is db38e70 but https://rubygems.org/gems/rake-compiler only has 1.3.0 not 1.3.1, so it seems you forgot to push the gem or it didn't work? That would also explain why CI failed on ruby/strscan#155 And now I found the discussion I recalled: ruby/strscan#151 |
|
@headius IMO this is messy enough that I think it would be better to add |
* See discussion in rake-compiler/rake-compiler#247 it is messy if that's not the case and also creates inconsistencies based on which Java tool/executable is used.
|
I went ahead and did a PR to do that so we can't run into such issues again: ruby/setup-ruby#836 |
* See discussion in rake-compiler/rake-compiler#247 it is messy if that's not the case and also creates inconsistencies based on which Java tool/executable is used.
|
Oh, sorry. I didn't notice it. I've published 1.3.1. |
JRuby-head is using JDK 21. This is not the default on GHA.
setup-rubyadded code to changeJAVA_HOME, assuming it would trigger the correct JDK being used.Puma tests against jruby-head, and it was failing when rake compile ran. After reviewing the code,
javacis being called without a path.Added code to check if
File.join(ENV["JAVA_HOME"], "bin", "javac")exists. If it does, use the full path, otherwise fallback to current behavior.I changed the Gemfile in Puma to use the PR branch, and the job correctly compiles.