Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 917139 - dev-ruby/erubi-1.12.0[ruby_targets_ruby32] with dev-lang/ruby-3.2.2-r5[static-libs] fails to install with error erubi.rb:23:in `<module:Erubi>': uninitialized constant Erubi::ERB (NameError)
Summary: dev-ruby/erubi-1.12.0[ruby_targets_ruby32] with dev-lang/ruby-3.2.2-r5[static...
Status: CONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo Ruby Team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-11-10 21:39 UTC by Sebastian Pipping
Modified: 2023-12-06 10:48 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
Build log (dev-ruby:erubi-1.12.0:20231110-211626.log,3.25 KB, text/x-log)
2023-11-10 21:39 UTC, Sebastian Pipping
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sebastian Pipping gentoo-dev 2023-11-10 21:39:51 UTC
Created attachment 874491 [details]
Build log

>>> Install dev-ruby/erubi-1.12.0 into /var/tmp/portage/dev-ruby/erubi-1.12.0/image
 * Running install phase for ruby31
 * Running install phase for ruby32
/var/tmp/portage/dev-ruby/erubi-1.12.0/work/ruby32/erubi-1.12.0/lib/erubi.rb:23:in `<module:Erubi>': uninitialized constant Erubi::ERB (NameError)

    define_singleton_method(:h, ERB::Escape.instance_method(:html_escape))
                                   ^^^^^^^^
        from /var/tmp/portage/dev-ruby/erubi-1.12.0/work/ruby32/erubi-1.12.0/lib/erubi.rb:3:in `<top (required)>'
        from <internal:/usr/lib64/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:86:in `require'
        from <internal:/usr/lib64/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:86:in `require'
        from (eval):2:in `<main>'
        from -e:1:in `eval'
        from -e:1:in `<main>'
 * ERROR: dev-ruby/erubi-1.12.0::gentoo failed (install phase):
 *   Unable to generate gemspec file.
Comment 1 Hans de Graaff gentoo-dev Security 2023-11-11 07:43:04 UTC
I can't reproduce this. ERB should be part of ruby itself, and it also available as a gem (dev-ruby/erb). When both are installed the gem takes precedence.

Do you have dev-ruby/erb installed? Does it help to toggle that?

Looking at this further it seems that ruby 3.1 might not correctly install erb, but it seems that you are getting this error with ruby 3.2 (I assume this is your eselected version).
Comment 2 Sebastian Pipping gentoo-dev 2023-11-11 15:29:38 UTC
Hi Hans, I do not have dev-ruby/erb installed and cannot find a package named like that also.  Is it a typo for dev-ruby/irb with "i"?  That I have installed with both 3.1 and 3.1 enabled via USE.  My eselected ruby is ruby31, not ruby32.
Comment 3 Hans de Graaff gentoo-dev Security 2023-12-03 10:01:32 UTC
(In reply to Sebastian Pipping from comment #2)
> Hi Hans, I do not have dev-ruby/erb installed and cannot find a package
> named like that also.

Ah, my mistake. That package is (still) in my graaff overlay. And I can reproduce this without that package installed, but only for ruby31.
Comment 4 Hans de Graaff gentoo-dev Security 2023-12-03 10:08:05 UTC
(In reply to Hans de Graaff from comment #3)

> Ah, my mistake. That package is (still) in my graaff overlay. And I can
> reproduce this without that package installed, but only for ruby31.

The error I get is different. Your error seems to indicate that erb/escape can be required but doesn't define the module.

What is the output of

ruby31 -e "require 'erb/escape'; puts ERB::Escape.class.inspect"

Bonus points to using strace to determine which escape.so actually gets read.
Comment 5 Sebastian Pipping gentoo-dev 2023-12-03 15:01:29 UTC
> What is the output of
> 
> ruby31 -e "require 'erb/escape'; puts ERB::Escape.class.inspect"

# ruby31 -e "require 'erb/escape'; puts ERB::Escape.class.inspect"
<internal:/usr/lib64/ruby/site_ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:86:in `require': cannot load such file -- erb/escape (LoadError)
Did you mean?  erb/version
        from <internal:/usr/lib64/ruby/site_ruby/3.1.0/rubygems/core_ext/kernel_require.rb>:86:in `require'
        from -e:1:in `<main>'
        

> Bonus points to using strace to determine which escape.so actually gets read.

Did someone say strace? :)  I love strace! :)

# strace -F -efile ruby31 -e "require 'erb/escape'; puts ERB::Escape.class.inspect" |& grep -F escape.so | grep -v ENOENT
<no output, i.e. no escape.so found and loaded?>
Comment 6 Hans de Graaff gentoo-dev Security 2023-12-06 08:30:01 UTC
(In reply to Sebastian Pipping from comment #5)

> # ruby31 -e "require 'erb/escape'; puts ERB::Escape.class.inspect"
> <internal:/usr/lib64/ruby/site_ruby/3.1.0/rubygems/core_ext/kernel_require.
> rb>:86:in `require': cannot load such file -- erb/escape (LoadError)

That is unexpected because the error in the build log happens inside a block where this require has succeeded... so I would expect it to succeed here as well.

> Did someone say strace? :)  I love strace! :)

