Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplified wrapper command, closes #4180
- Loading branch information
Showing
14 changed files
with
55 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,16 @@ | ||
# Wrapper | ||
|
||
Show path to wrapper / to all wrappers and | ||
generate links to wrappers to `$rvm_path/bin` for easier use. | ||
Show/regenrate wrappers. | ||
|
||
Wrappers itself are generated always using <https://github.com/rvm/gem-wrappers>. | ||
NOTE: This command delegates to 'gem wrapper' => <https://github.com/rvm/gem-wrappers> | ||
|
||
## Usage | ||
|
||
rvm wrapper ruby_string show [binary] | ||
rvm wrapper ruby_string [wrapper_prefix|--no-prefix] [binary[ binary[ ...]]] | ||
rvm wrapper show [ruby-version] | ||
rvm wrapper regenrate [ruby-version] | ||
rvm wrapper path executable_name [ruby-version] | ||
rvm wrapper [help] | ||
|
||
where `ruby_string` is the ruby version and gemset combination to provide wrapper links for | ||
(it can also refer to a valid project path or alias), wrapper_prefix is what to prepend to the name | ||
of the generated wrapper, and binary and binaries are the names of the binaries for which you wish | ||
to provide a wrapper (e.g. gem). | ||
|
||
## Default binaries | ||
|
||
When no binaries are provided, rvm will (by default) generate wrapper links for | ||
|
||
ruby, gem, rake, irb, rdoc, ri, testrb | ||
|
||
## Example | ||
|
||
If you wish to provide an environment-specific wrapper links for rspec with a rails3 gemset, | ||
you could do: | ||
|
||
$ rvm --create ree@rails3 | ||
$ rvm wrapper ree@rails3 r3 spec | ||
|
||
Which would add r3_spec with the specified environment to the bin | ||
directory where you installed rvm. | ||
|
||
Alternatively, if you do: | ||
|
||
$ rvm wrapper ruby-1.9.2-head --no-prefix | ||
|
||
It will create links named ruby, gem, rake, irb, rdoc, ri and tesrb | ||
in the rvm bin directory. | ||
|
||
Finally, to show another real and common use, you can use wrapper | ||
to generate ruby executables and gems for passenger to use. Namely: | ||
|
||
$ rvm use ree@rails3 --passenger | ||
|
||
is equivelant to: | ||
|
||
$ rvm use ree@rails3 | ||
$ rvm wrapper ree@rails3 passenger | ||
|
||
Which creates passenger_* binaries in the rvm bin directory using | ||
ree and the rails3 gemset. | ||
Where: | ||
- `ruby-version` is the ruby version and gemset, it can also refer to a valid project path or alias, | ||
- `executable_name` is something like `ruby` or `rake`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,146 +1,36 @@ | ||
#!/usr/bin/env bash | ||
|
||
default_flag="$rvm_default_flag" | ||
|
||
# Prevent recursion | ||
unset rvm_default_flag rvm_wrapper_name prefix | ||
unset rvm_default_flag | ||
|
||
source "$rvm_scripts_path/base" | ||
|
||
# Empty ruby string: show usage and exit. | ||
[[ -n "${1:-}" ]] || | ||
__use_ruby_if_needed() | ||
{ | ||
rvm_help wrapper "$@" | ||
exit 1 | ||
} | ||
|
||
ruby_string="$1" | ||
shift | ||
prefix="${1:-}" | ||
(( $# == 0 )) || shift | ||
|
||
case "${prefix:-}" in | ||
(--no-links) | ||
rvm_error "Used '--no-links' this no operation as wrappers only creates links now." | ||
exit 1 | ||
;; | ||
esac | ||
|
||
if (( $# )) | ||
then binaries=("$@") | ||
else binaries=(ruby gem irb ri rdoc rake erb testrb) | ||
fi | ||
|
||
override_check=0 | ||
(( ${rvm_default_flag:-0} == 0 )) || prefix="default" | ||
|
||
# Use the correct ruby. | ||
__rvm_become "$ruby_string" || { | ||
rvm_error "Could not load ruby $ruby_string." | ||
exit 3 | ||
[[ -z "$1" ]] || __rvm_become "$1" || { | ||
rvm_error "Could not load ruby $1" | ||
exit 2 | ||
} | ||
} | ||
|
||
# strip trailing / so we can use ${...%/*} to get parent | ||
rvm_bin_path="${rvm_bin_path%/}" | ||
rvm_wrappers_path="${rvm_wrappers_path%/}" | ||
if | ||
[[ -d "$rvm_bin_path" && ! -w "$rvm_bin_path" ]] || | ||
[[ ! -d "$rvm_bin_path" && ! -w "${rvm_bin_path%/*}" ]] | ||
then | ||
# can not write currently set location, try to switch relatively to wrappers path | ||
rvm_error "No bin path suitable for linking wrapper. Try setting 'rvm_bin_path'." | ||
exit 4 | ||
fi | ||
[[ -d "$rvm_bin_path" ]] || mkdir -p "$rvm_bin_path" | ||
|
||
environment_identifier="$(__rvm_env_string)" | ||
|
||
case "${prefix:-}" in | ||
case "${1:-}" in | ||
(show) | ||
ls "${rvm_wrappers_path}/${environment_identifier}/"${1:-*} | ||
exit $? | ||
__use_ruby_if_needed "${2:-}" | ||
run_gem_wrappers show | ||
;; | ||
(regenerate) | ||
__use_ruby_if_needed "${2:-}" | ||
run_gem_wrappers regenerate | ||
;; | ||
(path) | ||
__use_ruby_if_needed "${3:-}" | ||
run_gem_wrappers show $2 | ||
;; | ||
(help) | ||
shift | ||
rvm_help wrapper "$@" | ||
;; | ||
("") | ||
rvm_help wrapper "$@" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
__rvm_log_command "gemset.wrappers.$ruby_string" \ | ||
"Regenerating $environment_identifier wrappers" \ | ||
run_gem_wrappers_regenerate 2>/dev/null || true | ||
|
||
__rvm_ensure_has_environment_files | ||
if [[ -d "$rvm_rubies_path/$ruby_string" ]] | ||
then environment_source="$ruby_string" | ||
else environment_source="$environment_identifier" | ||
fi | ||
|
||
find_all_wrappers() | ||
{ | ||
\typeset -a search_paths | ||
\typeset _path | ||
search_paths=() | ||
for _path in \ | ||
"$rvm_gems_path/${environment_identifier}"/bin/ \ | ||
"$rvm_gems_path/${environment_identifier%%@*}@global"/bin/ \ | ||
"$rvm_rubies_path/${environment_identifier%%@*}"/bin/ | ||
do | ||
if [[ -d "${_path}" ]] | ||
then search_paths+=( "${_path}" ) | ||
fi | ||
done | ||
(( ${#search_paths[@]} )) || return 0 | ||
__rvm_find "${search_paths[@]}" -type f -perm -u=x | __rvm_awk -F/ '{print $NF}' | ||
} | ||
|
||
if | ||
[[ " ${binaries[*]} " == *" --all "* ]] | ||
then | ||
old_binaries=( "${binaries[@]}" ) | ||
__rvm_read_lines binaries <( | ||
for binary_name in "${old_binaries[@]}" | ||
do | ||
if | ||
[[ "$binary_name" == "--all" ]] | ||
then | ||
find_all_wrappers "${environment_identifier}" | ||
else | ||
echo "${binary_name}" | ||
fi | ||
done | sort -u | ||
) | ||
fi | ||
|
||
# For each binary, we want to generate the wrapper / symlink | ||
# it to the existing wrapper if needed. | ||
for binary_name in "${binaries[@]}" | ||
do | ||
file_name="$rvm_wrappers_path/${environment_source}/${binary_name##*\/}" | ||
file_name=${file_name// /_} | ||
if | ||
[[ -f "$file_name" || -f "$binary_name" ]] || | ||
__rvm_which "$binary_name" | ||
then | ||
if [[ ! -f "$file_name" && -f "$binary_name" ]] | ||
then gem wrappers "$binary_name" | ||
fi | ||
case "${prefix:-}" in | ||
(--no-prefix) destination="$rvm_bin_path/${binary_name##*\/}" ;; | ||
("") destination="$rvm_bin_path/${binary_name##*\/}-${environment_identifier}" ;; | ||
(*) destination="$rvm_bin_path/${prefix}_${binary_name##*\/}" ;; | ||
esac | ||
else | ||
rvm_warn "Could not find file '$binary_name' nor '$file_name'." | ||
destination="" | ||
fi | ||
if | ||
[[ -n "$destination" ]] | ||
then | ||
destination="${destination// /_}" | ||
destination="${destination//ruby-ruby-/ruby-}" | ||
if | ||
[[ -s "$destination" ]] | ||
then | ||
\command \rm -f "$destination" | ||
fi | ||
ln -sf "$file_name" "$destination" | ||
rvm_verbose_log "Saved wrapper: $destination" | ||
fi | ||
done |