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

Cygwin install places gem bins outside of $PATH environment #1537

Open
dan-bryant opened this Issue Mar 7, 2016 · 19 comments

Comments

Projects
None yet
9 participants
@dan-bryant

dan-bryant commented Mar 7, 2016

Fresh Ruby installs on Cygwin systems place gems in ~/bin which is not in the $PATH environment. This causes obvious command not found errors on gem based utilities.

This issue is related to:

  • Installing a library
  • The command line gem

Here are my current environment details:

$ gem env version
2.4.8

$ ruby -v
ruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-cygwin]

I will abide by the code of conduct.

  • I Agree
@segiddins

This comment has been minimized.

Show comment
Hide comment
@segiddins

segiddins Mar 7, 2016

Member

Did the warning at

alert_warning "You don't have #{user_bin_dir} in your PATH,\n\t gem executables will not run."
not print for you?

Member

segiddins commented Mar 7, 2016

Did the warning at

alert_warning "You don't have #{user_bin_dir} in your PATH,\n\t gem executables will not run."
not print for you?

@dan-bryant

This comment has been minimized.

Show comment
Hide comment
@dan-bryant

dan-bryant Mar 7, 2016

gem installs complete error free

$ gem install bundler
Successfully installed bundler-1.11.2
Parsing documentation for bundler-1.11.2
Done installing documentation for bundler after 29 seconds
1 gem installed

I assume the error should show up whenever gem install is called without a proper environment.

Just for completeness, Cygwin setup log also showed no such error.

$ grep "gem executables will not run" /var/log/setup.log* || echo "Not Found"
Not Found

My Cygwin install method was to install the entire Ruby category and entire Devl category, leaving the rest as Default.

dan-bryant commented Mar 7, 2016

gem installs complete error free

$ gem install bundler
Successfully installed bundler-1.11.2
Parsing documentation for bundler-1.11.2
Done installing documentation for bundler after 29 seconds
1 gem installed

I assume the error should show up whenever gem install is called without a proper environment.

Just for completeness, Cygwin setup log also showed no such error.

$ grep "gem executables will not run" /var/log/setup.log* || echo "Not Found"
Not Found

My Cygwin install method was to install the entire Ruby category and entire Devl category, leaving the rest as Default.

@segiddins

This comment has been minimized.

Show comment
Hide comment
@segiddins

segiddins Mar 7, 2016

Member

What happens if you delete the binstub in ~/bin and then install again? (Just curious since I don't have a Windows environment handy)

Member

segiddins commented Mar 7, 2016

What happens if you delete the binstub in ~/bin and then install again? (Just curious since I don't have a Windows environment handy)

@dan-bryant

This comment has been minimized.

Show comment
Hide comment
@dan-bryant

dan-bryant Mar 7, 2016

Same

$ mv ~/bin ~/bin.hidden && gem install bundler
Successfully installed bundler-1.11.2
Parsing documentation for bundler-1.11.2
Done installing documentation for bundler after 9 seconds
1 gem installed

dan-bryant commented Mar 7, 2016

Same

$ mv ~/bin ~/bin.hidden && gem install bundler
Successfully installed bundler-1.11.2
Parsing documentation for bundler-1.11.2
Done installing documentation for bundler after 9 seconds
1 gem installed
@roeme

This comment has been minimized.

Show comment
Hide comment
@roeme

roeme Mar 22, 2016

Did the warning at

alert_warning "You don't have #{user_bin_dir} in your PATH,\n\t gem executables will not run."
not print for you?

Can confirm that no warnig is emitted with rubygems 2.6 / Ruby 2.2.4 when ~/bin is not part of $PATH.

$ export PATH=/usr/local/bin:/usr/bin
$ hash -r
$ gem --version
2.6.2
$ ruby --version
ruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-cygwin]
 $ gem install -N bundler
Fetching: bundler-1.11.2.gem (100%)
Successfully installed bundler-1.11.2
1 gem installed
$

roeme commented Mar 22, 2016

Did the warning at

alert_warning "You don't have #{user_bin_dir} in your PATH,\n\t gem executables will not run."
not print for you?

Can confirm that no warnig is emitted with rubygems 2.6 / Ruby 2.2.4 when ~/bin is not part of $PATH.

$ export PATH=/usr/local/bin:/usr/bin
$ hash -r
$ gem --version
2.6.2
$ ruby --version
ruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-cygwin]
 $ gem install -N bundler
