Skip to content

Commit a273a8d

Browse files
author
Konstantin Gredeskoul
committed
Fixing brittle Host Ruby version detection.
Instead of using ruby --version we should let ruby print it's own version, which is just a string, eg "2.6.5" so no fancy substring logic is required.
1 parent ad27aff commit a273a8d

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

ruby/private/toolchains/ruby_runtime.bzl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,19 @@ def _install_ruby(ctx, ruby):
8888

8989
def host_ruby_is_correct_version(ctx, version):
9090
interpreter_path = ctx.which("ruby")
91+
9192
if not interpreter_path:
93+
print("Can't find ruby interpreter in the PATH")
9294
return False
9395

94-
ruby_version = ctx.execute(["ruby", "--version"]).stdout
95-
version_string = "ruby %sp" % version
96+
ruby_version = ctx.execute(["ruby", "-e", "print RUBY_VERSION"]).stdout
97+
98+
have_ruby_version = (version == ruby_version)
99+
100+
if have_ruby_version:
101+
print("Found local Ruby SDK version '%s' which matches requested version '%s'" % (ruby_version, version))
96102

97-
print("Checking for version '%s' in '%s'" % (version_string, ruby_version))
98-
return version_string in ruby_version
103+
return have_ruby_version
99104

100105
def _ruby_runtime_impl(ctx):
101106
# If the current version of ruby is correct use that

0 commit comments

Comments
 (0)