scripts/rvm-utility in rvm-0.0.42 vs scripts/rvm-utility in rvm-0.0.43

- old
+ new

@@ -173,26 +173,26 @@ rvm_system_ps1=$PS1 __rvm_db "system_ps1" "$rvm_system_ps1" fi rvm_system_ruby=`__rvm_db "system_ruby"` - if [ -z "$rvm_system_ruby" ] ; then + if [ ! -z "$rvm_system_ruby" ] ; then rvm_system_ruby=`which ruby` if [ $? -ne 0 ] ; then __rvm_log "info" "System ruby not found, no db will be stored." else __rvm_db "system_ruby" "$rvm_system_ruby" # Now store system system & user gem paths rvm_system_user_gem_path=`__rvm_db "system_user_gem_path"` if [ -z "$rvm_system_user_gem_path" ] ; then - rvm_system_user_gem_path=`ruby -r rubygems -e "puts Gem::default_path.compact.first"` + rvm_system_user_gem_path=$( rvm system ; gem env gemdir user; ) __rvm_db "system_user_gem_path" "$rvm_system_user_gem_path" fi rvm_system_gem_path=`__rvm_db "system_gem_path"` if [ -z "$rvm_system_gem_path" ] ; then - rvm_system_gem_path=`ruby -r rubygems -e "puts Gem::default_path.compact[1] || Gem::default_path.compact.first"` + rvm_system_gem_path=$( rvm system ; gem env gemdir; ) __rvm_db "system_gem_path" "$rvm_system_gem_path" fi fi fi @@ -210,10 +210,12 @@ for system_config in system_ps1 system_path system_ruby system_gem_path system_user_gem_path ; do __rvm_db "$system_config" "delete" done ; unset system_config variable + rm -f $rvm_path/bin/ruby $rvm_path/bin/gem $rvm_path/bin/rake $rvm_path/bin/irb $rvm_path/bin/default* + } function __rvm_implode { while : ; do __rvm_log "warn" "Are you SURE you wish for rvm to implode? This will remove $rvm_path ? (type 'yes' or 'no')" @@ -256,17 +258,21 @@ } # clones from source implementation/version to default function __rvm_gem-dup { - - if [ "$1" = "default" ] ; then + __rvm_log "debug" "$rvm_ruby_interpreter" + if [ "$rvm_ruby_interpreter" = "default" ] ; then + # TODO: ~/.rvm/default first, then system user rvm_source_gem_dir="$rvm_system_user_gem_path" - elif [ "$1" = "system" ] ; then + elif [ "$rvm_ruby_interpreter" = "user" ] ; then + rvm_source_gem_dir="$rvm_system_user_gem_path" + elif [ "$rvm_ruby_interpreter" = "system" ] ; then rvm_source_gem_dir="$rvm_system_gem_path" else - rvm_source_gem_dir=${1:-$rvm_system_user_gem_path} # TODO: check for and remove trailing /gems + # TODO: use selector for this? + rvm_source_gem_dir=${rvm_gem_home/$rvm_ruby_interpreter/$rvm_ruby_version} fi if [ ! -z "$rvm_source_gem_dir" ] ; then for rvm_gem_name_version in `/bin/ls $rvm_source_gem_dir/gems` ; do rvm_gem_name=${rvm_gem_name_version%-*} @@ -279,11 +285,10 @@ done unset rvm_gem_name_version rvm_gem_name rvm_gem_version else __rvm_log "fail" "Unknown $rvm_ruby_interpreter version: $rvm_ruby_version" fi - } function __rvm_db { rvm_hash_file="$rvm_config_path/db" touch $rvm_hash_file @@ -528,21 +533,21 @@ if [ $result -eq 0 ]; then eval "successes=(${successes[*]} $rvm_ruby_string)" else eval "errors=(${errors[*]} $rvm_ruby_string)" fi - eval "all=(${all[*]} $rvm_ruby_string)" - eval "results=(${results[*]} $result)" + eval "rubies=(${rubies[*]} $rvm_ruby_string)" + eval "statuses=(${statuses[*]} $result)" # TODO: keep track of and re-set the previous selected ruby ;) else __rvm_log "warn" "'$rvm_ruby_home/bin/$binary' either does not exist or is not executable? :(" fi unset rvm_ruby_interpreter rvm_ruby_version rvm_ruby_repo_url rvm_ruby_package_name rvm_ruby_patch_level rvm_ruby_configure rvm_ruby_make rvm_ruby_make_install rvm_ruby_rev rvm_ruby_tag rvm_major_version rvm_minor_version rvm_gem_set_name rvm_gem_home rvm_ruby_binary rvm_ruby_package_name rvm_ruby_home rvm_ruby_log_path rvm_ruby_src_path rvm_ruby_irbrc rvm_selected } function __rvm_do { - all=() ; successes=() ; errors=() ; results=() + rubies=() ; successes=() ; errors=() ; statuses=() # TODO: Extract the common functionality out of the if below if [ ! -z "$rvm_ruby_version" ] ; then for rvm_ruby_selector in `echo $rvm_ruby_version | tr ',' ' '` ; do temp=$(echo $rvm_ruby_selector | awk '{print substr($1, 0, 1)}') if [ ! -z "$(echo $temp | grep '[0-9]')" ] ; then @@ -564,20 +569,79 @@ fi done < <(/bin/ls $rvm_path/*/bin/ruby 2> /dev/null) fi if [ ! -z "$rvm_summary_flag" ] ; then - export successes errors results + export successes errors statuses echo -e "\nSummary:" echo -e "\033[0;32msuccessful (${#successes[*]}) : [ $(echo "${successes[*]}" | sed 's/ /, /g') ]\033[0m" echo -e "\033[0;31merrors (${#errors[*]}) : [ $(echo "${errors[*]}" | sed 's/ /, /g') ]\033[0m" - echo -e "all (${#all[*]}) : [ $(echo "${all[*]}" | sed 's/ /, /g') ]" - echo -e "exit results: [ $(echo "${results[*]}" | sed 's/ /, /g') ]\n" + echo -e "rubies (${#rubies[*]}) : [ $(echo "${rubies[*]}" | sed 's/ /, /g') ]" + echo -e "statuses: [ $(echo "${statuses[*]}" | sed 's/ /, /g') ]\n" + fi + + if [ ! -z "$rvm_yaml_flag" ] ; then + export successes errors statuses + echo -e "\nYAML:" + echo -e " totals:" + echo -e " rubies: ${#rubies[*]}" + echo -e " successes: ${#successes[*]}" + echo -e " errors: ${#errors[*]}" + echo -e " successes:" + for var in ${successes[*]} ; do + echo -e " - $var" + done + echo -e " errors:" + for var in ${errors[*]} ; do + echo -e " - $var" + done + echo -e " rubies:" + for var in ${rubies[*]} ; do + echo -e " - $var" + done + echo -e " statuses:" + for var in ${statuses[*]} ; do + echo -e " - $var" + done + fi + + if [ ! -z "$rvm_json_flag" ] ; then + summary=$(cat <<-Summary + \nSummary: + JSON: + { + "totals": { "rubies": ${#rubies[*]}, "successes": ${#successes[*]}, "errors": ${#errors[*]}}, + "successful": [ "$(echo ${successes[*]} | sed 's/ /", "/g')" ], + "errors": [ "$(echo ${errors[*]} | sed 's/ /", "/g')" ], + "rubies": [ "$(echo ${rubies[*]} | sed 's/ /", "/g')" ], + "statuses": [ $(echo ${statuses[*]} | sed 's/ /, /g') ] + } +Summary +) + echo -e "$summary" else - unset bin_line rvm_summary_flag - # successes errors + unset bin_line rvm_summary_flag fi return ${#errors[*]} +} + +function __rvm_benchmark { +rvm_code="$(cat <<RubyCode +#!/usr/bin/env ruby +require "benchmark" +Benchmark.bmbm do|benchmark| + benchmark.report("benchmarking '$rvm_ruby_file'") do + +RubyCode +)" +echo "$rvm_code" > /tmp/$$.rb +cat $rvm_ruby_file >> /tmp/$$.rb +echo -e "\n end\nend\n" >> /tmp/$$.rb +unset rvm_code +rvm_ruby_args="/tmp/$$.rb" +rvm_action="rubydo" +if [ ! -z "$rvm_debug_flag" ] ; then echo -e "/tmp/$$.rb:\n$(cat /tmp/$$.rb)" ; fi +__rvm_do } function __rvm_ruby_string { if [ "$rvm_ruby_interpreter" = "system" ] ; then rvm_ruby_string="system"