'Difference between bin and exe when creating a gem

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?



Solution 1:[1]

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'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1