Skip to content

Commit e275d94

Browse files
authored
Merge pull request #56 from bazelruby/kig/fix-ruby-version-detection
Fixing brittle Host Ruby version detection.
2 parents ad27aff + a273a8d commit e275d94

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)