From: Gary V. Vaughan Date: Wed, 16 Nov 2011 05:43:53 +0000 (+0700) Subject: options-parser: provide a saner pluggable API. X-Git-Tag: v2.4.2.418~268 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=de4c35b8109cd06aae1e1b125dbbbca397111fd0;p=thirdparty%2Flibtool.git 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 --- diff --git a/bootstrap b/bootstrap index d18316acd..b0413ff2c 100755 --- a/bootstrap +++ b/bootstrap @@ -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" } diff --git a/bootstrap.conf b/bootstrap.conf index 0f89559e3..e1537e237 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -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 diff --git a/libltdl/config/options-parser b/libltdl/config/options-parser index 540083347..decddb78f 100644 --- a/libltdl/config/options-parser +++ b/libltdl/config/options-parser @@ -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 `_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