-
Notifications
You must be signed in to change notification settings - Fork 222
Fix #5406 - Regression in CLI on Windows: openstudio ruby_version fails on develop #5407
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
jmarrec
left a comment
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 particularly happy about how fragile this all seems, but it fixes the immediate issue.
@kbenne please review!
|
|
||
| openstudio::evalString(initScript); | ||
|
|
||
| #ifndef _WIN32 // no io/console available |
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.
When LogLevel = Trace, don't pre-require IRB on windows, it fails
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.
Fixes #5216?
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 thanks.
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.
Wait, so why no irb on windows? It fails due to no io/console or because of the logging bug?
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.
no io/console
| absolute_path = ':' + absolute_path | ||
| else | ||
| absolute_path = File.expand_path p2 | ||
| absolute_path = File.expand_path p |
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.
Weirdly enough, this has always been broken. p2 isn't defined 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.
so we never called this function on a non embedded file?
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.
correct. We don't use it directly basically, and checks were doing prior to calling it.
| end | ||
|
|
||
| def self.glob(pattern, *args, **options) | ||
| def self.glob(pattern, _flags = 0, flags: _flags, base: nil, sort: 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.
Right, so strap yourself.
First off: In Ruby 3.x, especially post-3.1, many core methods have been migrated to use the new RubyVM Primitive interface — which acts as a bridge between Ruby and C-defined functions, often exposed via FFI-like syntax for performance and modularity.
https://github.com/ruby/ruby/blob/f91480d7a671b1b114270a4b5e4d3c5aa6dabce9/dir.rb#L219-L221
def self.glob(pattern, _flags = 0, flags: _flags, base: nil, sort: true)
Primitive.dir_s_glob(pattern, flags, base, sort)
endThere 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.
Side note about what the heck that this:
def self.glob(pattern, _flags = 0, flags: _flags, base: nil, sort: true)
This is subtle Ruby trick used for backward compatibility with older versions of Ruby where Dir.glob accepted a positional second argument (flags) instead of keyword arguments.
_flags = 0 # Default value if the second positional argument isn't given
flags: _flags # Keyword argument `:flags` defaults to the positional `_flags`
In other words:
-
Calling
Dir.glob("*.rb", File::FNM_DOTMATCH)(using the old 2-argument form),_flagswill be assigned File::FNM_DOTMATCH, andflags:will default to that. -
Calling
Dir.glob("*.rb", flags: File::FNM_DOTMATCH), the keyword argument will override the default.
ruby/engine/embedded_help.rb
Outdated
| def self.glob(pattern, _flags = 0, flags: _flags, base: nil, sort: true) | ||
|
|
||
| debug = false | ||
| debug = !base.nil? && base.start_with?(':/ruby/gems/3.2.0/specifications/default') |
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 need to remove this
| pattern_has_embedded = pattern_array.any? {|p| p.to_s.chars.first == ':'} | ||
| base_has_embedded = (!base.nil? && base.to_s.chars.first == ':') | ||
| if !pattern_has_embedded && !base_has_embedded | ||
| # puts "Original glob" | ||
| return self.original_glob(pattern, flags: flags, base: base, sort: sort) | ||
| 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.
If nothing has an embedded thingy, just forward to the original method.
| absolute_base = if base.nil? | ||
| nil | ||
| else | ||
| OpenStudio.get_absolute_path(base) | ||
| 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.
If the base is provided, get_absolute_path it, which will just do File.expand_path base if base is not embedded. I could have used File.expand_path or File.absolute_path I guess, which we override.
| absolute_pattern = if pattern.to_s.chars.first == ':' | ||
| OpenStudio.get_absolute_path(pattern) | ||
| else | ||
| pattern | ||
| 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.
Now, the pattern needs to be expanded only if it's an embedded one.
Eg if this is '*.gemspec', don't expand it to $(pwd)/*.gemspec which is going to be on your actual host filesystem always.
(Note: I suppose doing File.expand_path(pattern, base) was a possibility)
| EmbeddedScripting::fileNames.each do |name| | ||
| absolute_path = OpenStudio.get_absolute_path(name) | ||
| if base_has_embedded | ||
| next unless absolute_path.start_with?(absolute_base) | ||
| if debug | ||
| puts "name=#{name}, absolute_path=#{absolute_path}" | ||
| puts "absolute_path.start_with?(absolute_base)=#{absolute_path.start_with?(absolute_base)}" |
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.
loop on the embedded fileNames (which all start with ':/'), skip if they don't match the base
| #if override_args_extglob | ||
| # if File.fnmatch( absolute_pattern, absolute_path, File::FNM_EXTGLOB ) | ||
| if File.fnmatch(absolute_pattern, absolute_path, flags) | ||
| #puts "#{absolute_path} is a match!" | ||
| result << 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.
Can fnmatch, afaik there's no need to override the flags.
|
Oh cool, I have new failures in bundle test on Ubuntu! Only when --loglevel Trace. Nice. |
|
Are we missing some kind of CI test for the Windows issue? Seems like we shouldn’t have to rely on someone installing OS on their machine to discover this problem. |
893f134 to
e2ea133
Compare
|
Not sure what's up on CI 24.04, locally I have: 1/7 Test #4019: CLITest-test_bundle-bundle_native ............ Passed 23.26 sec (note: I no longer use rvm, but rbenv) |
CI was (and somewhat still is, we have open issues tagged "Continuous Integration") so utterly bricked that this just didn't raise any alarms. I'm still going to add a quick test though: 6667e19 |
* rubygems.rb calls Gem::Specification.load_defaults
* https://github.com/ruby/ruby/blob/f91480d7a671b1b114270a4b5e4d3c5aa6dabce9/lib/rubygems.rb#L1355
* That uses each_spec([Gem.default_specifications_dir]),
* Gem.default_specifications_dir is now `:/ruby/gems/3.2.0/specifications/default"`
* That ends up calling rubygems/util.rb#glob_files_in_dir
* https://github.com/ruby/ruby/blob/f91480d7a671b1b114270a4b5e4d3c5aa6dabce9/lib/rubygems/util.rb#L100-L102
* Essentially calling `Dir.glob('*.gemspec', ':/ruby/gems/3.2.0/specifications/default')`
e2ea133 to
6667e19
Compare
|
CI Results for 6667e19:
|
|
FWIW, using the Windows installer from this PR I no longer see "Segmentation fault" or "Failed to execute ..." for |
|
It doesn't seem any more fragile than what we have been doing all along. The fragility just seems to be highlighted when Ruby changes things. My main thought is that I'm glad you were able to make this work, but I'm still in favor of ditching the embedded system. |
|
|
||
| openstudio::evalString(initScript); | ||
|
|
||
| #ifndef _WIN32 // no io/console available |
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.
Wait, so why no irb on windows? It fails due to no io/console or because of the logging bug?
| absolute_path = ':' + absolute_path | ||
| else | ||
| absolute_path = File.expand_path p2 | ||
| absolute_path = File.expand_path p |
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.
so we never called this function on a non embedded file?
Pull request overview
--loglevel Tracefails on Windows #5216More ruby shenanigans due to embedded filesystem! Yay!
Eventually I traced down the issue.
rubygems.rbcallsGem::Specification.load_defaultseach_spec([Gem.default_specifications_dir])Gem.default_specifications_diris now:/ruby/gems/3.2.0/specifications/default"because Fix #5388 - --bundle options not working for CLI in docker-openstudio, possibly OS itself + Fix #5190 - Don't pick up system gem in CLI #5394 changed the rubylibprefix and co to point to the embedded filesystemrubygems/util.rb#glob_files_in_dirDir.glob('*.gemspec', ':/ruby/gems/3.2.0/specifications/default')Pull Request Author
src/model/test)src/energyplus/Test)src/osversion/VersionTranslator.cpp)Labels:
IDDChangeAPIChangePull Request - Ready for CIso that CI builds your PRReview Checklist
This will not be exhaustively relevant to every PR.