Fetching: bundler-1.11.2.gem (100%)
Successfully installed bundler-1.11.2
1 gem installed
$
@gmacario

This comment has been minimized.

Show comment
Hide comment
@gmacario

gmacario Dec 20, 2016

I just installed latest version of ruby available on Cygwin x86_64 (Windows 10 64-bit) and the issue is still present

gmacario@ITM-GPAOLO-W10 ~
$ ruby --version
ruby 2.2.5p319 (2016-04-26 revision 54774) [x86_64-cygwin]

gmacario@ITM-GPAOLO-W10 ~
$ gem --version
2.4.8

gmacario@ITM-GPAOLO-W10 ~
$

The binaries as a result of gem install bundler get installed under ${HOME}/bin and no warning is emitted if this was not in PATH (I added it as a workaround)

gmacario@ITM-GPAOLO-W10 ~
$ gem install -N bundler
Fetching: bundler-1.13.6.gem (100%)
Successfully installed bundler-1.13.6
1 gem installed

gmacario@ITM-GPAOLO-W10 ~
$ which bundler
/home/gmacario/bin/bundler

gmacario@ITM-GPAOLO-W10 ~
$

gmacario commented Dec 20, 2016

I just installed latest version of ruby available on Cygwin x86_64 (Windows 10 64-bit) and the issue is still present

gmacario@ITM-GPAOLO-W10 ~
$ ruby --version
ruby 2.2.5p319 (2016-04-26 revision 54774) [x86_64-cygwin]

gmacario@ITM-GPAOLO-W10 ~
$ gem --version
2.4.8

gmacario@ITM-GPAOLO-W10 ~
$

The binaries as a result of gem install bundler get installed under ${HOME}/bin and no warning is emitted if this was not in PATH (I added it as a workaround)

gmacario@ITM-GPAOLO-W10 ~
$ gem install -N bundler
Fetching: bundler-1.13.6.gem (100%)
Successfully installed bundler-1.13.6
1 gem installed

gmacario@ITM-GPAOLO-W10 ~
$ which bundler
/home/gmacario/bin/bundler

gmacario@ITM-GPAOLO-W10 ~
$
@wbrianwhite

This comment has been minimized.

Show comment
Hide comment
@wbrianwhite

wbrianwhite Jan 17, 2017

I can confirm this still happens. Freshly installed cygwin, selected ruby, gem installed rspec, same behavior as original report, same issue with paths.

Although... this feels like a cygwin issue

wbrianwhite commented Jan 17, 2017

I can confirm this still happens. Freshly installed cygwin, selected ruby, gem installed rspec, same behavior as original report, same issue with paths.

Although... this feels like a cygwin issue

@drbrain

This comment has been minimized.

Show comment
Hide comment
@drbrain

drbrain Jan 17, 2017

Member

What does your gem env say?

Member

drbrain commented Jan 17, 2017

What does your gem env say?

@calebtote

This comment has been minimized.

Show comment
Hide comment
@calebtote

calebtote Feb 22, 2017

For those looking for a workaround until this is resolved:
Ruby executables are stored in ~/bin, which by default isn't set in your cygwin path. So you'll just need to add this to your path, preferably by editing your ~/.bashrc to include: PATH=$PATH:~/bin -- relaunch your terminal, or source ~/.bashrc for immediate effect.

calebtote commented Feb 22, 2017

For those looking for a workaround until this is resolved:
Ruby executables are stored in ~/bin, which by default isn't set in your cygwin path. So you'll just need to add this to your path, preferably by editing your ~/.bashrc to include: PATH=$PATH:~/bin -- relaunch your terminal, or source ~/.bashrc for immediate effect.

@drbrain

This comment has been minimized.

Show comment
Hide comment
@drbrain

drbrain Feb 22, 2017

Member

We're still looking for a full gem env output on this one, one without PATH or ~/.gemrc changes, or where such changes are noted.

Member

