aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/utils/ruby.sh
blob: 98fd34c1b44e7d015740c28380d0dd9a06a58d05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
original-setup-ruby-path() {
  if [[ -z "$HOMEBREW_DEVELOPER" ]]
  then
    unset HOMEBREW_RUBY_PATH
  fi

  if [[ -z "$HOMEBREW_RUBY_PATH" ]]
  then
    if [[ -n "$HOMEBREW_OSX" ]]
    then
      HOMEBREW_RUBY_PATH="/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby"
    else
      HOMEBREW_RUBY_PATH="$(which ruby)"
      if [[ -z "$HOMEBREW_RUBY_PATH" ]]
      then
        odie "No Ruby found, cannot proceed."
      fi
    fi
  fi

  export HOMEBREW_RUBY_PATH
}

setup-ruby-path() {
  if [[ -z "$HOMEBREW_USE_VENDOR_RUBY" && -z "$HOMEBREW_FORCE_VENDOR_RUBY" ]]
  then
    original-setup-ruby-path
    return
  fi

  local vendor_dir
  local vendor_ruby_current_version
  local vendor_ruby_path
  local ruby_version_major

  vendor_dir="$HOMEBREW_LIBRARY/Homebrew/vendor"
  vendor_ruby_current_version="$vendor_dir/portable-ruby/current"
  vendor_ruby_path="$vendor_ruby_current_version/bin/ruby"

  if [[ -z "$HOMEBREW_DEVELOPER" ]]
  then
    unset HOMEBREW_RUBY_PATH
  fi

  if [[ -z "$HOMEBREW_RUBY_PATH" && "$HOMEBREW_COMMAND" != "vendor-install" ]]
  then
    if [[ -x "$vendor_ruby_path" ]]
    then
      HOMEBREW_RUBY_PATH="$vendor_ruby_path"

      if [[ $(readlink "$vendor_ruby_current_version") != "$(<"$vendor_dir/portable-ruby-version")" ]]
      then
        if ! brew vendor-install ruby --quiet
        then
          onoe "Failed to upgrade vendor Ruby."
        fi
      fi
    else
      if [[ -n "$HOMEBREW_OSX" ]]
      then
        HOMEBREW_RUBY_PATH="/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby"
      else
        HOMEBREW_RUBY_PATH="$(which ruby)"
      fi

      if [[ -n "$HOMEBREW_RUBY_PATH" ]]
      then
        ruby_version_major="$("$HOMEBREW_RUBY_PATH" --version)"
        ruby_version_major="${ruby_version_major#ruby }"
        ruby_version_major="${ruby_version_major%%.*}"
      fi

      if [[ "$ruby_version_major" != "2" || -n "$HOMEBREW_FORCE_VENDOR_RUBY" ]]
      then
        brew vendor-install ruby --quiet
        if [[ ! -x "$vendor_ruby_path" ]]
        then
          odie "Failed to install vendor Ruby."
        fi
        HOMEBREW_RUBY_PATH="$vendor_ruby_path"
      fi
    fi
  fi

  export HOMEBREW_RUBY_PATH
}