49 Commits

Author SHA1 Message Date
Maxim Belkin
50f47e88ec utils/ruby.sh: reoganize code
Moved OS-specific logic to functions:
 - `find_ruby`: returns (via echo) Ruby that can be used
 - `usable_ruby`: checks whether Ruby satisfies Homebrew

Pre-create OS-specific error messages:
 - `upgrade_fail`: message that is printed when Homebrew fails to upgrade
   vendor Ruby
 - `install_fail`: message that is printed when Homebrew fails to install
   vendor Ruby

Unconditionally set `TERMINFO_DIRS` when installing/upgrading vendor Ruby
**but** export it on Linux only.

Motivation: move OS-specific logic to functions so that it's easier to
understand the main steps.
2020-08-13 23:57:23 +00:00
Maxim Belkin
f3283b60cc
utils/ruby.sh: test_ruby(): keep temporary variables local 2020-08-12 17:07:41 -05:00
Mike McQuaid
15a2abd9df
style: re-enable shellcheck.
Ensure that `shellcheck` is run by `brew style` again and fix the
various failures.
2020-07-07 11:53:55 +01:00
Mike McQuaid
07ea18e2d2
ruby.sh: don't print recoverable error.
This prints "error" even when we can install a portable ruby.
2020-06-23 13:13:31 +01:00
Mike McQuaid
854e96c7c5
Merge pull request #7686 from maxim-belkin/test_ruby_update
utils/ruby.sh: update `test-ruby` (and rename to test_ruby)
2020-06-12 09:13:15 +01:00
Bo Anderson
87931e1c03 utils/ruby.sh: set TERMINFO_DIRS to bundled terminfo 2020-06-10 14:36:18 +01:00
Maxim Belkin
23d24dfed7
utils/ruby.sh: rely on test_ruby's exit code
Instead of printing "true" or "false", test_ruby now returns 1 when
tested Ruby is not usable and 0 if it is.
2020-06-10 07:56:37 -05:00
Maxim Belkin
9751d3bb8c
Fix calls to 'test_ruby' in conditional statements
Co-authored-by: Shaun Jackman <sjackman@gmail.com>
2020-06-06 12:03:51 -05:00
Maxim Belkin
58f3e49c0b
utils/ruby.sh: rename test-ruby to test_ruby. Cosmetic changes 2020-06-03 18:01:38 -05:00
Maxim Belkin
5d3456f485
utils/ruby.sh: make code more readable
1. Repurpose 'vendor_ruby_current_version' variable:
   now this is not a pointer to a file but actual version number
2. Introduce 'vendor_ruby_latest_version' variable:
   it holds the value of the latest version of portable Ruby
2020-05-21 17:15:14 -05:00
Maxim Belkin
db561eb7b9
utils/ruby.sh: setup-ruby: handle 'vendor-install' cmd early
Exit from the 'setup-ruby' function when user issued
`vendor-install` command.
We do so instead of wrapping everything in

```sh
if [[ "$HOMEBREW_COMMAND" != "vendor-install" ]]
```

`git diff` when whitespaces are ignored:

$ git diff -w
diff --git a/Library/Homebrew/utils/ruby.sh b/Library/Homebrew/utils/ruby.sh
index 7974e909c..4be204309 100644
--- a/Library/Homebrew/utils/ruby.sh
+++ b/Library/Homebrew/utils/ruby.sh
@@ -27,8 +27,11 @@ If there's no Homebrew Portable Ruby available for your processor:

   unset HOMEBREW_RUBY_PATH

-  if [[ "$HOMEBREW_COMMAND" != "vendor-install" ]]
+  if [[ "$HOMEBREW_COMMAND" == "vendor-install" ]]
   then
+    return 0
+  fi
+
   if [[ -x "$vendor_ruby_path" ]]
   then
     HOMEBREW_RUBY_PATH="$vendor_ruby_path"
@@ -85,7 +88,6 @@ If there's no Homebrew Portable Ruby available for your processor:
       HOMEBREW_RUBY_PATH="$vendor_ruby_path"
     fi
   fi
-  fi

   export HOMEBREW_RUBY_PATH
 }
