shopify-ruby-definitions 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +7 -0
  2. data/.rubocop.yml +22 -0
  3. data/Gemfile +12 -0
  4. data/LICENSE.txt +21 -0
  5. data/README.md +0 -0
  6. data/Rakefile +16 -0
  7. data/lib/shopify_ruby_definitions/ruby_build.rb +10 -0
  8. data/lib/shopify_ruby_definitions/ruby_versions.rb +49 -0
  9. data/lib/shopify_ruby_definitions/version.rb +6 -0
  10. data/lib/shopify_ruby_definitions.rb +12 -0
  11. data/sorbet/config +4 -0
  12. data/sorbet/rbi/annotations/rainbow.rbi +269 -0
  13. data/sorbet/rbi/gems/ast@2.4.2.rbi +584 -0
  14. data/sorbet/rbi/gems/diff-lcs@1.5.0.rbi +1083 -0
  15. data/sorbet/rbi/gems/json@2.6.3.rbi +1533 -0
  16. data/sorbet/rbi/gems/minitest@5.18.0.rbi +1491 -0
  17. data/sorbet/rbi/gems/netrc@0.11.0.rbi +158 -0
  18. data/sorbet/rbi/gems/parallel@1.23.0.rbi +273 -0
  19. data/sorbet/rbi/gems/parser@3.2.2.1.rbi +7253 -0
  20. data/sorbet/rbi/gems/rainbow@3.1.1.rbi +402 -0
  21. data/sorbet/rbi/gems/rake@13.0.6.rbi +3024 -0
  22. data/sorbet/rbi/gems/rbi@0.0.16.rbi +3049 -0
  23. data/sorbet/rbi/gems/regexp_parser@2.8.0.rbi +3748 -0
  24. data/sorbet/rbi/gems/rexml@3.2.5.rbi +4717 -0
  25. data/sorbet/rbi/gems/rubocop-ast@1.28.1.rbi +6969 -0
  26. data/sorbet/rbi/gems/rubocop-minitest@0.31.0.rbi +2528 -0
  27. data/sorbet/rbi/gems/rubocop-shopify@2.13.0.rbi +8 -0
  28. data/sorbet/rbi/gems/rubocop@1.51.0.rbi +55313 -0
  29. data/sorbet/rbi/gems/ruby-progressbar@1.13.0.rbi +1317 -0
  30. data/sorbet/rbi/gems/spoom@1.2.1.rbi +2536 -0
  31. data/sorbet/rbi/gems/tapioca@0.11.6.rbi +3301 -0
  32. data/sorbet/rbi/gems/thor@1.2.2.rbi +3965 -0
  33. data/sorbet/rbi/gems/unicode-display_width@2.4.2.rbi +65 -0
  34. data/sorbet/rbi/gems/unparser@0.6.7.rbi +4524 -0
  35. data/sorbet/rbi/gems/yard-sorbet@0.8.1.rbi +428 -0
  36. data/sorbet/rbi/gems/yard@0.9.34.rbi +18219 -0
  37. data/sorbet/tapioca/config.yml +13 -0
  38. data/sorbet/tapioca/require.rb +4 -0
  39. data/vendor/ruby-build/LICENSE +19 -0
  40. data/vendor/ruby-build/bin/ruby-build +1572 -0
  41. data/vendor/ruby-build/share/ruby-build/2.6.0 +2 -0
  42. data/vendor/ruby-build/share/ruby-build/2.6.0-dev +2 -0
  43. data/vendor/ruby-build/share/ruby-build/2.6.0-preview1 +2 -0
  44. data/vendor/ruby-build/share/ruby-build/2.6.0-preview2 +2 -0
  45. data/vendor/ruby-build/share/ruby-build/2.6.0-preview3 +2 -0
  46. data/vendor/ruby-build/share/ruby-build/2.6.0-rc1 +2 -0
  47. data/vendor/ruby-build/share/ruby-build/2.6.0-rc2 +2 -0
  48. data/vendor/ruby-build/share/ruby-build/2.6.1 +2 -0
  49. data/vendor/ruby-build/share/ruby-build/2.6.10 +2 -0
  50. data/vendor/ruby-build/share/ruby-build/2.6.2 +2 -0
  51. data/vendor/ruby-build/share/ruby-build/2.6.3 +2 -0
  52. data/vendor/ruby-build/share/ruby-build/2.6.4 +2 -0
  53. data/vendor/ruby-build/share/ruby-build/2.6.5 +2 -0
  54. data/vendor/ruby-build/share/ruby-build/2.6.6 +2 -0
  55. data/vendor/ruby-build/share/ruby-build/2.6.7 +2 -0
  56. data/vendor/ruby-build/share/ruby-build/2.6.8 +2 -0
  57. data/vendor/ruby-build/share/ruby-build/2.6.9 +2 -0
  58. data/vendor/ruby-build/share/ruby-build/2.7.0 +2 -0
  59. data/vendor/ruby-build/share/ruby-build/2.7.0-dev +2 -0
  60. data/vendor/ruby-build/share/ruby-build/2.7.0-preview1 +2 -0
  61. data/vendor/ruby-build/share/ruby-build/2.7.0-preview2 +2 -0
  62. data/vendor/ruby-build/share/ruby-build/2.7.0-preview3 +2 -0
  63. data/vendor/ruby-build/share/ruby-build/2.7.0-rc1 +2 -0
  64. data/vendor/ruby-build/share/ruby-build/2.7.0-rc2 +2 -0
  65. data/vendor/ruby-build/share/ruby-build/2.7.1 +2 -0
  66. data/vendor/ruby-build/share/ruby-build/2.7.2 +2 -0
  67. data/vendor/ruby-build/share/ruby-build/2.7.3 +2 -0
  68. data/vendor/ruby-build/share/ruby-build/2.7.4 +2 -0
  69. data/vendor/ruby-build/share/ruby-build/2.7.5 +2 -0
  70. data/vendor/ruby-build/share/ruby-build/2.7.6 +2 -0
  71. data/vendor/ruby-build/share/ruby-build/2.7.7 +2 -0
  72. data/vendor/ruby-build/share/ruby-build/2.7.8 +2 -0
  73. data/vendor/ruby-build/share/ruby-build/3.0.0 +2 -0
  74. data/vendor/ruby-build/share/ruby-build/3.0.0-dev +2 -0
  75. data/vendor/ruby-build/share/ruby-build/3.0.0-preview1 +2 -0
  76. data/vendor/ruby-build/share/ruby-build/3.0.0-preview2 +2 -0
  77. data/vendor/ruby-build/share/ruby-build/3.0.0-pshopify9 +9 -0
  78. data/vendor/ruby-build/share/ruby-build/3.0.0-rc1 +2 -0
  79. data/vendor/ruby-build/share/ruby-build/3.0.1 +2 -0
  80. data/vendor/ruby-build/share/ruby-build/3.0.1-pshopify2 +7 -0
  81. data/vendor/ruby-build/share/ruby-build/3.0.2 +2 -0
  82. data/vendor/ruby-build/share/ruby-build/3.0.2-pshopify3 +11 -0
  83. data/vendor/ruby-build/share/ruby-build/3.0.3 +2 -0
  84. data/vendor/ruby-build/share/ruby-build/3.0.4 +2 -0
  85. data/vendor/ruby-build/share/ruby-build/3.0.5 +2 -0
  86. data/vendor/ruby-build/share/ruby-build/3.0.6 +2 -0
  87. data/vendor/ruby-build/share/ruby-build/3.1.0 +2 -0
  88. data/vendor/ruby-build/share/ruby-build/3.1.0-dev +2 -0
  89. data/vendor/ruby-build/share/ruby-build/3.1.0-preview1 +2 -0
  90. data/vendor/ruby-build/share/ruby-build/3.1.0-pshopify1 +9 -0
  91. data/vendor/ruby-build/share/ruby-build/3.1.1 +2 -0
  92. data/vendor/ruby-build/share/ruby-build/3.1.1-pshopify2 +8 -0
  93. data/vendor/ruby-build/share/ruby-build/3.1.2 +2 -0
  94. data/vendor/ruby-build/share/ruby-build/3.1.2-pshopify2 +10 -0
  95. data/vendor/ruby-build/share/ruby-build/3.1.3 +2 -0
  96. data/vendor/ruby-build/share/ruby-build/3.1.3-pshopify1 +9 -0
  97. data/vendor/ruby-build/share/ruby-build/3.1.4 +2 -0
  98. data/vendor/ruby-build/share/ruby-build/3.1.4-pshopify1 +8 -0
  99. data/vendor/ruby-build/share/ruby-build/3.2.0 +2 -0
  100. data/vendor/ruby-build/share/ruby-build/3.2.0-dev +2 -0
  101. data/vendor/ruby-build/share/ruby-build/3.2.0-preview1 +2 -0
  102. data/vendor/ruby-build/share/ruby-build/3.2.0-preview2 +2 -0
  103. data/vendor/ruby-build/share/ruby-build/3.2.0-preview3 +2 -0
  104. data/vendor/ruby-build/share/ruby-build/3.2.0-pshopify2 +12 -0
  105. data/vendor/ruby-build/share/ruby-build/3.2.0-rc1 +2 -0
  106. data/vendor/ruby-build/share/ruby-build/3.2.1 +2 -0
  107. data/vendor/ruby-build/share/ruby-build/3.2.1-pshopify5 +29 -0
  108. data/vendor/ruby-build/share/ruby-build/3.2.2 +2 -0
  109. data/vendor/ruby-build/share/ruby-build/3.2.2-pshopify3 +33 -0
  110. data/vendor/ruby-build/share/ruby-build/3.3.0-dev +2 -0
  111. data/vendor/ruby-build/share/ruby-build/3.3.0-preview1 +2 -0
  112. data/vendor/ruby-build/share/ruby-build/truffleruby-21.0.0 +13 -0
  113. data/vendor/ruby-build/share/ruby-build/truffleruby-21.1.0 +13 -0
  114. data/vendor/ruby-build/share/ruby-build/truffleruby-21.2.0 +17 -0
  115. data/vendor/ruby-build/share/ruby-build/truffleruby-21.2.0.1 +17 -0
  116. data/vendor/ruby-build/share/ruby-build/truffleruby-21.3.0 +17 -0
  117. data/vendor/ruby-build/share/ruby-build/truffleruby-22.0.0.2 +17 -0
  118. data/vendor/ruby-build/share/ruby-build/truffleruby-22.1.0 +17 -0
  119. data/vendor/ruby-build/share/ruby-build/truffleruby-22.2.0 +21 -0
  120. data/vendor/ruby-build/share/ruby-build/truffleruby-22.3.0 +21 -0
  121. data/vendor/ruby-build/share/ruby-build/truffleruby-22.3.1 +21 -0
  122. data/vendor/ruby-build/share/ruby-build/truffleruby-23.0.0-preview1 +21 -0
  123. data/vendor/ruby-build/share/ruby-build/truffleruby-dev +21 -0
  124. data/vendor/ruby-build/share/ruby-build/yjit-3.1.0-dev +2 -0
  125. metadata +252 -0