drbrain commented Feb 22, 2017

We're still looking for a full gem env output on this one, one without PATH or ~/.gemrc changes, or where such changes are noted.

@calebtote

This comment has been minimized.

Show comment
Hide comment
@calebtote

calebtote Feb 23, 2017

Here's mine -- it wasn't working until I modified my PATH as above. The below is my current working terminal, with PATH=$PATH:~/bin:

RubyGems Environment:
  - RUBYGEMS VERSION: 2.4.8
  - RUBY VERSION: 2.2.5 (2016-04-26 patchlevel 319) [x86_64-cygwin]
  - INSTALLATION DIRECTORY: /home/ctote/.gem/ruby
  - RUBY EXECUTABLE: /usr/bin/ruby.exe
  - EXECUTABLE DIRECTORY: /home/ctote/bin
  - SPEC CACHE DIRECTORY: /home/ctote/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-cygwin
  - GEM PATHS:
     - /home/ctote/.gem/ruby
     - /usr/share/gems
     - /usr/local/share/gems
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /usr/local/bin
     - /usr/bin
     - /cygdrive/c/Program Files/Docker/Docker/Resources/bin
     - /cygdrive/c/Program Files/Common Files/Microsoft Shared/Windows Live
     - /cygdrive/c/Program Files (x86)/Common Files/Microsoft Shared/Windows Live
     - /cygdrive/c/ProgramData/Oracle/Java/javapath
     - /cygdrive/c/Python25
     - /cygdrive/c/Perl/site/bin
     - /cygdrive/c/Perl/bin
     - /cygdrive/c/windows/system32
     - /cygdrive/c/windows
     - /cygdrive/c/windows/System32/Wbem
     - /cygdrive/c/windows/System32/WindowsPowerShell/v1.0
     - /cygdrive/c/Program Files/Perforce
     - /cygdrive/c/Program Files (x86)/Xoreax/IncrediBuild
     - /cygdrive/c/Program Files (x86)/Code Collaborator Client
     - /cygdrive/c/Program Files (x86)/Microsoft SQL Server/100/Tools/Binn/VSShell/Common7/IDE
     - /cygdrive/c/Program Files (x86)/Microsoft SQL Server/100/Tools/Binn
     - /cygdrive/c/Program Files/Microsoft SQL Server/100/Tools/Binn
     - /cygdrive/c/Program Files (x86)/Microsoft SQL Server/100/DTS/Binn
     - /cygdrive/c/Program Files/Microsoft SQL Server/100/DTS/Binn
     - /cygdrive/c/Program Files (x86)/Microsoft Visual Studio 9.0/Common7/IDE/PrivateAssemblies
     - /cygdrive/c/Program Files (x86)/Graphviz2.26.3/bin
     - /cygdrive/c/Program Files/Microsoft/Web Platform Installer
     - /cygdrive/c/Program Files (x86)/Microsoft ASP.NET/ASP.NET Web Pages/v1.0
     - /cygdrive/c/Program Files/Microsoft SQL Server/110/Tools/Binn
     - /cygdrive/c/Program Files (x86)/Windows Kits/8.1/Windows Performance Toolkit
     - /cygdrive/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common
     - /cygdrive/c/Program Files/Code Collaborator Client
     - /cygdrive/c/Program Files (x86)/MySQL/MySQL Utilities
     - /cygdrive/c/Program Files (x86)/MySQL/MySQL Utilities/Doctrine extensions for PHP
     - /cygdrive/c/Program Files (x86)/Windows Live/Shared
     - /cygdrive/c/Program Files/nodejs
     - /cygdrive/c/WINDOWS/system32
     - /cygdrive/c/WINDOWS
     - /cygdrive/c/WINDOWS/System32/Wbem
     - /cygdrive/c/WINDOWS/System32/WindowsPowerShell/v1.0
     - /cygdrive/c/Users/ctote/AppData/Local/Continuum/Anaconda2
     - /cygdrive/c/Users/ctote/AppData/Local/Continuum/Anaconda2/Scripts
     - /cygdrive/c/Users/ctote/AppData/Local/Continuum/Anaconda2/Library/bin
     - /cygdrive/c/Program Files (x86)/IDM Computer Solutions/UltraCompare
     - /cygdrive/c/Users/ctote/AppData/Roaming/npm
     - /cygdrive/c/Program Files (x86)/Microsoft VS Code/bin
     - /cygdrive/c/Users/ctote/AppData/Local/Microsoft/WindowsApps

