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

Support ruby-build ruby-X.Y.Z DIR #2448

Merged
merged 6 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions bin/ruby-build
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 18 additions & 6 deletions share/man/man1/ruby-build.1

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 13 additions & 6 deletions share/man/man1/ruby-build.1.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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 /path/to/destination -- --disable-install-doc --with-openssl-dir=/opt/openssl
----

Install a Ruby version to `~/.rubies/ruby-3.2.2`:
----
$ ruby-build 3.2.2 /opt/rubies/ruby-3.2.2 -- --disable-install-doc --with-openssl-dir=/opt/openssl
$ ruby-build --dir ruby-3.2.2 ~/.rubies
----

Install Ruby version 3.3.5 under `~/.rbenv/versions`:
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
Expand Down
37 changes: 37 additions & 0 deletions test/build.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<DEF
install_package "ruby-3.2.0" "http://ruby-lang.org/ruby/2.0/ruby-3.2.0.tar.gz"
DEF

RUBY_BUILD_DEFINITIONS="$TMP"/definitions run ruby-build --dir ruby-3.2.0 "$INSTALL_ROOT"
assert_success

unstub brew
unstub make

assert_build_log <<OUT
ruby-3.2.0: [--prefix=$INSTALL_ROOT/ruby-3.2.0,--with-ext=openssl,psych,+]
make -j 2
make install
OUT
}

@test "definition file with ruby prefix" {
export RUBY_BUILD_CACHE_PATH="$FIXTURE_ROOT"

cd "$TMP"
cat > ruby-123-internal <<DEF
install_package "package-1.0.0" "http://example.com/packages/package-1.0.0.tar.gz" copy
DEF

run ruby-build ruby-123-internal "$INSTALL_ROOT"
assert_success
assert [ -x "$INSTALL_ROOT"/bin/package ]
}

@test "custom relative install destination" {
export RUBY_BUILD_CACHE_PATH="$FIXTURE_ROOT"

Expand Down