diff --git a/README.md b/README.md index c325bb38..e36c7443 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ PREFIX=/usr/local ./ruby-build-*/install.sh # As a standalone program $ ruby-build --list # lists available versions of Ruby $ ruby-build 3.2.2 /opt/rubies/ruby-3.2.2 # installs Ruby 3.2.2 +$ ruby-build -d ruby-3.2.2 /opt/rubies # alternate form for the previous example # As an rbenv plugin $ rbenv install 3.2.2 # installs Ruby 3.2.2 to ~/.rbenv/versions/3.2.2 diff --git a/bin/ruby-build b/bin/ruby-build index a3770eaf..8db3456a 100755 --- a/bin/ruby-build +++ b/bin/ruby-build @@ -1465,6 +1465,17 @@ if [ ! -f "$DEFINITION_PATH" ]; then fi done + # If the given definition is like ruby-X.Y.Z, search again with X.Y.Z + if [[ "$DEFINITION_PATH" =~ ^ruby-[0-9] ]]; then + DEFINITION_PATH="${DEFINITION_PATH#ruby-}" + for DEFINITION_DIR in "${RUBY_BUILD_DEFINITIONS[@]}"; do + if [ -f "${DEFINITION_DIR}/${DEFINITION_PATH}" ]; then + DEFINITION_PATH="${DEFINITION_DIR}/${DEFINITION_PATH}" + break + fi + done + fi + if [ ! -f "$DEFINITION_PATH" ]; then echo "ruby-build: definition not found: ${DEFINITION_PATH}" >&2 exit 2 diff --git a/share/man/man1/ruby-build.1 b/share/man/man1/ruby-build.1 index 20058c5f..22bf27ad 100644 --- a/share/man/man1/ruby-build.1 +++ b/share/man/man1/ruby-build.1 @@ -41,6 +41,9 @@ ruby\-build \-\-version ruby\-build downloads, compiles, and installs a Ruby version named by the \fIdefinition\fP argument into the location specified by \fIprefix\fP. .sp +The \fIdefinition\fP argument can optionally start with "ruby\-", in which case +it resolves to a CRuby that matches the version number that follows. +.sp The \fIdefinition\fP argument can be a path to a file on disk, in which case it is sourced into ruby\-build as a bash script. .sp @@ -98,18 +101,27 @@ Resolve names to IPv6 addresses only .RE .SH "EXAMPLES" .sp -Install Ruby version 3.2.2 under \f(CR/opt/rubies\fP while tweaking some -configuration options: +Install a Ruby version while tweaking some configuration options: .sp .if n .RS 4 .nf .fam C -$ ruby\-build 3.2.2 /opt/rubies/ruby\-3.2.2 \-\- \-\-disable\-install\-doc \-\-with\-openssl\-dir=/opt/openssl +$ ruby\-build 3.2.2 /path/to/destination \-\- \-\-disable\-install\-doc \-\-with\-openssl\-dir=/opt/openssl .fam .fi .if n .RE .sp -Install Ruby version 3.3.5 under \f(CR~/.rbenv/versions\fP: +Install a Ruby version to \f(CR~/.rubies/ruby\-3.2.2\fP: +.sp +.if n .RS 4 +.nf +.fam C +$ ruby\-build \-\-dir ruby\-3.2.2 ~/.rubies +.fam +.fi +.if n .RE +.sp +Install a Ruby version to \f(CR~/.rbenv/versions/3.3.5\fP: .sp .if n .RS 4 .nf @@ -119,12 +131,12 @@ $ ruby\-build \-\-dir 3.3.5 ~/.rbenv/versions .fi .if n .RE .sp -Usage as rbenv plugin: +Usage as rbenv plugin, accomplishes the same as the previous example: .sp .if n .RS 4 .nf .fam C -$ rbenv install 3.2.2 +$ rbenv install 3.3.5 .fam .fi .if n .RE diff --git a/share/man/man1/ruby-build.1.adoc b/share/man/man1/ruby-build.1.adoc index f6cd1ece..b579296e 100644 --- a/share/man/man1/ruby-build.1.adoc +++ b/share/man/man1/ruby-build.1.adoc @@ -20,6 +20,9 @@ ruby-build --version ruby-build downloads, compiles, and installs a Ruby version named by the _definition_ argument into the location specified by _prefix_. +The _definition_ argument can optionally start with "ruby-", in which case +it resolves to a CRuby that matches the version number that follows. + The _definition_ argument can be a path to a file on disk, in which case it is sourced into ruby-build as a bash script. @@ -61,20 +64,24 @@ and print everything to standard streams. == Examples -Install Ruby version 3.2.2 under `/opt/rubies` while tweaking some -configuration options: +Install a Ruby version while tweaking some configuration options: ---- -$ ruby-build 3.2.2 /opt/rubies/ruby-3.2.2 -- --disable-install-doc --with-openssl-dir=/opt/openssl +$ ruby-build 3.2.2 /path/to/destination -- --disable-install-doc --with-openssl-dir=/opt/openssl ---- -Install Ruby version 3.3.5 under `~/.rbenv/versions`: +Install a Ruby version to `~/.rubies/ruby-3.2.2`: +---- +$ ruby-build --dir ruby-3.2.2 ~/.rubies +---- + +Install a Ruby version to `~/.rbenv/versions/3.3.5`: ---- $ ruby-build --dir 3.3.5 ~/.rbenv/versions ---- -Usage as rbenv plugin: +Usage as rbenv plugin, accomplishes the same as the previous example: ---- -$ rbenv install 3.2.2 +$ rbenv install 3.3.5 ---- == Environment Variables diff --git a/test/build.bats b/test/build.bats index 0ac24633..bae3e23c 100755 --- a/test/build.bats +++ b/test/build.bats @@ -629,6 +629,43 @@ OUT assert [ -x "$INSTALL_ROOT"/without-checksum/bin/package ] } +@test "nested install destination with ruby prefix" { + cached_tarball "ruby-3.2.0" configure + + stub_repeated brew false + stub_make_install + + mkdir -p "$TMP"/definitions + cat > "$TMP"/definitions/3.2.0 < ruby-123-internal <