calebtote commented Feb 23, 2017

Here's mine -- it wasn't working until I modified my PATH as above. The below is my current working terminal, with PATH=$PATH:~/bin:

RubyGems Environment:
  - RUBYGEMS VERSION: 2.4.8
  - RUBY VERSION: 2.2.5 (2016-04-26 patchlevel 319) [x86_64-cygwin]
  - INSTALLATION DIRECTORY: /home/ctote/.gem/ruby
  - RUBY EXECUTABLE: /usr/bin/ruby.exe
  - EXECUTABLE DIRECTORY: /home/ctote/bin
  - SPEC CACHE DIRECTORY: /home/ctote/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /etc
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-cygwin
  - GEM PATHS:
     - /home/ctote/.gem/ruby
     - /usr/share/gems
     - /usr/local/share/gems
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /usr/local/bin
     - /usr/bin
     - /cygdrive/c/Program Files/Docker/Docker/Resources/bin
     - /cygdrive/c/Program Files/Common Files/Microsoft Shared/Windows Live
     - /cygdrive/c/Program Files (x86)/Common Files/Microsoft Shared/Windows Live
     - /cygdrive/c/ProgramData/Oracle/Java/javapath
     - /cygdrive/c/Python25
     - /cygdrive/c/Perl/site/bin
     - /cygdrive/c/Perl/bin
     - /cygdrive/c/windows/system32
     - /cygdrive/c/windows
     - /cygdrive/c/windows/System32/Wbem
     - /cygdrive/c/windows/System32/WindowsPowerShell/v1.0
     - /cygdrive/c/Program Files/Perforce
     - /cygdrive/c/Program Files (x86)/Xoreax/IncrediBuild
     - /cygdrive/c/Program Files (x86)/Code Collaborator Client
     - /cygdrive/c/Program Files (x86)/Microsoft SQL Server/100/Tools/Binn/VSShell/Common7/IDE
     - /cygdrive/c/Program Files (x86)/Microsoft SQL Server/100/Tools/Binn
     - /cygdrive/c/Program Files/Microsoft SQL Server/100/Tools/Binn
     - /cygdrive/c/Program Files (x86)/Microsoft SQL Server/100/DTS/Binn
     - /cygdrive/c/Program Files/Microsoft SQL Server/100/DTS/Binn
     - /cygdrive/c/Program Files (x86)/Microsoft Visual Studio 9.0/Common7/IDE/PrivateAssemblies
     - /cygdrive/c/Program Files (x86)/Graphviz2.26.3/bin
     - /cygdrive/c/Program Files/Microsoft/Web Platform Installer
     - /cygdrive/c/Program Files (x86)/Microsoft ASP.NET/ASP.NET Web Pages/v1.0
     - /cygdrive/c/Program Files/Microsoft SQL Server/110/Tools/Binn
     - /cygdrive/c/Program Files (x86)/Windows Kits/8.1/Windows Performance Toolkit
     - /cygdrive/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common
     - /cygdrive/c/Program Files/Code Collaborator Client
     - /cygdrive/c/Program Files (x86)/MySQL/MySQL Utilities
     - /cygdrive/c/Program Files (x86)/MySQL/MySQL Utilities/Doctrine extensions for PHP
     - /cygdrive/c/Program Files (x86)/Windows Live/Shared
     - /cygdrive/c/Program Files/nodejs
     - /cygdrive/c/WINDOWS/system32
     - /cygdrive/c/WINDOWS
     - /cygdrive/c/WINDOWS/System32/Wbem
     - /cygdrive/c/WINDOWS/System32/WindowsPowerShell/v1.0
     - /cygdrive/c/Users/ctote/AppData/Local/Continuum/Anaconda2
     - /cygdrive/c/Users/ctote/AppData/Local/Continuum/Anaconda2/Scripts
     - /cygdrive/c/Users/ctote/AppData/Local/Continuum/Anaconda2/Library/bin
     - /cygdrive/c/Program Files (x86)/IDM Computer Solutions/UltraCompare
     - /cygdrive/c/Users/ctote/AppData/Roaming/npm
     - /cygdrive/c/Program Files (x86)/Microsoft VS Code/bin
     - /cygdrive/c/Users/ctote/AppData/Local/Microsoft/WindowsApps