@@ -0,0 +1,1572 @@
1
+ #!/usr/bin/env bash
2
+ #
3
+ # Usage: ruby-build [-kpv] <definition> <prefix>
4
+ # ruby-build --definitions
5
+ # ruby-build --version
6
+ #
7
+ # -k/--keep Do not remove source tree after installation
8
+ # -p/--patch Apply a patch from stdin before building
9
+ # -v/--verbose Verbose mode: print compilation status to stdout
10
+ # -4/--ipv4 Resolve names to IPv4 addresses only
11
+ # -6/--ipv6 Resolve names to IPv6 addresses only
12
+ # --definitions List all local definitions
13
+ # -l/--list List latest stable releases for each Ruby
14
+ # --version Show version of ruby-build
15
+ #
16
+
17
+ RUBY_BUILD_VERSION="20230512"
18
+
19
+ OLDIFS="$IFS"
20
+
21
+ set -E
22
+ exec 3<&2 # preserve original stderr at fd 3
23
+
24
+
25
+ lib() {
26
+ parse_options() {
27
+ OPTIONS=()
28
+ ARGUMENTS=()
29
+ local arg option index
30
+
31
+ for arg in "$@"; do
32
+ if [ "${arg:0:1}" = "-" ]; then
33
+ if [ "${arg:1:1}" = "-" ]; then
34
+ OPTIONS[${#OPTIONS[*]}]="${arg:2}"
35
+ else
36
+ index=1
37
+ while option="${arg:$index:1}"; do
38
+ [ -n "$option" ] || break
39
+ OPTIONS[${#OPTIONS[*]}]="$option"
40
+ index=$(($index+1))
41
+ done
42
+ fi
43
+ else
44
+ ARGUMENTS[${#ARGUMENTS[*]}]="$arg"
45
+ fi
46
+ done
47
+ }
48
+
49
+ if [ "$1" == "--$FUNCNAME" ]; then
50
+ declare -f "$FUNCNAME"
51
+ echo "$FUNCNAME \"\$1\";"
52
+ exit
53
+ fi
54
+ }
55
+ lib "$1"
56
+
57
+
58
+ resolve_link() {
59
+ $(type -p greadlink readlink | head -1) "$1"
60
+ }
61
+
62
+ abs_dirname() {
63
+ local cwd="$(pwd)"
64
+ local path="$1"
65
+
66
+ while [ -n "$path" ]; do
67
+ cd "${path%/*}"
68
+ local name="${path##*/}"
69
+ path="$(resolve_link "$name" || true)"
70
+ done
71
+
72
+ pwd
73
+ cd "$cwd"
74
+ }
75
+
76
+ capitalize() {
77
+ printf "%s" "$1" | tr a-z A-Z
78
+ }
79
+
80
+ sanitize() {
81
+ printf "%s" "$1" | sed "s/[^A-Za-z0-9.-]/_/g; s/__*/_/g"
82
+ }
83
+
84
+ colorize() {
85
+ if [ -t 1 ]; then printf "\e[%sm%s\e[m" "$1" "$2"
86
+ else echo -n "$2"
87
+ fi
88
+ }
89
+
90
+ os_information() {
91
+ if type -p lsb_release >/dev/null; then
92
+ lsb_release -sir | xargs echo
93
+ elif type -p sw_vers >/dev/null; then
94
+ echo "$(sw_vers -productName) $(sw_vers -productVersion)"
95
+ elif [ -r /etc/os-release ]; then
96
+ source /etc/os-release
97
+ echo "$NAME" $VERSION_ID
98
+ else
99
+ local os="$(cat /etc/{centos,redhat,fedora,system}-release /etc/debian_version 2>/dev/null | head -1)"
100
+ echo "${os:-$(uname -sr)}"
101
+ fi
102
+ }
103
+
104
+ is_mac() {
105
+ [ "$(uname -s)" = "Darwin" ] || return 1
106
+ [ $# -eq 0 ] || [ "$(osx_version)" "$@" ]
107
+ }
108
+
109
+ is_freebsd() {
110
+ [ "$(uname -s)" = "FreeBSD" ]
111
+ }
112
+
113
+ freebsd_package_prefix() {
114
+ local package="$1"
115
+ pkg info --prefix "$package" 2>/dev/null | cut -wf2
116
+ }
117
+
118
+ # 9.1 -> 901
119
+ # 10.9 -> 1009
120
+ # 10.10 -> 1010
121
+ osx_version() {
122
+ local -a ver
123
+ IFS=. ver=( `sw_vers -productVersion` )
124
+ IFS="$OLDIFS"
125
+ echo $(( ${ver[0]}*100 + ${ver[1]} ))
126
+ }
127
+
128
+ build_failed() {
129
+ { echo
130
+ colorize 1 "BUILD FAILED"
131
+ echo " ($(os_information) using $(version))"
132
+ echo
133
+
134
+ if ! rmdir "${BUILD_PATH}" 2>/dev/null; then
135
+ echo "Inspect or clean up the working tree at ${BUILD_PATH}"
136
+
137
+ if file_is_not_empty "$LOG_PATH"; then
138
+ colorize 33 "Results logged to ${LOG_PATH}"
139
+ printf "\n\n"
140
+ echo "Last 10 log lines:"
141
+ tail -n 10 "$LOG_PATH"
142
+ fi
143
+ fi
144
+ } >&3
145
+ exit 1
146
+ }
147
+
148
+ file_is_not_empty() {
149
+ local filename="$1"
150
+ local line_count="$(wc -l "$filename" 2>/dev/null || true)"
151
+
152
+ if [ -n "$line_count" ]; then
153
+ words=( $line_count )
154
+ [ "${words[0]}" -gt 0 ]
155
+ else
156
+ return 1
157
+ fi
158
+ }
159
+
160
+ num_cpu_cores() {
161
+ local num
162
+ case "$(uname -s)" in
163
+ Darwin | *BSD )
164
+ num="$(sysctl -n hw.ncpu 2>/dev/null || true)"
165
+ ;;
166
+ SunOS )
167
+ num="$(getconf NPROCESSORS_ONLN 2>/dev/null || true)"
168
+ ;;
169
+ * )
170
+ num="$({ getconf _NPROCESSORS_ONLN ||
171
+ grep -c ^processor /proc/cpuinfo; } 2>/dev/null)"
172
+ num="${num#0}"
173
+ ;;
174
+ esac
175
+ echo "${num:-2}"
176
+ }
177
+
178
+ install_package() {
179
+ install_package_using "tarball" 1 "$@"
180
+ }
181
+
182
+ install_git() {
183
+ install_package_using "git" 2 "$@"
184
+ }
185
+
186
+ install_package_using() {
187
+ local package_type="$1"
188
+ local package_type_nargs="$2"
189
+ local package_name="$3"
190
+ shift 3
191
+
192
+ local fetch_args=( "$package_name" "${@:1:$package_type_nargs}" )
193
+ local make_args=( "$package_name" )
194
+ local arg last_arg
195
+
196
+ for arg in "${@:$(( $package_type_nargs + 1 ))}"; do
197
+ if [ "$last_arg" = "--if" ]; then
198
+ "$arg" || return 0
199
+ elif [ "$arg" != "--if" ]; then
200
+ make_args["${#make_args[@]}"]="$arg"
201
+ fi
202
+ last_arg="$arg"
203
+ done
204
+
205
+ pushd "$BUILD_PATH" >&4
206
+ "fetch_${package_type}" "${fetch_args[@]}"
207
+ make_package "${make_args[@]}"
208
+ popd >&4
209
+
210
+ { echo "Installed ${package_name} to ${PREFIX_PATH}"
211
+ echo
212
+ } >&2
213
+ }
214
+
215
+ make_package() {
216
+ local package_name="$1"
217
+ shift
218
+
219
+ pushd "$package_name" >&4
220
+ before_install_package "$package_name"
221
+ build_package "$package_name" $*
222
+ after_install_package "$package_name"
223
+ popd >&4
224
+ }
225
+
226
+ compute_sha2() {
227
+ local output
228
+ if type shasum &>/dev/null; then
229
+ output="$(shasum -a 256 -b)" || return 1
230
+ echo "${output% *}"
231
+ elif type openssl &>/dev/null; then
232
+ local openssl="$(command -v "$(brew --prefix openssl 2>/dev/null || true)"/bin/openssl openssl | head -1)"
233
+ output="$("$openssl" dgst -sha256 2>/dev/null)" || return 1
234
+ echo "${output##* }"
235
+ elif type sha256sum &>/dev/null; then
236
+ output="$(sha256sum -b)" || return 1
237
+ echo "${output%% *}"
238
+ else
239
+ return 1
240
+ fi
241
+ }
242
+
243
+ compute_md5() {
244
+ local output
245
+ if type md5 &>/dev/null; then
246
+ md5 -q
247
+ elif type openssl &>/dev/null; then
248
+ output="$(openssl md5)" || return 1
249
+ echo "${output##* }"
250
+ elif type md5sum &>/dev/null; then
251
+ output="$(md5sum -b)" || return 1
252
+ echo "${output%% *}"
253
+ else
254
+ return 1
255
+ fi
256
+ }
257
+
258
+ has_checksum_support() {
259
+ local checksum_command="$1"
260
+ local has_checksum_var="HAS_CHECKSUM_SUPPORT_${checksum_command}"
261
+
262
+ if [ -z "${!has_checksum_var+defined}" ]; then
263
+ printf -v "$has_checksum_var" "$(echo test | "$checksum_command" >/dev/null; echo $?)"
264
+ fi
265
+ return "${!has_checksum_var}"
266
+ }
267
+
268
+ verify_checksum() {
269
+ local checksum_command
270
+ local filename="$1"
271
+ local expected_checksum="$(echo "$2" | tr [A-Z] [a-z])"
272
+
273
+ # If the specified filename doesn't exist, return success
274
+ [ -e "$filename" ] || return 0
275
+
276
+ case "${#expected_checksum}" in
277
+ 0) return 0 ;; # empty checksum; return success
278
+ 32) checksum_command="compute_md5" ;;
279
+ 64) checksum_command="compute_sha2" ;;
280
+ *)
281
+ { echo
282
+ echo "unexpected checksum length: ${#expected_checksum} (${expected_checksum})"
283
+ echo "expected 0 (no checksum), 32 (MD5), or 64 (SHA2-256)"
284
+ echo
285
+ } >&4
286
+ return 1 ;;
287
+ esac
288
+
289
+ # If chosen provided checksum algorithm isn't supported, return success
290
+ has_checksum_support "$checksum_command" || return 0
291
+
292
+ # If the computed checksum is empty, return failure
293
+ local computed_checksum=`echo "$($checksum_command < "$filename")" | tr [A-Z] [a-z]`
294
+ [ -n "$computed_checksum" ] || return 1
295
+
296
+ if [ "$expected_checksum" != "$computed_checksum" ]; then
297
+ { echo
298
+ echo "checksum mismatch: ${filename} (file is corrupt)"
299
+ echo "expected $expected_checksum, got $computed_checksum"
300
+ echo
301
+ } >&4
302
+ return 1
303
+ fi
304
+ }
305
+
306
+ http() {
307
+ local method="$1"
308
+ [ -n "$2" ] || return 1
309
+ shift 1
310
+
311
+ RUBY_BUILD_HTTP_CLIENT="${RUBY_BUILD_HTTP_CLIENT:-$(detect_http_client 2>&3)}"
312
+ [ -n "$RUBY_BUILD_HTTP_CLIENT" ] || return 1
313
+
314
+ "http_${method}_${RUBY_BUILD_HTTP_CLIENT}" "$@"
315
+ }
316
+
317
+ detect_http_client() {
318
+ local client
319
+ for client in aria2c curl wget; do
320
+ if type "$client" &>/dev/null; then
321
+ echo "$client"
322
+ return
323
+ fi
324
+ done
325
+ echo "error: install \`curl\`, \`wget\`, or \`aria2c\` to download packages" >&2
326
+ return 1
327
+ }
328
+
329
+ http_head_aria2c() {
330
+ aria2c --dry-run --no-conf=true ${ARIA2_OPTS} "$1" >&4 2>&1
331
+ }
332
+
333
+ http_get_aria2c() {
334
+ local out="${2:-$(mktemp "out.XXXXXX")}"
335
+ if aria2c --allow-overwrite=true --no-conf=true -o "${out}" ${ARIA2_OPTS} "$1" >&4; then
336
+ [ -n "$2" ] || cat "${out}"
337
+ else
338
+ false
339
+ fi
340
+ }
341
+
342
+ http_head_curl() {
343
+ curl -qsILf ${CURL_OPTS} "$1" >&4 2>&1
344
+ }
345
+
346
+ http_get_curl() {
347
+ curl -q -o "${2:--}" -sSLf ${CURL_OPTS} "$1"
348
+ }
349
+
350
+ http_head_wget() {
351
+ wget -q --spider ${WGET_OPTS} "$1" >&4 2>&1
352
+ }
353
+
354
+ http_get_wget() {
355
+ wget -nv ${WGET_OPTS} -O "${2:--}" "$1"
356
+ }
357
+
358
+ fetch_tarball() {
359
+ local package_name="$1"
360
+ local package_url="$2"
361
+ local mirror_url
362
+ local checksum
363
+ local extracted_dir
364
+
365
+ if [ "$package_url" != "${package_url/\#}" ]; then
366
+ checksum="${package_url#*#}"
367
+ package_url="${package_url%%#*}"
368
+
369
+ if [ -n "$RUBY_BUILD_MIRROR_URL" ]; then
370
+ if [[ -z "$RUBY_BUILD_DEFAULT_MIRROR" || $package_url != */cache.ruby-lang.org/* ]]; then
371
+ mirror_url="${RUBY_BUILD_MIRROR_URL}/$checksum"
372
+ fi
373
+ elif [ -n "$RUBY_BUILD_MIRROR_PACKAGE_URL" ]; then
374
+ mirror_url="$RUBY_BUILD_MIRROR_PACKAGE_URL"
375
+ fi
376
+ fi
377
+
378
+ local tar_args="xzf"
379
+ local package_filename="${package_name}.tar.gz"
380
+
381
+ if [ "$package_url" != "${package_url%bz2}" ]; then
382
+ if ! type -p bzip2 >/dev/null; then
383
+ echo "warning: bzip2 not found; consider installing \`bzip2\` package" >&4
384
+ fi
385
+ package_filename="${package_filename%.gz}.bz2"
386
+ tar_args="${tar_args/z/j}"
387
+ fi
388
+
389
+ if ! reuse_existing_tarball "$package_filename" "$checksum"; then
390
+ local tarball_filename="$(basename "$package_url")"
391
+ echo "Downloading ${tarball_filename}..." >&2
392
+ http head "$mirror_url" &&
393
+ download_tarball "$mirror_url" "$package_filename" "$checksum" ||
394
+ download_tarball "$package_url" "$package_filename" "$checksum"
395
+ fi
396
+
397
+ { if tar $tar_args "$package_filename"; then
398
+ if [ ! -d "$package_name" ]; then
399
+ extracted_dir="$(find_extracted_directory)"
400
+ mv "$extracted_dir" "$package_name"
401
+ fi
402
+
403
+ if [ -z "$KEEP_BUILD_PATH" ]; then
404
+ rm -f "$package_filename"
405
+ else
406
+ true
407
+ fi
408
+ fi
409
+ } >&4 2>&1
410
+ }
411
+
412
+ find_extracted_directory() {
413
+ for f in *; do
414
+ if [ -d "$f" ]; then
415
+ echo "$f"
416
+ return
417
+ fi
418
+ done
419
+ echo "Extracted directory not found" >&2
420
+ return 1
421
+ }
422
+
423
+ reuse_existing_tarball() {
424
+ local package_filename="$1"
425
+ local checksum="$2"
426
+
427
+ # Reuse existing file in build location
428
+ if [ -e "$package_filename" ] && verify_checksum "$package_filename" "$checksum"; then
429
+ return 0
430
+ fi
431
+
432
+ # Reuse previously downloaded file in cache location
433
+ [ -n "$RUBY_BUILD_CACHE_PATH" ] || return 1
434
+ local cached_package_filename="${RUBY_BUILD_CACHE_PATH}/$package_filename"
435
+
436
+ [ -e "$cached_package_filename" ] || return 1
437
+ verify_checksum "$cached_package_filename" "$checksum" >&4 2>&1 || return 1
438
+ ln -s "$cached_package_filename" "$package_filename" >&4 2>&1 || return 1
439
+ }
440
+
441
+ download_tarball() {
442
+ local package_url="$1"
443
+ [ -n "$package_url" ] || return 1
444
+
445
+ local package_filename="$2"
446
+ local checksum="$3"
447
+
448
+ echo "-> $package_url" >&2
449
+
450
+ if http get "$package_url" "$package_filename" >&4 2>&1; then
451
+ verify_checksum "$package_filename" "$checksum" >&4 2>&1 || return 1
452
+ else
453
+ echo "error: failed to download $package_filename" >&2
454
+ return 1
455
+ fi
456
+
457
+ if [ -n "$RUBY_BUILD_CACHE_PATH" ]; then
458
+ local cached_package_filename="${RUBY_BUILD_CACHE_PATH}/$package_filename"
459
+ { mv "$package_filename" "$cached_package_filename"
460
+ ln -s "$cached_package_filename" "$package_filename"
461
+ } >&4 2>&1 || return 1
462
+ fi
463
+ }
464
+
465
+ fetch_git() {
466
+ local package_name="$1"
467
+ local git_url="$2"
468
+ local git_ref="$3"
469
+
470
+ echo "Cloning ${git_url}..." >&2
471
+
472
+ if type git &>/dev/null; then
473
+ if [ -n "$RUBY_BUILD_CACHE_PATH" ]; then
474
+ pushd "$RUBY_BUILD_CACHE_PATH" >&4
475
+ local clone_name="$(sanitize "$git_url")"
476
+ if [ -e "${clone_name}" ]; then
477
+ { cd "${clone_name}"
478
+ git fetch --force "$git_url" "+${git_ref}:${git_ref}"
479
+ } >&4 2>&1
480
+ else
481
+ git clone --bare --branch "$git_ref" "$git_url" "${clone_name}" >&4 2>&1
482
+ fi
483
+ git_url="$RUBY_BUILD_CACHE_PATH/${clone_name}"
484
+ popd >&4
485
+ fi
486
+
487
+ if [ -e "${package_name}" ]; then
488
+ ( cd "${package_name}"
489
+ git fetch --depth 1 origin "+${git_ref}"
490
+ git checkout -q -B "$git_ref" "origin/${git_ref}"
491
+ ) >&4 2>&1
492
+ else
493
+ git clone --depth 1 --branch "$git_ref" "$git_url" "${package_name}" >&4 2>&1
494
+ fi
495
+ else
496
+ echo "error: please install \`git\` and try again" >&2
497
+ exit 1
498
+ fi
499
+ }
500
+
501
+ build_package() {
502
+ local package_name="$1"
503
+ shift
504
+
505
+ if [ "$#" -eq 0 ]; then
506
+ local commands="standard"
507
+ else
508
+ local commands="$*"
509
+ fi
510
+
511
+ echo "Installing ${package_name}..." >&2
512
+
513
+ [ -n "$HAS_PATCH" ] && apply_ruby_patch "$package_name"
514
+
515
+ for command in $commands; do
516
+ "build_package_${command}" "$package_name"
517
+ done
518
+ }
519
+
520
+ package_option() {
521
+ local package_name="$1"
522
+ local command_name="$2"
523
+ local variable="$(capitalize "${package_name}_${command_name}")_OPTS_ARRAY"
524
+ local array="$variable[@]"
525
+ shift 2
526
+ local value=( "${!array}" "$@" )
527
+ eval "$variable=( \"\${value[@]}\" )"
528
+ }
529
+
530
+ build_package_warn_eol() {
531
+ local package_name="$1"
532
+
533
+ { echo
534
+ echo "WARNING: $package_name is past its end of life and is now unsupported."
535
+ echo "It no longer receives bug fixes or critical security updates."
536
+ echo
537
+ } >&3
538
+ }
539
+
540
+ build_package_warn_unsupported() {
541
+ local package_name="$1"
542
+
543
+ { echo
544
+ echo "WARNING: $package_name is nearing its end of life."
545
+ echo "It only receives critical security updates, no bug fixes."
546
+ echo
547
+ } >&3
548
+ }
549
+
550
+ build_package_standard_build() {
551
+ local package_name="$1"
552
+
553
+ if [ "${MAKEOPTS+defined}" ]; then
554
+ MAKE_OPTS="$MAKEOPTS"
555
+ elif [ -z "${MAKE_OPTS+defined}" ]; then
556
+ MAKE_OPTS="-j $(num_cpu_cores)"
557
+ fi
558
+
559
+ # Support YAML_CONFIGURE_OPTS, RUBY_CONFIGURE_OPTS, etc.
560
+ local package_var_name="$(capitalize "${package_name%%-*}")"
561
+ local PACKAGE_CONFIGURE="${package_var_name}_CONFIGURE"
562
+ local PACKAGE_PREFIX_PATH="${package_var_name}_PREFIX_PATH"
563
+ local PACKAGE_CONFIGURE_OPTS="${package_var_name}_CONFIGURE_OPTS"
564
+ local PACKAGE_CONFIGURE_OPTS_ARRAY="${package_var_name}_CONFIGURE_OPTS_ARRAY[@]"
565
+ local PACKAGE_MAKE_OPTS="${package_var_name}_MAKE_OPTS"
566
+ local PACKAGE_MAKE_OPTS_ARRAY="${package_var_name}_MAKE_OPTS_ARRAY[@]"
567
+ local PACKAGE_CFLAGS="${package_var_name}_CFLAGS"
568
+
569
+ if [ "$package_var_name" = "RUBY" ]; then
570
+ if [[ "$RUBY_CONFIGURE_OPTS ${RUBY_CONFIGURE_OPTS_ARRAY[*]}" != *--with-readline-dir=* ]]; then
571
+ use_homebrew_readline || use_freebsd_readline || true
572
+ fi
573
+ if [[ "$RUBY_CONFIGURE_OPTS ${RUBY_CONFIGURE_OPTS_ARRAY[*]}" != *--with-libffi-dir=* ]]; then
574
+ use_freebsd_libffi || true
575
+ fi
576
+ if [[ "$RUBY_CONFIGURE_OPTS ${RUBY_CONFIGURE_OPTS_ARRAY[*]}" != *--with-libyaml-dir=* ]]; then
577
+ use_homebrew_yaml || use_freebsd_yaml || true
578
+ fi
579
+ if [[ "$RUBY_CONFIGURE_OPTS ${RUBY_CONFIGURE_OPTS_ARRAY[*]}" != *--with-gmp-dir=* ]]; then
580
+ use_homebrew_gmp || true
581
+ fi
582
+ if [[ "$RUBY_CONFIGURE_OPTS ${RUBY_CONFIGURE_OPTS_ARRAY[*]}" != *--with-openssl-dir=* ]]; then
583
+ if is_freebsd && [ -f /usr/local/include/openssl/ssl.h ]; then
584
+ # use openssl installed from Ports Collection
585
+ package_option ruby configure --with-openssl-dir="/usr/local"
586
+ fi
587
+ fi
588
+ fi
589
+
590
+ ( if [ "${CFLAGS+defined}" ] || [ "${!PACKAGE_CFLAGS+defined}" ]; then
591
+ export CFLAGS="$CFLAGS ${!PACKAGE_CFLAGS}"
592
+ fi
593
+ if [ -z "$CC" ] && is_mac -ge 1010; then
594
+ export CC=clang
595
+ fi
596
+ ${!PACKAGE_CONFIGURE:-./configure} --prefix="${!PACKAGE_PREFIX_PATH:-$PREFIX_PATH}" \
597
+ "${!PACKAGE_CONFIGURE_OPTS_ARRAY}" $CONFIGURE_OPTS ${!PACKAGE_CONFIGURE_OPTS} || return 1
598
+ ) >&4 2>&1
599
+
600
+ { "$MAKE" "${!PACKAGE_MAKE_OPTS_ARRAY}" $MAKE_OPTS ${!PACKAGE_MAKE_OPTS}
601
+ } >&4 2>&1
602
+ }
603
+
604
+ build_package_standard_install() {
605
+ local package_name="$1"
606
+ local package_var_name="$(capitalize "${package_name%%-*}")"
607
+
608
+ local PACKAGE_MAKE_INSTALL_OPTS="${package_var_name}_MAKE_INSTALL_OPTS"
609
+ local PACKAGE_MAKE_INSTALL_OPTS_ARRAY="${package_var_name}_MAKE_INSTALL_OPTS_ARRAY[@]"
610
+
611
+ { "$MAKE" ${MAKE_INSTALL_TARGET:-install} "${!PACKAGE_MAKE_INSTALL_OPTS_ARRAY}" $MAKE_INSTALL_OPTS ${!PACKAGE_MAKE_INSTALL_OPTS}
612
+ } >&4 2>&1
613
+ }
614
+
615
+ build_package_standard_install_with_bundled_gems() {
616
+ { "$MAKE" update-gems
617
+ "$MAKE" extract-gems
618
+ } >&4 2>&1
619
+
620
+ build_package_standard_install "$@"
621
+ }
622
+
623
+ # Backward Compatibility for standard function
624
+ build_package_standard() {
625
+ build_package_standard_build "$@"
626
+ build_package_standard_install "$@"
627
+ }
628
+
629
+ build_package_autoconf() {
630
+ { autoreconf -i
631
+ } >&4 2>&1
632
+ }
633
+
634
+ build_package_ruby() {
635
+ local package_name="$1"
636
+
637
+ { "$RUBY_BIN" setup.rb
638
+ } >&4 2>&1
639
+ }
640
+
641
+ build_package_ree_installer() {
642
+ build_package_auto_tcltk
643
+
644
+ local options=""
645
+ is_mac && options="--no-tcmalloc"
646
+
647
+ local option
648
+ for option in ${RUBY_CONFIGURE_OPTS_ARRAY[@]} $RUBY_CONFIGURE_OPTS; do
649
+ options="$options -c $option"
650
+ done
651
+
652
+ # Work around install_useful_libraries crash with --dont-install-useful-gems
653
+ mkdir -p "$PREFIX_PATH/lib/ruby/gems/1.8/gems"
654
+
655
+ { ./installer --auto "$PREFIX_PATH" --dont-install-useful-gems $options $CONFIGURE_OPTS
656
+ } >&4 2>&1
657
+ }
658
+
659
+ build_package_rbx() {
660
+ local package_name="$1"
661
+
662
+ { [ ! -e "Gemfile" ] || bundle --path=vendor/bundle
663
+ if [ -n "$RUBY_BUILD_CACHE_PATH" ]; then
664
+ mkdir -p vendor
665
+ ln -s "$RUBY_BUILD_CACHE_PATH" vendor/prebuilt
666
+ fi
667
+
668
+ local opt
669
+ local -a configure_opts
670
+ for opt in "${RUBY_CONFIGURE_OPTS_ARRAY[@]}"; do
671
+ if [[ $opt == --with-openssl-dir=* ]]; then
672
+ local openssl_dir="${opt#*=}"
673
+ configure_opts[${#configure_opts[@]}]="--with-lib-dir=${openssl_dir}/lib"
674
+ configure_opts[${#configure_opts[@]}]="--with-include-dir=${openssl_dir}/include"
675
+ else
676
+ configure_opts[${#configure_opts[@]}]="$opt"
677
+ fi
678
+ done
679
+
680
+ RUBYOPT="-rrubygems $RUBYOPT" ./configure --prefix="$PREFIX_PATH" "${configure_opts[@]}" $RUBY_CONFIGURE_OPTS
681
+ rake install
682
+ fix_rbx_gem_binstubs "$PREFIX_PATH"
683
+ fix_rbx_irb "$PREFIX_PATH"
684
+ } >&4 2>&1
685
+ }
686
+
687
+ build_package_mruby() {
688
+ { ./minirake
689
+ mkdir -p "$PREFIX_PATH"
690
+ cp -fR build/host/* include "$PREFIX_PATH"
691
+ ln -fs mruby "$PREFIX_PATH/bin/ruby"
692
+ ln -fs mirb "$PREFIX_PATH/bin/irb"
693
+ } >&4 2>&1
694
+ }
695
+
696
+ build_package_picoruby() {
697
+ { ./minirake
698
+ mkdir -p "$PREFIX_PATH"
699
+ cp -fR build/host/* include "$PREFIX_PATH"
700
+ ln -fs picoruby "$PREFIX_PATH/bin/ruby"
701
+ ln -fs picoirb "$PREFIX_PATH/bin/irb"
702
+ } >&4 2>&1
703
+ }
704
+
705
+ build_package_maglev() {
706
+ build_package_copy
707
+
708
+ { cd "${PREFIX_PATH}"
709
+ ./install.sh
710
+ cd "${PREFIX_PATH}/bin"
711
+ echo "Creating symlink for ruby*"
712
+ ln -fs maglev-ruby ruby
713
+ echo "Creating symlink for irb*"
714
+ ln -fs maglev-irb irb
715
+ } >&4 2>&1
716
+ echo
717
+ echo "Run 'maglev start' to start up the stone before using 'ruby' or 'irb'"
718
+ }
719
+
720
+ build_package_topaz() {
721
+ build_package_copy
722
+ { cd "${PREFIX_PATH}/bin"
723
+ echo "Creating symlink for ruby*"
724
+ ln -fs topaz ruby
725
+ } >&4 2>&1
726
+ }
727
+
728
+ topaz_architecture() {
729
+ case "$(uname -s)" in
730
+ "Darwin") echo "osx64";;
731
+ "Linux") [[ "$(uname -m)" = "x86_64" ]] && echo "linux64" || echo "linux32";;
732
+ *)
733
+ echo "no nightly builds available" >&2
734
+ exit 1;;
735
+ esac
736
+ }
737
+
738
+ build_package_jruby() {
739
+ build_package_copy
740
+ cd "${PREFIX_PATH}/bin"
741
+ ln -fs jruby ruby
742
+ chmod +x ruby
743
+ install_jruby_launcher
744
+ remove_windows_files
745
+ fix_jruby_shebangs
746
+ }
747
+
748
+ install_jruby_launcher() {
749
+ cd "${PREFIX_PATH}/bin"
750
+ { ./ruby gem install jruby-launcher
751
+ } >&4 2>&1
752
+ }
753
+
754
+ fix_jruby_shebangs() {
755
+ for file in "${PREFIX_PATH}/bin"/*; do
756
+ if [ "$(head -c 20 "$file" | tr -d '\0')" = "#!/usr/bin/env jruby" ]; then
757
+ sed -i.bak "1 s:.*:#\!${PREFIX_PATH}\/bin\/jruby:" "$file"
758
+ rm "$file".bak
759
+ fi
760
+ done
761
+ }
762
+
763
+ build_package_truffleruby() {
764
+ clean_prefix_path_truffleruby || return $?
765
+ build_package_copy
766
+
767
+ cd "${PREFIX_PATH}"
768
+ "${PREFIX_PATH}/lib/truffle/post_install_hook.sh"
769
+ }
770
+
771
+ build_package_truffleruby_graalvm() {
772
+ clean_prefix_path_truffleruby || return $?
773
+ build_package_copy_to "${PREFIX_PATH}/graalvm"
774
+
775
+ cd "${PREFIX_PATH}/graalvm"
776
+ if is_mac; then
777
+ cd Contents/Home || return $?
778
+ fi
779
+
780
+ if [ -e bin/gu ]; then
781
+ bin/gu install ruby || return $?
782
+ fi
783
+
784
+ local ruby_home
785
+ ruby_home=$(bin/ruby -e 'print RbConfig::CONFIG["prefix"]')
786
+
787
+ # Make gu available in PATH (useful to install other languages)
788
+ ln -s "$PWD/bin/gu" "$ruby_home/bin/gu"
789
+
790
+ cd "${PREFIX_PATH}"
791
+ ln -s "${ruby_home#"$PREFIX_PATH/"}/bin" . || return $?
792
+
793
+ "$ruby_home/lib/truffle/post_install_hook.sh"
794
+ }
795
+
796
+ build_package_artichoke() {
797
+ build_package_copy
798
+
799
+ mkdir -p "$PREFIX_PATH/bin"
800
+ cd "${PREFIX_PATH}/bin"
801
+ ln -fs ../artichoke ruby
802
+ ln -fs ../airb irb
803
+ ln -fs ../artichoke artichoke
804
+ ln -fs ../airb airb
805
+ }
806
+
807
+ remove_windows_files() {
808
+ cd "$PREFIX_PATH"
809
+ rm -f bin/*.exe bin/*.dll bin/*.bat bin/jruby.sh
810
+ }
811
+
812
+ clean_prefix_path_truffleruby() {
813
+ if [ -d "$PREFIX_PATH" ] &&
814
+ [ ! -e "$PREFIX_PATH/bin/truffleruby" ] &&
815
+ [ ! -z "$(ls -A $PREFIX_PATH)" ]; then
816
+ echo
817
+ echo "ERROR: cannot install TruffleRuby to $PREFIX_PATH, which does not look like a valid TruffleRuby prefix" >&2
818
+ echo "TruffleRuby only supports being installed to a not existing directory, an empty directory, or replacing an existing TruffleRuby installation"
819
+ echo "See https://github.com/oracle/truffleruby/issues/1389 for details" >&2
820
+ return 1
821
+ fi
822
+
823
+ # Make sure there are no leftover files in $PREFIX_PATH
824
+ rm -rf "$PREFIX_PATH"
825
+ }
826
+
827
+ build_package_copy_to() {
828
+ to="$1"
829
+ mkdir -p "$to"
830
+ cp -fR . "$to"
831
+ }
832
+
833
+ build_package_copy() {
834
+ build_package_copy_to "$PREFIX_PATH"
835
+ }
836
+
837
+ before_install_package() {
838
+ local stub=1
839
+ }
840
+
841
+ after_install_package() {
842
+ local stub=1
843
+ }
844
+
845
+ fix_rbx_gem_binstubs() {
846
+ local prefix="$1"
847
+ local gemdir="${prefix}/gems/bin"
848
+ local bindir="${prefix}/bin"
849
+ local file binstub
850
+ # Symlink Rubinius' `gems/bin/` into `bin/`
851
+ if [ -d "$gemdir" ] && [ ! -L "$gemdir" ]; then
852
+ for file in "$gemdir"/*; do
853
+ binstub="${bindir}/${file##*/}"
854
+ rm -f "$binstub"
855
+ { echo "#!${bindir}/ruby"
856
+ grep -v '^#!' "$file"
857
+ } > "$binstub"
858
+ chmod +x "$binstub"
859
+ done
860
+ rm -rf "$gemdir"
861
+ ln -s ../bin "$gemdir"
862
+ fi
863
+ }
864
+
865
+ fix_rbx_irb() {
866
+ local prefix="$1"
867
+ "${prefix}/bin/irb" --version &>/dev/null ||
868
+ "${prefix}/bin/gem" install rubysl-tracer -v '~> 2.0' --no-rdoc --no-ri &>/dev/null ||
869
+ true
870
+ }
871
+
872
+ require_java() {
873
+ local required="$1"
874
+ local java_version="$(java -version 2>&1)"
875
+ local version_string="$(grep 'java version' <<<"$java_version" | head -1 | grep -o '[0-9.]\+' | head -1 || true)"
876
+ [ -n "$version_string" ] || version_string="$(grep 'openjdk version' <<<"$java_version" | head -1 | grep -o '[0-9.]\+' | head -1 || true)"
877
+ IFS="."
878
+ local nums=($version_string)
879
+ IFS="$OLDIFS"
880
+ local found_version="${nums[0]}"
881
+ [ "$found_version" -gt 1 ] 2>/dev/null || found_version="${nums[1]}"
882
+ [ "$found_version" -ge "$required" ] 2>/dev/null && return 0
883
+ colorize 1 "ERROR" >&3
884
+ echo ": Java >= ${required} required, but your Java version was:" >&3
885
+ cat <<<"$java_version" >&3
886
+ return 1
887
+ }
888
+
889
+ # keep for backwards compatibility
890
+ require_java7() {
891
+ require_java 7
892
+ }
893
+
894
+ require_gcc() {
895
+ local gcc="$(locate_gcc || true)"
896
+
897
+ if [ -z "$gcc" ]; then
898
+ { echo
899
+ colorize 1 "ERROR"
900
+ echo ": This package must be compiled with GCC, but ruby-build couldn't"
901
+ echo "find a suitable \`gcc\` executable on your system. Please install GCC"
902
+ echo "and try again."
903
+ echo
904
+
905
+ if is_mac; then
906
+ colorize 1 "DETAILS"
907
+ echo ": Apple no longer includes the official GCC compiler with Xcode"
908
+ echo "as of version 4.2. Instead, the \`gcc\` executable is a symlink to"
909
+ echo "\`llvm-gcc\`, a modified version of GCC which outputs LLVM bytecode."
910
+ echo
911
+ echo "For most programs the \`llvm-gcc\` compiler works fine. However,"
912
+ echo "versions of Ruby older than 1.9.3-p125 are incompatible with"
913
+ echo "\`llvm-gcc\`. To build older versions of Ruby you must have the official"
914
+ echo "GCC compiler installed on your system."
915
+ echo
916
+
917
+ colorize 1 "TO FIX THE PROBLEM"
918
+ if type brew &>/dev/null; then
919
+ echo ": Install Homebrew's GCC package with this"
920
+ echo -n "command: "
921
+ colorize 4 "brew install gcc@4.9"
922
+ else
923
+ echo ": Install the official GCC compiler using these"
924
+ echo -n "packages: "
925
+ colorize 4 "https://github.com/kennethreitz/osx-gcc-installer/downloads"
926
+ fi
927
+
928
+ echo
929
+ echo
930
+ echo "You will need to install the official GCC compiler to build older"
931
+ echo "versions of Ruby even if you have installed Apple's Command Line Tools"
932
+ echo "for Xcode package. The Command Line Tools for Xcode package only"
933
+ echo "includes \`llvm-gcc\`."
934
+ fi
935
+ } >&3
936
+ return 1
937
+ fi
938
+
939
+ export CC="$gcc"
940
+ if is_mac -ge 1010; then
941
+ export MACOSX_DEPLOYMENT_TARGET=10.9
942
+ fi
943
+ }
944
+
945
+ locate_gcc() {
946
+ local gcc gccs
947
+ IFS=: gccs=($(gccs_in_path))
948
+ IFS="$OLDIFS"
949
+
950
+ verify_gcc "$CC" ||
951
+ verify_gcc "$(command -v gcc || true)" || {
952
+ for gcc in "${gccs[@]}"; do
953
+ verify_gcc "$gcc" && break || true
954
+ done
955
+ }
956
+
957
+ return 1
958
+ }
959
+
960
+ gccs_in_path() {
961
+ local gcc path paths
962
+ local gccs=()
963
+ IFS=: paths=($PATH)
964
+ IFS="$OLDIFS"
965
+
966
+ shopt -s nullglob
967
+ for path in "${paths[@]}"; do
968
+ for gcc in "$path"/gcc-*; do
969
+ gccs["${#gccs[@]}"]="$gcc"
970
+ done
971
+ done
972
+ shopt -u nullglob
973
+
974
+ printf :%s "${gccs[@]}"
975
+ }
976
+
977
+ verify_gcc() {
978
+ local gcc="$1"
979
+ if [ -z "$gcc" ]; then
980
+ return 1
981
+ fi
982
+
983
+ local version="$("$gcc" --version 2>/dev/null || true)"
984
+ if [ -z "$version" ]; then
985
+ return 1
986
+ fi
987
+
988
+ if echo "$version" | grep LLVM >/dev/null; then
989
+ return 1
990
+ fi
991
+
992
+ echo "$gcc"
993
+ }
994
+
995
+ require_llvm() {
996
+ local llvm_version="$1"
997
+ if is_mac -ge 1010; then
998
+ if [[ "$RUBY_CONFIGURE_OPTS" != *--llvm-* ]]; then
999
+ case "$llvm_version" in
1000
+ 3.2 )
1001
+ package_option ruby configure --prebuilt-name="llvm-3.2-x86_64-apple-darwin13.tar.bz2"
1002
+ ;;
1003
+ 3.[56] )
1004
+ local llvm_config="$(locate_llvm "$llvm_version")"
1005
+ if [ -n "$llvm_config" ]; then
1006
+ package_option ruby configure --llvm-config="$llvm_config"
1007
+ else
1008
+ local homebrew_package="llvm@$llvm_version"
1009
+ { echo
1010
+ colorize 1 "ERROR"
1011
+ echo ": Rubinius will not be able to compile using Apple's LLVM-based "
1012
+ echo "build tools on OS X. You will need to install LLVM $llvm_version first."
1013
+ echo
1014
+ colorize 1 "TO FIX THE PROBLEM"
1015
+ echo ": Install Homebrew's llvm package with this"
1016
+ echo -n "command: "
1017
+ colorize 4 "brew install $homebrew_package"
1018
+ echo
1019
+ } >&3
1020
+ return 1
1021
+ fi
1022
+ ;;
1023
+ esac
1024
+ fi
1025
+ fi
1026
+ }
1027
+
1028
+ locate_llvm() {
1029
+ local llvm_version="$1"
1030
+ local package llvm_config
1031
+ shopt -s nullglob
1032
+ for package in `brew list 2>/dev/null | grep "^llvm"`; do
1033
+ llvm_config="$(echo "$(brew --prefix "$package")/bin/llvm-config"*)"
1034
+ if [ -n "$llvm_config" ] && [[ "$("$llvm_config" --version)" = "$llvm_version"* ]]; then
1035
+ echo "$llvm_config"
1036
+ break
1037
+ fi
1038
+ done
1039
+ shopt -u nullglob
1040
+ }
1041
+
1042
+ needs_yaml() {
1043
+ [[ "$RUBY_CONFIGURE_OPTS" != *--with-libyaml-dir=* ]] &&
1044
+ ! use_homebrew_yaml
1045
+ }
1046
+
1047
+ use_homebrew_yaml() {
1048
+ local libdir="$(brew --prefix libyaml 2>/dev/null || true)"
1049
+ if [ -d "$libdir" ]; then
1050
+ echo "ruby-build: using libyaml from homebrew"
1051
+ package_option ruby configure --with-libyaml-dir="$libdir"
1052
+ else
1053
+ return 1
1054
+ fi
1055
+ }
1056
+
1057
+ use_freebsd_yaml() {
1058
+ if is_freebsd; then
1059
+ local libyaml_prefix="$(freebsd_package_prefix libyaml)"
1060
+ if [ -n "$libyaml_prefix" ]; then
1061
+ package_option ruby configure --with-libyaml-dir="$libyaml_prefix"
1062
+ fi
1063
+ fi
1064
+ }
1065
+
1066
+ use_homebrew_gmp() {
1067
+ local libdir="$(brew --prefix gmp 2>/dev/null || true)"
1068
+ if [ -d "$libdir" ]; then
1069
+ echo "ruby-build: using gmp from homebrew"
1070
+ package_option ruby configure --with-gmp-dir="$libdir"
1071
+ else
1072
+ return 1
1073
+ fi
1074
+ }
1075
+
1076
+ use_freebsd_readline() {
1077
+ if is_freebsd; then
1078
+ local readline_prefix="$(freebsd_package_prefix readline)"
1079
+ local libedit_prefix="$(freebsd_package_prefix libedit)"
1080
+ if [ -n "$readline_prefix" ]; then
1081
+ package_option ruby configure --with-readline-dir="$readline_prefix"
1082
+ elif [ -n "$libedit_prefix" ]; then
1083
+ package_option ruby configure --enable-libedit
1084
+ package_option ruby configure --with-libedit-dir="$libedit_prefix"
1085
+ fi
1086
+ fi
1087
+ }
1088
+
1089
+ use_homebrew_readline() {
1090
+ local libdir="$(brew --prefix readline 2>/dev/null || true)"
1091
+ if [ -d "$libdir" ]; then
1092
+ echo "ruby-build: using readline from homebrew"
1093
+ package_option ruby configure --with-readline-dir="$libdir"
1094
+ else
1095
+ return 1
1096
+ fi
1097
+ }
1098
+
1099
+ use_freebsd_libffi() {
1100
+ if is_freebsd; then
1101
+ local libffi_prefix="$(freebsd_package_prefix libffi)"
1102
+ if [ -n "$libffi_prefix" ]; then
1103
+ package_option ruby configure --with-libffi-dir="$libffi_prefix"
1104
+ fi
1105
+ fi
1106
+ }
1107
+
1108
+ has_broken_mac_openssl() {
1109
+ is_mac || return 1
1110
+ local openssl_version="$(/usr/bin/openssl version 2>/dev/null || true)"
1111
+ [[ $openssl_version = "OpenSSL 0.9.8"?* || $openssl_version = "LibreSSL"* ]]
1112
+ }
1113
+
1114
+ system_openssl_version() {
1115
+ local version_text=$(printf '#include <openssl/opensslv.h>\nOPENSSL_VERSION_TEXT\n' | cc -xc -E - 2>/dev/null)
1116
+ if [[ $version_text == *"OpenSSL "* ]]; then
1117
+ local version=${version_text#*OpenSSL }
1118
+ version=${version%% *}
1119
+ echo $version | sed 's/[^0-9]//g' | sed 's/^0*//'
1120
+ else
1121
+ echo "No system openssl version was found, ensure openssl headers are installed (https://github.com/rbenv/ruby-build/wiki#suggested-build-environment)" >&2
1122
+ echo 000
1123
+ fi
1124
+ }
1125
+
1126
+ # openssl gem 1.1.1
1127
+ needs_openssl_096_102() {
1128
+ [[ "$RUBY_CONFIGURE_OPTS" == *--with-openssl-dir=* ]] && return 1
1129
+ has_broken_mac_openssl && return 0
1130
+
1131
+ local version=$(system_openssl_version)
1132
+ (( $version < 96 || $version >= 110 ))
1133
+ }
1134
+
1135
+ # openssl gem 2.2.1
1136
+ needs_openssl_101_111() {
1137
+ [[ "$RUBY_CONFIGURE_OPTS" == *--with-openssl-dir=* ]] && return 1
1138
+ has_broken_mac_openssl && return 0
1139
+
1140
+ local version=$(system_openssl_version)
1141
+ (( $version < 101 || $version >= 300 ))
1142
+ }
1143
+
1144
+ # openssl gem 3.0.0
1145
+ needs_openssl_102_300() {
1146
+ [[ "$RUBY_CONFIGURE_OPTS" == *--with-openssl-dir=* ]] && return 1
1147
+ has_broken_mac_openssl && return 0
1148
+
1149
+ local version=$(system_openssl_version)
1150
+ (( $version < 102 || $version >= 400 ))
1151
+ }
1152
+
1153
+ use_homebrew_openssl() {
1154
+ local ssldir="$(brew --prefix openssl@1.1 2>/dev/null || true)"
1155
+ if [ -d "$ssldir" ]; then
1156
+ echo "ruby-build: using openssl from homebrew"
1157
+ package_option ruby configure --with-openssl-dir="$ssldir"
1158
+ else
1159
+ colorize 1 "ERROR openssl@1.1 from Homebrew is required, run 'brew install openssl@1.1'"
1160
+ return 1
1161
+ fi
1162
+ }
1163
+
1164
+ build_package_openssl() {
1165
+ # Install to a subdirectory since we don't want shims for bin/openssl.
1166
+ OPENSSL_PREFIX_PATH="${PREFIX_PATH}/openssl"
1167
+
1168
+ # Put openssl.conf, certs, etc in ~/.rbenv/versions/*/openssl/ssl
1169
+ OPENSSLDIR="${OPENSSLDIR:-$OPENSSL_PREFIX_PATH/ssl}"
1170
+
1171
+ # Tell Ruby to use this openssl for its extension.
1172
+ package_option ruby configure --with-openssl-dir="$OPENSSL_PREFIX_PATH"
1173
+
1174
+ # Make sure pkg-config finds our build first.
1175
+ export PKG_CONFIG_PATH="${OPENSSL_PREFIX_PATH}/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}"
1176
+
1177
+ # Hint OpenSSL that we prefer a 64-bit build.
1178
+ export KERNEL_BITS="64"
1179
+ OPENSSL_CONFIGURE="${OPENSSL_CONFIGURE:-./config}"
1180
+
1181
+ local nokerberos
1182
+ [[ "$1" != openssl-1.0.* ]] || nokerberos=1
1183
+
1184
+ # Compile a shared lib with zlib dynamically linked.
1185
+ package_option openssl configure --openssldir="$OPENSSLDIR" zlib-dynamic no-ssl3 shared ${nokerberos:+no-ssl2 no-krb5}
1186
+
1187
+ # Default MAKE_OPTS are -j 2 which can confuse the build. Thankfully, make
1188
+ # gives precedence to the last -j option, so we can override that.
1189
+ package_option openssl make -j 1
1190
+
1191
+ # Use install_sw install_ssldirs instead of install to skip building docs which is slow.
1192
+ # OpenSSL 1.1+ also needs install_ssldirs, 1.0 does not have that target.
1193
+ if [[ "$1" == openssl-1.0.* ]]; then
1194
+ MAKE_INSTALL_TARGET="install_sw" build_package_standard "$@"
1195
+ else
1196
+ MAKE_INSTALL_TARGET="install_sw install_ssldirs" build_package_standard "$@"
1197
+ fi
1198
+
1199
+ local pem_file="$OPENSSLDIR/cert.pem"
1200
+ if is_mac; then
1201
+ # Extract root certs from the system keychain in .pem format.
1202
+ security find-certificate -a -p /Library/Keychains/System.keychain > "$pem_file"
1203
+ security find-certificate -a -p /System/Library/Keychains/SystemRootCertificates.keychain >> "$pem_file"
1204
+ elif [ -e /etc/pki/tls/cert.pem ]; then # RedHat
1205
+ # See https://github.com/rubygems/rubygems/issues/2415#issuecomment-509806259
1206
+ rm -rf "$OPENSSLDIR/certs" "$pem_file"
1207
+ ln -s /etc/pki/tls/certs "$OPENSSLDIR/certs"
1208
+ ln -s /etc/pki/tls/cert.pem "$pem_file"
1209
+ elif [ -e /etc/ssl/certs/ca-certificates.crt ]; then # Debian
1210
+ # See https://github.com/rubygems/rubygems/issues/2415#issuecomment-509806259
1211
+ rm -rf "$OPENSSLDIR/certs" "$pem_file"
1212
+ ln -s /etc/ssl/certs "$OPENSSLDIR/certs"
1213
+ ln -s /etc/ssl/certs/ca-certificates.crt "$pem_file"
1214
+ elif type -p openssl >/dev/null; then
1215
+ # symlink to the system openssl certs
1216
+ local SYSTEM_OPENSSLDIR
1217
+ SYSTEM_OPENSSLDIR=$(openssl version -d 2>/dev/null | cut -d'"' -f2)
1218
+ if [ -n "$SYSTEM_OPENSSLDIR" ]; then
1219
+ ln -sf "$SYSTEM_OPENSSLDIR/cert.pem" "$OPENSSLDIR/cert.pem"
1220
+ ln -snf "$SYSTEM_OPENSSLDIR/certs" "$OPENSSLDIR/certs"
1221
+ fi
1222
+ else
1223
+ echo "Could not find OpenSSL certificates" >&2
1224
+ exit 1
1225
+ fi
1226
+ }
1227
+
1228
+ # Post-install check that the openssl extension was built.
1229
+ build_package_verify_openssl() {
1230
+ "$RUBY_BIN" -e '
1231
+ manager = ARGV[0]
1232
+ packages = {
1233
+ "apt-get" => Hash.new {|h,k| "lib#{k}-dev" }.update(
1234
+ "openssl" => "libssl-dev",
1235
+ "zlib" => "zlib1g-dev"
1236
+ ),
1237
+ "yum" => Hash.new {|h,k| "#{k}-devel" }.update(
1238
+ "yaml" => "libyaml-devel"
1239
+ )
1240
+ }
1241
+
1242
+ failed = %w[openssl readline zlib yaml].reject do |lib|
1243
+ begin
1244
+ require lib
1245
+ rescue LoadError
1246
+ $stderr.puts "The Ruby #{lib} extension was not compiled."
1247
+ end
1248
+ end
1249
+
1250
+ if failed.size > 0
1251
+ $stderr.puts "ERROR: Ruby install aborted due to missing extensions"
1252
+ $stderr.print "Try running `%s install -y %s` to fetch missing dependencies.\n\n" % [
1253
+ manager,
1254
+ failed.map { |lib| packages.fetch(manager)[lib] }.join(" ")
1255
+ ] unless manager.empty?
1256
+ $stderr.puts "Configure options used:"
1257
+ require "rbconfig"; require "shellwords"
1258
+ RbConfig::CONFIG.fetch("configure_args").shellsplit.each { |arg| $stderr.puts " #{arg}" }
1259
+ exit 1
1260
+ end
1261
+ ' "$(basename "$(type -p yum apt-get | head -1)")" >&4 2>&1
1262
+ }
1263
+
1264
+ # Ensure that directories listed in LDFLAGS exist
1265
+ build_package_ldflags_dirs() {
1266
+ local arg dir
1267
+ set - $LDFLAGS
1268
+ while [ $# -gt 0 ]; do
1269
+ dir=""
1270
+ case "$1" in
1271
+ -L ) dir="$2" ;;
1272
+ -L* ) dir="${1#-L}" ;;
1273
+ esac
1274
+ [ -z "$dir" ] || mkdir -p "$dir"
1275
+ shift 1
1276
+ done
1277
+ }
1278
+
1279
+ build_package_enable_shared() {
1280
+ if [[ " ${RUBY_CONFIGURE_OPTS} " != *" --disable-shared"* ]]; then
1281
+ package_option ruby configure --enable-shared
1282
+ fi
1283
+ }
1284
+
1285
+ build_package_auto_tcltk() {
1286
+ if is_mac && [ ! -d /usr/include/X11 ]; then
1287
+ if [ -d /opt/X11/include ]; then
1288
+ if [[ "$CPPFLAGS" != *-I/opt/X11/include* ]]; then
1289
+ export CPPFLAGS="-I/opt/X11/include $CPPFLAGS"
1290
+ fi
1291
+ else
1292
+ package_option ruby configure --without-tk
1293
+ fi
1294
+ fi
1295
+ }
1296
+
1297
+ rake() {
1298
+ if [ -e "./Gemfile" ]; then
1299
+ bundle exec rake "$@"
1300
+ else
1301
+ isolated_gem_dependency "rake --version" rake -v '~> 10.1.0'
1302
+ command rake "$@"
1303
+ fi
1304
+ }
1305
+
1306
+ bundle() {
1307
+ isolated_gem_dependency "bundle --version" bundler -v '~> 1.3.5'
1308
+ command bundle "$@"
1309
+ }
1310
+
1311
+ isolated_gem_dependency() {
1312
+ set +E
1313
+ ( command $1 &>/dev/null ) || {
1314
+ set -E
1315
+ shift 1
1316
+ isolated_gem_install "$@"
1317
+ }
1318
+ set -E
1319
+ }
1320
+
1321
+ isolated_gem_install() {
1322
+ export GEM_HOME="${PWD}/.gem"
1323
+ export PATH="${GEM_HOME}/bin:${PATH}"
1324
+ gem install "$@"
1325
+ }
1326
+
1327
+ apply_ruby_patch() {
1328
+ local patchfile
1329
+ case "$1" in
1330
+ ruby-* | jruby-* | rubinius-* | truffleruby-* )
1331
+ patchfile="$(mktemp "${TMP}/ruby-patch.XXXXXX")"
1332
+ cat "${2:--}" >"$patchfile"
1333
+
1334
+ local striplevel=0
1335
+ grep -q '^--- a/' "$patchfile" && striplevel=1
1336
+ patch -p$striplevel --force -i "$patchfile"
1337
+ ;;
1338
+ esac
1339
+ }
1340
+
1341
+ version() {
1342
+ local git_revision
1343
+ # Read the revision from git if the remote points to "ruby-build" repository
1344
+ if GIT_DIR="$RUBY_BUILD_INSTALL_PREFIX/.git" git remote -v 2>/dev/null | grep -q /ruby-build; then
1345
+ git_revision="$(GIT_DIR="$RUBY_BUILD_INSTALL_PREFIX/.git" git describe --tags HEAD 2>/dev/null || true)"
1346
+ git_revision="${git_revision#v}"
1347
+ fi
1348
+ echo "ruby-build ${git_revision:-$RUBY_BUILD_VERSION}"
1349
+ }
1350
+
1351
+ usage() {
1352
+ sed -ne '/^#/!q;s/.\{1,2\}//;1,2d;p' < "$0"
1353
+ [ -z "$1" ] || exit "$1"
1354
+ }
1355
+
1356
+ # list all versions
1357
+ list_definitions() {
1358
+ { for DEFINITION_DIR in "${RUBY_BUILD_DEFINITIONS[@]}"; do
1359
+ [ -d "$DEFINITION_DIR" ] && ls "$DEFINITION_DIR"
1360
+ done
1361
+ } | sort_versions | uniq
1362
+ }
1363
+
1364
+ # list only latest stable versions excluding RC, preview, dev and EoL'ed
1365
+ list_maintained_versions() {
1366
+ { for DEFINITION_DIR in "${RUBY_BUILD_DEFINITIONS[@]}"; do
1367
+ [ -d "$DEFINITION_DIR" ] && \
1368
+ grep -L -e warn_eol "$DEFINITION_DIR"/* 2>/dev/null | \
1369
+ sed 's|.*/||' | \
1370
+ grep -v -e '-rc[0-9]*$' -e '-preview[0-9]*$' -e '-dev$'
1371
+ done
1372
+ } | extract_latest_versions | sort_versions | uniq
1373
+ }
1374
+
1375
+ extract_latest_versions() {
1376
+ # sort in this function looks redundunt but it is necessary
1377
+ # rbx-3.99 appears latest unless the sort
1378
+ sed 'h; s/[-]/./g; s/.p\([[:digit:]]\)/.z.\1/; s/$/.z/; G; s/\n/ /' | \
1379
+ LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | \
1380
+ sed 's/[.]/ /; s/[0-9].*z //; s/^\([0-9].[0-9]\)/mri\1 \1/' | \
1381
+ awk '{ latest[$1] =$2 } END{ for(key in latest) { print latest[key] } }'
1382
+ }
1383
+
1384
+ sort_versions() {
1385
+ sed 'h; s/[-]/./g; s/.p\([[:digit:]]\)/.z.\1/; s/$/.z/; G; s/\n/ /' | \
1386
+ LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}'
1387
+ }
1388
+
1389
+
1390
+ unset VERBOSE
1391
+ unset KEEP_BUILD_PATH
1392
+ unset HAS_PATCH
1393
+ unset IPV4
1394
+ unset IPV6
1395
+
1396
+ RUBY_BUILD_INSTALL_PREFIX="$(abs_dirname "$0")/.."
1397
+
1398
+ IFS=: RUBY_BUILD_DEFINITIONS=($RUBY_BUILD_DEFINITIONS ${RUBY_BUILD_ROOT:-$RUBY_BUILD_INSTALL_PREFIX}/share/ruby-build)
1399
+ IFS="$OLDIFS"
1400
+
1401
+ parse_options "$@"
1402
+
1403
+ for option in "${OPTIONS[@]}"; do
1404
+ case "$option" in
1405
+ "h" | "help" )
1406
+ version
1407
+ echo
1408
+ usage 0
1409
+ ;;
1410
+ "definitions" )
1411
+ list_definitions
1412
+ exit 0
1413
+ ;;
1414
+ "l" | "list")
1415
+ list_maintained_versions
1416
+ exit 0
1417
+ ;;
1418
+ "k" | "keep" )
1419
+ KEEP_BUILD_PATH=true
1420
+ ;;
1421
+ "v" | "verbose" )
1422
+ VERBOSE=true
1423
+ ;;
1424
+ "p" | "patch" )
1425
+ HAS_PATCH=true
1426
+ ;;
1427
+ "4" | "ipv4")
1428
+ IPV4=true
1429
+ ;;
1430
+ "6" | "ipv6")
1431
+ IPV6=true
1432
+ ;;
1433
+ "version" )
1434
+ version
1435
+ exit 0
1436
+ ;;
1437
+ esac
1438
+ done
1439
+
1440
+ [ "${#ARGUMENTS[@]}" -eq 2 ] || usage 1 >&2
1441
+
1442
+ DEFINITION_PATH="${ARGUMENTS[0]}"
1443
+ if [ -z "$DEFINITION_PATH" ]; then
1444
+ usage 1 >&2
1445
+ elif [ ! -f "$DEFINITION_PATH" ]; then
1446
+ for DEFINITION_DIR in "${RUBY_BUILD_DEFINITIONS[@]}"; do
1447
+ if [ -f "${DEFINITION_DIR}/${DEFINITION_PATH}" ]; then
1448
+ DEFINITION_PATH="${DEFINITION_DIR}/${DEFINITION_PATH}"
1449
+ break
1450
+ fi
1451
+ done
1452
+
1453
+ if [ ! -f "$DEFINITION_PATH" ]; then
1454
+ echo "ruby-build: definition not found: ${DEFINITION_PATH}" >&2
1455
+ exit 2
1456
+ fi
1457
+ fi
1458
+
1459
+ PREFIX_PATH="${ARGUMENTS[1]}"
1460
+ if [ -z "$PREFIX_PATH" ]; then
1461
+ usage 1 >&2
1462
+ elif [ "${PREFIX_PATH#/}" = "$PREFIX_PATH" ]; then
1463
+ PREFIX_PATH="${PWD}/${PREFIX_PATH}"
1464
+ fi
1465
+
1466
+ if [ -z "$TMPDIR" ]; then
1467
+ TMP="/tmp"
1468
+ else
1469
+ TMP="${TMPDIR%/}"
1470
+ fi
1471
+
1472
+ # Check if TMPDIR is accessible and can hold executables.
1473
+ tmp_executable="${TMP}/ruby-build-test.$$"
1474
+ noexec=""
1475
+ if mkdir -p "$TMP" && touch "$tmp_executable" 2>/dev/null; then
1476
+ cat > "$tmp_executable" <<-EOF
1477
+ #!${BASH}
1478
+ exit 0
1479
+ EOF
1480
+ chmod +x "$tmp_executable"
1481
+ else
1482
+ echo "ruby-build: TMPDIR=$TMP is set to a non-accessible location" >&2
1483
+ exit 1
1484
+ fi
1485
+ "$tmp_executable" 2>/dev/null || noexec=1
1486
+ rm -f "$tmp_executable"
1487
+ if [ -n "$noexec" ]; then
1488
+ echo "ruby-build: TMPDIR=$TMP cannot hold executables (partition possibly mounted with \`noexec\`)" >&2
1489
+ exit 1
1490
+ fi
1491
+
1492
+ # Apply following work around, if gcc is not installed.
1493
+ if [ -z "$(locate_gcc)" ]; then
1494
+ # Work around warnings building Ruby 2.0 on Clang 2.x:
1495
+ # pass -Wno-error=shorten-64-to-32 if the compiler accepts it.
1496
+ #
1497
+ # When we set CFLAGS, Ruby won't apply its default flags, though. Since clang
1498
+ # builds 1.9.x and 2.x only, where -O3 is default, we can safely set that flag.
1499
+ # Ensure it's the first flag since later flags take precedence.
1500
+ if "${CC:-cc}" -x c /dev/null -E -Wno-error=shorten-64-to-32 &>/dev/null; then
1501
+ RUBY_CFLAGS="-O3 -Wno-error=shorten-64-to-32 $RUBY_CFLAGS"
1502
+ fi
1503
+ fi
1504
+
1505
+ if [ -z "$MAKE" ]; then
1506
+ if is_freebsd; then
1507
+ # Workaround for Ruby bug 16331: https://bugs.ruby-lang.org/issues/16331
1508
+ # Due to this bug, build will fail with FreeBSD's make after #1368
1509
+ # The bug is already fixed in upstream but GNU make is still required
1510
+ # when building older releases of Ruby. Use GNU make rather than switching
1511
+ # depending of Ruby version.
1512
+ export MAKE="gmake"
1513
+ else
1514
+ export MAKE="make"
1515
+ fi
1516
+ fi
1517
+
1518
+ if [ -n "$RUBY_BUILD_CACHE_PATH" ] && [ -d "$RUBY_BUILD_CACHE_PATH" ]; then
1519
+ RUBY_BUILD_CACHE_PATH="${RUBY_BUILD_CACHE_PATH%/}"
1520
+ else
1521
+ unset RUBY_BUILD_CACHE_PATH
1522
+ fi
1523
+
1524
+ if [ -z "$RUBY_BUILD_MIRROR_URL" -a -z "$RUBY_BUILD_MIRROR_PACKAGE_URL" ]; then
1525
+ RUBY_BUILD_MIRROR_URL="https://dqw8nmjcqpjn7.cloudfront.net"
1526
+ RUBY_BUILD_DEFAULT_MIRROR=1
1527
+ else
1528
+ RUBY_BUILD_MIRROR_URL="${RUBY_BUILD_MIRROR_URL%/}"
1529
+ RUBY_BUILD_DEFAULT_MIRROR=
1530
+ fi
1531
+
1532
+ if [ -n "$RUBY_BUILD_SKIP_MIRROR" ] || ! has_checksum_support compute_sha2; then
1533
+ unset RUBY_BUILD_MIRROR_URL RUBY_BUILD_MIRROR_PACKAGE_URL
1534
+ fi
1535
+
1536
+ ARIA2_OPTS="${RUBY_BUILD_ARIA2_OPTS} ${IPV4+--disable-ipv6=true} ${IPV6+--disable-ipv6=false}"
1537
+ CURL_OPTS="${RUBY_BUILD_CURL_OPTS} ${IPV4+--ipv4} ${IPV6+--ipv6}"
1538
+ WGET_OPTS="${RUBY_BUILD_WGET_OPTS} ${IPV4+--inet4-only} ${IPV6+--inet6-only}"
1539
+
1540
+ SEED="$(date "+%Y%m%d%H%M%S").$$"
1541
+ LOG_PATH="${TMP}/ruby-build.${SEED}.log"
1542
+ RUBY_BIN="${PREFIX_PATH}/bin/ruby"
1543
+ CWD="$(pwd)"
1544
+
1545
+ if [ -z "$RUBY_BUILD_BUILD_PATH" ]; then
1546
+ BUILD_PATH="$(mktemp -d "${LOG_PATH%.log}.XXXXXX")"
1547
+ else
1548
+ BUILD_PATH="$RUBY_BUILD_BUILD_PATH"
1549
+ fi
1550
+
1551
+ exec 4<> "$LOG_PATH" # open the log file at fd 4
1552
+ if [ -n "$VERBOSE" ]; then
1553
+ tail -f "$LOG_PATH" &
1554
+ TAIL_PID=$!
1555
+ trap "kill $TAIL_PID" SIGINT SIGTERM EXIT
1556
+ else
1557
+ if [ -z "$RUBY_BUILD_TESTING" ]; then
1558
+ echo "To follow progress, use 'tail -f $LOG_PATH' or pass --verbose" >&2
1559
+ fi
1560
+ fi
1561
+
1562
+ export LDFLAGS="-L${PREFIX_PATH}/lib ${LDFLAGS}"
1563
+ export CPPFLAGS="-I${PREFIX_PATH}/include ${CPPFLAGS}"
1564
+
1565
+ unset RUBYOPT
1566
+ unset RUBYLIB
1567
+
1568
+ trap build_failed ERR
1569
+ mkdir -p "$BUILD_PATH"
1570
+ source "$DEFINITION_PATH"
1571
+ [ -z "${KEEP_BUILD_PATH}" ] && rm -fr "$BUILD_PATH"
1572
+ trap - ERR