FreeBSD 无法在任何来源中找到 gem

FreeBSD Could not find gem in any of the sources

我试图在 FreeBSD 上捆绑,但找不到 grpc gem。我使用 FreeBSD 软件包安装了 grpc 1.30.2 版本,但它找不到系统 gem.

我希望有一个 bundle config 设置来查找和使用已经构建和安装的系统 gem。

我得到的错误是:

An error occurred while installing grpc (1.30.2), and Bundler cannot continue.
Make sure that `gem install grpc -v '1.30.2' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  grpc
* bundle install
Warning: the running version of Bundler (2.0.2) is older than the version that created the lockfile (2.2.11). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
/usr/local/lib/ruby/site_ruby/2.7/rubygems/package.rb:509: warning: Using the last argument as keyword parameters is deprecated
/usr/local/lib/ruby/site_ruby/2.7/rubygems/package.rb:509: warning: Using the last argument as keyword parameters is deprecated
/usr/local/lib/ruby/site_ruby/2.7/rubygems/package.rb:509: warning: Using the last argument as keyword parameters is deprecated
/usr/local/lib/ruby/site_ruby/2.7/rubygems/package.rb:509: warning: Using the last argument as keyword parameters is deprecated
Some gems seem to be missing from your vendor/cache directory.
Could not find grpc-1.30.2 in any of the sources
* Visruleparser
A    extras/visruleparser.pl
Export complete.
* precompile assets
Could not find grpc-1.30.2 in any of the sources
Run `bundle install` to install missing gems.

我的 Gemfile 有这些行

source 'https://rubygems.org'
gem 'grpc', '1.30.2'
gem 'grpc-tools', '1.30.2'

Gemfile.lock有这些

  grpc (= 1.30.2)
  grpc-tools (= 1.30.2)

这些 FreeBSD 软件包已安装

>pkg info -x grpc
grpc-1.22.0_4,2
rubygem-grpc-1.30.2
>gem list grpc

*** LOCAL GEMS ***

grpc (1.30.2)

列出远程 gems 在 FreeBSD 上没有显示任何内容

>gem list --remote -all gprc 

*** LOCAL GEMS ***

但是在 macOS 上我得到了这些(以及其他)

>gem list --remote --all grpc
grpc (1.37.0 ruby universal-darwin x64-mingw32 x86-linux x86-mingw32 x86_64-linux,
1.36.0 ruby universal-darwin x64-mingw32 x86-linux x86-mingw32 x86_64-linux,
...
1.30.2 ruby universal-darwin x64-mingw32 x86-linux x86-mingw32 x86_64-linux,
...

gem 安装在目录 /usr/local/lib/ruby/gems/2.7/gems/grpc-1.30.2 中,其下有一个 src 子目录和一个 ruby 子目录。

>ls /usr/local/lib/ruby/gems/2.7/gems/grpc-1.30.2/src/ruby
bin ext lib pb  spec

环境

FreeBSD       11.4
Ruby          2.7.2p137
RubyGems      3.0.8
Bundler       2.1.4

看来这可能是我的错。 gem 包有目的地从 gem 中删除缓存目录。这最初是在这里添加的:

https://cgit.freebsd.org/ports/commit/Mk/bsd.ruby.mk?id=8d77480356f58d6d8d1c69884d1ba9cc98ed383a

并住在这里:

https://cgit.freebsd.org/ports/tree/Mk/Uses/gem.mk#n111

    ${RM} -r ${STAGEDIR}${PREFIX}/${CACHE_DIR} 2> /dev/null || ${TRUE}

添加此内容是因为很多 gem 包含缓存目录中从未使用过的大量内容,包括源代码的完整副本、中间构建输出等,这些实际上不应打包.

如果您正在构建自己的包,您可以尝试 gem.mk 中删除缓存目录的行。否则,我们可能需要重新访问这个上游。无论如何,您应该在上游打开一个错误:

https://bugs.freebsd.org/bugzilla/

但是需要权衡取舍,我不确定从系统包安装的捆绑 gems 的用例。 (我最近没怎么用 Ruby。)