Skip to content

Commit

Permalink
debug for #5335
Browse files Browse the repository at this point in the history
$os_build3/Products/openstudio --loglevel Debug --bundle Gemfile --bundle_path ./gems -e "puts ''; puts ''; puts 'REQUIRE AGAIN'; STDOUT.flush; require 'bundler/errors'" &> log.txt
  • Loading branch information
jmarrec committed Dec 20, 2024
1 parent 73e12b9 commit a8588f8
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 40 deletions.
94 changes: 55 additions & 39 deletions ruby/bindings/InitRubyBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ module IRB # :nodoc:
@CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
# puts @CONF[:PROMPT_MODE]
os_version = "3.8.0" # OpenStudio::openStudioVersion
os_version = "3.9.0" # OpenStudio::openStudioVersion
@CONF[:PROMPT][:OPENSTUDIO] = {
:PROMPT_I=>"(os #{os_version}) :%03n > ",
:PROMPT_S=>"(os #{os_version}) :%03n%l> ",
Expand Down Expand Up @@ -758,6 +758,15 @@ ENV.reject! { |k, _| ['GEM', 'BUNDLE'].any? { |x| k.start_with?(x) } }
if md = /specifications\/.*\.gemspec$/.match(f) ||
md = /bundler\/.*\.gemspec$/.match(f)
begin
puts "* #{f}"
if /bundler.*gemspec/.match(f)
if f.include?('specifications')
puts "Skipping bundler from specifications/: #{f}"
next
else
puts "Catching #{f}"
end
end
spec = EmbeddedScripting::getFileAsString(f)
s = eval(spec)
Expand Down Expand Up @@ -851,6 +860,7 @@ ENV.reject! { |k, _| ['GEM', 'BUNDLE'].any? { |x| k.start_with?(x) } }

if (use_bundler) {
initCmd += R"ruby(
puts "embedded_gems_to_activate=#{embedded_gems_to_activate}"
# Load the bundle before activating any embedded gems
embedded_gems_to_activate.each do |spec|
if spec.name == "bundler"
Expand All @@ -861,7 +871,12 @@ ENV.reject! { |k, _| ['GEM', 'BUNDLE'].any? { |x| k.start_with?(x) } }
begin
# Activate will manipulate the $LOAD_PATH to include the gem
puts "=" * 80
puts "LOAD_PATH=#{$LOAD_PATH}"
puts "Activating spec"
spec.activate
puts "LOAD_PATH=#{$LOAD_PATH}"
puts "=" * 80
rescue Gem::LoadError => e
# There may be conflicts between the bundle and the embedded gems,
# those will be logged here
Expand All @@ -884,53 +899,54 @@ ENV.reject! { |k, _| ['GEM', 'BUNDLE'].any? { |x| k.start_with?(x) } }
RbConfig::CONFIG['arch'] = 'x64-mingw32'
end
# require bundler
# have to do some forward declaration and pre-require to get around autoload cycles
require 'bundler/errors'
#require 'bundler/environment_preserver'
require 'bundler/plugin'
#require 'bundler/rubygems_ext'
require 'bundler/rubygems_integration'
# Global list, to be populated below
$ignore_native_gem_names = []
puts "Requiring bundler"
# require bundler
# have to do some forward declaration and pre-require to get around autoload cycles
require 'bundler/errors'
#require 'bundler/environment_preserver'
require 'bundler/plugin'
#require 'bundler/rubygems_ext'
require 'bundler/rubygems_integration'
module Bundler
class RubygemsIntegration
# Global list, to be populated below
$ignore_native_gem_names = []
alias :ori_spec_missing_extensions? :spec_missing_extensions?
module Bundler
class RubygemsIntegration
def spec_missing_extensions?(spec, default = true)
alias :ori_spec_missing_extensions? :spec_missing_extensions?
# This avoids getting an annoying message for no reason
if $ignore_native_gem_names.any? {|name| name == spec.name }
return false
end
def spec_missing_extensions?(spec, default = true)
return ori_spec_missing_extensions?(spec, default)
# This avoids getting an annoying message for no reason
if $ignore_native_gem_names.any? {|name| name == spec.name }
return false
end
return ori_spec_missing_extensions?(spec, default)
end
end
end
require 'bundler/version'
require 'bundler/ruby_version'
#require 'bundler/constants'
#require 'bundler/current_ruby'
require 'bundler/gem_helpers'
#require 'bundler/plugin'
require 'bundler/source'
require 'bundler/definition'
require 'bundler/dsl'
require 'bundler/uri_credentials_filter'
require 'bundler/uri_normalizer'
require 'bundler/index'
require 'bundler/digest'
require 'bundler/source/git'
require 'bundler/source/git/git_proxy'
require 'bundler/match_remote_metadata'
require 'bundler/remote_specification'
require 'bundler/stub_specification'
require 'bundler'
require 'bundler/version'
require 'bundler/ruby_version'
#require 'bundler/constants'
#require 'bundler/current_ruby'
require 'bundler/gem_helpers'
#require 'bundler/plugin'
require 'bundler/source'
require 'bundler/definition'
require 'bundler/dsl'
require 'bundler/uri_credentials_filter'
require 'bundler/uri_normalizer'
require 'bundler/index'
require 'bundler/digest'
require 'bundler/source/git'
require 'bundler/source/git/git_proxy'
require 'bundler/match_remote_metadata'
require 'bundler/remote_specification'
require 'bundler/stub_specification'
require 'bundler'
begin
# activate bundled gems
Expand Down
16 changes: 15 additions & 1 deletion ruby/engine/embedded_help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def require_embedded_extension path
end

def require path
puts "\nrequire, path=#{path}"
result = false
original_directory = Dir.pwd
path_with_extension = path
Expand All @@ -158,20 +159,25 @@ def require path
if extname.empty? or ! RUBY_FILE_EXTS.include? extname
path_with_extension = path + '.rb'
end
puts "path_with_extension=#{path_with_extension}"

if path.include? 'openstudio/energyplus/find_energyplus'
puts "ladder1"
return false
elsif path_with_extension.to_s.chars.first == ':'
puts "ladder2"
# Give absolute embedded paths first priority
if $LOADED.include?(path_with_extension)
return true
puts "ladder2 - already loaded"
return true
else
return require_embedded_absolute(path_with_extension)
end
elsif path_with_extension == 'openstudio.rb'
# OpenStudio is loaded by default and does not need to be required
return true
elsif require_embedded(path_with_extension, $LOAD_PATH)
puts "ladder3"
# Load embedded files that are no required using full paths now
# This does not included the openstudio-gems set of default, baked in gems
# because we want to give anything provided by --bundle the first chance
Expand All @@ -182,6 +188,7 @@ def require path
result = original_require path
end
rescue Exception => e
puts "exception - embedded gems"
# This picks up the embedded gems
# Important to do this now, so that --bundle has first chance
# using rescue in normal program flow, might have poor performance
Expand Down Expand Up @@ -211,6 +218,7 @@ def require path
end

def require_embedded(path, search_paths)
puts "require_embedded, path=#{path}, search_paths=#{search_paths}"
search_paths = [] if not search_paths
search_paths.each do |p|
if p.to_s.chars.first == ':'
Expand All @@ -227,12 +235,16 @@ def require_embedded(path, search_paths)
end

def require_embedded_absolute path
puts "require_embedded_absolute path=#{path}"
original_directory = Dir.pwd

$LOADED << path
s = EmbeddedScripting::getFileAsString(path)
s = OpenStudio::preprocess_ruby_script(s)

puts $LOADED
STDOUT.flush

result = Kernel::eval(s,BINDING,path)


Expand All @@ -247,8 +259,10 @@ def require_embedded_absolute path

def require_relative path
absolute_path = File.dirname(caller_locations(1,1)[0].path) + '/' + path
puts "\n\nrequire_relative, path=#{path}, absolute_path=#{absolute_path}"
if absolute_path.to_s.chars.first == ':'
absolute_path = OpenStudio.get_absolute_path(absolute_path)
puts "get_absolute_path=#{absolute_path}"
end
return require absolute_path
end
Expand Down

0 comments on commit a8588f8

Please sign in to comment.