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?
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 theexecutablesdirectory and where we put binstubs and other development-only executables such asbin/rails orbin/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 anexecutable, the Bundler team has chosen to use a different directory,exe/, as theexecutablesdirectory 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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With