Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 911401 - dev-lang/ruby: 010-default-gem-location.patch not enough to change "DESTDIR" of gems
Summary: dev-lang/ruby: 010-default-gem-location.patch not enough to change "DESTDIR" ...
Status: UNCONFIRMED
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-07-29 03:43 UTC by konsolebox
Modified: 2023-07-31 02:31 UTC (History)
0 users

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


Attachments
Patch (010-default-gem-location-r1.patch,690 bytes, patch)
2023-07-29 03:48 UTC, konsolebox
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description konsolebox 2023-07-29 03:43:58 UTC
It's currently:

+++ b/tool/rbinstall.rb	2022-11-13 08:16:09.110406705 +0100
@@ -994,7 +994,7 @@
 end
 
 install?(:ext, :comm, :gem, :'bundled-gems') do
-  gem_dir = Gem.default_dir
+  gem_dir = ENV['GEM_DESTDIR']
   install_dir = with_destdir(gem_dir)
   prepare "bundled gems", gem_dir
   RbInstall.no_write do

It should be:

diff --git a/tool/rbinstall.rb b/tool/rbinstall.rb
index f910fca..2f21884 100755
--- a/tool/rbinstall.rb
+++ b/tool/rbinstall.rb
@@ -942,7 +942,7 @@ def load_gemspec(file, base = nil)
 end
 
 def install_default_gem(dir, srcdir, bindir)
-  gem_dir = Gem.default_dir
+  gem_dir = ENV['GEM_DESTDIR']
   install_dir = with_destdir(gem_dir)
   prepare "default gems from #{dir}", gem_dir
   RbInstall.no_write do
@@ -991,7 +991,7 @@ def install_default_gem(dir, srcdir, bindir)
 end
 
 install?(:ext, :comm, :gem, :'bundled-gems') do
-  gem_dir = Gem.default_dir
+  gem_dir = ENV['GEM_DESTDIR']
   install_dir = with_destdir(gem_dir)
   prepare "bundled gems", gem_dir
   RbInstall.no_write do

Tested with ruby-3.2.2-r4.ebuild.

As to why I was able to detect this, I use my own "operating_systems.rb" which changes Gem.default_dir to home directory and the value reflected when I installed ruby:3.2.

# frozen_string_literal: true

module Gem
  module OperatingSystemDefaults
    def user_dir
      gentoo_user_dir
    end

    def default_dir
      gentoo_user_dir
    end

    def default_bindir
      gentoo_user_bindir
    end

    def default_path
      path = []
      path << gentoo_user_dir unless gentoo_local_dir == gentoo_user_dir
      path << gentoo_local_dir
      path << gentoo_dir
      path << vendor_dir if vendor_dir && File.directory?(vendor_dir)
      path
    end

    def operating_system_defaults
      { 'custom_shebang' => '/usr/bin/env ruby' }
    end

    def default_specifications_dir
      @default_specifications_dir ||= File.join(orig_default_dir, "specifications", "default")
    end

  private
    def gentoo_dir
      @gentoo_dir ||= RbConfig::CONFIG['sitelibdir'].gsub('site_ruby', 'gems')
    end

    def gentoo_local_dir
      @gentoo_local_dir ||= gentoo_dir.gsub('/usr', '/usr/local')
    end

    def gentoo_user_dir
      @gentoo_user_dir ||= Process.euid.zero? ? gentoo_local_dir : orig_user_dir
    end

    def gentoo_user_bindir
      @gentoo_user_bindir ||= Process.euid.zero? ? '/usr/local/bin' : File.join(user_home, 'bin')
    end

    def orig_default_dir
      method(:default_dir).super_method.call
    end

    def orig_user_dir
      method(:user_dir).super_method.call
    end
  end

  self.singleton_class.prepend OperatingSystemDefaults
end

I first shared it in a Github thread which I can no longer find.

It's a bit outdated because it should have the @GENTOO_PORTAGE_EPREFIX@ stuff gentoo-defaults.rb have. Originally it also doesn't override default_specifications_dir but default gems aren't detected unless I add it.  It wasn't needed until rubygems' 90c1919f94 commit, probably.
Comment 1 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-07-29 03:45:01 UTC
When giving (fixed) patches, please attach them so the formatting is correct.
Comment 2 konsolebox 2023-07-29 03:48:28 UTC
Created attachment 866531 [details, diff]
Patch
Comment 3 konsolebox 2023-07-31 02:31:44 UTC
>      { 'custom_shebang' => '/usr/bin/env ruby' }

I'm now testing this to have /usr/bin/ruby in my system instead for the same reason as https://bugs.gentoo.org/911513.