2020-05-21 15:06:21 -05:00
Maxim Belkin
8dcb1636ce
utils/ruby.sh: add explanatory comments 2020-05-20 12:29:45 -05:00
Maxim Belkin
dcc486fa9e
utils/ruby.sh: find usable Ruby from PATH only 2020-05-19 12:24:00 -05:00
Maxim Belkin
b4267d80e4
utils/ruby.sh: avoid nested ifs 2020-05-17 16:32:06 -05:00
Maxim Belkin
083f56fafe
utils/ruby.sh: quote HOMEBREW_RUBY_PATH when calling test-ruby 2020-05-15 16:35:42 -05:00
Maxim Belkin
f7e0705164
utils/ruby.sh: try installing portable Ruby ...
when no usable Ruby is found.
2020-05-15 15:12:20 -05:00
Maxim Belkin
44ef1abd1f
utils/ruby.sh: suppress standard error in test-ruby 2020-05-15 15:04:06 -05:00
Maxim Belkin
ec6e449f4f
utils/ruby.sh: unset HOMEBREW_RUBY_PATH unconditionally 2020-05-15 14:21:51 -05:00
Maxim Belkin
d21ecffae6
utils/ruby.sh: break down long ruby code in test-ruby 2020-05-15 14:20:03 -05:00
Maxim Belkin
cbc266bf0e
utils/ruby.sh: split long line in test-ruby() function
Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
2020-05-15 13:49:22 -05:00
Maxim Belkin
328c75fc33
Move logic related to HOMEBREW_RUBY_PATH to utils/ruby.sh 2020-05-15 10:30:45 -05:00
Mike McQuaid
6123cdb767
Improve Homebrew Portable Ruby messaging
As-of https://github.com/Homebrew/homebrew-portable-ruby/pull/100 we've
removed ARM builds for Portable Ruby due to months of breakage.
Similarly, when we last bumped Portable Ruby the ARM build was much
delayed but, despite Homebrew/brew being completely unusable to anyone
using it on ARM in that case, no-one complained or filed issues.

Instead of attempting to maintain and update a Portable Ruby on niche
(Homebrew) platforms like ARM (or, in past/future PPC) improve the
messaging to provide users with a workaround.

Now we allow only a major/minor version match it should be pretty
doable for those users to install e.g. a prebuilt Ruby binary from a PPA
or built it from source if needed using `ruby-build` and `rbenv`.

The messaging could be improved further but we're somewhat limited by
`ruby.sh` and `vendor-install.sh` being separate. I'm tempted to combine
them (or at least have `vendor-install.sh` not be so generic as to not
be able to give Ruby-specific advice).
2020-05-02 13:53:45 +01:00
Eric Knibbe
fa1ce146e4 ruby.sh: allow running on older ruby versions 2020-04-22 17:36:00 -04:00
Mike McQuaid
8471421c86
utils/ruby.sh: fix macOS portable Ruby detection.
Avoid unconditionally installing due to a variable name change.
2020-02-01 19:10:17 +01:00
Mike McQuaid
0b09c07862
ruby.sh: fix whitespace and tweak required ruby version check. 2020-02-01 12:49:35 +01:00
Emre Erhan
cad7f98527
Clean up variable names
Co-Authored-By: Mike McQuaid <mike@mikemcquaid.com>
2020-01-31 15:17:32 -08:00
emreerhan
a1102f253c Remove checks to variable that is not set anywhere 2020-01-30 15:48:41 -08:00
emreerhan
027cc68534 Add condition to check if ruby version is < 2.7 2020-01-30 15:01:26 -08:00
Mike McQuaid
e9aba2efb6
Require and provide portable Ruby 2.6.3. 2019-10-10 15:53:16 +01:00
Mike McQuaid
86f43f79ee
Enable/fix optional Ruby frozen string literal usage
Combined with https://github.com/Homebrew/homebrew-test-bot/pull/247
this will test Homebrew's use of frozen strings in CI. After this we
will then enable it for Homebrew developers and eventually all Homebrew
users.
2019-04-19 10:30:41 +09:00
Mike McQuaid
9e7b98d3e2
Don't check system Ruby is new enough when unnecessary.
We know this is the case in macOS >=10.13.3 so save a Ruby process call.
2019-04-18 21:42:28 +09:00
Mike McQuaid
ef2e297d3b
Disable RubyGems by default.
This speeds up all Ruby invocations where we don't need RubyGems by
around 10%. Where we do need RubyGems: include it manually.
2019-04-18 17:45:03 +09:00
Mike McQuaid
d33c225e47
utils/ruby: don't remove cleanup bundler.
We're sharing this directory now.
2019-02-22 15:59:14 +00:00
Mike McQuaid
a11fe57cd2
cache_store: handle corrupt DBM database.
When the DBM database cannot be read by the current version of Ruby's
DBM library (due to corruption or another incompatibility) it segfaults
or freezes which takes down the entire Homebrew Ruby process.

