macruby 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. #!/usr/bin/env bash
  2. macruby_install_extract_pkg()
  3. (
  4. set -x
  5. \typeset __source __target __temp1 __temp1_org __temp2 __result
  6. __source="$1"
  7. __target="$2"
  8. __temp1="$( TMPDIR="${rvm_tmp_path}" mktemp -d -t rvm-tmp1.XXXXXXXXX )"
  9. __temp2="$( TMPDIR="${rvm_tmp_path}" mktemp -d -t rvm-tmp2.XXXXXXXXX )"
  10. [[ -n "${__temp1}" && -d "${__temp1}" && -n "${__temp2}" && -d "${__temp2}" ]] || return $?
  11. __result=0
  12. __temp1_org="${__temp1}"
  13. __temp1+="/${rvm_ruby_package_name}" # required for the next command to run at all
  14. pkgutil --expand "${__source}" "${__temp1}" || __result=$?
  15. __temp1="$( __rvm_find "${__temp1}" -name Payload -type f )"
  16. [[ -n "${__temp1}" ]] &&
  17. tar xzf "${__temp1}" -C "${__temp2}" &&
  18. mkdir -p "${__target}/" &&
  19. mv -f "${__temp2}/Library/Frameworks/MacRuby.framework/Versions/Current"/* "${__target}/" ||
  20. __result=$?
  21. rm -rf "${__temp1}" "${__temp1_org}" "${__temp2}" || true
  22. return ${__result}
  23. )
  24. macruby_install_extract_zip()
  25. {
  26. mkdir -p ${rvm_src_path}/$rvm_ruby_string &&
  27. unzip -o -j "${rvm_archives_path}/$rvm_ruby_package_file" \
  28. "MacRuby ${rvm_ruby_version}/MacRuby ${rvm_ruby_version}.pkg" \
  29. -d "${rvm_src_path}/$rvm_ruby_string" &&
  30. \command \mv "${rvm_src_path}/$rvm_ruby_string/MacRuby ${rvm_ruby_version}.pkg" \
  31. "${rvm_src_path}/$rvm_ruby_string/$rvm_ruby_string.pkg" &&
  32. macruby_install_extract_pkg "${rvm_src_path}/$rvm_ruby_string/$rvm_ruby_string.pkg" "$rvm_ruby_home" ||
  33. return $?
  34. }
  35. macruby_install_wrapper()
  36. {
  37. \command \cat <<RubyWrapper
  38. #!/usr/bin/env bash
  39. export DYLD_LIBRARY_PATH="$rvm_ruby_home/usr/lib\${DYLD_LIBRARY_PATH:+:}\${DYLD_LIBRARY_PATH:-}"
  40. export RUBYOPT="\${RUBYOPT:-} $extra_rubyopt"
  41. export GEM_HOME="\${GEM_HOME:-$rvm_ruby_gem_home}"
  42. export GEM_PATH="\${GEM_PATH:-$rvm_ruby_gem_path}"
  43. export MY_RUBY_HOME="$rvm_ruby_home"
  44. export PATH="$rvm_ruby_gem_home/bin:$rvm_ruby_global_gems_path/bin:$rvm_ruby_home/bin:\$PATH"
  45. exec "$rvm_ruby_home/usr/bin/mac$1" "\$@"
  46. RubyWrapper
  47. }
  48. macruby_install_wrap_binaries_detect_rubyopt()
  49. {
  50. \typeset __path
  51. extra_rubyopt=""
  52. for __path in $(
  53. DYLD_LIBRARY_PATH="$rvm_ruby_home/usr/lib" "$rvm_ruby_home/usr/bin/macruby" -e 'puts $LOAD_PATH'
  54. )
  55. do
  56. [[ "${__path}" == "." ]] ||
  57. extra_rubyopt+="-I$rvm_ruby_home/usr${__path#*/usr} "
  58. done
  59. }
  60. macruby_install_fix_shebang()
  61. {
  62. case "$1" in
  63. (ruby) return 0 ;; # it's a binary, no fixing needed
  64. esac
  65. {
  66. echo "#!$rvm_ruby_home/usr/bin/macruby"
  67. __rvm_tail -n +2 "$rvm_ruby_home/usr/bin/mac$1"
  68. } > "$rvm_ruby_home/usr/bin/mac$1.new"
  69. mv -f "$rvm_ruby_home/usr/bin/mac$1.new" "$rvm_ruby_home/usr/bin/mac$1"
  70. chmod +x "$rvm_ruby_home/usr/bin/mac$1"
  71. }
  72. macruby_install_wrap_binary()
  73. {
  74. binary_name="${binary_name#$rvm_ruby_home/usr/bin/mac}"
  75. file_name="$rvm_ruby_home/bin/$binary_name"
  76. if [[ -f "$file_name" ]]
  77. then \command \rm -f "$file_name"
  78. fi
  79. macruby_install_fix_shebang "$binary_name"
  80. macruby_install_wrapper "$binary_name" > "$file_name"
  81. [[ -x "$file_name" ]] || chmod +x $file_name
  82. }
  83. macruby_install_wrap_binaries()
  84. {
  85. mkdir -p "$rvm_ruby_home/bin/" ||
  86. {
  87. rvm_error "Can not create binaries directory => $rvm_ruby_home/bin/"
  88. return 1
  89. }
  90. \typeset binary_name extra_rubyopt
  91. macruby_install_wrap_binaries_detect_rubyopt
  92. for binary_name in "$rvm_ruby_home/usr/bin"/mac*
  93. do
  94. macruby_install_wrap_binary
  95. done
  96. }
  97. macruby_install()
  98. {
  99. [[ "Darwin" == "${_system_type}" ]] ||
  100. {
  101. rvm_error "MacRuby can only be installed on a Darwin OS."
  102. exit 1
  103. }
  104. if
  105. (( rvm_head_flag == 1 ))
  106. then
  107. rvm_error "macruby-head is temporarily disabled(broken), use macruby-nightly for now."
  108. return 1
  109. if (( ${rvm_llvm_flag:=0} == 1 ))
  110. then "$rvm_scripts_path/package" llvm install
  111. fi
  112. macruby_path="/usr/local/bin"
  113. # TODO: configure & make variables should be set here.
  114. rvm_ruby_configure=" true "
  115. rvm_ruby_make="rake"
  116. rvm_ruby_make_install="$rvm_bin_path/rvmsudo rake install"
  117. __rvm_db "${rvm_ruby_interpreter}_repo_url" "rvm_ruby_url"
  118. rvm_ruby_repo_url=$rvm_ruby_url
  119. __rvm_setup_compile_environment "${rvm_ruby_string}"
  120. __rvm_install_source $* ||
  121. {
  122. result=$?
  123. rvm_error "There has been an error while trying to install from source. \nHalting the installation."
  124. return $result
  125. }
  126. else
  127. macruby_path="/Library/Frameworks/MacRuby.framework/Versions/${rvm_ruby_version}/usr/bin"
  128. rvm_log "Retrieving MacRuby ${rvm_ruby_version} ..."
  129. "$rvm_scripts_path/fetch" "$rvm_ruby_url" ||
  130. {
  131. result=$?
  132. rvm_error "There has been an error while trying to fetch the source. Halting the installation."
  133. return $result
  134. }
  135. case "$rvm_ruby_package_file" in
  136. (*.zip)
  137. __rvm_log_command "install" "Installing package" \
  138. macruby_install_extract_zip ||
  139. return $?
  140. ;;
  141. (*.pkg)
  142. __rvm_log_command "install" "Installing package" \
  143. macruby_install_extract_pkg "${rvm_archives_path}/$rvm_ruby_package_file" "$rvm_ruby_home" ||
  144. return $?
  145. ;;
  146. (*)
  147. rvm_error "Do not know what to do with archive: ${rvm_archives_path}/$rvm_ruby_package_file"
  148. return 1
  149. ;;
  150. esac
  151. fi
  152. macruby_install_wrap_binaries
  153. __rvm_initial_gemsets_create "$rvm_ruby_home/bin/ruby"
  154. binaries=()
  155. __rvm_post_install
  156. }