@drbrain

This comment has been minimized.

Show comment
Hide comment
@drbrain

drbrain Feb 23, 2017

Member

Thanks, can I also see the result of:

ruby -rrbconfig -e 'p RbConfig::CONFIG["bindir"]'
Member

drbrain commented Feb 23, 2017

Thanks, can I also see the result of:

ruby -rrbconfig -e 'p RbConfig::CONFIG["bindir"]'
@calebtote

This comment has been minimized.

Show comment
Hide comment
@calebtote

calebtote Feb 23, 2017

"/usr/bin"

calebtote commented Feb 23, 2017

"/usr/bin"
@drbrain

This comment has been minimized.

Show comment
Hide comment
@drbrain

drbrain Feb 23, 2017

Member

Sorry, one more:

$ ruby -de 'p Gem.bindir'

I get:

Exception `LoadError' at /usr/local/lib/ruby/site_ruby/2.3.0/rubygems.rb:1304 - cannot load such file -- rubygems/defaults/operating_system
Exception `LoadError' at /usr/local/lib/ruby/site_ruby/2.3.0/rubygems.rb:1313 - cannot load such file -- rubygems/defaults/ruby
Exception `LoadError' at /usr/local/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55 - cannot load such file -- did_you_mean
"/usr/local/bin"

This last one will tell me if cygwin is overriding RbConfig::CONFIG['bindir']

Member

drbrain commented Feb 23, 2017

Sorry, one more:

$ ruby -de 'p Gem.bindir'

I get:

Exception `LoadError' at /usr/local/lib/ruby/site_ruby/2.3.0/rubygems.rb:1304 - cannot load such file -- rubygems/defaults/operating_system
Exception `LoadError' at /usr/local/lib/ruby/site_ruby/2.3.0/rubygems.rb:1313 - cannot load such file -- rubygems/defaults/ruby
Exception `LoadError' at /usr/local/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55 - cannot load such file -- did_you_mean
"/usr/local/bin"

This last one will tell me if cygwin is overriding RbConfig::CONFIG['bindir']

@calebtote

This comment has been minimized.

Show comment
Hide comment
@calebtote

calebtote Feb 24, 2017

Exception `LoadError' at /usr/share/rubygems/rubygems.rb:1230 - cannot load such file -- rubygems/defaults/ruby
"/home/Home/bin"

calebtote commented Feb 24, 2017

Exception `LoadError' at /usr/share/rubygems/rubygems.rb:1230 - cannot load such file -- rubygems/defaults/ruby
"/home/Home/bin"
@drbrain

This comment has been minimized.

Show comment
Hide comment
@drbrain

drbrain Feb 24, 2017

Member

Since you don't have a line for rubygems/defaults/operating_system I think this is a cygwin default

cat `gem which rubygems/defaults/operating_system`

Will confirm

Member

drbrain commented Feb 24, 2017

Since you don't have a line for rubygems/defaults/operating_system I think this is a cygwin default

cat `gem which rubygems/defaults/operating_system`

Will confirm

@calebtote

This comment has been minimized.

Show comment
Hide comment
@calebtote

calebtote Feb 24, 2017

