简体   繁体   中英

Ruby gems missing when run from Xcode shell script

I'm attempting to run a grunt script to compile a bunch of stuff, including grunt-contrib-compass from Xcode. Running grunt debug works fine from outside of Xcode, but not when invoked as a shell script as part of a build phase in Xcode.

running grunt debug I receive:

/Users/MY_USER/.rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/dependency.rb:298:in `to_specs': Could not find 'compass' (>= 0) among 14 total gem(s) (Gem::LoadError)

Having loaded in my PATH variables at the top of the script with:

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

Xcode seems to be loading in the correct versions of 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

These are the same as those reported from bash.

However, gem query --local returns a different list when executed within Xcode than when run from bash. This list does not contain compass - I guess this might be why I receive the Could not find 'compass' error, any idea what I can do to fix this?

Here's my gem env, as reported from the shell script executed by Xcode:

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

So I've ended up cheating -

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

runs the grunt command in a new bash instance, which does not inherit Xcode's environment variables, and is the same as bash outside of Xcode.

It's not perfect though - while echoing out the result of bash gives me all the log messages, they're poorly formatted, and it doesn't halt execution of the main script if there's an error.

So ideally I'd still like a proper solution to my original question, if anyone has any suggestions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM