options-parser: provide a saner pluggable API.

It's much too easy to forget that the functions you hook into
the option parser need to return unconsumed options in the
variable `func_run_hooks_result'; better to follow the
convention used in the rest of bootstrap and return results in a
variable named after the function with `_result' appended.
* libltdl/config/options-parser (func_run_hooks): implement this
new API.
(Option parsing): Update the example in the header comment for
this section to reflect the changes.
* bootstrap (bootstrap_options_prep, bootstrap_parse_options)
(bootstrap_validate_options): Adjust.
* bootstrap.conf (libtool_options_prep, libtool_parse_options)
(libtool_validate_options): Ditto.

Signed-off-by: Gary V. Vaughan <gary@gnu.org>
This commit is contained in:
Gary V. Vaughan 2011-11-16 12:43:53 +07:00
parent a5ef08182c
commit de4c35b810
3 changed files with 20 additions and 26 deletions

View File

@ -2336,17 +2336,14 @@ bootstrap_options_prep ()
# Pass back the list of options we consumed.
func_quote_for_eval ${1+"$@"}
func_run_hooks_result="$func_quote_for_eval_result"
bootstrap_options_prep_result="$func_quote_for_eval_result"
}
func_add_hook func_options_prep bootstrap_options_prep
# bootstrap_parse_options [ARG]...
# --------------------------------
# Provide handling for Bootstrap specific options. Note
# `func_parse_options' passes in the unconsumed positional parameters, and
# this function has to pass back whatever remains after its own
# processing in the `func_run_hooks_result' variable.
# Provide handling for Bootstrap specific options.
bootstrap_parse_options ()
{
$debug_cmd
@ -2417,7 +2414,7 @@ bootstrap_parse_options ()
# save modified positional parameters for caller
func_quote_for_eval ${1+"$@"}
func_run_hooks_result="$func_quote_for_eval_result"
bootstrap_parse_options_result="$func_quote_for_eval_result"
}
func_add_hook func_parse_options bootstrap_parse_options
@ -2439,7 +2436,7 @@ bootstrap_validate_options ()
# Pass back the list of unconsumed options left.
func_quote_for_eval ${1+"$@"}
func_run_hooks_result="$func_quote_for_eval_result"
bootstrap_validate_options_result="$func_quote_for_eval_result"
}

View File

@ -177,7 +177,7 @@ Libtool Specific Options:
# pass back the list of options we consumed
func_quote_for_eval ${1+"$@"}
func_run_hooks_result="$func_quote_for_eval_result"
libtool_options_prep_result="$func_quote_for_eval_result"
}
func_add_hook func_options_prep libtool_options_prep
@ -185,9 +185,7 @@ func_add_hook func_options_prep libtool_options_prep
# libtool_parse_options [ARG...]
# ------------------------------
# Provide handling for additional Libtool options inside the main option
# parsing loop. Note that `bootstrap' passes in the current positional
# parameters, and this function has to pass back whatever is left after
# its own processing in the `func_run_hooks_result' variable.
# parsing loop.
libtool_parse_options ()
{
$debug_cmd
@ -217,7 +215,7 @@ libtool_parse_options ()
# pass back the list of options we consumed
func_quote_for_eval ${1+"$@"}
func_run_hooks_result="$func_quote_for_eval_result"
libtool_parse_options_result="$func_quote_for_eval_result"
}
func_add_hook func_parse_options libtool_parse_options
@ -246,7 +244,7 @@ libtool_validate_options ()
# pass back the list of options we consumed
func_quote_for_eval ${1+"$@"}
func_run_hooks_result="$func_quote_for_eval_result"
libtool_validate_options_result="$func_quote_for_eval_result"
}
func_add_hook func_validate_options libtool_validate_options

View File

@ -1,7 +1,7 @@
#! /bin/sh
# Set a version string for this script.
scriptversion=2011-11-04.03; # UTC
scriptversion=2011-11-16.05; # UTC
# A pluggable option parser for Bourne shell.
# Written by Gary V. Vaughan, 2010
@ -272,20 +272,18 @@ func_run_hooks ()
*) func_fatal_error "\`$1' does not support hook funcions.n" ;;
esac
eval _G_hook_fns="\$$1_hooks"
# shift away the first argument (FUNC_NAME)
shift
func_quote_for_eval ${1+"$@"}
func_run_hooks_result=$func_quote_for_eval_result
eval _G_hook_fns="\$$1_hooks"; shift
for _G_hook in $_G_hook_fns; do
eval $_G_hook '"$@"'
# store returned options list back into positional
# parameters for next `cmd' execution.
eval set dummy $func_run_hooks_result; shift
eval set dummy \$${_G_hook}_result; shift
done
func_quote_for_eval ${1+"$@"}
func_run_hooks_result=$func_quote_for_eval_result
}
@ -297,8 +295,8 @@ func_run_hooks ()
# In order to add your own option parsing hooks, you must accept the
# full positional parameter list in your hook function, remove any
# options that you action, and then pass back the remaining unprocessed
# options in `func_run_hooks_result', escaped suitably for `eval'. Like
# this:
# options in `<hooked_function_name>_result', escaped suitably for
# `eval'. Like this:
#
# my_options_prep ()
# {
@ -310,7 +308,7 @@ func_run_hooks ()
# '
#
# func_quote_for_eval ${1+"$@"}
# func_run_hooks_result=$func_quote_for_eval_result
# my_options_prep_result=$func_quote_for_eval_result
# }
# func_add_hook func_options_prep my_options_prep
#
@ -337,7 +335,7 @@ func_run_hooks ()
# done
#
# func_quote_for_eval ${1+"$@"}
# func_run_hooks_result=$func_quote_for_eval_result
# my_silent_option_result=$func_quote_for_eval_result
# }
# func_add_hook func_parse_options my_silent_option
#
@ -350,8 +348,9 @@ func_run_hooks ()
# \`--silent' and \`--verbose' options are mutually exclusive."
#
# func_quote_for_eval ${1+"$@"}
# func_run_hooks_result=$func_quote_for_eval_result
# my_option_validation_result=$func_quote_for_eval_result
# }
# func_add_hook func_validate_options my_option_validation
#
# You'll alse need to manually amend $usage_message to reflect the extra
# options you parse. It's preferable to append if you can, so that