This isn't desirable so instead perform a shell out with the Homebrew
Ruby to see if it can read the DBM database before we try to use the
information. If this hangs or crashes: silently delete the database and
recreate it.
2018-09-20 10:57:27 +01:00
Mike McQuaid
f2d823445e ruby.sh: remove linkage cache on upgrade.
This may not be compatible between portable ruby versions and between
portable and system ruby versions.

Fixes #4485.
2018-07-18 14:09:43 +01:00
Mike McQuaid
9b86ff6214 ruby.sh: cleanup gems on portable Ruby installation.
This avoids `brew style` and friends from getting upset when they
attempt to use the native gem extensions from a previous portable Ruby
or a system Ruby.

ABI? What's that?
2018-07-13 14:37:12 +01:00
Mike McQuaid
e1eb7dd3e3 Use Ruby 2.3.7
Fixes #4459.
2018-07-13 08:22:33 +01:00
Buck Evan
0a2e649f00 type -P is more portable than which
Migrated from https://github.com/Linuxbrew/brew/pull/621
2018-03-18 16:51:22 -07:00
Mike McQuaid
78933b3ee9 ruby.sh: fix version check.
- Rather than checking for the absence of a failure check for an actual success in the check
- Fix the check to work on Ruby 1.9 (where `RUBY_VERSION.to_s.dup` is required to avoid modifying a frozen string).
2018-01-26 21:47:33 +00:00
Shaun Jackman
7a0488e803 setup-ruby-path: Ensure that Ruby is installed
Fix the error:
/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/brew.sh: line 372:
exec: : not found
2017-10-17 15:14:58 -07:00
Mike McQuaid
598ea0cdec portable-ruby: fix installation on Leopard.
Download it insecurely there and require `rubygems` for `Gem::Version`.
2017-09-25 15:46:58 +01:00
Mike McQuaid
aa665b9458 portable-ruby: improve installation messaging.
- Use “Pouring” to be more consistent with our normal messaging.
- Don’t be silent by default.
2017-09-22 15:54:29 +01:00
Mike McQuaid
b2b413165f Upgrade vendored Ruby to 2.3.3.
Use this version whenever 2.3.3 isn't installed. Also, remove the Linux
portable Ruby for now until it's built to be the same version.
2017-09-21 14:27:17 +01:00
Mike McQuaid
3f9cce0a03 Use new "macOS" naming where appropriate.
Not quite a mass replacement as I've used OS X and Mac OS X where
describing specific older versions and added compatibility methods
for things in the DSL.
2016-09-18 19:57:19 +01:00
Mike McQuaid
4eaa40ae1f Enable vendored Ruby 2.0. 2016-08-10 20:06:14 +01:00
Mike McQuaid
5a2eaf9a12 ruby.sh: allow forcing the usage of the vendored Ruby. 2016-07-12 08:51:36 +01:00
Mike McQuaid
b418fe94c8 ruby.sh: fix original setup ruby path name. 2016-07-12 08:51:36 +01:00
Xu Cheng
dff6bfde9a
ruby.sh: add test flag 2016-07-11 21:12:57 +08:00
Xu Cheng
534bf08ec3
brew.sh: new HOMEBREW_RUBY_PATH resolution logic
* Use vendor Ruby if it's present
* Install vendor Ruby for system without Ruby 2.x
2016-07-11 21:12:56 +08:00