簡體   English   中英

從Xcode shell腳本運行時缺少Ruby gem

[英]Ruby gems missing when run from Xcode shell script

我正在嘗試運行一個grunt腳本來編譯一堆東西,包括來自Xcode的grunt-contrib-compass 運行grunt debug可以在Xcode外部正常工作,但在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':找不到'指南針'(> = 0) 14個總寶石中的一個(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 env,正如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

所以我最終作弊 -

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

在新的bash實例中運行grunt命令,該實例不繼承Xcode的環境變量,並且與Xcode之外的bash相同。

雖然它並不完美 - 雖然回顯bash的結果給了我所有的日志消息,它們的格式很差,並且如果出現錯誤它也不會停止執行主腳本。

理想情況下,如果有人有任何建議,我仍然希望找到原始問題的正確解決方案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM