Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"ruby" matches "truffleruby" #447

Closed
esotericpig opened this issue Oct 2, 2020 · 4 comments
Closed

"ruby" matches "truffleruby" #447

esotericpig opened this issue Oct 2, 2020 · 4 comments

Comments

@esotericpig
Copy link

With TruffleRuby installed, if you do chruby ruby, you'll get this:

   jruby-9.2.13.0
   jruby-9.2.9.0
   ruby-2.6.5
   ruby-2.7.0
   ruby-2.7.1
 * truffleruby-20.2.0

Which isn't expected I think. I expected to get ruby-2.7.1.

In chruby() in chruby.sh, I think it'd be good to add this line to match ruby first:

case "$ruby" in
	"$1")	match="$dir" && break ;;
	"$1"*)	match="$dir" && break ;; # NEW CODE
	*"$1"*)	match="$dir" ;;
esac

Is this fine? If so, I can make a pull request, or if someone can add this, that'd be awesome.

esotericpig added a commit to esotericpig/chruby that referenced this issue Oct 7, 2020
@havenwood
Copy link
Collaborator

@esotericpig Yes, looks right to me. I think with the current matching, adding the line you propose is a good solution.

@esotericpig
Copy link
Author

I thought that it would be an easy fix, but actually, it will require parsing the version numbers like issue #445.

In fact, these 2 issues could be merged into 1 (close this one or that one).

I'll leave it open for now for one of the maintainers to decide.

@eregon
Copy link
Contributor

eregon commented Dec 11, 2020

Note: the rubies that chruby see could be any valid directory name, so it might be e.g. foo-bar, so there isn't always a version.
I'm not sure what's a good way to fix this.

FWIW in ruby/setup-ruby, we can reliably split ruby implementation and version, so then it's much easier to match e.g. ruby or 2.1 correctly.

@esotericpig
Copy link
Author

Note: the rubies that chruby see could be any valid directory name, so it might be e.g. foo-bar, so there isn't always a version.
I'm not sure what's a good way to fix this.

FWIW in ruby/setup-ruby, we can reliably split ruby implementation and version, so then it's much easier to match e.g. ruby or 2.1 correctly.

Well, in Ruby, it isn't so bad with regexes, but don't know how you can do it in Bash while keeping compatibility in mind for Zsh and all environments.

# Copied from https://semver.org
SEM_VER_REGEX = /(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)(?:-(?<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?\s*\z/

sem_ver = SEM_VER_REGEX.match(some_string)

if !sem_ver.nil?
  sem_ver = sem_ver.named_captures
  
  sem_ver[:major] = sem_ver[:major].to_i
  sem_ver[:minor] = sem_ver[:minor].to_i
  sem_ver[:patch] = sem_ver[:patch].to_i
end

# Can test if sem_ver is nil, so this would account for "foo-bar" (without a semantic version).
# If not nil, can test the major, minor, patch integers.

All I would like, in its simplest form, is that chruby ruby would grab the latest ruby, but it grabs truffleruby on my system.

However, it's probably too complicated in Bash, and I doubt anyone wants to write that code lol.

@esotericpig esotericpig closed this as not planned Won't fix, can't repro, duplicate, stale Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants