Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between bin and exe when creating a gem

Tags:

ruby

rubygems

I'm creating a gem for the first time and I'm a bit confused by the bin/ and exe/ directories. I've added an executable to spec.executables with:

spec.bindir        = "exe"
spec.executables   = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }

but when I gem build it it asks me for a "binary" in both bin/ and exe/ and I'm very confused because I can't really understand the difference between the 2. I solved the problem by copying the executable in bin/ into exe/ and everything works, but looks somewhat weird and suboptimal. Can anybody explain?

like image 694
ngw Avatar asked May 28 '26 07:05

ngw


1 Answers

bin/ is for development executables and will not be included in the built gem.

exe/ is for end user executables and will be included in the built gem, and thus copied to the user's bin/ in their PATH.

Ref: https://bundler.io/blog/2015/03/20/moving-bins-to-exe.html

This is a new convention. The current practice of both specifying bin/ as the executables directory and where we put binstubs and other development-only executables such as bin/rails or bin/setup, meant that Bundler-generated gems with executables were quite likely to have these development executables included in the built gem, and then installed along with the gem.

Rather than make the gemspec template more restrictive by only specifying one executable in bin/ as an executable, the Bundler team has chosen to use a different directory, exe/, as the executables directory in the template.

The post indicates that the reason for the exe/ directory is to allow blanket add all files in there to the user's bin or PATH.

You can still use the bin/ directory and manually specify the user executables.

  spec.bindir        = 'bin'
  spec.executables   = 'new_gem'
like image 80
go2null Avatar answered May 30 '26 21:05

go2null



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!