1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205
|
#!/usr/bin/env bats
load test_helper
export RUBY_BUILD_CACHE_PATH="$TMP/cache"
export MAKE=make
export MAKE_OPTS="-j 2"
export CC=cc
export -n RUBY_CONFIGURE_OPTS
export -n PKG_CONFIG_PATH
setup() {
mkdir -p "$INSTALL_ROOT"
stub md5 false
stub curl false
}
executable() {
local file="$1"
mkdir -p "${file%/*}"
cat > "$file"
chmod +x "$file"
}
cached_tarball() {
local save_to_fixtures
case "$*" in
"ruby-3.2.0 configure" | "yaml-0.1.6 configure" | "jruby-9000.dev bin/jruby" )
save_to_fixtures=1
;;
esac
local tarball="${1}.tar.gz"
local fixture_tarball="${FIXTURE_ROOT}/${tarball}"
local cached_tarball="${RUBY_BUILD_CACHE_PATH}/${tarball}"
shift 1
if [ -n "$save_to_fixtures" ] && [ -e "$fixture_tarball" ]; then
mkdir -p "$(dirname "$cached_tarball")"
cp "$fixture_tarball" "$cached_tarball"
return 0
fi
generate_tarball "$cached_tarball" "$@"
[ -z "$save_to_fixtures" ] || cp "$cached_tarball" "$fixture_tarball"
}
generate_tarball() {
local tarfile="$1"
shift 1
local name path
name="$(basename "${tarfile%.tar.gz}")"
path="$(mktemp -d "$TMP/tarball.XXXXX")/${name}"
local file target
for file; do
case "$file" in
config | configure )
mkdir -p "$(dirname "${path}/${file}")"
cat > "${path}/${file}" <<OUT
#!$BASH
IFS=,
echo "$name: [\$*]" \${RUBYOPT:+RUBYOPT=\$RUBYOPT} \${PKG_CONFIG_PATH:+PKG_CONFIG_PATH=\$PKG_CONFIG_PATH} >> build.log
OUT
chmod +x "${path}/${file}"
;;
*:* )
target="${file#*:}"
file="${file%:*}"
mkdir -p "$(dirname "${path}/${file}")"
cp "$target" "${path}/${file}"
;;
* )
mkdir -p "$(dirname "${path}/${file}")"
touch "${path}/${file}"
;;
esac
done
mkdir -p "$(dirname "$tarfile")"
tar czf "$tarfile" -C "${path%/*}" "$name"
rm -rf "$path"
}
stub_make_install() {
local target="${1:-install}"
stub "$MAKE" \
" : echo \"\${PKG_CONFIG_PATH:+PKG_CONFIG_PATH=\$PKG_CONFIG_PATH }$MAKE \$(inspect_args \"\$@\")\" >> build.log" \
"$target : echo \"$MAKE \$(inspect_args \"\$@\")\" >> build.log && cat build.log >> '$INSTALL_ROOT/build.log'"
}
assert_build_log() {
run cat "$INSTALL_ROOT/build.log"
assert_output
}
@test "yaml is installed for ruby" {
cached_tarball "yaml-0.1.6" configure
cached_tarball "ruby-3.2.0" configure
stub_repeated uname '-s : echo Linux'
stub_repeated brew false
stub_make_install
stub_make_install
install_fixture definitions/needs-yaml
assert_success
unstub uname
unstub brew
unstub make
assert_build_log <<OUT
yaml-0.1.6: [--prefix=$INSTALL_ROOT]
make -j 2
make install
ruby-3.2.0: [--prefix=$INSTALL_ROOT,--with-ext=openssl,psych,+]
make -j 2
make install
OUT
}
@test "apply ruby patch before building" {
cached_tarball "yaml-0.1.6" configure
cached_tarball "ruby-3.2.0" configure
stub_repeated uname '-s : echo Linux'
stub_repeated brew false
stub_make_install
stub_make_install
stub patch ' : echo patch "$@" | sed -E "s/\.[[:alnum:]]+$/.XXX/" >> build.log'
TMPDIR="$TMP" install_fixture --patch definitions/needs-yaml <<PATCH
diff -pU3 align.c align.c
--- align.c 2017-09-14 21:09:29.000000000 +0900
+++ align.c 2017-09-15 05:56:46.000000000 +0900
PATCH
assert_success
unstub uname
unstub brew
unstub make
unstub patch
assert_build_log <<OUT
yaml-0.1.6: [--prefix=$INSTALL_ROOT]
make -j 2
make install
patch -p0 --force -i $TMP/ruby-patch.XXX
ruby-3.2.0: [--prefix=$INSTALL_ROOT,--with-ext=openssl,psych,+]
make -j 2
make install
OUT
}
@test "striplevel ruby patch before building" {
cached_tarball "yaml-0.1.6" configure
cached_tarball "ruby-3.2.0" configure
stub_repeated uname '-s : echo Linux'
stub_repeated brew false
stub_make_install
stub_make_install
stub patch ' : echo patch "$@" | sed -E "s/\.[[:alnum:]]+$/.XXX/" >> build.log'
TMPDIR="$TMP" install_fixture --patch definitions/needs-yaml <<PATCH
diff -pU3 a/configure b/configure
--- a/configure 2017-09-14 21:09:29.000000000 +0900
+++ b/configure 2017-09-15 05:56:46.000000000 +0900
PATCH
assert_success
unstub uname
unstub brew
unstub make
unstub patch
assert_build_log <<OUT
yaml-0.1.6: [--prefix=$INSTALL_ROOT]
make -j 2
make install
patch -p1 --force -i $TMP/ruby-patch.XXX
ruby-3.2.0: [--prefix=$INSTALL_ROOT,--with-ext=openssl,psych,+]
make -j 2
make install
OUT
}
@test "apply ruby patch from git diff before building" {
cached_tarball "yaml-0.1.6" configure
cached_tarball "ruby-3.2.0" configure
stub_repeated uname '-s : echo Linux'
stub_repeated brew false
stub_make_install
stub_make_install
stub patch ' : echo patch "$@" | sed -E "s/\.[[:alnum:]]+$/.XXX/" >> build.log'
TMPDIR="$TMP" install_fixture --patch definitions/needs-yaml <<PATCH
diff --git a/test/build.bats b/test/build.bats
index 4760c31..66a237a 100755
--- a/test/build.bats
+++ b/test/build.bats
PATCH
assert_success
unstub uname
unstub brew
unstub make
unstub patch
assert_build_log <<OUT
yaml-0.1.6: [--prefix=$INSTALL_ROOT]
make -j 2
make install
patch -p1 --force -i $TMP/ruby-patch.XXX
ruby-3.2.0: [--prefix=$INSTALL_ROOT,--with-ext=openssl,psych,+]
make -j 2
make install
OUT
}
@test "yaml is linked from Homebrew" {
cached_tarball "ruby-3.2.0" configure
brew_libdir="$TMP/homebrew-yaml"
mkdir -p "$brew_libdir"
stub_repeated uname '-s : echo Linux'
stub_repeated brew "--prefix libyaml : echo '$brew_libdir'"
stub_make_install
run_inline_definition <<DEF
install_package "ruby-3.2.0" "http://ruby-lang.org/ruby/2.0/ruby-3.2.0.tar.gz"
DEF
assert_success
unstub uname
unstub brew
unstub make
assert_build_log <<OUT
ruby-3.2.0: [--prefix=$INSTALL_ROOT,--with-libyaml-dir=$brew_libdir,--with-ext=openssl,psych,+]
make -j 2
make install
OUT
}
@test "gmp is linked from Homebrew" {
cached_tarball "ruby-3.2.0" configure
gmp_libdir="$TMP/homebrew-gmp"
mkdir -p "$gmp_libdir"
stub_repeated brew "--prefix gmp : echo '$gmp_libdir'"
stub_make_install
run_inline_definition <<DEF
install_package "ruby-3.2.0" "http://ruby-lang.org/ruby/2.0/ruby-3.2.0.tar.gz"
DEF
assert_success
unstub brew
unstub make
assert_build_log <<OUT
ruby-3.2.0: [--prefix=$INSTALL_ROOT,--with-gmp-dir=$gmp_libdir,--with-ext=openssl,psych,+]
make -j 2
make install
OUT
}
@test "readline is linked from Homebrew" {
cached_tarball "ruby-3.2.0" configure
readline_libdir="$TMP/homebrew-readline"
mkdir -p "$readline_libdir"
stub_repeated brew "--prefix readline : echo '$readline_libdir'"
stub_make_install
run_inline_definition <<DEF
install_package "ruby-3.2.0" "http://ruby-lang.org/ruby/2.0/ruby-3.2.0.tar.gz"
DEF
assert_success
unstub brew
unstub make
assert_build_log <<OUT
ruby-3.2.0: [--prefix=$INSTALL_ROOT,--with-readline-dir=$readline_libdir,--with-ext=openssl,psych,+]
make -j 2
make install
OUT
}
@test "readline is not auto-discovered for Ruby 3.3" {
cached_tarball "ruby-3.3.0" configure
readline_libdir="$TMP/homebrew-readline"
mkdir -p "$readline_libdir"
stub_repeated brew "--prefix readline : echo '$readline_libdir'"
stub_make_install
run_inline_definition <<DEF
install_package "ruby-3.3.0" "http://ruby-lang.org/ruby/3.0/ruby-3.3.0.tar.gz"
DEF
assert_success
unstub brew
unstub make
assert_build_log <<OUT
ruby-3.3.0: [--prefix=$INSTALL_ROOT,--with-ext=openssl,psych,+]
make -j 2
make install
OUT
}
@test "readline is not linked from Homebrew when explicitly defined" {
cached_tarball "ruby-3.2.0" configure
readline_libdir="$TMP/homebrew-readline"
mkdir -p "$readline_libdir"
stub_repeated brew "--prefix readline : echo '$readline_libdir'" ' : false'
stub_make_install
export RUBY_CONFIGURE_OPTS='--with-readline-dir=/custom'
run_inline_definition <<DEF
install_package "ruby-3.2.0" "http://ruby-lang.org/ruby/2.0/ruby-3.2.0.tar.gz"
DEF
assert_success
unstub brew
unstub make
assert_build_log <<OUT
ruby-3.2.0: [--prefix=$INSTALL_ROOT,--with-ext=openssl,psych,+,--with-readline-dir=/custom]
make -j 2
make install
OUT
}
@test "use system OpenSSL" {
cached_tarball "ruby-3.2.0" configure
stub_repeated uname '-s : echo Linux'
stub_repeated brew false
# shellcheck disable=SC2016
stub cc '-xc -E - : [[ "$(cat)" == *OPENSSL_VERSION_TEXT* ]] && printf "# <unrelated> 4.0.2\n\"OpenSSL 1.0.3a 1 Aug 202\"\n0 errors.\n"'
stub_repeated pkg-config false
stub_make_install
mkdir -p "$INSTALL_ROOT"/openssl/ssl # OPENSSLDIR
run_inline_definition <<DEF
install_package "openssl-1.1.1w" "https://www.openssl.org/source/openssl-1.1.1w.tar.gz" openssl --if needs_openssl_102_300
install_package "ruby-3.2.0" "http://ruby-lang.org/ruby/2.0/ruby-3.2.0.tar.gz"
DEF
assert_success
unstub uname
unstub brew
unstub pkg-config
unstub make
assert_build_log <<OUT
ruby-3.2.0: [--prefix=$INSTALL_ROOT,--with-ext=openssl,psych,+]
make -j 2
make install
OUT
}
@test "use pkg-config OpenSSL" {
cached_tarball "ruby-3.2.0" configure
openssl_libdir="$TMP/opt/local/libexec/openssl"
stub_repeated uname '-s : echo Linux'
stub_repeated brew false
stub pkg-config \
"--variable=prefix openssl : echo '$openssl_libdir'" \
"--modversion openssl : echo 1.0.2k"
stub_make_install
run_inline_definition <<DEF
install_package "openssl-1.1.1w" "https://www.openssl.org/source/openssl-1.1.1w.tar.gz" openssl --if needs_openssl_102_300
install_package "ruby-3.2.0" "http://ruby-lang.org/ruby/2.0/ruby-3.2.0.tar.gz"
DEF
assert_success
unstub uname
unstub brew
unstub pkg-config
unstub make
assert_build_log <<OUT
ruby-3.2.0: [--prefix=$INSTALL_ROOT,--with-ext=openssl,psych,+]
make -j 2
make install
OUT
}
@test "install bundled OpenSSL on Linux" {
cached_tarball "openssl-1.1.1w" config
cached_tarball "ruby-3.2.0" configure
mkdir -p "${TMP}/ssl/certs"
touch "${TMP}/ssl/cert.pem"
stub_repeated uname '-s : echo Linux'
stub_repeated brew false
stub cc '-xc -E - : echo "OpenSSL 1.0.1a 1 Aug 2023"' # system_openssl_version
stub openssl "version -d : echo 'OPENSSLDIR: \"${TMP}/ssl\"'"
stub_repeated pkg-config false
stub_make_install "install_sw"
stub_make_install
mkdir -p "$INSTALL_ROOT"/openssl/ssl # OPENSSLDIR
run_inline_definition <<DEF
install_package "openssl-1.1.1w" "https://www.openssl.org/source/openssl-1.1.1w.tar.gz" openssl --if needs_openssl_102_300
install_package "ruby-3.2.0" "http://ruby-lang.org/ruby/2.0/ruby-3.2.0.tar.gz"
DEF
assert_success
sanitized_output="$(grep -v '^\(->\|==>\)' <<<"$output" || true)"
if [ -n "$sanitized_output" ]; then
echo "expected no warnings, got: $sanitized_output"
return 1
fi
unstub uname
unstub brew
unstub cc
unstub pkg-config
# Depending on certain system certificate files being present under /etc/,
# `openssl version -d` might not have been called, so avoid unstubbing it
# since that would verify the number of invocations.
#unstub openssl
unstub make
assert_build_log <<OUT
openssl-1.1.1w: [--prefix=${INSTALL_ROOT}/openssl,--openssldir=${INSTALL_ROOT}/openssl/ssl,--libdir=lib,zlib-dynamic,no-ssl3,shared,-Wl,-rpath,${INSTALL_ROOT}/openssl/lib]
make -j 2
make install_sw install_ssldirs
ruby-3.2.0: [--prefix=$INSTALL_ROOT,--with-openssl-dir=$INSTALL_ROOT/openssl,--with-ext=openssl,psych,+] PKG_CONFIG_PATH=${TMP}/install/openssl/lib/pkgconfig
PKG_CONFIG_PATH=${TMP}/install/openssl/lib/pkgconfig make -j 2
make install
OUT
}
@test "install bundled OpenSSL on macOS" {
cached_tarball "openssl-1.1.1w" config
cached_tarball "ruby-3.2.0" configure
stub_repeated uname '-s : echo Darwin'
stub security \
'find-certificate -a -p /Library/Keychains/System.keychain : echo "System.keychain"' \
'find-certificate -a -p /System/Library/Keychains/SystemRootCertificates.keychain : echo "SystemRootCertificates.keychain"'
stub_repeated brew false
stub cc '-xc -E - : echo "OpenSSL 1.0.1a 1 Aug 2023"' # system_openssl_version
stub openssl
stub_repeated pkg-config false
stub_make_install "install_sw"
stub_make_install
mkdir -p "$INSTALL_ROOT"/openssl/ssl # OPENSSLDIR
run_inline_definition <<DEF
install_package "openssl-1.1.1w" "https://www.openssl.org/source/openssl-1.1.1w.tar.gz" openssl --if needs_openssl_102_300
install_package "ruby-3.2.0" "http://ruby-lang.org/ruby/2.0/ruby-3.2.0.tar.gz"
DEF
assert_success
unstub uname
unstub security
unstub brew
unstub pkg-config
# Depending on the state of system `/usr/bin/openssl` in the test runner,
# `cc` might not have been called, so avoid unstubbing it since that would
# verify the number of invocations.
#unstub cc
unstub openssl
unstub make
# No rpath on macOS, OpenSSL sets it itself: https://wiki.openssl.org/index.php/Compilation_and_Installation#Using_RPATHs
assert_build_log <<OUT
openssl-1.1.1w: [--prefix=${INSTALL_ROOT}/openssl,--openssldir=${INSTALL_ROOT}/openssl/ssl,--libdir=lib,zlib-dynamic,no-ssl3,shared]
make -j 2
make install_sw install_ssldirs
ruby-3.2.0: [--prefix=$INSTALL_ROOT,--with-openssl-dir=$INSTALL_ROOT/openssl,--with-ext=openssl,psych,+] PKG_CONFIG_PATH=${TMP}/install/openssl/lib/pkgconfig
PKG_CONFIG_PATH=${TMP}/install/openssl/lib/pkgconfig make -j 2
make install
OUT
run cat "$INSTALL_ROOT"/openssl/ssl/cert.pem
assert_output <<PEM
System.keychain
SystemRootCertificates.keychain
PEM
}
@test "skip bundling OpenSSL if custom openssl dir was specified" {
cached_tarball "ruby-3.2.0" configure
stub_repeated uname '-s : echo Darwin'
stub_repeated brew false
stub_make_install
RUBY_CONFIGURE_OPTS="--with-openssl-dir=/path/to/openssl" run_inline_definition <<DEF
install_package "openssl-1.1.1w" "https://www.openssl.org/source/openssl-1.1.1w.tar.gz" openssl --if needs_openssl_102_300
install_package "ruby-3.2.0" "http://ruby-lang.org/ruby/2.0/ruby-3.2.0.tar.gz"
DEF
assert_success
unstub uname
unstub brew
unstub make
assert_build_log <<OUT
ruby-3.2.0: [--prefix=$INSTALL_ROOT,--with-ext=openssl,psych,+,--with-openssl-dir=/path/to/openssl]
make -j 2
make install
OUT
}
@test "explicit OpenSSL dir sets PKG_CONFIG_PATH for older Rubies" {
cached_tarball "ruby-2.7.3" configure
stub_repeated uname '-s : echo Darwin'
stub_repeated brew false
stub_make_install
PKG_CONFIG_PATH=/orig/searchpath RUBY_CONFIGURE_OPTS="--with-openssl-dir=/path/to/openssl" run_inline_definition <<DEF
install_package "ruby-2.7.3" "http://ruby-lang.org/ruby/2.0/ruby-2.7.3.tar.gz"
DEF
assert_success
unstub uname
unstub brew
unstub make
assert_build_log <<OUT
ruby-2.7.3: [--prefix=$INSTALL_ROOT,--with-ext=openssl,psych,+,--with-openssl-dir=/path/to/openssl] PKG_CONFIG_PATH=/path/to/openssl/lib/pkgconfig:/orig/searchpath
PKG_CONFIG_PATH=/path/to/openssl/lib/pkgconfig:/orig/searchpath make -j 2
make install
OUT
}
@test "link to Homebrew OpenSSL" {
cached_tarball "ruby-3.2.0" configure
local homebrew_prefix="${TMP}/homebrew"
executable "${homebrew_prefix}/opt/openssl@3/bin/openssl" <<EXE
#!/$BASH
[ "\$1" = "version" ] || exit 1
echo 'OpenSSL 3.2.1 20 Dec 2019'
EXE
executable "${homebrew_prefix}/opt/openssl@3.1/bin/openssl" <<EXE
#!/$BASH
[ "\$1" = "version" ] || exit 1
echo 'OpenSSL 3.1.22 20 Dec 2019'
EXE
executable "${homebrew_prefix}/opt/openssl@3.0/bin/openssl" <<EXE
#!/$BASH
[ "\$1" = "version" ] || exit 1
echo 'OpenSSL 3.0.2 20 Dec 2019'
EXE
executable "${homebrew_prefix}/opt/openssl@1.1/bin/openssl" <<EXE
#!/$BASH
[ "\$1" = "version" ] || exit 1
echo 'OpenSSL 1.1.1v 20 Dec 2019'
EXE
stub_repeated uname '-s : echo Linux'
stub cc '-xc -E - : echo "OpenSSL 1.0.1a 1 Aug 2023"'
stub_repeated brew \
'list : printf "git\nopenssl@3\nopenssl-utils\nopenssl@1.1\nopenssl@3.0\nwget\nopenssl@3.1"' \
"--prefix : if [ \$# -ge 2 ]; then echo '$homebrew_prefix'/opt/\$2; else echo '$homebrew_prefix'; fi " \
"--repository : echo '$homebrew_prefix'"
stub_repeated pkg-config false
stub_make_install
run_inline_definition <<DEF
install_package "openssl-1.1.1w" "https://www.openssl.org/source/openssl-1.1.1w.tar.gz" openssl --if needs_openssl:1.1.0-3.0.x
install_package "ruby-3.2.0" "http://ruby-lang.org/ruby/2.0/ruby-3.2.0.tar.gz"
DEF
assert_success
unstub uname
unstub cc
unstub brew
unstub pkg-config
unstub make
assert_build_log <<OUT
ruby-3.2.0: [--prefix=$INSTALL_ROOT,--with-openssl-dir=$TMP/homebrew/opt/openssl@3.0,--with-ext=openssl,psych,+]
make -j 2
make install
OUT
}
@test "link to Homebrew OpenSSL ignoring pkg-config" {
cached_tarball "ruby-3.2.0" configure
local homebrew_prefix="${TMP}/homebrew"
executable "${homebrew_prefix}/opt/openssl@3/bin/openssl" <<EXE
#!/$BASH
[ "\$1" = "version" ] || exit 1
echo 'OpenSSL 3.2.1 20 Dec 2019'
EXE
stub_repeated uname '-s : echo Linux'
stub cc '-xc -E - : echo "OpenSSL 1.0.1a 1 Aug 2023"'
stub_repeated brew \
'list : echo "openssl@3"' \
"--prefix : if [ \$# -ge 2 ]; then echo '$homebrew_prefix'/opt/\$2; else echo '$homebrew_prefix'; fi " \
"--repository : echo '$homebrew_prefix'"
stub pkg-config "--variable=prefix openssl : echo '$homebrew_prefix'/Cellar/openssl@3/3.2.1"
stub_make_install
run_inline_definition <<DEF
install_package "openssl-1.1.1w" "https://www.openssl.org/source/openssl-1.1.1w.tar.gz" openssl --if needs_openssl:1.1.0-3.2.x
install_package "ruby-3.2.0" "http://ruby-lang.org/ruby/2.0/ruby-3.2.0.tar.gz"
DEF
assert_success
unstub uname
unstub cc
unstub brew
unstub pkg-config
unstub make
assert_build_log <<OUT
ruby-3.2.0: [--prefix=$INSTALL_ROOT,--with-openssl-dir=$TMP/homebrew/opt/openssl@3,--with-ext=openssl,psych,+]
make -j 2
make install
OUT
}
@test "forward extra command-line arguments as configure flags" {
cached_tarball "ruby-3.2.0" configure
stub_repeated brew false
stub_make_install
cat > "$TMP/build-definition" <<DEF
install_package "ruby-3.2.0" "http://ruby-lang.org/ruby/2.0/ruby-3.2.0.tar.gz"
DEF
RUBY_CONFIGURE_OPTS='--with-readline-dir=/custom' run ruby-build "$TMP/build-definition" "$INSTALL_ROOT" -- cppflags="-DYJIT_FORCE_ENABLE -DRUBY_PATCHLEVEL_NAME=test" --with-openssl-dir=/path/to/openssl
assert_success
unstub brew
unstub make
assert_build_log <<OUT
ruby-3.2.0: [--prefix=$INSTALL_ROOT,cppflags=-DYJIT_FORCE_ENABLE -DRUBY_PATCHLEVEL_NAME=test,--with-openssl-dir=/path/to/openssl,--with-ext=openssl,psych,+,--with-readline-dir=/custom]
make -j 2
make install
OUT
}
@test "number of CPU cores defaults to 2" {
cached_tarball "ruby-3.2.0" configure
stub_repeated uname '-s : echo Darwin'
stub sysctl false
stub_make_install
export -n MAKE_OPTS
run_inline_definition <<DEF
install_package "ruby-3.2.0" "http://ruby-lang.org/ruby/2.0/ruby-3.2.0.tar.gz"
DEF
assert_success
unstub uname
unstub make
assert_build_log <<OUT
ruby-3.2.0: [--prefix=$INSTALL_ROOT,--with-ext=openssl,psych,+]
make -j 2
make install
OUT
}
@test "number of CPU cores is detected on Mac" {
cached_tarball "ruby-3.2.0" configure
stub_repeated uname '-s : echo Darwin'
stub sysctl '-n hw.ncpu : echo 4'
stub_make_install
export -n MAKE_OPTS
run_inline_definition <<DEF
install_package "ruby-3.2.0" "http://ruby-lang.org/ruby/2.0/ruby-3.2.0.tar.gz"
DEF
assert_success
unstub uname
unstub sysctl
unstub make
assert_build_log <<OUT
ruby-3.2.0: [--prefix=$INSTALL_ROOT,--with-ext=openssl,psych,+]
make -j 4
make install
OUT
}
@test "number of CPU cores is detected on FreeBSD" {
cached_tarball "ruby-3.2.0" configure
stub_repeated uname '-s : echo FreeBSD'
stub sysctl '-n hw.ncpu : echo 1'
stub_make_install
export -n MAKE_OPTS
RUBY_CONFIGURE_OPTS="--with-openssl-dir=/test" run_inline_definition <<DEF
install_package "ruby-3.2.0" "http://ruby-lang.org/ruby/2.0/ruby-3.2.0.tar.gz"
DEF
assert_success
unstub uname
unstub sysctl
unstub make
assert_build_log <<OUT
ruby-3.2.0: [--prefix=$INSTALL_ROOT,--with-ext=openssl,psych,+,--with-openssl-dir=/test]
make -j 1
make install
OUT
}
@test "using MAKE_INSTALL_OPTS" {
cached_tarball "ruby-3.2.0" configure
stub_repeated uname '-s : echo Linux'
stub_make_install
export MAKE_INSTALL_OPTS="--globalmake"
export RUBY_MAKE_INSTALL_OPTS="RUBYMAKE=true with spaces"
run_inline_definition <<DEF
install_package "ruby-3.2.0" "http://ruby-lang.org/ruby/2.0/ruby-3.2.0.tar.gz"
DEF
assert_success
unstub uname
unstub make
assert_build_log <<OUT
ruby-3.2.0: [--prefix=$INSTALL_ROOT,--with-ext=openssl,psych,+]
make -j 2
make install --globalmake RUBYMAKE=true with spaces
OUT
}
@test "nested install destination" {
export RUBY_BUILD_CACHE_PATH="$FIXTURE_ROOT"
run ruby-build -d "$FIXTURE_ROOT"/definitions/without-checksum "$INSTALL_ROOT"
assert_success
refute [ -d "$INSTALL_ROOT"/bin ]
assert [ -x "$INSTALL_ROOT"/without-checksum/bin/package ]
}
@test "nested install destination with ruby prefix" {
cached_tarball "ruby-3.2.0" configure
stub_repeated brew false
stub_make_install
mkdir -p "$TMP"/definitions
cat > "$TMP"/definitions/3.2.0 <<DEF
install_package "ruby-3.2.0" "http://ruby-lang.org/ruby/2.0/ruby-3.2.0.tar.gz"
DEF
RUBY_BUILD_DEFINITIONS="$TMP"/definitions run ruby-build --dir ruby-3.2.0 "$INSTALL_ROOT"
assert_success
unstub brew
unstub make
assert_build_log <<OUT
ruby-3.2.0: [--prefix=$INSTALL_ROOT/ruby-3.2.0,--with-ext=openssl,psych,+]
make -j 2
make install
OUT
}
@test "definition file with ruby prefix" {
export RUBY_BUILD_CACHE_PATH="$FIXTURE_ROOT"
cd "$TMP"
cat > ruby-123-internal <<DEF
install_package "package-1.0.0" "http://example.com/packages/package-1.0.0.tar.gz" copy
DEF
run ruby-build ruby-123-internal "$INSTALL_ROOT"
assert_success
assert [ -x "$INSTALL_ROOT"/bin/package ]
}
@test "custom relative install destination" {
export RUBY_BUILD_CACHE_PATH="$FIXTURE_ROOT"
cd "$TMP"
install_fixture definitions/without-checksum ./here
assert_success
assert [ -x ./here/bin/package ]
}
@test "can use RUBY_CONFIGURE to apply a patch" {
cached_tarball "ruby-3.2.0" configure
executable "${TMP}/custom-configure" <<CONF
#!$BASH
apply -p1 -i /my/patch.diff
exec ./configure "\$@"
CONF
stub_repeated uname '-s : echo Linux'
stub apply 'echo apply "$@" >> build.log'
stub_make_install
RUBY_CONFIGURE="${TMP}/custom-configure" run_inline_definition <<DEF
install_package "ruby-3.2.0" "http://ruby-lang.org/pub/ruby-3.2.0.tar.gz"
DEF
assert_success
unstub uname
unstub make
unstub apply
assert_build_log <<OUT
apply -p1 -i /my/patch.diff
ruby-3.2.0: [--prefix=$INSTALL_ROOT,--with-ext=openssl,psych,+]
make -j 2
make install
OUT
}
@test "Ruby 2.4 and older does not pass --with-ext" {
cached_tarball "ruby-2.4.10" configure
stub_repeated uname '-s : echo Linux'
stub_make_install
run_inline_definition <<DEF
install_package "ruby-2.4.10" "http://ruby-lang.org/pub/ruby-2.4.10.tar.gz"
DEF
assert_success
unstub uname
unstub make
assert_build_log <<OUT
ruby-2.4.10: [--prefix=$INSTALL_ROOT]
make -j 2
make install
OUT
}
@test "copy strategy forces overwrite" {
export RUBY_BUILD_CACHE_PATH="$FIXTURE_ROOT"
mkdir -p "$INSTALL_ROOT/bin"
touch "$INSTALL_ROOT/bin/package"
chmod -w "$INSTALL_ROOT/bin/package"
install_fixture definitions/without-checksum
assert_success
run "$INSTALL_ROOT/bin/package" "world"
assert_success "hello world"
}
@test "dev Ruby install strategy" {
cached_tarball "ruby-3.2.0" configure
stub_repeated uname '-s : echo Linux'
stub_repeated brew false
# shellcheck disable=SC2016
stub autoreconf ' : echo "autoreconf $(inspect_args "$@")" >> build.log'
stub_make_install "update-gems"
run_inline_definition <<DEF
install_package "ruby-3.2.0" "http://ruby-lang.org/ruby/3.0/ruby-3.2.0.tar.gz" autoconf enable_shared standard_install_with_bundled_gems
DEF
assert_success
unstub uname
unstub brew
unstub make
unstub autoreconf
assert_build_log <<OUT
autoreconf -i
ruby-3.2.0: [--prefix=${TMP}/install,--enable-shared,--with-ext=openssl,psych,+]
make -j 2
make update-gems extract-gems install
OUT
}
@test "mruby strategy" {
executable "$TMP/minirake" <<OUT
#!$BASH
set -e
IFS=,
echo "\$0 [\$*]" >> '$INSTALL_ROOT'/build.log
mkdir -p build/host/bin
touch build/host/bin/{mruby,mirb}
chmod +x build/host/bin/{mruby,mirb}
OUT
cached_tarball "mruby-1.0" "minirake:$TMP/minirake" include/mruby.h
stub gem false
stub rake false
mkdir -p "$INSTALL_ROOT/bin"
touch "$INSTALL_ROOT/bin/mruby"
chmod -w "$INSTALL_ROOT/bin/mruby"
run_inline_definition <<DEF
install_package "mruby-1.0" "http://ruby-lang.org/pub/mruby-1.0.tar.gz" mruby
DEF
assert_success
assert_build_log <<OUT
./minirake []
OUT
assert [ -w "$INSTALL_ROOT/bin/mruby" ]
assert [ -e "$INSTALL_ROOT/bin/ruby" ]
assert [ -e "$INSTALL_ROOT/bin/irb" ]
assert [ -e "$INSTALL_ROOT/include/mruby.h" ]
}
@test "rbx uses bundle then rake" {
cached_tarball "rubinius-2.0.0" Gemfile configure
stub gem false
stub rake false
stub bundle \
'--version : echo 1' \
' : echo bundle "$@" >> build.log' \
"exec rake install : { cat build.log; echo bundle \"\$@\"; } >> '$INSTALL_ROOT/build.log'"
run_inline_definition <<DEF
install_package "rubinius-2.0.0" "http://releases.rubini.us/rubinius-2.0.0.tar.gz" rbx
DEF
assert_success
unstub bundle
assert_build_log <<OUT
bundle --path=vendor/bundle
rubinius-2.0.0: [--prefix=$INSTALL_ROOT] RUBYOPT=-rrubygems
bundle exec rake install
OUT
}
@test "fixes rbx binstubs" {
executable "${TMP}/rbx-rake" <<OUT
#!rbx
puts 'rake'
OUT
executable "${TMP}/rbx-irb" <<OUT
#!rbx
print '>>'
OUT
cached_tarball "rubinius-2.0.0" configure bin/ruby \
gems/bin/rake:"$TMP"/rbx-rake \
gems/bin/irb:"$TMP"/rbx-irb
stub bundle false
stub rake \
'--version : echo 1' \
"install : mkdir -p '$INSTALL_ROOT'; cp -fR . '$INSTALL_ROOT'"
run_inline_definition <<DEF
install_package "rubinius-2.0.0" "http://releases.rubini.us/rubinius-2.0.0.tar.gz" rbx
DEF
assert_success
unstub rake
run ls "${INSTALL_ROOT}/bin"
assert_output <<OUT
irb
rake
ruby
OUT
run $(type -p greadlink readlink | head -1) "${INSTALL_ROOT}/gems/bin"
assert_success '../bin'
assert [ -x "${INSTALL_ROOT}/bin/rake" ]
run cat "${INSTALL_ROOT}/bin/rake"
assert_output <<OUT
#!${INSTALL_ROOT}/bin/ruby
puts 'rake'
OUT
assert [ -x "${INSTALL_ROOT}/bin/irb" ]
run cat "${INSTALL_ROOT}/bin/irb"
assert_output <<OUT
#!${INSTALL_ROOT}/bin/ruby
print '>>'
OUT
}
@test "JRuby build" {
executable "${TMP}/jruby-bin" <<OUT
#!${BASH}
IFS=,
echo "jruby [\$*]" >> ../build.log
OUT
executable "${TMP}/jruby-gem" <<OUT
#!/usr/bin/env jruby
nice gem things
OUT
cached_tarball "jruby-1.7.9" bin/foo.exe bin/bar.dll bin/baz.bat \
bin/jruby:"$TMP"/jruby-bin \
bin/gem:"$TMP"/jruby-gem
run_inline_definition <<DEF
install_package "jruby-1.7.9" "http://jruby.org/downloads/jruby-bin-1.7.9.tar.gz" jruby
DEF
assert_success
assert_build_log <<OUT
jruby [gem,install,jruby-launcher,--no-document]
OUT
run ls "${INSTALL_ROOT}/bin"
assert_output <<OUT
gem
jruby
ruby
OUT
assert [ -x "${INSTALL_ROOT}/bin/gem" ]
run cat "${INSTALL_ROOT}/bin/gem"
assert_output <<OUT
#!${INSTALL_ROOT}/bin/jruby
nice gem things
OUT
}
@test "JRuby Java 7 missing" {
cached_tarball "jruby-9000.dev" bin/jruby
stub java false
run_inline_definition <<DEF
require_java7
install_package "jruby-9000.dev" "http://ci.jruby.org/jruby-dist-9000.dev-bin.tar.gz" jruby
DEF
assert_failure
assert_output_contains "ERROR: Java >= 7 required, but your Java version was:"
}
@test "JRuby Java is outdated" {
cached_tarball "jruby-9000.dev" bin/jruby
stub java "-version : echo 'java version \"1.6.0_21\"' >&2"
run_inline_definition <<DEF
require_java7
install_package "jruby-9000.dev" "http://ci.jruby.org/jruby-dist-9000.dev-bin.tar.gz" jruby
DEF
assert_failure
assert_output_contains "ERROR: Java >= 7 required, but your Java version was:"
assert_output_contains 'java version "1.6.0_21"'
}
@test "JRuby Java 7 up-to-date" {
cached_tarball "jruby-9000.dev" bin/jruby
stub java '-version : echo java version "1.7.0_21" >&2'
run_inline_definition <<DEF
require_java7
install_package "jruby-9000.dev" "http://ci.jruby.org/jruby-dist-9000.dev-bin.tar.gz" jruby
DEF
assert_success
}
@test "Java version string not on first line" {
cached_tarball "jruby-9000.dev" bin/jruby
stub java "-version : echo 'Picked up JAVA_TOOL_OPTIONS' >&2; echo 'java version \"1.8.0_31\"' >&2"
run_inline_definition <<DEF
require_java7
install_package "jruby-9000.dev" "http://ci.jruby.org/jruby-dist-9000.dev-bin.tar.gz" jruby
DEF
assert_success
}
@test "Java version string on OpenJDK" {
cached_tarball "jruby-9000.dev" bin/jruby
stub java "-version : echo 'openjdk version \"1.8.0_40\"' >&2"
run_inline_definition <<DEF
require_java7
install_package "jruby-9000.dev" "http://ci.jruby.org/jruby-dist-9000.dev-bin.tar.gz" jruby
DEF
assert_success
}
@test "JRuby Java 9 version string" {
cached_tarball "jruby-9000.dev" bin/jruby
stub java "-version : echo 'java version \"9\"' >&2"
run_inline_definition <<DEF
require_java7
install_package "jruby-9000.dev" "http://ci.jruby.org/jruby-dist-9000.dev-bin.tar.gz" jruby
DEF
assert_success
}
@test "JRuby Java 10 version string" {
cached_tarball "jruby-9000.dev" bin/jruby
stub java "-version : echo 'java version \"10.8\"' >&2"
run_inline_definition <<DEF
require_java 9
install_package "jruby-9000.dev" "http://ci.jruby.org/jruby-dist-9000.dev-bin.tar.gz" jruby
DEF
assert_success
}
@test "JRuby Java 11 version string" {
cached_tarball "jruby-9000.dev" bin/jruby
stub java "-version : echo 'openjdk version \"11.0.10\" 2021-01-19' >&2"
run_inline_definition <<DEF
require_java 8
install_package "jruby-9000.dev" "http://ci.jruby.org/jruby-dist-9000.dev-bin.tar.gz" jruby
DEF
assert_success
}
@test "JRuby Java 17 version string" {
cached_tarball "jruby-9000.dev" bin/jruby
stub java "-version : echo 'openjdk version \"17\" 2021-09-14' >&2"
run_inline_definition <<DEF
require_java 8
install_package "jruby-9000.dev" "http://ci.jruby.org/jruby-dist-9000.dev-bin.tar.gz" jruby
DEF
assert_success
}
@test "TruffleRuby post-install hook" {
executable "${TMP}/hook.sh" <<OUT
echo Running post-install hook >> build.log
OUT
cached_tarball "truffleruby-test" bin/truffleruby lib/truffle/post_install_hook.sh:"$TMP"/hook.sh
run_inline_definition <<DEF
install_package "truffleruby-test" "URL" truffleruby
DEF
assert_success
run cat "$INSTALL_ROOT"/build.log
assert_success "Running post-install hook"
}
@test "non-writable TMPDIR aborts build" {
export TMPDIR="${TMP}/build"
mkdir -p "$TMPDIR"
chmod -w "$TMPDIR"
touch "${TMP}/build-definition"
run ruby-build "${TMP}/build-definition" "$INSTALL_ROOT"
assert_failure "ruby-build: TMPDIR=$TMPDIR is set to a non-accessible location"
}
@test "non-executable TMPDIR aborts build" {
export TMPDIR="${TMP}/build"
mkdir -p "$TMPDIR"
chmod -x "$TMPDIR"
touch "${TMP}/build-definition"
run ruby-build "${TMP}/build-definition" "$INSTALL_ROOT"
assert_failure "ruby-build: TMPDIR=$TMPDIR is set to a non-accessible location"
}
@test "does not initialize LDFLAGS directories" {
cached_tarball "ruby-3.2.0" configure
export LDFLAGS="-L ${BATS_TEST_DIRNAME}/what/evs"
run_inline_definition <<DEF
install_package "ruby-3.2.0" "http://ruby-lang.org/ruby/2.0/ruby-3.2.0.tar.gz" ldflags_dirs
DEF
assert_success
assert [ ! -d "${INSTALL_ROOT}/lib" ]
assert [ ! -d "${BATS_TEST_DIRNAME}/what/evs" ]
}
|