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

Debug bundler #5159

Merged
merged 7 commits into from
Apr 22, 2024
Merged

Debug bundler #5159

merged 7 commits into from
Apr 22, 2024

Conversation

jmarrec
Copy link
Collaborator

@jmarrec jmarrec commented Apr 19, 2024

Pull request overview

Pull Request Author

  • Model API Changes / Additions
  • Any new or modified fields have been implemented in the EnergyPlus ForwardTranslator (and ReverseTranslator as appropriate)
  • Model API methods are tested (in src/model/test)
  • EnergyPlus ForwardTranslator Tests (in src/energyplus/Test)
  • If a new object or method, added a test in NREL/OpenStudio-resources: Add Link
  • If needed, added VersionTranslation rules for the objects (src/osversion/VersionTranslator.cpp)
  • Verified that C# bindings built fine on Windows, partial classes used as needed, etc.
  • All new and existing tests passes
  • If methods have been deprecated, update rest of code to use the new methods

Labels:

  • If change to an IDD file, add the label IDDChange
  • If breaking existing API, add the label APIChange
  • If deemed ready, add label Pull Request - Ready for CI so that CI builds your PR

Review Checklist

This will not be exhaustively relevant to every PR.

  • Perform a Code Review on GitHub
  • Code Style, strip trailing whitespace, etc.
  • All related changes have been implemented: model changes, model tests, FT changes, FT tests, VersionTranslation, OS App
  • Labeling is ok
  • If defect, verify by running develop branch and reproducing defect, then running PR and reproducing fix
  • If feature, test running new feature, try creative ways to break it
  • CI status: all green or justified

@jmarrec jmarrec requested a review from kbenne April 19, 2024 12:50
@jmarrec jmarrec self-assigned this Apr 19, 2024
Comment on lines +476 to +513
# require 'logger'
# $logger = Logger.new(STDOUT)
# $logger.level = Logger::DEBUG #WARN
# Mimic ruby Logger, but forward to OpenStudio, so we don't have to worry about setting the LogLevel
class ConvenienceLogger

attr_accessor :level

def initialize(log_level)
@level = log_level
end

def trace?
@level <= OpenStudio::Trace
end

def debug(msg)
OpenStudio::logFree(OpenStudio::Debug, "ruby", msg)
end

def info(msg)
OpenStudio::logFree(OpenStudio::Info, "ruby", msg)
end

def warn(msg)
OpenStudio::logFree(OpenStudio::Warn, "ruby", msg)
end

def error(msg)
OpenStudio::logFree(OpenStudio::Error, "ruby", msg)
end

def fatal(msg)
OpenStudio::logFree(OpenStudio::Fatal, "ruby", msg)
end

end
$logger = ConvenienceLogger.new(OpenStudio::Logger.instance.standardOutLogger.logLevel.get)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A clever way to keep the "$logger" code below working, while respecting the user's choice in terms of log level. PReviosuly the C++ CLI was lacking the ability to debug this stuff because the loglevel was set in stone to WARN.

Comment on lines +516 to +518
if $logger.trace?
ENV['DEBUG_RESOLVER'] = "1"
end
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even better than the ruby cli

Comment on lines +766 to +771
rescue Gem::LoadError => e
# There may be conflicts between the bundle and the embedded gems,
# those will be logged here
exception_msg = "Error activating gem #{spec.spec_file}: #{e.class}: #{e.message}\nTraceback:\n"
exception_msg += e.backtrace.join("\n")
STDERR.puts exception_msg
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No matter what I do, I can't get the failure like I do in the ruby cli.

cd OpenStudio/src/cli/test/bundle
ruby --version
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]
bundle install --path ./test_gems

C++

$ $os_build_rel/Products/openstudio --bundle Gemfile.lock --bundle_path './test_gems' --loglevel Debug test.rb
[...]
[ruby] <-2> Adding dependency on tbd '~> 3.4.1'
[ruby] <-2> Adding dependency on topolys '~> 0.6.2'
[ruby] <-2> Adding dependency on unicode-display_width '~> 2.5.0'
[ruby] <-2> Adding dependency on uuid '~> 2.3.9'
[ruby] <-2> Adding dependency on yamler '~> 0.1.0'
[ruby] <-2> Adding dependency on zliby '~> 0.0.5'
[ruby] <-2> Processing 136 activation requests
[ruby] <-2> Activating Bundler gem :/ruby/3.2.0/specifications/bundler-2.5.5.gemspec
Failed to execute '/home/julien/Software/Others/OpenStudio/src/cli/test/bundle/test.rb'

Classic

$ $os_build_rel/Products/openstudio classic --bundle Gemfile.lock --bundle_path './test_gems' --verbose test.rb

