Permalink
Browse files

reworked gemset initialization to support rvm_with_default_gems, fix #…

  • Loading branch information...
1 parent 07297ae commit d80282de1f2b2b1ff51740e05d9f5d84ebf3209f @mpapis mpapis committed Dec 31, 2013
View
@@ -581,16 +581,14 @@ rvm_install_parse_params()
forwarded_flags+=( "$token" )
;;
- (--with-gems=*)
+ (--without-gems=*|--with-gems=*|--with-default-gems=*)
flags+=( "$token" )
- export rvm_with_gems="${token#--with-gems=}"
- printf "%b" "Installing RVM with gems: ${rvm_with_gems}.\n"
- ;;
-
- (--without-gems=*)
- flags+=( "$token" )
- export rvm_without_gems="${token#--without-gems=}"
- printf "%b" "Installing RVM without gems: ${rvm_without_gems}.\n"
+ value="${token#*=}"
+ token="${token%%=*}"
+ token="${token#--}"
+ token="${token//-/_}"
+ export "rvm_${token}"="${value}"
+ printf "%b" "Installing RVM ${token/_/ }: ${value}.\n"
;;
(--version|version)
View
@@ -0,0 +1 @@
+It is important to keep `default.gems` and `global.gems` even empty to triger automatic addition of gems to this files.
View
No changes.
@@ -165,7 +165,8 @@ __variables_definition()
rvm_error_message rvm_gemset_name rvm_parse_break rvm_token rvm_action rvm_export_args
rvm_gemset_separator rvm_expanding_aliases rvm_tar_command rvm_tar_options
rvm_patch_original_pwd rvm_project_rvmrc rvm_archive_extension rvm_autoinstall_bundler_flag
- rvm_codesign_identity rvm_expected_gemset_name rvm_with_gems rvm_without_gems
+ rvm_codesign_identity rvm_expected_gemset_name
+ rvm_without_gems rvm_with_gems rvm_with_default_gems
rvm_ignore_dotfiles_flag rvm_latest_binary_flag rvm_fuzzy_flag rvm_autolibs_flag
rvm_autolibs_flag_number rvm_autolibs_flag_runner rvm_quiet_curl_flag rvm_max_time_flag
rvm_error_clr rvm_warn_clr rvm_debug_clr rvm_notify_clr rvm_reset_clr
View
@@ -179,21 +179,73 @@ gem_install_force()
return $?
}
+__rvm_lines_without_comments()
+{
+ __rvm_remove_from_array lines "#*|+([[:space:]])" "${lines[@]}"
+}
+
+__rvm_lines_without_gems()
+{
+ [[ -n "${rvm_without_gems}" ]] || return 0
+
+ typeset -a __gems_to_remove
+ __gems_to_remove=()
+ __rvm_custom_separated_array __gems_to_remove " " "${rvm_without_gems}"
+
+ (( ${#__gems_to_remove[@]} )) || return 0
+
+ typeset __gem
+ for __gem in "${__gems_to_remove[@]}"
+ do __rvm_remove_from_array lines "${__gem% *} *" "${lines[@]}"
+ done
+}
+
+__rvm_lines_with_gems()
+{
+ typeset -a __gems_to_add
+ __gems_to_add=()
+ case "${1}" in
+ (global) __rvm_custom_separated_array __gems_to_add " " "${rvm_with_gems:-}" ;;
+ (default) __rvm_custom_separated_array __gems_to_add " " "${rvm_with_default_gems:-}" ;;
+ (*) return 0 ;;
+ esac
+
+ (( ${#__gems_to_add[@]} )) || return 0
+
+ typeset __gem __version
+ for __gem in "${__gems_to_add[@]}"
+ do
+ __version="${__gem#*=}"
+ __gem="${__gem%%=*}"
+ if [[ "${__gem}" == "${__version}" ]] # no version given
+ then lines+=( "${__gem}" )
+ else lines+=( "${__gem} -v ${__version}" )
+ fi
+ done
+}
+
+gemset_import_list()
+{
+ typeset line
+ for line
+ do gem_install $line || rvm_error "there was an error installing gem $line"
+ done
+}
+
gemset_import()
{
- typeset rvm_file_name
+ typeset __prefix rvm_file_name
typeset -a gem_file_names
unset -f gem
__rvm_select
- gem_file_names=(
- "${1%.gems*}.gems"
- "${rvm_gemset_name}.gems"
- "default.gems"
- "system.gems"
- ".gems"
- )
+ __prefix="$1"
+
+ if [[ -n "${2:-}" ]]
+ then gem_file_names=( "${2%.gems*}.gems" )
+ else gem_file_names=( "${rvm_gemset_name}.gems" "default.gems" "system.gems" ".gems" )
+ fi
__rvm_find_first_file rvm_file_name "${gem_file_names[@]}" ||
{
rvm_error "No *.gems file found."
@@ -202,24 +254,32 @@ gemset_import()
[[ -d "$rvm_ruby_gem_home/specifications/" ]] || mkdir -p "$rvm_ruby_gem_home/specifications/"
[[ -d "$rvm_gems_cache_path" ]] || mkdir -p "$rvm_gems_cache_path" # Ensure the base cache dir is initialized.
+
+ typeset -a lines
+ lines=()
if
[[ -s "$rvm_file_name" ]]
then
- rvm_log "\nInstalling gems listed in $rvm_file_name file...\n"
- typeset -a lines
__rvm_read_lines lines "${rvm_file_name}"
+ __rvm_lines_without_comments
+ fi
+ rvm_debug "lines from ${rvm_file_name}: ${lines[*]}"
+ if
+ [[ -n "${3:-}" ]]
+ then
+ __rvm_lines_without_gems
+ __rvm_lines_with_gems "${3}"
+ rvm_debug "recalculated lines($3): ${lines[*]}"
+ fi
- for line in "${lines[@]}"
- do
- # Parse the lines, throwing out comments and empty lines.
- if [[ ! "${line}" =~ ^# && -n "${line// /}" ]]
- then gem_install $line || rvm_error "there was an error installing gem $line"
- fi
- done
- rvm_log "\nProcessing of $rvm_file_name is complete.\n"
+ if
+ (( ${#lines[@]} ))
+ then
+ __rvm_log_command "gemsets.import${3:+.}${3:-}" \
+ "${__prefix}installing gems listed in $rvm_file_name file" \
+ gemset_import_list "${lines[@]}"
else
- rvm_error "${rvm_file_name} does not exist to import from."
- return 1
+ rvm_log "${__prefix}file $rvm_file_name evaluated to empty gem list"
fi
}
@@ -242,18 +302,10 @@ gemset_initial()
if
[[ -f "${_iterator}/$1.gems" ]]
then
- if
- [[ -s "${_iterator}/$1.gems" ]]
- then
- __rvm_log_command "gemsets.initial.$1" \
- "$rvm_ruby_string - #importing gemset ${_iterator}/$1.gems" \
- gemset_import "${_iterator}/$1.gems"
- else
- rvm_warn "$rvm_ruby_string - #empty gemset defintion ${_iterator}/$1.gems"
- fi
+ gemset_import "$rvm_ruby_string - #" "${_iterator}/$1.gems" "$1"
break # stop right here
else
- rvm_debug "gemset definition does not exist ${_iterator}/$1.gems"
+ rvm_debug "$rvm_ruby_string - #gemset definition does not exist ${_iterator}/$1.gems"
fi
done
__rvm_log_command "gemset.wrappers.$1" \
@@ -145,11 +145,12 @@ parse_args()
(--autolibs=*)
export rvm_autolibs_flag="${token#--autolibs=}"
;;
- (--with-gems=*)
- export rvm_with_gems="${token#--with-gems=}"
- ;;
- (--without-gems=*)
- export rvm_without_gems="${token#--without-gems=}"
+ (--without-gems=*|--with-gems=*|--with-default-gems=*)
+ value="${token#*=}"
+ token="${token%%=*}"
+ token="${token#--}"
+ token="${token//-/_}"
+ export "rvm_${token}"="${value}"
;;
(--path)
export rvm_path="$1"
@@ -533,6 +534,22 @@ install_binaries()
return 0
}
+update_gemsets_rvmrc()
+{
+ if
+ [[ -n "$2" ]]
+ then
+ if [[ -f ~/.rvmrc ]] && __rvm_grep "^$1=" ~/.rvmrc >/dev/null
+ then __rvm_sed_i ~/.rvmrc -e "s/^$1=.*$/$1=\"$2\"/"
+ else printf "%b" "\n$1=\"$2\"\n" >> ~/.rvmrc
+ fi
+ else
+ if [[ -f ~/.rvmrc ]]
+ then __rvm_sed_i ~/.rvmrc -e "/^$1=/ d"
+ fi
+ fi
+}
+
install_gemsets()
{
typeset gemset_files
@@ -546,9 +563,10 @@ install_gemsets()
then
[[ -d "$rvm_path/gemsets" ]] || mkdir -p "$rvm_path/gemsets"
- gemset_files=($(
- __rvm_find "${PWD%%+(\/)}/gemsets" "${name_opt}" '*.gems' | __rvm_sed 's/^\.\///'
- ))
+ __rvm_read_lines gemset_files <(
+ __rvm_find "${PWD%%+(\/)}/gemsets" "${name_opt}" '*.gems' |
+ __rvm_sed 's/^\.\///'
+ )
for gemset_file in "${gemset_files[@]}"
do
@@ -559,47 +577,14 @@ install_gemsets()
then
destination_path="${destination%/*}"
[[ -d "$destination_path" ]] || mkdir -p "$destination_path"
- if
- [[ -n "${rvm_without_gems:-}" ]]
- then
- if [[ "${_system_type}" = "Darwin" ]]
- then __rvm_sed -E '/^('"${rvm_without_gems// /|}"')/ d' < "$gemset_file" > "$destination"
- else __rvm_sed -r '/^('"${rvm_without_gems// /|}"')/ d' < "$gemset_file" > "$destination"
- fi
- else
- \cat < "$gemset_file" > "$destination"
- fi
- if
- [[ -n "${rvm_with_gems:-}" && "${destination##*/}" == "global.gems" ]]
- then
- printf "%b" "${rvm_with_gems// /\n}\n" >> "$destination"
- fi
+ \cat < "$gemset_file" > "$destination"
fi
done
fi
- if
- [[ -n "${rvm_with_gems:-}" ]]
- then
- if
- __rvm_grep "rvm_with_gems=" ~/.rvmrc >/dev/null
- then
- __rvm_sed_i ~/.rvmrc -e 's/^rvm_with_gems=.*$/rvm_with_gems="'"${rvm_with_gems}"'"/'
- else
- printf "%b" "\nrvm_with_gems=\"${rvm_with_gems}\"\n" >> ~/.rvmrc
- fi
- fi
- if
- [[ -n "${rvm_without_gems:-}" ]]
- then
- if
- __rvm_grep "rvm_without_gems=" ~/.rvmrc >/dev/null
- then
- __rvm_sed_i ~/.rvmrc -e 's/^rvm_without_gems=.*$/rvm_without_gems="'"${rvm_without_gems}"'"/'
- else
- printf "%b" "\nrvm_without_gems=\"${rvm_without_gems}\"\n" >> ~/.rvmrc
- fi
- fi
+ update_gemsets_rvmrc rvm_without_gems "${rvm_without_gems}"
+ update_gemsets_rvmrc rvm_with_gems "${rvm_with_gems}"
+ update_gemsets_rvmrc rvm_with_default_gems "${rvm_with_default_gems}"
}
install_patchsets()
@@ -1271,7 +1256,7 @@ update_gemsets_install_rvm()
for _gem in rvm gem-wrappers
do
- [[ " ${rvm_without_gems:-} " =~ " ${_gem} " ]] ||
+ [[ " ${rvm_without_gems:-} " == *" ${_gem} "* ]] ||
{
for _iterator in "${paths[@]}"
do
View
@@ -644,16 +644,13 @@ case "$action" in
if
[[ -z "${rvm_ruby_strings:-""}" ]]
then
- gemset_import "$@"
+ gemset_import "" "$1"
else
rubies=()
__rvm_custom_separated_array rubies , "$rvm_ruby_strings"
for rvm_ruby_string in "${rubies[@]}"
do
- (
- __rvm_become
- gemset_import "$@"
- )
+ __rvm_with "$rvm_ruby_string" gemset_import "" "$1"
done
fi
;;

0 comments on commit d80282d

Please sign in to comment.