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

Add -d, --dir option to install to <prefix>/<definition> instead of <prefix> #2447

Merged
merged 3 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
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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My nitpick is that maybe this flag should receive a value instead of being a boolean flag.

When I see an invocation like this:

ruby-build 3.2.1 --dir ~/.rubies

it would seem to me like the --dir flag is passed a value of ~/.rubies, but that's not how this is implemented right now. This would likely work: ruby-build --dir 3.2.1 ~/.rubies, and so would this: ruby-build 3.2.1 ~/.rubies --dir, but I do not think these invocations should work because they look "wrong" and I believe that they should error out. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to fit the existing usage ruby-build [-kpv] <definition> <prefix>.
If the prefix becomes optional it feels like opening Pandora's box, so that's why I preferred an option without a value. Also it seems currently ruby-build doesn't have any option taking an argument, and I would like to avoid having to add that.

I think all 3 variants you showed are fine to use.
I used --dir in the example because it works and looks cool, but ruby-build --dir 3.2.1 ~/.rubies is just as fine.

I'm happy to update the PR's description if that helps.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I should update the usage line to ruby-build [-kpvd] and then the documented way to use this is ruby-build -d definition prefix.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the usage line and the PR descriptions to use ruby-build -d.
The fact -d in the middle works is then like an easter egg.

# -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