| 
									
										
										
										
											2016-06-28 23:41:28 +08:00
										 |  |  | setup-ruby-path() { | 
					
						
							|  |  |  |   local vendor_dir | 
					
						
							|  |  |  |   local vendor_ruby_current_version | 
					
						
							|  |  |  |   local vendor_ruby_path | 
					
						
							| 
									
										
										
										
											2020-02-01 19:10:17 +01:00
										 |  |  |   local usable_ruby_version | 
					
						
							| 
									
										
										
										
											2019-10-08 10:00:38 +01:00
										 |  |  |   # When bumping check if HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH (in brew.sh) | 
					
						
							|  |  |  |   # also needs to be changed. | 
					
						
							| 
									
										
										
										
											2020-02-01 12:49:12 +01:00
										 |  |  |   local required_ruby_version="2.6" | 
					
						
							| 
									
										
										
										
											2016-06-28 23:41:28 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   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 | 
					
						
							| 
									
										
										
										
											2017-09-22 15:54:29 +01:00
										 |  |  |         if ! brew vendor-install ruby | 
					
						
							| 
									
										
										
										
											2016-06-28 23:41:28 +08:00
										 |  |  |         then | 
					
						
							| 
									
										
										
										
											2020-05-02 13:53:45 +01:00
										 |  |  |           if [[ -n "$HOMEBREW_MACOS" ]] | 
					
						
							|  |  |  |           then | 
					
						
							|  |  |  |             odie "Failed to upgrade Homebrew Portable Ruby!" | 
					
						
							|  |  |  |           else | 
					
						
							|  |  |  |             odie <<-EOS | 
					
						
							|  |  |  | Failed to upgrade Homebrew Portable Ruby! | 
					
						
							|  |  |  | If there's no Homebrew Portable Ruby available for your processor: | 
					
						
							|  |  |  | - install Ruby $required_ruby_version with your system package manager (or rbenv/ruby-build) | 
					
						
							|  |  |  | - make it first in your PATH | 
					
						
							|  |  |  | - try again | 
					
						
							|  |  |  | EOS | 
					
						
							|  |  |  |           fi | 
					
						
							| 
									
										
										
										
											2016-06-28 23:41:28 +08:00
										 |  |  |         fi | 
					
						
							|  |  |  |       fi | 
					
						
							|  |  |  |     else | 
					
						
							| 
									
										
										
										
											2016-09-18 19:57:19 +01:00
										 |  |  |       if [[ -n "$HOMEBREW_MACOS" ]] | 
					
						
							| 
									
										
										
										
											2016-06-28 23:41:28 +08:00
										 |  |  |       then | 
					
						
							|  |  |  |         HOMEBREW_RUBY_PATH="/System/Library/Frameworks/Ruby.framework/Versions/Current/usr/bin/ruby" | 
					
						
							|  |  |  |       else | 
					
						
							| 
									
										
										
										
											2018-03-17 23:02:05 -07:00
										 |  |  |         HOMEBREW_RUBY_PATH="$(type -P ruby)" | 
					
						
							| 
									
										
										
										
											2016-06-28 23:41:28 +08:00
										 |  |  |       fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-18 17:54:05 +09:00
										 |  |  |       if [[ -n "$HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH" ]] | 
					
						
							|  |  |  |       then | 
					
						
							| 
									
										
										
										
											2020-02-01 19:10:17 +01:00
										 |  |  |         usable_ruby_version="true" | 
					
						
							| 
									
										
										
										
											2019-04-18 17:54:05 +09:00
										 |  |  |       elif [[ -n "$HOMEBREW_RUBY_PATH" && -z "$HOMEBREW_FORCE_VENDOR_RUBY" ]] | 
					
						
							| 
									
										
										
										
											2016-06-28 23:41:28 +08:00
										 |  |  |       then | 
					
						
							| 
									
										
										
										
											2020-04-22 15:57:03 -04:00
										 |  |  |         usable_ruby_version="$("$HOMEBREW_RUBY_PATH" --enable-frozen-string-literal --disable=gems,did_you_mean,rubyopt -rrubygems -e "puts Gem::Version.new(RUBY_VERSION.to_s.dup).to_s.split('.').first(2) == Gem::Version.new('$required_ruby_version').to_s.split('.').first(2)")" | 
					
						
							| 
									
										
										
										
											2016-06-28 23:41:28 +08:00
										 |  |  |       fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-31 15:17:32 -08:00
										 |  |  |       if [[ -z "$HOMEBREW_RUBY_PATH" || -n "$HOMEBREW_FORCE_VENDOR_RUBY" || "$usable_ruby_version" != "true" ]] | 
					
						
							| 
									
										
										
										
											2016-06-28 23:41:28 +08:00
										 |  |  |       then | 
					
						
							| 
									
										
										
										
											2017-09-22 15:54:29 +01:00
										 |  |  |         brew vendor-install ruby | 
					
						
							| 
									
										
										
										
											2016-06-28 23:41:28 +08:00
										 |  |  |         if [[ ! -x "$vendor_ruby_path" ]] | 
					
						
							|  |  |  |         then | 
					
						
							| 
									
										
										
										
											2020-05-02 13:53:45 +01:00
										 |  |  |           if [[ -n "$HOMEBREW_MACOS" ]] | 
					
						
							|  |  |  |           then | 
					
						
							|  |  |  |             odie "Failed to install Homebrew Portable Ruby (and your system version is too old)!" | 
					
						
							|  |  |  |           else | 
					
						
							|  |  |  |             odie <<-EOS | 
					
						
							|  |  |  | Failed to install Homebrew Portable Ruby and cannot find another Ruby $required_ruby_version! | 
					
						
							|  |  |  | If there's no Homebrew Portable Ruby available for your processor: | 
					
						
							|  |  |  | - install $required_ruby_version with your system package manager (or rbenv/ruby-build) | 
					
						
							|  |  |  | - make it first in your PATH | 
					
						
							|  |  |  | - try again | 
					
						
							|  |  |  | EOS | 
					
						
							|  |  |  |           fi | 
					
						
							| 
									
										
										
										
											2016-06-28 23:41:28 +08:00
										 |  |  |         fi | 
					
						
							|  |  |  |         HOMEBREW_RUBY_PATH="$vendor_ruby_path" | 
					
						
							|  |  |  |       fi | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  |   fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   export HOMEBREW_RUBY_PATH | 
					
						
							|  |  |  | } |