Skip to content

Commit

Permalink
make __rvm_run to use __rvm_log_command ... prepare for better code
Browse files Browse the repository at this point in the history
  • Loading branch information
mpapis committed Aug 21, 2012
1 parent 259bd30 commit 77778bb
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 57 deletions.
2 changes: 1 addition & 1 deletion scripts/functions/manage/base
Expand Up @@ -70,7 +70,7 @@ __rvm_apply_patches()
if [[ -f "$full_patch_path" ]]
then
__rvm_run "patch.apply.${patch_name/*\/}" \
"patch -F $patch_fuzziness -p$patch_level -N -f <\"$full_patch_path\"" \
"patch -F $patch_fuzziness -p$patch_level -N -f -i \"$full_patch_path\"" \
"Applying patch '$patch_name' (located at $full_patch_path)"
if (( $? > 0 ))
then
Expand Down
4 changes: 2 additions & 2 deletions scripts/functions/manage/ree
Expand Up @@ -28,7 +28,7 @@ ree_install()
__rvm_rm_rf "${rvm_src_path}/$rvm_ruby_string"

__rvm_run "extract" \
"gunzip < \"${rvm_archives_path}/$rvm_ruby_package_file.$rvm_archive_extension\" | $rvm_tar_command xf - -C ${rvm_src_path} ${rvm_tar_options:-}" \
"$rvm_tar_command xzf \"${rvm_archives_path}/$rvm_ruby_package_file.$rvm_archive_extension\" -C ${rvm_src_path} ${rvm_tar_options:-}" \
"$rvm_ruby_string - #extracting $rvm_ruby_package_file to ${rvm_src_path}/$rvm_ruby_string"
result=$?

Expand Down Expand Up @@ -70,7 +70,7 @@ ree_install()
full_patch_path="$(__rvm_lookup_full_patch_path lib64)"
cd "${rvm_src_path}/$rvm_ruby_string"
__rvm_run "patch.apply.lib64" \
"patch -F 3 -p1 -N -f <\"$full_patch_path\"" \
"patch -F 3 -p1 -N -f -i \"$full_patch_path\"" \
"Applying patch 'lib64' (located at $full_patch_path)"
)
result=$?
Expand Down
2 changes: 1 addition & 1 deletion scripts/functions/manage/rubinius
Expand Up @@ -105,7 +105,7 @@ rbx_install()
exit $result
fi
__rvm_run "extract" \
"gunzip < \"${rvm_archives_path}/$(basename ${rvm_ruby_package_file})\" | $rvm_tar_command xf - -C ${rvm_src_path} ${rvm_tar_options:-}" \
"$rvm_tar_command xzf \"${rvm_archives_path}/$(basename ${rvm_ruby_package_file})\" -C ${rvm_src_path} ${rvm_tar_options:-}" \
"$rvm_ruby_string - #extracting"
result=$?

Expand Down
2 changes: 1 addition & 1 deletion scripts/functions/pkg
Expand Up @@ -55,7 +55,7 @@ install_package()

if [[ ! -z "$patches" ]] ; then
for patch in $(echo $patches | \tr ',' ' ') ; do
__rvm_run "$package/patch" "patch -p0 -f < $patch" "Applying patch '$patch'..."
__rvm_run "$package/patch" "patch -p0 -f -i $patch" "Applying patch '$patch'..."
if [[ $? -gt 0 ]] ; then
rvm_error "Patch $patch did not apply cleanly... back to the patching board :(" ; exit 1
fi
Expand Down
61 changes: 10 additions & 51 deletions scripts/functions/utility
Expand Up @@ -102,59 +102,18 @@ __rvm_ruby_string_paths_under()
# Run a specified command and log it.
__rvm_run()
{
typeset name log temp_log_path _command message
true ${rvm_debug_flag:=0} ${rvm_niceness:=0}
typeset name message
typeset -a _command_array

name="${1:-}"
_command="${2:-}"
echo "1:$2" >&2
_command_array=( ${2:-} )
echo "2:${#_command_array[*]}:${_command_array[*]}" >&2
eval "_command_array=( ${2:-} )"
echo "3:${#_command_array[*]}:${_command_array[*]}" >&2
message="${3:-}"

if [[ -n "$message" ]]
then
rvm_log "$message"
fi

if (( rvm_debug_flag > 0 ))
then
rvm_debug "Executing: $_command"
fi

if [[ -n "${rvm_ruby_string:-}" ]]
then
temp_log_path="${rvm_log_path}/$rvm_ruby_string"
else
temp_log_path="${rvm_log_path}"
fi

log="$temp_log_path/$name.log"

if [[ ! -d "${log%\/*}" ]]
then
\mkdir -p "${log%\/*}"
fi

if [[ ! -f "$log" ]]
then
\touch "$log" # for zsh :(
fi

# TODO: Allow an 'append_flag' setting?
printf "%b" "[$(date +'%Y-%m-%d %H:%M:%S')] $_command\n" > "$log"

if (( rvm_niceness > 0 ))
then
_command="nice -n $rvm_niceness $_command"
fi

eval "$_command" >> "$log" 2>&1
result=$?

if (( result > 0 ))
then
rvm_error "Error running '$_command', please read $log"
fi

return ${result}
__rvm_log_command "$name" "$message" "${_command_array[@]}" || return $?
}

# Run a specified command and log it.
Expand Down Expand Up @@ -189,12 +148,12 @@ __rvm_log_command()
log="$temp_log_path/$name.log"

[[ -d "${log%\/*}" ]] || \mkdir -p "${log%\/*}"
[[ -f "$log" ]] || \touch "$log" # for zsh :(
[[ -f "$log" ]] || \touch "$log" # for zsh :(

# TODO: Allow an 'append_flag' setting?
printf "%b" "[$(date +'%Y-%m-%d %H:%M:%S')] $*\n" > "$log"

"${_command[@]}" >> "$log" 2>&1
env "${_command[@]}" >> "$log" 2>&1
result=$?

if (( result > 0 ))
Expand Down
2 changes: 1 addition & 1 deletion scripts/rubygems
Expand Up @@ -154,7 +154,7 @@ rubygems_setup()
fi

__rvm_run "rubygems.extract" \
"gunzip < ${rvm_archives_path}/$rvm_gem_package_name.tgz | $rvm_tar_command xf - -C ${rvm_src_path}" \
"$rvm_tar_command xzf ${rvm_archives_path}/$rvm_gem_package_name.tgz -C ${rvm_src_path}" \
"Extracting $rvm_gem_package_name ..."
fi

Expand Down

0 comments on commit 77778bb

Please sign in to comment.