Skip to content

Commit

Permalink
Add -d, --dir option to install to <prefix>/<definition> instead of <…
Browse files Browse the repository at this point in the history
…prefix> (#2447)

Similar to ruby-install's -r, --rubies-dir flag.

---------

Co-authored-by: Mislav Marohnić <[email protected]>
  • Loading branch information
eregon and mislav authored Sep 23, 2024
1 parent ed384c8 commit 2d00d40
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
11 changes: 10 additions & 1 deletion bin/ruby-build
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/usr/bin/env bash
#
# Usage: ruby-build [-kpv] <definition> <prefix> [-- <configure-args...>]
# Usage: ruby-build [-dvpk] <definition> <prefix> [-- <configure-args...>]
# ruby-build {--list|--definitions}
# ruby-build --version
#
# -l, --list List latest stable releases for each Ruby
# --definitions List all local definitions, including outdated ones
# --version Show version of ruby-build
#
# -d, --dir Install the Ruby in <prefix>/<definition> instead of <prefix>
# -v, --verbose Verbose mode: forward all build output to stdout/stderr
# -p, --patch Apply a patch from stdin before building
# -k, --keep Do not remove source tree after installation
Expand Down Expand Up @@ -1358,6 +1359,7 @@ unset HAS_PATCH
unset IPV4
unset IPV6
unset EARLY_EXIT
unset APPEND_DEFINITION_TO_PREFIX

RUBY_BUILD_INSTALL_PREFIX="$(abs_dirname "$0")/.."

Expand All @@ -1378,6 +1380,9 @@ for option in "${OPTIONS[@]}"; do
"l" | "list")
EARLY_EXIT=list_maintained_versions
;;
"d" | "dir")
APPEND_DEFINITION_TO_PREFIX=true
;;
"k" | "keep" )
KEEP_BUILD_PATH=true
;;
Expand Down Expand Up @@ -1425,6 +1430,10 @@ if [ "${#EXTRA_ARGUMENTS[@]}" -gt 0 ]; then
RUBY_CONFIGURE_OPTS_ARRAY=("${EXTRA_ARGUMENTS[@]}")
fi

if [ "$APPEND_DEFINITION_TO_PREFIX" = "true" ]; then
PREFIX_PATH="$PREFIX_PATH/$(basename "$DEFINITION_PATH")"
fi

case "$EARLY_EXIT" in
help )
version
Expand Down
21 changes: 18 additions & 3 deletions share/man/man1/ruby-build.1

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

10 changes: 9 additions & 1 deletion share/man/man1/ruby-build.1.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ruby-build - Download, compile, and install a version of Ruby

== Synopsis

ruby-build [-kpv] _<definition>_ _<prefix>_ [-- _<configure-args>_...] +
ruby-build [-dvpk] _<definition>_ _<prefix>_ [-- _<configure-args>_...] +
ruby-build {--list|--definitions} +
ruby-build --version

Expand Down Expand Up @@ -41,6 +41,9 @@ and print everything to standard streams.
*--version*::
Show version of ruby-build

*-d, --dir*::
Install the Ruby in the _prefix/definition_ destination instead of directly in _prefix_

*-v, --verbose*::
Verbose mode: forward all build output to stdout/stderr

Expand All @@ -64,6 +67,11 @@ configuration options:
$ ruby-build 3.2.2 /opt/rubies/ruby-3.2.2 -- --disable-install-doc --with-openssl-dir=/opt/openssl
----

Install Ruby version 3.3.5 under `~/.rbenv/versions`:
----
$ ruby-build --dir 3.3.5 ~/.rbenv/versions
----

Usage as rbenv plugin:
----
$ rbenv install 3.2.2
Expand Down
9 changes: 9 additions & 0 deletions test/build.bats
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,15 @@ make install --globalmake RUBYMAKE=true with spaces
OUT
}

@test "nested install destination" {
export RUBY_BUILD_CACHE_PATH="$FIXTURE_ROOT"

run ruby-build -d "$FIXTURE_ROOT"/definitions/without-checksum "$INSTALL_ROOT"
assert_success
refute [ -d "$INSTALL_ROOT"/bin ]
assert [ -x "$INSTALL_ROOT"/without-checksum/bin/package ]
}

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

Expand Down

0 comments on commit 2d00d40

Please sign in to comment.