尝试使用分叉 gem 时 Gem::LoadError

Jac*_*son 5 ruby ruby-on-rails bundler

我的目标是使用 libmspack。这取决于 ffi-compiler,我已经分叉了 ffi-compiler,以添加一些自定义代码,并且我希望 libmspack 使用我的修改版本。我有一个简单的 Gemfile:

source 'http://rubygems.org'

gem 'ffi-compiler', :github =>'survili/ffi-compiler'
gem 'libmspack'
Run Code Online (Sandbox Code Playgroud)

运行“bundle install”时,“ffi-compiler”的安装可以正常完成,但“libmspack”安装失败并显示找不到“ffi-compiler”的错误。(LoadError: cannot load such file -- ffi-compiler /编译任务)

我注意到如果我从 Gemfile 中删除“libmspack”,并尝试使用“bundle exec install libmspack”安装它,它工作正常。

有人可以解释一下,实现我的目标的正确方法是什么,导致 libmspack 使用自定义 ffi-compiler gem ?

我找到了这个 SO post,它提出了同样的问题,但没有答案:Gem::LoadError when using a git repo in Gemfile

先感谢您

------ 包的输出(使用 RVM 的空 gemset)-------

jackju at macbook-air  ~/tmp/delme1
$ rvm use 2.1.1@stackoverproblem --create
ruby-2.1.1 - #gemset created /home/jackju/.rvm/gems/ruby-2.1.1@stackoverproblem
ruby-2.1.1 - #generating stackoverproblem wrappers...........
Using /home/jackju/.rvm/gems/ruby-2.1.1 with gemset stackoverproblem
jackju at macbook-air  ~/tmp/delme1
$ rvm current
ruby-2.1.1@stackoverproblem
jackju at macbook-air  ~/tmp/delme1
$ vim Gemfile

[1]+  Stopped                 vim Gemfile
jackju at macbook-air  ~/tmp/delme1
$ rvm current
ruby-2.1.1@stackoverproblem
jackju at macbook-air  ~/tmp/delme1
$ gem list

*** LOCAL GEMS ***

bigdecimal (1.2.4)
bundler (1.5.3)
bundler-unload (1.0.2)
executable-hooks (1.3.1)
gem-wrappers (1.2.4)
io-console (0.4.2)
json (1.8.1)
minitest (4.7.5)
psych (2.0.3)
rake (10.1.0)
rdoc (4.1.0)
rubygems-bundler (1.4.2)
rvm (1.11.3.9)
test-unit (2.1.1.0)
jackju at macbook-air  ~/tmp/delme1
$ bundle
Fetching git://github.com/survili/ffi-compiler.git
remote: Reusing existing pack: 260, done.
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 265 (delta 2), reused 0 (delta 0)
Receiving objects: 100% (265/265), 38.59 KiB | 0 bytes/s, done.
Resolving deltas: 100% (116/116), done.
Fetching gem metadata from http://rubygems.org/.........
Fetching additional metadata from http://rubygems.org/..
Resolving dependencies...
Installing rake (10.3.1)
Installing ffi (1.9.3)
Using ffi-compiler (0.1.4) from git://github.com/survili/ffi-compiler.git (at master)

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /home/jackju/.rvm/rubies/ruby-2.1.1/bin/ruby -rubygems /home/jackju/.rvm/gems/ruby-2.1.1@stackoverproblem/gems/rake-10.3.1/bin/rake RUBYARCHDIR=/home/jackju/.rvm/gems/ruby-2.1.1@stackoverproblem/extensions/x86_64-linux/2.1.0/libmspack-0.0.4 RUBYLIBDIR=/home/jackju/.rvm/gems/ruby-2.1.1@stackoverproblem/extensions/x86_64-linux/2.1.0/libmspack-0.0.4
rake aborted!
LoadError: cannot load such file -- ffi-compiler/compile_task
/home/jackju/.rvm/gems/ruby-2.1.1@stackoverproblem/gems/libmspack-0.0.4/ext/Rakefile:1:in `<top (required)>'
(See full trace by running task with --trace)

rake failed, exit code 1

Gem files will remain installed in /home/jackju/.rvm/gems/ruby-2.1.1@stackoverproblem/gems/libmspack-0.0.4 for inspection.
Results logged to /home/jackju/.rvm/gems/ruby-2.1.1@stackoverproblem/extensions/x86_64-linux/2.1.0/libmspack-0.0.4/gem_make.out
An error occurred while installing libmspack (0.0.4), and Bundler cannot
continue.
Make sure that `gem install libmspack -v '0.0.4'` succeeds before bundling.
jackju at macbook-air  ~/tmp/delme1
$ ls
Gemfile
jackju at macbook-air  ~/tmp/delme1
$ 
Run Code Online (Sandbox Code Playgroud)

Sye*_*lam 2

问题是缺少在此 gem 中找到的“rubygems/tasks”: https: //github.com/postmodern/rubygems-tasks

我能够按照以下步骤在我的计算机上安装 libmspack:

  1. gem 安装 ruby​​gems-tasks

  2. git 克隆 git@github.com:survili/ffi-compiler.git

  3. cd ffi 编译器

  4. 耙子建造宝石

  5. gem 安装 pkg/ffi-compiler-0.1.4.gem

  6. gem 安装 libmspack -v '0.0.4'

Successfully installed libmspack-0.0.4 
1 gem installed
Run Code Online (Sandbox Code Playgroud)

  • 如果你想自动完成这一切,你需要 fork `libmspack` 并添加到 Gemfile `gem 'ffi-compiler', :github =&gt;'survili/ffi-compiler'` ,然后在你的应用程序中添加你的像 `gem 'libmspack', :github =&gt;'survili/libmspack'` 这样的分支。我没有将“ffi-compiler”主分支添加到“libmspack”的 Gemfile 中,因为这只是暂时的,有一天“ffi-compiler”将发布新版本,因此不需要任何特殊步骤。但看看https://github.com/ffi/ffi/issues/339 (3认同)
  • 这是正确的方法,克隆后您也可以只执行“gem build ffi-compiler.gemspec”和“gem install ffi-compiler-0.1.4.gem”,然后您将不需要“rubygems-tasks”。否则必须手动安装,因为“rake”任务依赖于它,因此无法安装它。至于“bundle install”,它不起作用,因为在安装“libmspack”时,Bundler 不会将您的“ffi-compiler”版本附加到加载路径,原因是在 Gemfile 中您指定了应用程序的依赖项,而不是其他依赖项。 (2认同)