[...]
D, [2024-04-19T14:52:29.102995 #1611746] DEBUG -- : Processing 136 activation requests
D, [2024-04-19T14:52:29.119140 #1611746] DEBUG -- : Activating gem :/ruby/3.2.0/specifications/bundler-2.5.5.gemspec
Error executing argv: ["--bundle", "Gemfile.lock", "--bundle_path", "./test_gems", "--verbose", "test.rb"]
Error: 
[!] There was an error parsing `Gemfile.lock`: syntax error, unexpected ':', expecting end-of-input -   remote: http://rubygems.org/
        ^
. Bundler cannot continue.

 #  from /home/julien/Software/Others/OpenStudio/src/cli/test/bundle/Gemfile.lock:2
 #  -------------------------------------------
 #  GEM
 >    remote: http://rubygems.org/
 #    specs:
 #  -------------------------------------------
 in :/ruby/3.2.0/gems/bundler-2.5.5/lib/bundler/dsl.rb:49:in `instance_eval'
:/ruby/3.2.0/gems/bundler-2.5.5/lib/bundler/dsl.rb:49:in `eval_gemfile'
:/ruby/3.2.0/gems/bundler-2.5.5/lib/bundler/dsl.rb:12:in `evaluate'
:/ruby/3.2.0/gems/bundler-2.5.5/lib/bundler/definition.rb:38:in `build'
:/ruby/3.2.0/gems/bundler-2.5.5/lib/bundler.rb:326:in `definition'
:/openstudio_cli.rb:645:in `parse_main_args'
:/openstudio_cli.rb:791:in `execute'
:/openstudio_cli.rb:1994:in `<main>'
eval:233:in `eval'
eval:233:in `require_embedded_absolute'
eval:218:in `block in require_embedded'
eval:212:in `each'
eval:212:in `require_embedded'
eval:171:in `require'
eval:3:in `<main>'

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kbenne that error makes zero sense to me.

@jmarrec jmarrec added the Pull Request - Ready for CI This pull request if finalized and is ready for continuous integration verification prior to merge. label Apr 19, 2024
@jmarrec
Copy link
Collaborator Author

jmarrec commented Apr 19, 2024

Seems like we try to tell Bundler to load a Gemfile.lock when it exepcts a Gemfile instead

image

@jmarrec
Copy link
Collaborator Author

jmarrec commented Apr 19, 2024

I've modified dsl.rb locally in build/openstudio-gems which corresponds to https://github.com/rubygems/rubygems/blob/63bec47bb84105aec729bc12be02770d3f5b48e6/bundler/lib/bundler/dsl.rb#L44-L54

    def eval_gemfile(gemfile, contents = nil)
      expanded_gemfile_path = Pathname.new(gemfile).expand_path(@gemfile&.parent)
      original_gemfile = @gemfile
      @gemfile = expanded_gemfile_path
      @gemfiles << expanded_gemfile_path
      puts "contents=#{contents}"
      contents ||= Bundler.read_file(@gemfile.to_s)
      puts "gemfile=#{gemfile}"
      puts "@gemfile=#{@gemfile.to_s}"
      puts "expanded_gemfile_path=#{expanded_gemfile_path}"
      puts "contents=#{contents}"
      instance_eval(contents, gemfile.to_s, 1)

When I pass the "Gemfile" to the CLI (not the Gemfile.lock) I still have an error

$os_build_rel/Products/openstudio classic --bundle Gemfile --bundle_path './test_gems' --verbose test.rb
D, [2024-04-19T15:30:20.040158 #1628991] DEBUG -- : Activating gem :/ruby/3.2.0/specifications/bundler-2.5.5.gemspec
contents=
gemfile=/home/julien/Software/Others/OpenStudio/src/cli/test/bundle/Gemfile
@gemfile=/home/julien/Software/Others/OpenStudio/src/cli/test/bundle/Gemfile
expanded_gemfile_path=/home/julien/Software/Others/OpenStudio/src/cli/test/bundle/Gemfile
contents=source 'http://rubygems.org'

gem 'openstudio-workflow', '2.2.0' # This is compatible with bundler 2.1 (OS 3.x), and already older than currently used at this time
gem 'tilt', '2.0.8'
Error executing argv: ["--bundle", "Gemfile", "--bundle_path", "./test_gems", "--verbose", "test.rb"]
Error: 
[!] There was an error parsing `Gemfile`: nil is not a class/module. Bundler cannot continue.

 #  from /home/julien/Software/Others/OpenStudio/src/cli/test/bundle/Gemfile:1
 #  -------------------------------------------
 >  source 'http://rubygems.org'
 #  
 #  -------------------------------------------
 in :/ruby/3.2.0/gems/bundler-2.5.5/lib/bundler/source/rubygems.rb:24:in `initialize'
:/ruby/3.2.0/gems/bundler-2.5.5/lib/bundler/source_list.rb:12:in `new'
:/ruby/3.2.0/gems/bundler-2.5.5/lib/bundler/source_list.rb:12:in `global_rubygems_source'
:/ruby/3.2.0/gems/bundler-2.5.5/lib/bundler/source_list.rb:72:in `add_global_rubygems_remote'
:/ruby/3.2.0/gems/bundler-2.5.5/lib/bundler/dsl.rb:180:in `source'
/home/julien/Software/Others/OpenStudio/src/cli/test/bundle/Gemfile:1:in `eval_gemfile'
:/ruby/3.2.0/gems/bundler-2.5.5/lib/bundler/dsl.rb:54:in `instance_eval'
:/ruby/3.2.0/gems/bundler-2.5.5/lib/bundler/dsl.rb:54:in `eval_gemfile'
:/ruby/3.2.0/gems/bundler-2.5.5/lib/bundler/dsl.rb:12:in `evaluate'
:/ruby/3.2.0/gems/bundler-2.5.5/lib/bundler/definition.rb:38:in `build'
:/ruby/3.2.0/gems/bundler-2.5.5/lib/bundler.rb:326:in `definition'
:/openstudio_cli.rb:645:in `parse_main_args'
:/openstudio_cli.rb:791:in `execute'
:/openstudio_cli.rb:1994:in `<main>'
eval:233:in `eval'
eval:233:in `require_embedded_absolute'
eval:218:in `block in require_embedded'
eval:212:in `each'
eval:212:in `require_embedded'
eval:171:in `require'
eval:3:in `<main>'

Base automatically changed from 5147_modernize_measure_templates to develop April 19, 2024 13:41
@jmarrec
Copy link
Collaborator Author

jmarrec commented Apr 19, 2024

Wait, so in that bit where we try to activate the bundler spec, we call bundler itself? Isn't that strange or something?

@jmarrec
Copy link
Collaborator Author

jmarrec commented Apr 19, 2024

So the error happens here:

D, [2024-04-19T15:58:11.967007 #1633316] DEBUG -- : Activating gem :/ruby/3.2.0/specifications/bundler-2.5.5.gemspec
contents=
gemfile=/home/julien/Software/Others/OpenStudio/src/cli/test/bundle/Gemfile
@gemfile=/home/julien/Software/Others/OpenStudio/src/cli/test/bundle/Gemfile
expanded_gemfile_path=/home/julien/Software/Others/OpenStudio/src/cli/test/bundle/Gemfile
contents=source "https://rubygems.org"

# gem 'openstudio-workflow', '2.4.0' # This is compatible with bundler 2.5 / Ruby 3.2 (OS 3.8+), but **NOT** already older than currently used at this time
gem 'tilt', '2.0.8'
Error executing argv: ["--bundle", "Gemfile", "--bundle_path", "./test_gems", "--verbose", "test.rb"]
Error: 
[!] There was an error parsing `Gemfile`: nil is not a class/module. Bundler cannot continue.

 #  from /home/julien/Software/Others/OpenStudio/src/cli/test/bundle/Gemfile:1
 #  -------------------------------------------
 >  source "https://rubygems.org"
 #  
 #  -------------------------------------------
 in :/ruby/3.2.0/gems/bundler-2.5.5/lib/bundler/source/rubygems.rb:24:in `initialize'
:/ruby/3.2.0/gems/bundler-2.5.5/lib/bundler/source_list.rb:12:in `new'
:/ruby/3.2.0/gems/bundler-2.5.5/lib/bundler/source_list.rb:12:in `global_rubygems_source'
:/ruby/3.2.0/gems/bundler-2.5.5/lib/bundler/source_list.rb:72:in `add_global_rubygems_remote'
:/ruby/3.2.0/gems/bundler-2.5.5/lib/bundler/dsl.rb:180:in `source'
+/home/julien/Software/Others/OpenStudio/src/cli/test/bundle/Gemfile:1:in `eval_gemfile'
:/ruby/3.2.0/gems/bundler-2.5.5/lib/bundler/dsl.rb:54:in `instance_eval'
:/ruby/3.2.0/gems/bundler-2.5.5/lib/bundler/dsl.rb:54:in `eval_gemfile'
:/ruby/3.2.0/gems/bundler-2.5.5/lib/bundler/dsl.rb:12:in `evaluate'
:/ruby/3.2.0/gems/bundler-2.5.5/lib/bundler/definition.rb:38:in `build'
:/ruby/3.2.0/gems/bundler-2.5.5/lib/bundler.rb:326:in `definition'
:/openstudio_cli.rb:645:in `parse_main_args'
:/openstudio_cli.rb:791:in `execute'
:/openstudio_cli.rb:1994:in `<main>'
eval:233:in `eval'
eval:233:in `require_embedded_absolute'
eval:218:in `block in require_embedded'
eval:212:in `each'
eval:212:in `require_embedded'
eval:171:in `require'
eval:3:in `<main>'

@kbenne kbenne merged commit d2f4b05 into develop Apr 22, 2024
2 checks passed
@kbenne kbenne deleted the debug_bundler branch April 22, 2024 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Developer Issue Pull Request - Ready for CI This pull request if finalized and is ready for continuous integration verification prior to merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants