使用rvm在Xcode中强制特定的Ruby运行脚本生成阶段

使用rvm在Xcode中强制特定的Ruby运行脚本生成阶段

问题描述:

Xcode之外我使用特定版本的Ruby,使用RVM来管理多个Ruby安装。使用rvm在Xcode中强制特定的Ruby运行脚本生成阶段

苹果的命令行开发工具安装Ruby在/usr/bin/ruby和版本1.8.7。

我使用1.9.3通过RVM。

有没有办法强制Xcode在运行Run Script构建阶段时使用我的1.9.3安装?

我已经尝试将Shell路径设置为我特定Ruby的完整路径,但这似乎没有什么区别,我的意思是我在1.9.3中安装的特定Gems不是在Xcode中运行时脚本可用/可见。

如果我在命令行上通过xcodebuild运行我的项目,运行脚本阶段使用我的特定Ruby,因为它是从我的shell环境中运行的(即使项目文件中的Shell路径设置为/usr/bin/ruby,它仍然使用我的1.9.3)。

怎样才能让IDE使用我的1.9.3 Ruby安装?

+0

会不会创建符号链接做的伎俩?例如:'ln -s $ HOME/.rvm/bin/rvm-auto-ruby/usr/bin/ruby​​' – fmendez 2013-03-18 11:39:27

+0

我想它可以,但是我想保留默认安装,如果可能的话 - 我想一个可以在另一台机器上工作的解决方案,而不必混淆它的默认安装(显然需要安装RVM,但是如果我可以单独离开/ usr/bin安装,这非常理想) – Jasarien 2013-03-18 11:46:28

在Xcode在脚本的开头试试这个:

source "$HOME/.rvm/scripts/rvm" 

我有同样的(好,坏)的问题,下面为我工作的代码。 实现关键的一点是,在命令行中,使用的是<something>/bin/rvm,但在一个shell脚本,为了RVM改变环境中,你必须使用一个功能,而且必须先负载通过调用source <something>/scripts/rvm可以运行到您的shell脚本。更多关于这一切here

此代码也是gisted

#!/usr/bin/env bash 

# Xcode scripting does not invoke rvm. To get the correct ruby, 
# we must invoke rvm manually. This requires loading the rvm 
# *shell function*, which can manipulate the active shell-script 
# environment. 
# cf. http://rvm.io/workflow/scripting 

# Load RVM into a shell session *as a function* 
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then 

    # First try to load from a user install 
    source "$HOME/.rvm/scripts/rvm" 

elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then 

    # Then try to load from a root install 
    source "/usr/local/rvm/scripts/rvm" 
else 

    printf "ERROR: An RVM installation was not found.\n" 
    exit 128 
fi 

# rvm will use the controlling versioning (e.g. .ruby-version) for the 
# pwd using this function call. 
rvm use . 

作为protip,我发现在project.pbxproj文件中嵌入shell代码。对于所有,但最琐碎的东西,我的实际运行脚本步骤通常只是一个行调出到外部脚本:

enter image description here