2013-03-18 60 views
7

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

回答

3

在Xcode在腳本的開頭試試這個:

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

我有同樣的(好,壞)的問題,下面爲我工作的代碼。 實現關鍵的一點是,在命令行中,使用的是<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

相關問題