Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
788 views
in Technique[技术] by (71.8m points)

ruby - Missing File in Gem after Build

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...