From 996646a79e344824a481e24f20b6fdac538a90a3 Mon Sep 17 00:00:00 2001 From: Darcy Laycock Date: Sun, 30 May 2010 21:18:09 +0800 Subject: [PATCH 1/2] Update rvm_environment_identifier to respect system and the current state of ruby --- README | 1 + scripts/cli | 2 +- scripts/docs | 35 ++++++++++++++++++++++++++--------- scripts/manage | 9 +++++++++ scripts/utility | 10 ++++++++-- 5 files changed, 45 insertions(+), 12 deletions(-) diff --git a/README b/README index 7d476d59a1..36d1ee501e 100644 --- a/README +++ b/README @@ -15,6 +15,7 @@ Flags --jit - Used with rubinius install to build with JIT --latest - with gemset --dump skips version strings for latest gem. --gems - with uninstall/remove removes gems with the interpreter. + --docs - with install, attempt to generate ri after installation. --reconfigure - Force ./configure on install even if Makefile already exists. diff --git a/scripts/cli b/scripts/cli index cfab49ba4c..4dc6482872 100644 --- a/scripts/cli +++ b/scripts/cli @@ -326,7 +326,7 @@ __rvm_parse_args() { reboot|damnit|wtf|argh|BOOM|boom|wth) $rvm_action="reboot" ;; - --self|--gem|--rubygems|--reconfigure|--default|--debug|--force|--export|--summary|--latest|--yaml|--json|--archive|--shebang|--env|--path|--tail|--delete|--verbose|--import|--rvmrc|--sticky|--create|--rvmrc|--gems) + --self|--gem|--rubygems|--reconfigure|--default|--debug|--force|--export|--summary|--latest|--yaml|--json|--archive|--shebang|--env|--path|--tail|--delete|--verbose|--import|--rvmrc|--sticky|--create|--rvmrc|--gems|--docs) export rvm_$(echo $rvm_token | sed 's#-##g')_flag=1 if [[ "--debug" = "$rvm_token" ]] ; then rvm_debug_flag ; fi ;; diff --git a/scripts/docs b/scripts/docs index f26316eb4e..fe9f5b637f 100755 --- a/scripts/docs +++ b/scripts/docs @@ -5,6 +5,7 @@ if [[ ! -z "$rvm_trace_flag" ]] ; then set -x ; export rvm_trace_flag ; fi trap "if [[ -d $rvm_tmp_path/ ]] && [[ -f $rvm_tmp_path/$$ ]] ; then rm -f $rvm_tmp_path/$$ > /dev/null 2>&1 ; fi ; exit" 0 1 2 3 15 source $rvm_scripts_path/initialize +source $rvm_scripts_path/utility rvm_ruby_string="$(basename $GEM_HOME 2>/dev/null | awk -F'@' '{print $1}')" if [[ -z "$rvm_ruby_string" ]] && echo $GEM_HOME | grep -v 'rvm/' > /dev/null 2>&1 ; then @@ -31,26 +32,42 @@ open_docs() { fi } -generate_docs() { - builtin cd "$rvm_src_path/$rvm_ruby_string/" - rm -rf $rvm_docs_path/$rvm_ruby_string/$rvm_docs_type/ - $rvm_scripts_path/log "info" "Generating documentation, be aware that this could take a *long* time, and depends heavily on your system resources..." +generate_ri() { + # Generate ri docs + __rvm_pushpop "$rvm_src_path/$rvm_ruby_string/" + $rvm_scripts_path/log "info" "Generating ri documentation, be aware that this could take a *long* time, and depends heavily on your system resources..." + $rvm_scripts_path/log "info" "( Errors will be logged to $rvm_log_path/$rvm_ruby_string/docs.error.log )" + rdoc -a --ri --ri-site > /dev/null 2>> $rvm_log_path/$rvm_ruby_string/docs.error.log + __rvm_pushpop +} + +generate_rdoc() { + __rvm_pushpop "$rvm_src_path/$rvm_ruby_string/" + rm -rf "$rvm_docs_path/$rvm_ruby_string/$rvm_docs_type/" + $rvm_scripts_path/log "info" "Generating rdoc documentation, be aware that this could take a *long* time, and depends heavily on your system resources..." $rvm_scripts_path/log "info" "( Errors will be logged to $rvm_log_path/$rvm_ruby_string/docs.error.log )" if gem list | grep ^hanna >/dev/null 2>&1 ; then - hanna -o $rvm_docs_path/$rvm_ruby_string/$rvm_docs_type --inline-source --line-numbers --fmt=html 2>> $rvm_log_path/$rvm_ruby_string/docs.error.log + hanna -o $rvm_docs_path/$rvm_ruby_string/$rvm_docs_type --inline-source --line-numbers --fmt=html > /dev/null 2>> $rvm_log_path/$rvm_ruby_string/docs.error.log else - rdoc -a -o $rvm_docs_path/$rvm_ruby_string/$rvm_docs_type 2>> $rvm_log_path/$rvm_ruby_string/docs.error.log + rdoc -a -o $rvm_docs_path/$rvm_ruby_string/$rvm_docs_type > /dev/null 2>> $rvm_log_path/$rvm_ruby_string/docs.error.log fi - rdoc -a --ri-site 2>> $rvm_log_path/$rvm_ruby_string/docs.error.log + __rvm_pushpop } if [[ "open" = "$action" ]] ; then open_docs elif [[ "generate" = "$action" ]] ; then - generate_docs + generate_rdoc + generate_ri +elif [[ "generate-ri" = "$action" ]]; then + generate_ri +elif [[ "generate-rdoc" = "$action" ]]; then + generate_rdoc else - $rvm_scripts_path/log "error" "" + $rvm_scripts_path/log "error" "No action provided." exit 1 fi +printf "\n" + exit $result diff --git a/scripts/manage b/scripts/manage index 7687653199..2bbe076b3a 100755 --- a/scripts/manage +++ b/scripts/manage @@ -911,6 +911,15 @@ __rvm_post_install() { __rvm_irbrc __rvm_load_gemsets + + __rvm_generate_default_docs +} + +__rvm_generate_default_docs() { + if [[ "$rvm_docs_flag" = "1" && "$rvm_ruby_interpreter" != "macruby" ]]; then + $rvm_scripts_path/log "info" "Attempting to generate ri docs..." + $rvm_scripts_path/docs "generate-ri" + fi } __rvm_load_gemsets() { diff --git a/scripts/utility b/scripts/utility index 7d085147bc..66fc468b96 100644 --- a/scripts/utility +++ b/scripts/utility @@ -115,7 +115,7 @@ __rvm_cleanup_variables() { if [[ "$rvm_sticky_flag" = "1" ]] ; then export rvm_gemset_name ; else unset rvm_gemset_name ; fi - unset rvm_action rvm_irbrc_file rvm_command rvm_error_message rvm_url rvm_force_flag rvm_all_flag rvm_reconfigure_flag rvm_make_flags rvm_bin_flag rvm_import_flag rvm_export_flag rvm_self_flag rvm_gem_flag rvm_rubygems_flag rvm_debug_flag rvm_delete_flag rvm_summary_flag rvm_test_flag _rvm_spec_flag rvm_json_flag rvm_yaml_flag rvm_shebang_flag rvm_env_flag rvm_tail_flag rvm_use_flag rvm_dir_flag rvm_list_flag rvm_empty_flag rvm_file_name rvm_benchmark_flag rvm_clear_flag rvm_name_flag rvm_verbose_flag rvm_user_flag rvm_system_flag rvm_ruby_configure_flags rvm_uninstall_flag rvm_install_flag rvm_llvm_flag rvm_ruby_bits rvm_ruby_patch rvm_sticky_flagrvm_rvmrc_flag rvm_gems_flag rvm_only_path_flag + unset rvm_action rvm_irbrc_file rvm_command rvm_error_message rvm_url rvm_force_flag rvm_all_flag rvm_reconfigure_flag rvm_make_flags rvm_bin_flag rvm_import_flag rvm_export_flag rvm_self_flag rvm_gem_flag rvm_rubygems_flag rvm_debug_flag rvm_delete_flag rvm_summary_flag rvm_test_flag _rvm_spec_flag rvm_json_flag rvm_yaml_flag rvm_shebang_flag rvm_env_flag rvm_tail_flag rvm_use_flag rvm_dir_flag rvm_list_flag rvm_empty_flag rvm_file_name rvm_benchmark_flag rvm_clear_flag rvm_name_flag rvm_verbose_flag rvm_user_flag rvm_system_flag rvm_ruby_configure_flags rvm_uninstall_flag rvm_install_flag rvm_llvm_flag rvm_ruby_bits rvm_ruby_patch rvm_sticky_flagrvm_rvmrc_flag rvm_gems_flag rvm_only_path_flag rvm_docs_flag } # Unset ruby-specific variables @@ -549,7 +549,13 @@ __rvm_mono_env() { } __rvm_environment_identifier() { - echo "$GEM_HOME" | xargs basename + ruby_string="$(command -v ruby)" + if [ -n "$ruby_string" ] && echo "$ruby_string" | grep -q -F "$rvm_rubies_path"; then + echo "$GEM_HOME" | xargs basename + else + echo "system" + fi + unset ruby_string } __rvm_ensure_has_enviroment_files() { From cc7974cc0a04695211632950008449e860d12f5f Mon Sep 17 00:00:00 2001 From: Darcy Laycock Date: Mon, 31 May 2010 22:54:05 +0800 Subject: [PATCH 2/2] Allow users to install docs as a part of the install process --- scripts/cli | 2 +- scripts/docs | 61 ++++++++++++++++++++++++------------------------ scripts/manage | 2 +- scripts/selector | 2 -- scripts/utility | 10 ++++---- 5 files changed, 38 insertions(+), 39 deletions(-) diff --git a/scripts/cli b/scripts/cli index 4dc6482872..82920f5025 100644 --- a/scripts/cli +++ b/scripts/cli @@ -449,7 +449,7 @@ rvm() { fi result=$? ;; - docs) $rvm_scripts_path/docs ; result=$? ;; + docs) $rvm_scripts_path/docs $rvm_ruby_args ; result=$? ;; alias) $rvm_scripts_path/alias $rvm_ruby_args ; result=$? ;; help) $rvm_scripts_path/help $rvm_ruby_args ; result=$? ;; diff --git a/scripts/docs b/scripts/docs index fe9f5b637f..d83a94069b 100755 --- a/scripts/docs +++ b/scripts/docs @@ -7,23 +7,30 @@ trap "if [[ -d $rvm_tmp_path/ ]] && [[ -f $rvm_tmp_path/$$ ]] ; then rm -f $rvm_ source $rvm_scripts_path/initialize source $rvm_scripts_path/utility -rvm_ruby_string="$(basename $GEM_HOME 2>/dev/null | awk -F'@' '{print $1}')" -if [[ -z "$rvm_ruby_string" ]] && echo $GEM_HOME | grep -v 'rvm/' > /dev/null 2>&1 ; then +rvm_docs_ruby_string="$(__rvm_environment_identifier | awk -F"$rvm_gemset_separator" '{print $1}')" +if [[ "$rvm_docs_ruby_string" = "system" || -z "$rvm_docs_ruby_string" ]]; then $rvm_scripts_path/log "error" "Currently 'rvm docs ...' does not work with non-rvm rubies." exit 1 fi rvm_docs_type="${rvm_docs_type:-rdoc}" -action="$(echo $rvm_ruby_args | awk '{print $1}')" -if [[ ! -d "$rvm_docs_path" ]] ; then mkdir -p "$rvm_docs_path/rdoc" "$rvm_docs_path/yard" ; fi +# Ensure we have the doc directories. +if [[ ! -d "$rvm_docs_path" ]] ; then + mkdir -p "$rvm_docs_path/rdoc" "$rvm_docs_path/yard" +fi + +usage() { + printf "Usage: 'rvm docs {open,generate,generate-ri,generate-rdoc}'\n" + exit 1 +} open_docs() { - if [[ -s "$rvm_docs_path/$rvm_ruby_string/$rvm_docs_type/index.html" ]] ; then + if [[ -s "$rvm_docs_path/$rvm_docs_ruby_string/$rvm_docs_type/index.html" ]] ; then if command -v open >/dev/null ; then - open $rvm_docs_path/$rvm_ruby_string/$rvm_docs_type/index.html + open $rvm_docs_path/$rvm_docs_ruby_string/$rvm_docs_type/index.html elif command -v xdg-open >/dev/null ; then - xdg-open $rvm_docs_path/$rvm_ruby_string/$rvm_docs_type/index.html + xdg-open $rvm_docs_path/$rvm_docs_ruby_string/$rvm_docs_type/index.html else $rvm_scripts_path/log "error" "Neither open nor xdg-open were found, in order to open the docs one of these two are required. \n(OR you can let me know how else to open the html in your browser from comand line on your OS :) )" fi @@ -34,40 +41,32 @@ open_docs() { generate_ri() { # Generate ri docs - __rvm_pushpop "$rvm_src_path/$rvm_ruby_string/" + __rvm_pushpop "$rvm_src_path/$rvm_docs_ruby_string/" $rvm_scripts_path/log "info" "Generating ri documentation, be aware that this could take a *long* time, and depends heavily on your system resources..." - $rvm_scripts_path/log "info" "( Errors will be logged to $rvm_log_path/$rvm_ruby_string/docs.error.log )" - rdoc -a --ri --ri-site > /dev/null 2>> $rvm_log_path/$rvm_ruby_string/docs.error.log + $rvm_scripts_path/log "info" "( Errors will be logged to $rvm_log_path/$rvm_docs_ruby_string/docs.error.log )" + rdoc -a --ri --ri-site > /dev/null 2>> $rvm_log_path/$rvm_docs_ruby_string/docs.error.log __rvm_pushpop } generate_rdoc() { - __rvm_pushpop "$rvm_src_path/$rvm_ruby_string/" - rm -rf "$rvm_docs_path/$rvm_ruby_string/$rvm_docs_type/" + __rvm_pushpop "$rvm_src_path/$rvm_docs_ruby_string/" + rm -rf "$rvm_docs_path/$rvm_docs_ruby_string/$rvm_docs_type/" $rvm_scripts_path/log "info" "Generating rdoc documentation, be aware that this could take a *long* time, and depends heavily on your system resources..." - $rvm_scripts_path/log "info" "( Errors will be logged to $rvm_log_path/$rvm_ruby_string/docs.error.log )" - if gem list | grep ^hanna >/dev/null 2>&1 ; then - hanna -o $rvm_docs_path/$rvm_ruby_string/$rvm_docs_type --inline-source --line-numbers --fmt=html > /dev/null 2>> $rvm_log_path/$rvm_ruby_string/docs.error.log + $rvm_scripts_path/log "info" "( Errors will be logged to $rvm_log_path/$rvm_docs_ruby_string/docs.error.log )" + if gem list | grep -q ^hanna ; then + hanna -o $rvm_docs_path/$rvm_docs_ruby_string/$rvm_docs_type --inline-source --line-numbers --fmt=html > /dev/null 2>> $rvm_log_path/$rvm_docs_ruby_string/docs.error.log else - rdoc -a -o $rvm_docs_path/$rvm_ruby_string/$rvm_docs_type > /dev/null 2>> $rvm_log_path/$rvm_ruby_string/docs.error.log + rdoc -a -o $rvm_docs_path/$rvm_docs_ruby_string/$rvm_docs_type > /dev/null 2>> $rvm_log_path/$rvm_docs_ruby_string/docs.error.log fi __rvm_pushpop } -if [[ "open" = "$action" ]] ; then - open_docs -elif [[ "generate" = "$action" ]] ; then - generate_rdoc - generate_ri -elif [[ "generate-ri" = "$action" ]]; then - generate_ri -elif [[ "generate-rdoc" = "$action" ]]; then - generate_rdoc -else - $rvm_scripts_path/log "error" "No action provided." - exit 1 -fi - -printf "\n" +case "$1" in + open) open_docs ;; + generate) generate_ri; generate_rdoc ;; + generate-ri) generate_ri ;; + generate-rdoc) generate_rdoc ;; + *) usage ;; +esac exit $result diff --git a/scripts/manage b/scripts/manage index 2bbe076b3a..86038cec9c 100755 --- a/scripts/manage +++ b/scripts/manage @@ -918,7 +918,7 @@ __rvm_post_install() { __rvm_generate_default_docs() { if [[ "$rvm_docs_flag" = "1" && "$rvm_ruby_interpreter" != "macruby" ]]; then $rvm_scripts_path/log "info" "Attempting to generate ri docs..." - $rvm_scripts_path/docs "generate-ri" + (source $rvm_scripts_path/rvm; rvm use "$rvm_ruby_string"; rvm docs generate-ri) > ~/rvm-install-docs 2>&1 fi } diff --git a/scripts/selector b/scripts/selector index ba144c116b..31a437abbb 100755 --- a/scripts/selector +++ b/scripts/selector @@ -255,7 +255,6 @@ __rvm_use() { if [[ ! -z "$rvm_verbose_flag" ]] ; then $rvm_scripts_path/log "info" "Now using system ruby." - printf "\n" fi export rvm_ruby_string="system" @@ -287,7 +286,6 @@ __rvm_use() { if [[ ! -z "$rvm_verbose_flag" ]] ; then $rvm_scripts_path/log "info" "Using $(basename $GEM_HOME | tr '-' ' ' | sed 's/'${rvm_gemset_separator}'/ with gemset /')" - printf "\n" fi new_path="$(echo $PATH | tr ':' '\n' | awk '$0 !~ /rvm/' | paste -sd : -)" diff --git a/scripts/utility b/scripts/utility index 66fc468b96..795038f97d 100644 --- a/scripts/utility +++ b/scripts/utility @@ -356,10 +356,12 @@ __rvm_pushpop() { # Meant for use before and after an operation that might reset the currently selected ruby. __rvm_state() { if [[ -z "$rvm_state" ]] ; then - if [[ -z "$(command -v ruby | awk /$(basename $rvm_rubies_path)/)" ]] ; then - rvm_state=system - else - rvm_state="$(dirname "$(command -v ruby)" | xargs dirname | xargs basename)" + rvm_state="$(__rvm_environment_identifier)" + rvm_state="${rvm_state:-"system"}" + if [[ -n "$1" ]]; then + rvm_ruby_string="$1" + __rvm_select + __rvm_use fi else rvm_ruby_string="$rvm_state"