Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing File in Gem after Build

Tags:

ruby

bundler

gem

TL;DR:

Don't run bundle within an existing git repository. Weird things will happen without any error messages.

Original Question:

I've built a gem by adapting the steps in this tutorial:

http://net.tutsplus.com/tutorials/ruby/gem-creation-with-bundler/

As a final step, I've run gem build .gemspec

This succeeds, but when I install the gem I find the critical file, the one which contains my code, isn't in the gem. Another file in the same (lib) directory, "version.rb", does exist in the gem.

I don't know how to start debugging this...how does bundler/gem build decide which files to include in the gem?

Edit:

My workflow is:

gem build <project_name>.gemspec
gem unpack <project_name>
=> confirm file does not exist in <unpacked>/lib/

gem install <project name>
=> confirm file structure in ~/home/stefan/.rvm/... contains gem, but does not contain desired file

Edit 2 / Resolution:

I was finally able to get this working by committing all my code to a remote repository, creating a clean clone, and building the gem. The new gem included all the required files.

A bit of history...I originally created the code and committed it before thinking about making a gem (this is my first gem). I then used bundle inside the original repository, which didn't complain, but was probably the reason for the weirdness.

like image 571
Stefan Avatar asked Jun 04 '13 15:06

Stefan


1 Answers

One of the things bundler did for you is start a local git repo to version-manage your gem code. Check that you have added the file in git

git add lib/gem_name/missing_file.rb

Bundler generated gems use git internally to track "membership" of source files for the gem. You can see this in the .gemspec where it uses backticks to call out to git and generate a file list:

gem.files         = `git ls-files`.split($/)

Note this also means you should pay attention to what you list in .gitignore

like image 65
Neil Slater Avatar answered Oct 26 '22 19:10

Neil Slater