build_requirements 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. #!/usr/bin/env bash
  2. source "$rvm_scripts_path/functions/build_requirements_helpers"
  3. source "$rvm_scripts_path/functions/build_undesired_helpers"
  4. __rvm_requirements_run()
  5. {
  6. \typeset -a packages_installed packages_missing packages_to_install packages_flags
  7. \typeset -a packages_undesired packages_to_remove
  8. \typeset -a packages_custom packages_custom_after
  9. \typeset __type __lib_type __iterator
  10. __type=$1
  11. __lib_type=$1
  12. shift
  13. for __iterator in load reset before define summary remove before_update update custom install custom_after after
  14. do
  15. __rvm_requirements_run_${__iterator} "$@" || return $?
  16. done
  17. }
  18. __rvm_requirements_run_load()
  19. {
  20. if
  21. is_a_function requirements_${__type}_before ||
  22. is_a_function requirements_${__type}_define
  23. then
  24. rvm_debug "requirements code for ${__type} already loaded"
  25. else
  26. [[ -s "$rvm_scripts_path/functions/requirements/${__type}" ]] ||
  27. {
  28. rvm_error "Requirements support for ${__type} is not implemented yet,
  29. report a bug here => https://github.com/rvm/rvm/issues"
  30. return 1
  31. }
  32. source "$rvm_scripts_path/functions/requirements/${__type}"
  33. if
  34. is_a_function requirements_${__type}_before ||
  35. is_a_function requirements_${__type}_define
  36. then
  37. rvm_debug "requirements code for ${__type} loaded"
  38. else
  39. rvm_error "Failed loading requirements for ${__type}!"
  40. return 1
  41. fi
  42. fi
  43. }
  44. __rvm_requirements_run_reset()
  45. {
  46. packages_installed=()
  47. packages_missing=()
  48. packages_to_install=()
  49. packages_flags=()
  50. packages_undesired=()
  51. packages_to_remove=()
  52. packages_custom=()
  53. packages_custom_after=()
  54. }
  55. __rvm_requirements_run_before()
  56. {
  57. if is_a_function requirements_${__type}_before
  58. then requirements_${__type}_before "$@" || return $?
  59. fi
  60. if [[ "${__lib_type}" != "${__type}" ]]
  61. then rvm_debug "requirements lib type set to ${__lib_type}"
  62. fi
  63. if [[ "${__lib_type}" != "${__type}" ]] && is_a_function requirements_${__lib_type}_before
  64. then requirements_${__lib_type}_before "$@" || return $?
  65. fi
  66. true # for osx
  67. }
  68. __rvm_requirements_run_define()
  69. {
  70. \typeset -a list
  71. \typeset element __handler
  72. if is_a_function requirements_${__lib_type}_define
  73. then __handler=requirements_${__lib_type}_define
  74. else __handler=requirements_${__type}_define
  75. fi
  76. list=( rvm )
  77. while (( $# )) && [[ -z "$1" ]]
  78. do shift
  79. done
  80. if (( $# ))
  81. then list+=( "$@" )
  82. else list+=( ruby )
  83. fi
  84. for element in "${list[@]}"
  85. do ${__handler} "${element}" || return $?
  86. done
  87. true
  88. }
  89. __rvm_requirements_run_summary_custom()
  90. {
  91. if (( ${rvm_autolibs_flag_number} > 2 ))
  92. then rvm_debug "Install $1 packages: ${_list// /, }."
  93. fi
  94. rvm_requiremnts_fail_or_run_action 3 "Missing $1 packages: ${_list}" true ||
  95. return $?
  96. true
  97. }
  98. __rvm_requirements_run_summary()
  99. {
  100. \typeset __summary_status=0
  101. (( ${#packages_custom[@]} == 0 )) ||
  102. {
  103. _list="${packages_custom[*]}"
  104. __rvm_requirements_run_summary_custom "custom" ||
  105. __summary_status=$?
  106. }
  107. (( ${#packages_installed[@]} == 0 )) ||
  108. {
  109. if (( ${rvm_list_installed_packages_flag:-0} == 1 ))
  110. then
  111. requirements_print_list ${packages_installed[*]}
  112. fi
  113. _list="${packages_installed[*]}"
  114. rvm_debug "Found required packages: ${_list// /, }."
  115. }
  116. (( ${#packages_missing[@]} == 0 )) ||
  117. {
  118. if (( ${rvm_list_missing_packages_flag:-0} == 1 ))
  119. then
  120. requirements_print_list ${packages_missing[*]}
  121. __summary_status=1
  122. else
  123. _list="${packages_missing[*]}"
  124. rvm_requiremnts_fail_or_run_action 2 \
  125. "Missing required packages: ${_list}" true ||
  126. __summary_status=$?
  127. fi
  128. }
  129. (( ${#packages_undesired[@]} == 0 )) ||
  130. {
  131. if (( ${rvm_list_undesired_packages_flag:-0} == 1 ))
  132. then
  133. requirements_print_list ${packages_undesired[*]}
  134. __summary_status=1
  135. else
  136. _list="${packages_undesired[*]}"
  137. rvm_requiremnts_fail_or_run_action 2 \
  138. "Found undesired packages: ${_list}" true ||
  139. __summary_status=$?
  140. fi
  141. }
  142. (( ${#packages_custom_after[@]} == 0 )) ||
  143. {
  144. _list="${packages_custom_after[*]}"
  145. __rvm_requirements_run_summary_custom "custom after" ||
  146. __summary_status=$?
  147. }
  148. return ${__summary_status}
  149. }
  150. __rvm_requirements_run_before_update()
  151. {
  152. if is_a_function requirements_${__lib_type}_before_update
  153. then requirements_${__lib_type}_before_update "$@" || return $?
  154. fi
  155. true # for osx
  156. }
  157. __rvm_requirements_run_update()
  158. {
  159. if
  160. (( ${#packages_to_install[@]} > 0 )) ||
  161. (( ${#packages_custom[@]}+${#packages_custom_after[@]} > 0 && ${rvm_autolibs_flag_number} > 2 ))
  162. then
  163. rvm_log "Installing requirements for ${rvm_autolibs_flag_runner}."
  164. if
  165. is_a_function requirements_${__lib_type}_update_system
  166. then
  167. rvm_requiremnts_fail_or_run_action 3 \
  168. "Skipping system update, make sure your system is up to date." \
  169. __rvm_log_command update_system "Updating system" \
  170. requirements_${__lib_type}_update_system "$@" || return $?
  171. elif
  172. is_a_function requirements_${__type}_update_system
  173. then
  174. rvm_requiremnts_fail_or_run_action 3 \
  175. "Skipping system update, make sure your system is up to date." \
  176. __rvm_log_command update_system "Updating system" \
  177. requirements_${__type}_update_system "$@" || return $?
  178. fi
  179. fi
  180. }
  181. __rvm_requirements_run_custom_()
  182. {
  183. \typeset __package __custom
  184. \typeset -a __missing_custom
  185. __missing_custom=()
  186. __custom="$1"
  187. shift
  188. while
  189. (( $# ))
  190. do
  191. __package="$1"
  192. if
  193. is_a_function requirements_${__lib_type}_install_${__package}
  194. then
  195. rvm_requiremnts_fail_or_run_action 2 \
  196. "Skipping ${__package} installation, make sure ${__package} is installed." \
  197. __rvm_log_command install_${__custom}_${__package} \
  198. "Installing required ${__custom//_/ } package: ${__package}" \
  199. "requirements_${__lib_type}_install_${__package}" || return $?
  200. elif
  201. is_a_function requirements_install_${__package}
  202. then
  203. rvm_requiremnts_fail_or_run_action 2 \
  204. "Skipping ${__package} installation, make sure ${__package} is installed." \
  205. __rvm_log_command install_${__custom}_${__package} \
  206. "Installing required ${__custom//_/ } package: ${__package}" \
  207. "requirements_install_${__package}" || return $?
  208. else
  209. __rvm_add_once __missing_custom "${__package}"
  210. fi
  211. shift
  212. done
  213. if
  214. (( ${#__missing_custom[@]} ))
  215. then
  216. if
  217. is_a_function requirements_${__lib_type}_install_${__custom}
  218. then
  219. rvm_requiremnts_fail_or_run_action 2 \
  220. "Skipping ${__missing_custom[*]} installation, make sure listed software is installed." \
  221. __rvm_log_command install_${__custom} \
  222. "Installing required ${__custom//_/ } packages: ${__missing_custom[*]}" \
  223. "requirements_${__lib_type}_install_${__custom}" "${__missing_custom[@]}" || return $?
  224. else
  225. rvm_requiremnts_fail_always 2 "\
  226. Can not find function 'requirements_${__lib_type}_install_${__custom}' to install missing ${__custom//_/ } packages:
  227. ${__missing_custom[*]}
  228. report a bug here:
  229. https://github.com/rvm/rvm/issues
  230. " || return $?
  231. fi
  232. fi
  233. }
  234. __rvm_requirements_run_custom()
  235. {
  236. (( ${#packages_custom[@]} )) || return 0
  237. __rvm_requirements_run_custom_ "custom" "${packages_custom[@]}" || return $?
  238. }
  239. __rvm_requirements_run_install()
  240. {
  241. (( ${#packages_to_install[@]} )) || return 0
  242. if
  243. is_a_function requirements_${__lib_type}_lib_install
  244. then
  245. \typeset __package
  246. for __package in "${packages_to_install[@]}"
  247. do
  248. __rvm_log_command package_install_${__package} "Installing required package: ${__package}" \
  249. "requirements_${__lib_type}_lib_install" "${__package}" ||
  250. {
  251. \typeset __status=$?
  252. _list="${packages_to_install[*]}"
  253. rvm_warn "Failed installation package: ${__package} of: ${_list// /, }."
  254. return ${__status}
  255. }
  256. done
  257. else
  258. _list="${packages_to_install[*]}"
  259. __rvm_log_command package_install_${_list// /_} "Installing required packages: ${_list// /, }" \
  260. "requirements_${__lib_type}_libs_install" "${packages_to_install[@]}" ||
  261. return $?
  262. fi
  263. }
  264. __rvm_requirements_run_custom_after()
  265. {
  266. (( ${#packages_custom_after[@]} )) || return 0
  267. __rvm_requirements_run_custom_ "custom_after" "${packages_custom_after[@]}" || return $?
  268. }
  269. __rvm_requirements_run_after()
  270. {
  271. if
  272. is_a_function requirements_${__lib_type}_after
  273. then
  274. requirements_${__lib_type}_after "$@" || return $?
  275. elif
  276. is_a_function requirements_${__type}_after
  277. then
  278. requirements_${__type}_after "$@" || return $?
  279. fi
  280. true # for osx
  281. }