Project

General

Profile

Actions

Bug #14144

closed

__FILE__ displays wrong value for executables when run from project root w/Ruby 2.4.1

Added by keithrbennett (Keith Bennett) over 6 years ago. Updated over 6 years ago.

Status:
Third Party's Issue
Assignee:
-
Target version:
-
ruby -v:
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]
[ruby-core:83992]

Description

This problem can be illustrated by using the attached tar file, or the Github repo at https://github.com/keithrbennett/underscore_file_test.

When Ruby version == 2.4.1
and
current directory is the project root of this project
and
the gem is built and installed
and
the executable is run from the gem without preceding it with 'ruby'
and
the executable is run without specifying a directory
(i.e. as 'underscore_file_test', not 'bin/underscore_file_test')

Then (FILE below should be FILE surrounded by double underscores)

__FILE__ => $PROJECT_ROOT/exe/underscore_file_test

instead of pointing to a directory in the GEM_PATH, something like:

__FILE__ => /Users/kbennett/.rvm/gems/ruby-2.4.1/bin/underscore_file_test

This error occurred with Ruby 2.4.1 but not:

  • ruby 2.0.0p648 (2015-12-16 revision 53162) [x86_64-darwin15.6.0]
  • ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin16]
  • ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin16]
  • jruby 9.1.7.0 (2.3.1) 2017-01-11 68056ae Java HotSpot(TM) 64-Bit Server VM 25.77-b03 on 1.8.0_77-b03 +jit [darwin-x86_64]

My development machine was a MacBookPro running MacOs Sierra. uname -a output is:

  • Darwin MacBook-Pro-KB-13.local 16.7.0 Darwin Kernel Version 16.7.0: Wed Oct 4 00:17:00 PDT 2017; root:xnu-3789.71.6~1/RELEASE_X86_64 x86_64

Steps to Reproduce:

  • Download or git clone the Github project tree, or the attached tarball.
  • Change directory to the project root.
  • Run: clear; gem build *gemspec && gem install *gem && underscore_file_test
  • Note the directory component of the output.

If you cd somewhere else, the output will be correct,
i.e. will be located in a GEM_PATH directory.

If you run the command from the project root using a different Ruby,
it may work. I have not tested this on versions later than 2.4.1.


Files

underscore_file_test.tar.gz (29.7 KB) underscore_file_test.tar.gz Content of https://github.com/keithrbennett/underscore_file_test keithrbennett (Keith Bennett), 11/30/2017 02:59 AM

Updated by nobu (Nobuyoshi Nakada) over 6 years ago

  • Description updated (diff)
  • Status changed from Open to Third Party's Issue

Looks like a rubygems issue.

Updated by nobu (Nobuyoshi Nakada) over 6 years ago

Although I can't reproduce the exact same result, the file under bin directory should be a wrapper script generated by rubygems.
Your script is installed in the exe directory.
It should be a spec of rubygems.

Updated by keithrbennett (Keith Bennett) over 6 years ago

Nobu, thank you for your quick attention to this issue.

The problem occurred with both directory names, exe and bin.

This appears to have been an rvm issue. When I would gem uninstall rvm's executable_hooks gem, the behavior would be correct; and when I'd reinstall it, it would be incorrect again.

I did an rvm remove 2.4.1 and then a rvm install 2.4.1 --with-openssl-dir=/usr/local/opt/openssl, and the problem disappeared.

Updated by shevegen (Robert A. Heiler) over 6 years ago

Thanks for your explanation how you resolved it - other ruby hackers may benefit from it.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0