-
Notifications
You must be signed in to change notification settings - Fork 180
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
Set RUBY_ENGINE to truffleruby and fix related libs #46
Conversation
@@ -51,8 +51,7 @@ | |||
public static final String RUBY_VERSION = "2.3.1"; | |||
public static final int RUBY_REVISION = 0; | |||
public static final String COMPILE_DATE = "2017"; | |||
// TODO (pitr-ch 11-Jan-2017): use our value when we are recognized by rubygems |
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.
Specific workarounds are better than waiting for a new RubyGems version (but we should fix upstream as well obviously).
We can also patch our own Rubygems of course.
There may be some failures due to updating this. We'll probably need to shim/update in some places. This was one usage that came to mind: |
@bjfish This is in Bundler specs, right? |
I think there's similar usage in the lib somewhere. Maybe here: https://github.com/bundler/bundler/blob/121ada2a1842ebe9989f35567e2dd829ec06b7a1/lib/bundler/ruby_version.rb#L108 |
@bjfish please have a look at my commit introducing the change form jruby, it'll help to track down what has to be fixed |
@pitr-ch Which commit it that? |
@eregon git blame of line #46 (diff) |
83c0f24 is the commit |
421e2d1
to
4a715d7
Compare
It looks like bundler is not even resolving the tested gem as a dependency, therefore it is not put in $LOAD_PATH. This is why I went for the "ruby" originally to avoid untangling bundler complexities ;) until it's fixed properly without hacks. I rather not spend time on this. I think we all agree that RUBY_ENGINE should be 'truffleruby' but lets wait until bundler recognises truffleruby. |
What does it mean? We will need to find out how to make it work anyway and make a PR to Bundler. Maybe we can ask some help from the Bundler team? |
@eregon exactly, I'll update bundler and submit a PR. I would like to avoid hacking it in the meantime, especially if RUBY_ENGINE='ruby' works fine. |
fix #46 |
0f7c6d1
to
ead57a4
Compare
@@ -38,6 +38,8 @@ | |||
end | |||
end | |||
|
|||
require 'truffle/patching' |
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.
Isn't it too late? What if we want to patch something in rubygems?
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.
Most of the rubygem files is loaded lazily, so it works. If we need to patch any of the eagerly loaded files it can be done manually here. I rather expect we'll be removing the patches rather than adding new ones, it should not be a problem.
@@ -789,6 +789,7 @@ private void initializeConstants() { | |||
Layouts.MODULE.getFields(rubiniusFFIModule).setConstant(context, node, "TYPE_VARARGS", RubiniusTypes.TYPE_VARARGS); | |||
|
|||
Layouts.MODULE.getFields(objectClass).setConstant(context, node, "RUBY_VERSION", frozenUSASCIIString(RubyLanguage.RUBY_VERSION)); | |||
Layouts.MODULE.getFields(objectClass).setConstant(context, node, "TRUFFLERUBY_VERSION", frozenUSASCIIString(RubyLanguage.getTruffleRubyVersion())); |
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.
Should it be TRUFFLERUBY_VERSION
(like JRUBY_VERSION
)
or Truffle::VERSION
(like Rubinius::VERSION
) ?
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.
Both are fine to me, the advantage of TRUFFLERUBY_VERSION
is that's easier to check, even if defined?
is buggy (as we used to have) and it's not the "Truffle version" but the "TruffleRuby version".
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.
Since there is already RUBY_VERSION, JRUBY_VERSION I would follow this pattern.
@@ -687,7 +686,9 @@ def subcommand_run(rest) | |||
{}). | |||
merge(@options[:run][:offline] ? | |||
{ 'GEM_HOME' => @options[:run][:offline_gem_path].to_s, | |||
'GEM_PATH' => @options[:run][:offline_gem_path].to_s } : | |||
'GEM_PATH' => @options[:run][:offline_gem_path].to_s, | |||
'PATH' => [p(@options[:run][:offline_gem_path].join('bin').to_s), ENV['PATH']].join(':') |
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.
Debug p
in here.
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.
ah thanks
lib/truffle/truffle/patching.rb
Outdated
@@ -0,0 +1,38 @@ | |||
module Truffle::Patching | |||
TRUFFLE_PATCHES_DIRECTORY = File.join(Truffle::Boot.ruby_home, 'lib', 'patches') | |||
TRUFFLE_PATCHES = Dir.glob(File.join(TRUFFLE_PATCHES_DIRECTORY, '**', '*.rb')). |
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.
Please avoid File.join
, it just adds clutter, and in the case of Dir.glob
is even potentially incorrect (if File::SEPARATOR is changed). Filesystem pathnames in Ruby are always represented with /
.
lib/truffle/truffle/patching.rb
Outdated
TRUFFLE_PATCHES = Dir.glob(File.join(TRUFFLE_PATCHES_DIRECTORY, '**', '*.rb')). | ||
select { |path| File.file? path }. | ||
map { |path| path[(TRUFFLE_PATCHES_DIRECTORY.size+1)..-4] }. | ||
reduce ({}) { |h, v| h.update v => true } |
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 find the pure functional approach here more verbose and also much less efficient.
I propose:
TRUFFLE_PATCHES = {}
Dir.glob("#{TRUFFLE_PATCHES_DIRECTORY}/**/*.rb") do |path|
if File.file? path
feature = path[(TRUFFLE_PATCHES_DIRECTORY.size+1)...-3]
TRUFFLE_PATCHES[feature] = true
end
end
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's evaluated only once over about a dozen of files, I don't think performance is relevant in this particular case. As for functional vs. imperative style I think this is matter of taste, I find functional clearer, more readable. Since I think it's only a matter of personal taste in this case, I'll leave it as is.
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 matters because this runs during startup, isn't it?
It creates 3 extra Arrays, plus 2*n
(number of patch files) Hashes, not exactly optimal.
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.
Array#to_h
might be a good compromise here, with [path[...], true]
in the map block.
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 does run on startup, but 3 arrays of about ten elements, that's insignificant compared to everything else. The code will also be eventually removed anyway. It's a single hash though, update does not create new instances or did you mean something else?
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.
Ah, Hash#update
is Hash#merge!
(don't use update
, it's an uncommon alias)
v => true
creates a Hash per iteration.
Measure it if you want.
But anyway I think reduce/inject + modifying inplace the accumulator is an anti-pattern that just adds complexity with extra variables and caring of the return value, for no gain.
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.
to_h is best option
lib/patches/bundler/ruby_version.rb
Outdated
else | ||
# not defined in ruby 1.8.7 | ||
"ruby" | ||
end |
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.
This is very weirdly indented, I would rather keep the same indentation as the source to ease comparison.
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.
(on a side note, I personally find no value to aligning assignments)
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.
yeah, auto-formatted by mistake.
(I got used to them only because I prefer aligned hash's keys and values and there is only one option for both in idea and I won't go against auto-formatter.)
lib/patches/bundler/ruby_version.rb
Outdated
Rubinius::VERSION.dup | ||
when "jruby" | ||
JRUBY_VERSION.dup | ||
when 'truffleruby' # added case branch |
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 would be good to use a common prefix to mean "comment added for TruffleRuby support".
We used to have # Truffle: my comment
which I think is easy to spot.
I think we should be consistent.
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.
yeah, I'll use # TruffleRuby:
, and update the comments.
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.
They are quite a few # Truffle:
, I think it's best to update them all in a different PR.
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 already pushed here.
lib/patches/bundler/dependency.rb
Outdated
# add record for truffleruby | ||
Bundler::Dependency.send :const_set, | ||
:PLATFORM_MAP, | ||
old_value.merge(truffleruby: Gem::Platform::RUBY) |
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 prefer just:
Bundler::Dependency::PLATFORM_MAP[:truffleruby] = Gem::Platform::RUBY
It is much easier to see what's happening.
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.
The hash is frozen, therefore it has to be replaced.
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.
Unfortunate, maybe something like this would simplify a little:
class Bundler::Depedency
const_set PLATFORM_MAP, PLATFORM_MAP.merge(truffleruby: Gem::Platform::RUBY)
end
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.
Yeah, maybe, it's just a patch though.
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.
Might as well make it readable.
lib/patches/bundler/dependency.rb
Outdated
end | ||
|
||
reverse_platform_map.each { |_, platforms| platforms.freeze } | ||
end.freeze) |
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.
Same here, please use a clearer imperative approach with less nesting.
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.
This is a copy of original code, keeping it.
@@ -0,0 +1,38 @@ | |||
module Truffle::Patching |
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.
This approach is quite different than what I had in mind in #68 (comment). Your approach could also use that mechanism, but it is simpler and sufficient for now, so let's keep it simple 👍
Could you add a lib/patches/README.md
to document briefly what it is for and what it does?
1c74877
to
bbbfb5b
Compare
* introduce patching system, loads a file from patches directory after a file with same is required * replace bundler-workarounds with patches * make bundler recognize truffleruby * remove few unnecessary fixes * C extensions are not built by default, TRUFFLERUBY_CEXT_ENABLED can be set to enable
bbbfb5b
to
f3f85c2
Compare
* commit '0f3ffd2ecabba9de24ba8aaae5351755fcb42800': Change the imagename in the GraalVM property file.
Typo Merge-Requested-By: XrXr Merge-Queue-Emergency-Bypass: True
No description provided.