【问题标题】:Ruby gems missing when run from Xcode shell script从 Xcode shell 脚本运行时缺少 Ruby gem
【发布时间】:2014-02-12 21:09:17
【问题描述】:

我正在尝试运行一个 grunt 脚本来编译一堆东西,包括来自 Xcode 的grunt-contrib-compass。在 Xcode 外部运行 grunt debug 可以正常工作,但在 Xcode 中作为构建阶段的一部分作为 shell 脚本调用时就不行了。

运行grunt debug 我收到:

/Users/MY_USER/.rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/dependency.rb:298:in `to_specs': 在总共 14 个 gem(s) 中找不到 'compass' (>= 0) (Gem::LoadError)

在脚本顶部加载了我的 PATH 变量:

PATH=$(bash -l -c 'echo $PATH')

Xcode 似乎正在加载正确版本的 ruby​​ 和 gem:

which ruby     ->  /Users/MY_USER/.rvm/rubies/ruby-2.1.0/bin/ruby
which compass  ->  /Users/MY_USER/.rvm/gems/ruby-2.1.0/bin/compass
which gem      ->  /Users/MY_USER/.rvm/rubies/ruby-2.1.0/bin/gem

这些与从 bash 报告的相同。

但是,gem query --local 在 Xcode 中执行时与从 bash 中运行时返回的列表不同。此列表不包含指南针 - 我想这可能是我收到 Could not find 'compass' 错误的原因,知道我能做些什么来解决这个问题吗?

这是我的 gem 环境,由 Xcode 执行的 shell 脚本报告:

RubyGems Environment:
  - RUBYGEMS VERSION: 2.2.2
  - RUBY VERSION: 2.1.0 (2013-12-25 patchlevel 0) [x86_64-darwin12.0]
  - INSTALLATION DIRECTORY: /Users/MY_USER/.rvm/rubies/ruby-2.1.0/lib/ruby/gems/2.1.0
  - RUBY EXECUTABLE: /Users/MY_USER/.rvm/rubies/ruby-2.1.0/bin/ruby
  - EXECUTABLE DIRECTORY: /Users/MY_USER/.rvm/rubies/ruby-2.1.0/bin
  - SPEC CACHE DIRECTORY: /Users/MY_USER/.gem/specs
  - RUBYGEMS PLATFORMS:
    - ruby
    - x86_64-darwin-12
  - GEM PATHS:
     - /Users/MY_USER/.rvm/rubies/ruby-2.1.0/lib/ruby/gems/2.1.0
     - /Users/MY_USER/.gem/ruby/2.1.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /Users/MY_USER/.rvm/gems/ruby-2.1.0/bin
     - /Users/MY_USER/.rvm/gems/ruby-2.1.0@global/bin
     - /Users/MY_USER/.rvm/rubies/ruby-2.1.0/bin
     - /opt/local/bin
     - /opt/local/sbin
     - /usr/bin
     - /bin
     - /usr/sbin
     - /sbin
     - /usr/local/bin
     - /usr/local/git/bin
     - /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
     - /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/libexec
     - /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin
     - /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/local/bin
     - /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/usr/bin
     - /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/usr/local/bin
     - /Applications/Xcode.app/Contents/Developer/usr/bin
     - /Applications/Xcode.app/Contents/Developer/usr/local/bin
     - /Applications/Xcode.app/Contents/Developer/Tools
     - /Users/MY_USER/bin
     - /Users/MY_USER/Development/adt-bundle/sdk/platform-tools
     - /Users/MY_USER/Development/adt-bundle/sdk/tools
     - /Users/MY_USER/.rvm/bin

【问题讨论】:

  • 您是否考虑过添加Gemfile 并运行bundle exec grunt debug
  • 你的意思是我可以通过budle exec..运行grunt cli吗?

标签: ruby xcode gruntjs compass-sass


【解决方案1】:

所以我最终作弊了 -

echo $(bash -l -c  "source ~/.bashrc && cd $myProjectLocation && grunt debug")

在新的 bash 实例中运行 grunt 命令,该实例不继承 Xcode 的环境变量,与 Xcode 之外的 bash 相同。

虽然它并不完美 - 虽然回显 bash 的结果为我提供了所有日志消息,但它们的格式很差,如果出现错误,它不会停止主脚本的执行。

所以理想情况下,如果有人有任何建议,我仍然希望为我的原始问题提供适当的解决方案。

【讨论】:

  • 你有没有进一步了解这个?
  • 是的——我们不再使用任何依赖于 ruby​​ 的东西,并且已经开始使用 libsass 来构建 sass!作为 xcode 中脚本构建阶段的一部分,这可以正常工作:source ~/.bash_profile && sh scripts/build.sh 当 build.sh 脚本可能包含 gulp build 等时。
猜你喜欢
  • 1970-01-01
  • 2013-07-29
  • 2018-04-15
  • 2015-08-29
  • 2018-08-10
  • 2021-04-23
  • 2011-03-23
  • 2013-04-11
  • 1970-01-01
相关资源
最近更新 更多