Use rvm to force specific Ruby in Xcode Run Script build phase

后端 未结 2 1362
梦谈多话
梦谈多话 2020-12-11 17:12

Outside of Xcode I use a specific version of Ruby, using RVM to manage multiple Ruby installations.

Apple\'s command line dev tools install Ruby at /usr/bin/ru

相关标签:
2条回答
  • 2020-12-11 17:21

    I had the same (well, worse) problem, and the code that follows worked for me. The key thing to realize is that, on the command line, you are using <something>/bin/rvm, but in a shell script, in order for rvm to change that environment, you must use a function, and you must first load that function to your shell script by calling source <something>/scripts/rvm. More on all this here.

    This code is also 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 .
    

    As a protip, I find embedding shell code in a project.pbxproj file yucky. For all but the most trivial stuff, my actual run script step is usually just a one-line call out to an external script:

    enter image description here

    0 讨论(0)
  • 2020-12-11 17:38

    Try this at the beginning of your script in Xcode:

    source "$HOME/.rvm/scripts/rvm"
    
    0 讨论(0)
提交回复
热议问题