Skip to content

Commit d9af2ad

Browse files
authored
Merge pull request #2267 from rbenv/configure-args
Pass ruby configuration flags on the command line
2 parents 4cec390 + 1c8689b commit d9af2ad

File tree

6 files changed

+163
-78
lines changed

6 files changed

+163
-78
lines changed

bin/rbenv-install

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,12 @@ cleanup() {
221221

222222
trap cleanup SIGINT
223223

224+
build_args=(${KEEP:+--keep} ${VERBOSE:+--verbose} ${HAS_PATCH:+--patch} "$DEFINITION" "$PREFIX")
225+
[ ${#EXTRA_ARGUMENTS[@]} -eq 0 ] || build_args+=(-- "${EXTRA_ARGUMENTS[@]}")
226+
224227
# Invoke `ruby-build` and record the exit status in $STATUS.
225228
STATUS=0
226-
ruby-build $KEEP $VERBOSE $HAS_PATCH "$DEFINITION" "$PREFIX" || STATUS="$?"
229+
ruby-build "${build_args[@]}" || STATUS="$?"
227230

228231
# Display a more helpful message if the definition wasn't found.
229232
if [ "$STATUS" == "2" ]; then

bin/ruby-build

Lines changed: 73 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,15 @@ lib() {
2626
parse_options() {
2727
OPTIONS=()
2828
ARGUMENTS=()
29+
EXTRA_ARGUMENTS=()
2930
local arg option index
3031

31-
for arg in "$@"; do
32-
if [ "${arg:0:1}" = "-" ]; then
32+
while [ $# -gt 0 ]; do
33+
arg="$1"
34+
if [ "$arg" == "--" ]; then
35+
shift 1
36+
break
37+
elif [ "${arg:0:1}" = "-" ]; then
3338
if [ "${arg:1:1}" = "-" ]; then
3439
OPTIONS[${#OPTIONS[*]}]="${arg:2}"
3540
else
@@ -40,10 +45,14 @@ lib() {
4045
index=$(($index+1))
4146
done
4247
fi
48+
shift 1
4349
else
4450
ARGUMENTS[${#ARGUMENTS[*]}]="$arg"
51+
shift 1
4552
fi
4653
done
54+
55+
EXTRA_ARGUMENTS=("$@")
4756
}
4857

4958
if [ "$1" == "--$FUNCNAME" ]; then
@@ -520,6 +529,7 @@ build_package() {
520529
package_option() {
521530
local package_name="$1"
522531
local command_name="$2"
532+
# e.g. RUBY_CONFIGURE_OPTS_ARRAY, OPENSSL_MAKE_OPTS_ARRAY
523533
local variable="$(capitalize "${package_name}_${command_name}")_OPTS_ARRAY"
524534
local array="$variable[@]"
525535
shift 2
@@ -641,18 +651,18 @@ build_package_ruby() {
641651
build_package_ree_installer() {
642652
build_package_auto_tcltk
643653

644-
local options=""
645-
is_mac && options="--no-tcmalloc"
654+
local options=()
655+
is_mac && options+=(--no-tcmalloc)
646656

647657
local option
648-
for option in ${RUBY_CONFIGURE_OPTS_ARRAY[@]} $RUBY_CONFIGURE_OPTS; do
649-
options="$options -c $option"
658+
for option in "${RUBY_CONFIGURE_OPTS_ARRAY[@]}" $RUBY_CONFIGURE_OPTS; do
659+
options+=(-c "$option")
650660
done
651661

652662
# Work around install_useful_libraries crash with --dont-install-useful-gems
653663
mkdir -p "$PREFIX_PATH/lib/ruby/gems/1.8/gems"
654664

655-
{ ./installer --auto "$PREFIX_PATH" --dont-install-useful-gems $options $CONFIGURE_OPTS
665+
{ ./installer --auto "$PREFIX_PATH" --dont-install-useful-gems "${options[@]}" $CONFIGURE_OPTS
656666
} >&4 2>&1
657667
}
658668

@@ -1259,6 +1269,7 @@ unset KEEP_BUILD_PATH
12591269
unset HAS_PATCH
12601270
unset IPV4
12611271
unset IPV6
1272+
unset EARLY_EXIT
12621273

12631274
RUBY_BUILD_INSTALL_PREFIX="$(abs_dirname "$0")/.."
12641275

@@ -1270,17 +1281,13 @@ parse_options "$@"
12701281
for option in "${OPTIONS[@]}"; do
12711282
case "$option" in
12721283
"h" | "help" )
1273-
version
1274-
echo
1275-
usage 0
1284+
EARLY_EXIT=help
12761285
;;
12771286
"definitions" )
1278-
list_definitions
1279-
exit 0
1287+
EARLY_EXIT=list_definitions
12801288
;;
12811289
"l" | "list")
1282-
list_maintained_versions
1283-
exit 0
1290+
EARLY_EXIT=list_maintained_versions
12841291
;;
12851292
"k" | "keep" )
12861293
KEEP_BUILD_PATH=true
@@ -1298,18 +1305,61 @@ for option in "${OPTIONS[@]}"; do
12981305
IPV6=true
12991306
;;
13001307
"version" )
1301-
version
1302-
exit 0
1308+
EARLY_EXIT=version
1309+
;;
1310+
* )
1311+
printf "ruby-build: invalid flag '%s'\n" "$option" >&2
1312+
EARLY_EXIT=usage_error
13031313
;;
13041314
esac
13051315
done
13061316

1307-
[ "${#ARGUMENTS[@]}" -eq 2 ] || usage 1 >&2
1308-
13091317
DEFINITION_PATH="${ARGUMENTS[0]}"
1310-
if [ -z "$DEFINITION_PATH" ]; then
1318+
PREFIX_PATH="${ARGUMENTS[1]}"
1319+
1320+
if [ -z "$EARLY_EXIT" ] && [ -z "$DEFINITION_PATH" ]; then
1321+
echo "ruby-build: missing definition argument" >&2
1322+
EARLY_EXIT=usage_error
1323+
fi
1324+
1325+
if [ -z "$EARLY_EXIT" ] && [ -z "$PREFIX_PATH" ]; then
1326+
echo "ruby-build: missing prefix argument" >&2
1327+
EARLY_EXIT=usage_error
1328+
fi
1329+
1330+
if [ "${#ARGUMENTS[@]}" -gt 2 ]; then
1331+
echo "ruby-build: expected at most 2 arguments, got [${ARGUMENTS[*]}]" >&2
1332+
EARLY_EXIT=usage_error
1333+
fi
1334+
1335+
if [ "${#EXTRA_ARGUMENTS[@]}" -gt 0 ]; then
1336+
RUBY_CONFIGURE_OPTS_ARRAY=("${EXTRA_ARGUMENTS[@]}")
1337+
fi
1338+
1339+
case "$EARLY_EXIT" in
1340+
help )
1341+
version
1342+
echo
1343+
usage 0
1344+
;;
1345+
version | list_definitions | list_maintained_versions )
1346+
"$EARLY_EXIT"
1347+
exit 0
1348+
;;
1349+
usage_error )
1350+
echo >&2
13111351
usage 1 >&2
1312-
elif [ ! -f "$DEFINITION_PATH" ]; then
1352+
;;
1353+
'' )
1354+
;;
1355+
* )
1356+
echo "unimplemented EARLY_EXIT: $EARLY_EXIT" >&2
1357+
exit 1
1358+
;;
1359+
esac
1360+
1361+
# expand the <definition> argument to full path of the definition file
1362+
if [ ! -f "$DEFINITION_PATH" ]; then
13131363
for DEFINITION_DIR in "${RUBY_BUILD_DEFINITIONS[@]}"; do
13141364
if [ -f "${DEFINITION_DIR}/${DEFINITION_PATH}" ]; then
13151365
DEFINITION_PATH="${DEFINITION_DIR}/${DEFINITION_PATH}"
@@ -1323,10 +1373,8 @@ elif [ ! -f "$DEFINITION_PATH" ]; then
13231373
fi
13241374
fi
13251375

1326-
PREFIX_PATH="${ARGUMENTS[1]}"
1327-
if [ -z "$PREFIX_PATH" ]; then
1328-
usage 1 >&2
1329-
elif [ "${PREFIX_PATH#/}" = "$PREFIX_PATH" ]; then
1376+
# normalize the <prefix> argument
1377+
if [ "${PREFIX_PATH#/}" = "$PREFIX_PATH" ]; then
13301378
PREFIX_PATH="${PWD}/${PREFIX_PATH}"
13311379
fi
13321380

@@ -1357,7 +1405,7 @@ if [ -n "$noexec" ]; then
13571405
fi
13581406

13591407
if [ -z "$MAKE" ]; then
1360-
if is_freebsd && [[ $1 == jruby-* ]]; then
1408+
if is_freebsd && [[ ${ARGUMENTS[0]} == jruby-* ]]; then
13611409
# jruby-launcher requires gmake: https://github.com/ruby/ruby/pull/8591
13621410
export MAKE="gmake"
13631411
else

0 commit comments

Comments
 (0)