$ cat `gem which rubygems/defaults/operating_system`
module Gem
  class << self

    ##
    # Returns full path of previous but one directory of dir in path
    # E.g. for '/usr/share/ruby', 'ruby', it returns '/usr'

    def previous_but_one_dir_to(path, dir)
      split_path = path.split(File::SEPARATOR)
      File.join(split_path.take_while { |one_dir| one_dir !~ /^#{dir}$/ }[0..-2])
    end
    private :previous_but_one_dir_to

    ##
    # Tries to detect if arguments and environment variables suggest that
    # 'gem install' is executed from cygport.

    def cygport?
     # (ARGV.include?('--install-dir') || ARGV.include?('-i')) &&
      ENV['CYGPORT_PACKAGE_NAME']
    end
    private :cygport?

    ##
    # Default gems locations allowed on FHS system (/usr, /usr/share).
    # The locations are derived from directories specified during build
    # configuration.

    def default_locations
      @default_locations ||= {
        :system => previous_but_one_dir_to(ConfigMap[:vendordir], ConfigMap[:RUBY_INSTALL_NAME]),
        :local => previous_but_one_dir_to(ConfigMap[:sitedir], ConfigMap[:RUBY_INSTALL_NAME])
      }
    end

    ##
    # For each location provides set of directories for binaries (:bin_dir)
    # platform independent (:gem_dir) and dependent (:ext_dir) files.

    def default_dirs
      @libdir ||= case RUBY_PLATFORM
      when 'java'
        ConfigMap[:datadir]
      else
        ConfigMap[:libdir]
      end

      @default_dirs ||= Hash[default_locations.collect do |destination, path|
        [destination, {
          :bin_dir => File.join(path, ConfigMap[:bindir].split(File::SEPARATOR).last),
          :gem_dir => File.join(path, ConfigMap[:datadir].split(File::SEPARATOR).last, 'gems'),
          :ext_dir => File.join(path, @libdir.split(File::SEPARATOR).last, 'gems')
        }]
      end]
    end

    ##
    # Remove methods we are going to override. This avoids "method redefined;"
    # warnings otherwise issued by Ruby.

    remove_method :default_dir if method_defined? :default_dir
    remove_method :default_path if method_defined? :default_path
    remove_method :default_bindir if method_defined? :default_bindir
    remove_method :default_ext_dir_for if method_defined? :default_ext_dir_for

    ##
    # RubyGems default overrides.

    def default_dir
      if cygport?
        Gem.default_dirs[:system][:gem_dir]
      else
        Gem.user_dir
      end
    end

    def default_path
      path = default_dirs.collect {|location, paths| paths[:gem_dir]}
      path.unshift Gem.user_dir if File.exist? Gem.user_home
    end

    def default_bindir
      if cygport?
        Gem.default_dirs[:system][:bin_dir]
      else
        File.join [Dir.home, 'bin']
      end
    end

    def default_ext_dir_for base_dir
      dir = if cygport?
        build_dir = base_dir.chomp Gem.default_dirs[:system][:gem_dir]
        if build_dir != base_dir
          File.join build_dir, Gem.default_dirs[:system][:ext_dir]
        end
      else
        dirs = Gem.default_dirs.detect {|location, paths| paths[:gem_dir] == base_dir}
        dirs && dirs.last[:ext_dir]
      end
      dir && File.join(dir, RbConfig::CONFIG['RUBY_INSTALL_NAME'], File.basename(RbConfig::CONFIG['vendorarchdir']))
    end

    # This method should be available since RubyGems 2.2 until RubyGems 3.0.
    # https://github.com/rubygems/rubygems/issues/749
    if method_defined? :install_extension_in_lib
      remove_method :install_extension_in_lib

      def install_extension_in_lib
        false
      end
    end
  end
end

calebtote commented Feb 24, 2017

$ cat `gem which rubygems/defaults/operating_system`
module Gem
  class << self

    ##
    # Returns full path of previous but one directory of dir in path
    # E.g. for '/usr/share/ruby', 'ruby', it returns '/usr'

    def previous_but_one_dir_to(path, dir)
      split_path = path.split(File::SEPARATOR)
      File.join(split_path.take_while { |one_dir| one_dir !~ /^#{dir}$/ }[0..-2])
    end
    private :previous_but_one_dir_to

    ##
    # Tries to detect if arguments and environment variables suggest that
    # 'gem install' is executed from cygport.

    def cygport?
     # (ARGV.include?('--install-dir') || ARGV.include?('-i')) &&
      ENV['CYGPORT_PACKAGE_NAME']
    end
    private :cygport?

    ##
    # Default gems locations allowed on FHS system (/usr, /usr/share).
    # The locations are derived from directories specified during build
    # configuration.

    def default_locations
      @default_locations ||= {
        :system => previous_but_one_dir_to(ConfigMap[:vendordir], ConfigMap[:RUBY_INSTALL_NAME]),
        :local => previous_but_one_dir_to(ConfigMap[:sitedir], ConfigMap[:RUBY_INSTALL_NAME])
      }
    end

    ##
    # For each location provides set of directories for binaries (:bin_dir)
    # platform independent (:gem_dir) and dependent (:ext_dir) files.

    def default_dirs
      @libdir ||= case RUBY_PLATFORM
      when 'java'
        ConfigMap[:datadir]
      else
        ConfigMap[:libdir]
      end

      @default_dirs ||= Hash[default_locations.collect do |destination, path|
        [destination, {
          :bin_dir => File.join(path, ConfigMap[:bindir].split(File::SEPARATOR).last),
          :gem_dir => File.join(path, ConfigMap[:datadir].split(File::SEPARATOR).last, 'gems'),
          :ext_dir => File.join(path, @libdir.split(File::SEPARATOR).last, 'gems')
        }]
      end]
    end

    ##
    # Remove methods we are going to override. This avoids "method redefined;"
    # warnings otherwise issued by Ruby.

    remove_method :default_dir if method_defined? :default_dir
    remove_method :default_path if method_defined? :default_path
    remove_method :default_bindir if method_defined? :default_bindir
    remove_method :default_ext_dir_for if method_defined? :default_ext_dir_for

    ##
    # RubyGems default overrides.

    def default_dir
      if cygport?
        Gem.default_dirs[:system][:gem_dir]
      else
        Gem.user_dir
      end
    end

    def default_path
      path = default_dirs.collect {|location, paths| paths[:gem_dir]}
      path.unshift Gem.user_dir if File.exist? Gem.user_home
    end

    def default_bindir
      if cygport?
        Gem.default_dirs[:system][:bin_dir]
      else
        File.join [Dir.home, 'bin']
      end
    end

    def default_ext_dir_for base_dir
      dir = if cygport?
        build_dir = base_dir.chomp Gem.default_dirs[:system][:gem_dir]
        if build_dir != base_dir
          File.join build_dir, Gem.default_dirs[:system][:ext_dir]
        end
      else
        dirs = Gem.default_dirs.detect {|location, paths| paths[:gem_dir] == base_dir}
        dirs && dirs.last[:ext_dir]
      end
      dir && File.join(dir, RbConfig::CONFIG['RUBY_INSTALL_NAME'], File.basename(RbConfig::CONFIG['vendorarchdir']))
    end

    # This method should be available since RubyGems 2.2 until RubyGems 3.0.
    # https://github.com/rubygems/rubygems/issues/749
    if method_defined? :install_extension_in_lib
      remove_method :install_extension_in_lib

      def install_extension_in_lib
        false
      end
    end
  end
end
@drbrain

This comment has been minimized.

Show comment
Hide comment
@drbrain

drbrain Feb 24, 2017

Member

Yes, this is it:

    def default_bindir
      if cygport?
        Gem.default_dirs[:system][:bin_dir]
      else
        File.join [Dir.home, 'bin']
      end
    end

So this isn't a RubyGems bug, it's expected behavior according to your ruby packager 😒

Member

drbrain commented Feb 24, 2017

Yes, this is it:

    def default_bindir
      if cygport?
        Gem.default_dirs[:system][:bin_dir]
      else
        File.join [Dir.home, 'bin']
      end
    end

So this isn't a RubyGems bug, it's expected behavior according to your ruby packager 😒

@drbrain

This comment has been minimized.

Show comment
Hide comment
@drbrain

drbrain Feb 24, 2017

Member

… yep: it's in the cygwin rubygems package: https://cygwin.com/cgi-bin2/package-cat.cgi?file=x86_64%2Frubygems%2Frubygems-2.4.8-1&grep=ruby (search operating_system).

Member

drbrain commented Feb 24, 2017

… yep: it's in the cygwin rubygems package: https://cygwin.com/cgi-bin2/package-cat.cgi?file=x86_64%2Frubygems%2Frubygems-2.4.8-1&grep=ruby (search operating_system).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment