构建后 Gem 中缺少文件 [英] Missing File in Gem after Build

查看:11
本文介绍了构建后 Gem 中缺少文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TL;DR:

不要在现有的 git 存储库中运行 bundle.奇怪的事情会发生而没有任何错误消息.

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

原问题:

我通过调整本教程中的步骤构建了一个 gem:

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

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

作为最后一步,我已经运行 gem build .gemspec

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

这成功了,但是当我安装 gem 时,我发现包含我的代码的关键文件不在 gem 中.同一 (lib) 目录中的另一个文件version.rb"确实存在于 gem 中.

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.

我不知道如何开始调试... bundler/gem build 如何决定哪些文件包含在 gem 中?

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

我的工作流程是:

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

编辑 2/分辨率:

我终于能够通过将我的所有代码提交到远程存储库、创建一个干净的克隆并构建 gem 来完成这项工作.新 gem 包含所有必需的文件.

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.

有点历史......我最初创建了代码并在考虑制作 gem 之前提交了它(这是我的第一个 gem).然后我在原始存储库 inside 中使用了 bundle,它没有抱怨,但可能是奇怪的原因.

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.

推荐答案

bundler 为你做的一件事是启动一个本地 git repo 来对你的 gem 代码进行版本管理.检查你是否在 git 中添加了文件

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 生成的 gem 在内部使用 git 来跟踪 gem 源文件的成员资格".您可以在 .gemspec 中看到这一点,它使用反引号调用 git 并生成文件列表:

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($/)

注意这也意味着你应该注意你在 .gitignore

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

这篇关于构建后 Gem 中缺少文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