Perhaps it will be helpful to use the same strace on the emerge attempt that fails. You could also try looking for "escape.rb" to cover all the ways require may find and load code.
Comment 7 Sebastian Pipping gentoo-dev 2023-12-06 09:54:39 UTC
> Perhaps it will be helpful to use the same strace on the emerge attempt that
> fails. You could also try looking for "escape.rb" to cover all the ways
> require may find and load code.

It does not find escape.so or escape.rb anywhere:

  # strace -F -efile ebuild erubi-1.12.0.ebuild manifest clean install |& grep -F escape. | grep -vF ENOENT
  <no output>

And I don't seem to have either file anywhere:

  # find /usr/lib*/ruby/ -name escape.\*
  <no output>

Based on https://www.portagefilelist.de/?fs=escape.so#panchor output it seems that escape.so would be provided by dev-lang/ruby?  I re-installed dev-lang/ruby-3.2.2-r5 from source (with USE="gdbm ipv6 ssl static-libs") and I still do not have a file escape.so or escape.rb.  This is the 3.2.0 erb I do have:

  # qlist dev-lang/ruby | grep -Fw erb | grep -F 3.2
  /usr/lib64/ruby/gems/3.2.0/gems/erb-4.0.2/libexec/erb
  /usr/lib64/ruby/gems/3.2.0/specifications/default/erb-4.0.2.gemspec
  /usr/lib64/ruby/3.2.0/erb.rb
  /usr/lib64/ruby/3.2.0/erb/version.rb
  /usr/lib64/ruby/3.2.0/erb/util.rb
  /usr/lib64/ruby/3.2.0/erb/def_method.rb
  /usr/lib64/ruby/3.2.0/erb/compiler.rb

I found this block of interest in /usr/lib64/ruby/3.2.0/erb/util.rb :

  #--
  # ERB::Escape
  #
  # A subset of ERB::Util. Unlike ERB::Util#html_escape, we expect/hope
  # Rails will not monkey-patch ERB::Escape#html_escape.
  begin
    # We don't build the C extension for JRuby, TruffleRuby, and WASM
    if $LOAD_PATH.resolve_feature_path('erb/escape')
      require 'erb/escape'
    end
  rescue LoadError # resolve_feature_path raises LoadError on TruffleRuby 22.3.0
  end
  unless defined?(ERB::Escape)
    module ERB::Escape
      def html_escape(s)
        CGI.escapeHTML(s.to_s)
      end
      module_function :html_escape
    end
  end

So that file is trying to define ERB::Escape.  

What's interesting is that that once I change "require 'erb/escape'" to plain "require 'erb'" things start to work:

  # ruby32 -e "puts require 'erb/escape'; puts ERB::Escape.class.inspect"  # bad
  true  # okay?!
  -e:1:in `<main>': uninitialized constant ERB (NameError)

  puts require 'erb/escape'; puts ERB::Escape.class.inspect
                                     ^^^^^^^^

But:

  # ruby32 -e "puts require 'erb'; puts ERB::Escape.class.inspect"  # good
  true
  Module

So as a non-Rubyist I would think either (a) erubi needs a different import or (b) Ruby 3.2 needs a fix to to provide escape.so or (c) erubi needs ask for more use flags from Ruby to be sure that escape.so is provided.

I'm only guessing around here.  What do you think?
Comment 8 Sebastian Pipping gentoo-dev 2023-12-06 10:22:50 UTC
PS: All of dev-lang/ruby-3.2.2-r3 to -r5 seem to compile code ext/erb/escape/escape.c into a static .a file and link that right into libruby32.so.3.2.2 for me.
Comment 9 Sebastian Pipping gentoo-dev 2023-12-06 10:48:15 UTC
PPS: Turns out things start to work once I USE=-static-libs on dev-lang/ruby-3.2.2-r5.  So USE=static-libs breaks "require 'erb/escape'" with Ruby 3.2.  Extending the ticket title accordingly.