使用rvm在Xcode Run Script构建阶段强制使用特定的Ruby

Jas*_*ien 8 ruby xcode rvm

在Xcode之外我使用特定版本的Ruby,使用RVM来管理多个Ruby安装.

Apple的命令行开发工具安装Ruby,/usr/bin/ruby版本为1.8.7.

我通过RVM使用1.9.3.

有没有办法在运行Run Script构建阶段时强制Xcode使用我的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安装?

Cla*_*ges 6

我遇到了同样(好吧,更糟)的问题,接下来的代码对我有用。要意识到的关键是,在命令行上,您正在使用<something>/bin/rvm,但是在 shell 脚本中,为了让 rvm 更改环境,您必须使用一个函数,并且您必须首先将该函数加载到您的 shell 脚本中打电话source <something>/scripts/rvm。更多关于这一切在这里

这段代码也是要点

#!/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 .
Run Code Online (Sandbox Code Playgroud)

作为一个专业人士,我发现在project.pbxproj文件中嵌入 shell 代码很糟糕。除了最琐碎的事情之外,我的实际运行脚本步骤通常只是对外部脚本的一行调用:

在此处输入图片说明


sho*_*hin 4

在 Xcode 中的脚本开头尝试以下操作:

source "$HOME/.rvm/scripts/rvm"
Run Code Online (Sandbox Code Playgroud)