diff options
author | Jacob Bachmeyer <jcb62281@gmail.com> | 2018-12-20 21:24:35 +1100 |
---|---|---|
committer | Ben Elliston <bje@gnu.org> | 2018-12-20 21:24:35 +1100 |
commit | 2f6e46b9820647476ddd568e14d76661abb4f493 (patch) | |
tree | 39dbd80189617ad46ecabcbc2fee82a59d3e529d /dejagnu | |
parent | 80d14caf5d1b26233bb25431243fdfe38cd3f92a (diff) |
* Makefile.am (EXTRA_DIST): Add "dejagnu" launcher script and
contents of $(commands_DATA).
(bin_SCRIPTS): Add "dejagnu" launcher script.
(commandsdir): Installation directory for "dejagnu" subcommands is
$(pkgdatadir)/commands.
(commands_DATA): New, contains "commands/help.sh" as initial item.
(TESTSUITE_FILES): Add testsuite for same.
(DEJATOOL): Add "launcher" to list of tools to test.
(dist_man_MANS): Add man pages for "dejagnu" and "dejagnu help".
* doc/dejagnu.texi (Running other DejaGnu commands): New chapter.
(Invoking dejagnu): New node for dejagnu(1) launcher script.
(Invoking dejagnu help): New node.
* doc/dejagnu.1: New man page.
* doc/dejagnu-help.1: New man page.
* dejagnu: New script.
* commands/help.sh: New dejagnu subcommand for reading manpages.
* testsuite/launcher.all/command.exp: New file.
* testsuite/launcher.all/command/commands/bar-baz.awk: New file.
* testsuite/launcher.all/command/commands/bar.awk: New file.
* testsuite/launcher.all/command/commands/bar.sh: New file.
* testsuite/launcher.all/command/commands/baz-quux.gawk: New file.
* testsuite/launcher.all/command/commands/foo.sh: New file.
* testsuite/launcher.all/command/commands/foo.tcl: New file.
* testsuite/launcher.all/help.exp: New file.
* testsuite/launcher.all/interp.exp: New file.
* testsuite/launcher.all/verbose.exp: New file.
* testsuite/lib/launcher.exp: New file.
Signed-off-by: Ben Elliston <bje@gnu.org>
Diffstat (limited to 'dejagnu')
-rwxr-xr-x | dejagnu | 453 |
1 files changed, 453 insertions, 0 deletions
@@ -0,0 +1,453 @@ +#!/bin/sh +# +# Copyright (C) 2018 Free Software Foundation, Inc. +# +# This file is part of DejaGnu. +# +# DejaGnu is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# DejaGnu is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with DejaGnu; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. + +# Portions from runtest Copyright (C) 1992-2016 Free Software Foundation, Inc. + +# This script was written by Jacob Bachmeyer. Portions of this script are +# adapted from the existing runtest script originally written by Rob Savoye. + +# This script finds an implementation for the command given, finds the +# proper interpreter, and then dispatches the command. This script can +# either be run with a command name as the first (few) argument(s), via a +# link from the command name, or some combination of those. + +# shellcheck disable=SC2209 +# The shellcheck tool complains about assigning certain constant strings to +# variables. In this script, the intended meaning is obvious in context. + +# ##help +# #Usage: dejagnu <command> [--help|options...] +# #Usage: dejagnu --help +# #Usage: dejagnu --version +# # --help Print help text +# # --version Print DejaGnu version +# ##end + +# list of extensions supported for commands in priority order +readonly Variants="gawk awk tcl exp bash sh" + +## Recognize options + +# For testing and development +override_ext= +if test x"$1" = x--DGTimpl ; then + override_ext=$2 + shift 2 +fi + +want_help=false +want_version=false +verbose=0 +for a in "$@"; do + case $a in + --help) want_help=true ;; + -v|--v|-verbose|--verbose) verbose=$((verbose + 1)) ;; + -V|--V|-version|--version) want_version=true ;; + esac +done + +if expr "$verbose" \> 0 > /dev/null ; then + echo Verbose level is $verbose +fi + +## Get the file name of this script and deduce @bindir@. + +bindir="$(echo "$0" | sed -e 's@/[^/]*$@@')" +if expr "$verbose" \> 0 > /dev/null ; then + echo Running launcher from "$bindir" +fi + +## Find the commands. + +# If running from source tree, they are in ./commands/ relative to this script. +# If installed, they are in @datadir@/dejagnu/commands/ on the system. + +# This makes the same assumption as in runtest that one of these holds: +# +# @datadir@ == @bindir@/../share +# @datadir@ == @bindir@/../../share +# @datadir@ == /usr/share +# @datadir@ == /usr/local/share + +if test -n "$DEJAGNULIBS" ; then + commdir="${DEJAGNULIBS}/commands" + datadir="${DEJAGNULIBS}" +elif test -d "${bindir}/commands" && test -f "${bindir}/runtest.exp" ; then + if expr "$verbose" \> 1 > /dev/null ; then + echo Running from source directory + fi + commdir="${bindir}/commands" + datadir="${bindir}" +else + commdir= + for i in \ + "$(echo "$bindir" | sed -e 's@/[^/]*$@/share/dejagnu@')" \ + "$(echo "$bindir" | sed -e 's@/[^/]*/[^/]*$@/share/dejagnu@')" \ + /usr/share/dejagnu /usr/local/share/dejagnu + do + if expr "$verbose" \> 1 > /dev/null ; then + echo Probing directory "$i"/commands + fi + if test -d "$i"/commands ; then + commdir="$i"/commands + datadir="$i" + break + fi + done +fi + +if test -z "${commdir}" ; then + echo ERROR: could not find command directory. + exit 2 +fi + +if expr "$verbose" \> 0 > /dev/null ; then + echo Looking for commands in "$commdir" +fi + +## Get the name of the requested command. + +# Are we just looking for version information? +if $want_version ; then + frame_version=$(grep '^set frame_version' "${datadir}/runtest.exp" \ + | sed 's/^[^0-9]*//') + echo 'dejagnu auxiliary launcher (DejaGnu)' "$frame_version" + exit 0 +fi + +# Remove any leading autoconf platform prefix and the "dejagnu" prefix. +command="$(basename "$0" | sed -e 's/^.*-\?dejagnu-\?//')" +commext= + +while expr $# \> 0 > /dev/null +do + if test -z "${command}" ; then + if expr "$1" : - > /dev/null ; then + break + fi + command="$1" + shift + fi + if expr "$verbose" \> 2 > /dev/null ; then + echo Looking for "${commdir}/${command}.*" + fi + for ext in ${Variants} + do + if test -f "${commdir}/${command}.$ext" ; then + commext="$commext $ext" + fi + done + if expr "$1" : - > /dev/null ; then + break + fi + if test -n "$commext" ; then + break + fi + if test -n "$1" ; then + command="${command}-$1" + shift + else + break + fi +done + +if test -z "$commext" && test -n "$command" ; then + echo ERROR: could not resolve command "$command" + exit 2 +fi + +if expr "$verbose" \> 0 > /dev/null ; then + if test -n "$command"; then + if expr "$verbose" \> 1 > /dev/null ; then + echo Found subcommand "$command" with variants: "$commext" + else + echo Found subcommand "$command" + fi + else + echo Running nothing. + fi +fi + +## Find interpreters. + +# Awk and GNU awk +if test -n "$AWK" ; then + awkbin="$AWK" +elif test -x "${bindir}/awk" ; then + awkbin="${bindir}/awk" +else + awkbin=awk +fi +if test -n "$GAWK" ; then + gawkbin="$GAWK" +elif test -x "${bindir}/gawk" ; then + gawkbin="${bindir}/gawk" +else + gawkbin=gawk +fi +if command -v "$awkbin" > /dev/null 2>&1 ; then + have_awk=true +else + have_awk=false +fi +if command -v "$gawkbin" > /dev/null 2>&1 ; then + have_gawk=true +else + have_gawk=false +fi +# substitute GNU awk for awk if needed +if $have_gawk ; then + if $have_awk ; then : ; else + have_awk=$have_gawk + awkbin=$gawkbin + fi +fi +# is "awk" actually GNU Awk? +if $have_awk ; then + if "$awkbin" --version | sed 1q | grep -qi 'GNU Awk' ; then + have_gawk_as_awk=true + else + have_gawk_as_awk=false + fi +fi +if expr "$verbose" \> 2 > /dev/null ; then + if $have_awk ; then + echo Awk interpreter is "$awkbin" + else + echo Awk interpreter was not found + fi + if $have_gawk ; then + echo GNU Awk interpreter is "$gawkbin" + else + echo GNU Awk interpreter was not found + fi +fi + + +# Bash +if test -n "$BASH" ; then + bashbin="$BASH" +elif test -x "${bindir}/bash" ; then + bashbin="${bindir}/bash" +elif test -x /bin/bash ; then + bashbin=/bin/bash +else + bashbin=bash +fi +if command -v "$bashbin" > /dev/null 2>&1 ; then + have_bash=true +else + have_bash=false +fi +if expr "$verbose" \> 2 > /dev/null ; then + if $have_bash ; then + echo Bash interpreter is "$bashbin" + else + echo Bash interpreter was not found + fi +fi + +# Bourne shell +# This script is running, therefore we have a Bourne shell. +have_sh=true + +# Expect +# DejaGnu configure bails out if Expect is not available, but this script +# can be run from the source directory without first running configure. +if test -n "$EXPECT" ; then + expectbin="$EXPECT" +elif test -x "${bindir}/expect" ; then + expectbin="${bindir}/expect" +else + expectbin=expect +fi +if command -v "$expectbin" > /dev/null 2>&1 ; then + have_expect=true +else + have_expect=false +fi +if expr "$verbose" \> 2 > /dev/null ; then + if $have_expect ; then + echo Expect interpreter is "$expectbin" + else + echo Expect interpreter was not found + fi +fi + +# Tcl +if test -n "$TCLSH" ; then + tclbin="$TCLSH" +elif test -x "${bindir}/tclsh" ; then + tclbin="${bindir}/tclsh" +else + tclbin=tclsh +fi +# substitute expect if needed +if command -v "$tclbin" > /dev/null 2>&1 ; then : +elif command -v "$expectbin" > /dev/null 2>&1 ; then tclbin="$expectbin" +fi +if command -v "$tclbin" > /dev/null 2>&1 ; then + have_tcl=true +else + have_tcl=false +fi +if expr "$verbose" \> 2 > /dev/null ; then + if $have_tcl ; then + echo Tcl interpreter is "$tclbin" + else + echo Tcl interpreter was not found + fi +fi + +## Select a variant. + +if test -n "$override_ext" ; then + selected_ext="$override_ext" +else + selected_ext= + for v in $commext + do + case $v in + awk) + if $have_awk ; then + selected_ext=awk + break + fi + ;; + bash) + if $have_bash ; then + selected_ext=bash + break + fi + ;; + exp) + if $have_expect ; then + selected_ext=exp + break + fi + ;; + gawk) + if $have_gawk ; then + selected_ext=gawk + break + fi + ;; + tcl) + if $have_tcl ; then + selected_ext=tcl + break + fi + ;; + sh) + selected_ext=sh + break + ;; + *) + echo ERROR: '(select-variant)' unrecognized variant "$v" + ;; + esac + done + if test -z "$selected_ext" && test -n "$command" ; then + echo ERROR: no variant of "$command" was selected + exit 2 + fi +fi + +if test -n "$command" && expr "$verbose" \> 0 > /dev/null ; then + if test -n "$override_ext" ; then + echo Selected variant "$selected_ext" by override + else + echo Selected variant "$selected_ext" + fi +fi + +## Dispatch to the selected command. + +# Are we just looking for a usage message? +if $want_help ; then + if test -z "$command" ; then + # want help on the launcher itself + help_file=$0 + else + help_file="${commdir}/${command}.${selected_ext}" + fi + if test ! -r "$help_file" ; then + echo ERROR: file "'$help_file'" is not readable + exit 2 + fi + if grep -q '#help' "$help_file" \ + && grep -q '#end' "$help_file"; then : ; else + echo ERROR: file "'$help_file'" does not contain a help message + exit 2 + fi + help_prefix_pat=$(grep '#help' "$help_file" \ + | sed 's/#help.*$//;1q' | tr '[:print:][:blank:]' .) + if expr "$verbose" \> 1 > /dev/null ; then + echo Extracting help from "'$help_file'" with prefix "'$help_prefix_pat'" + fi + sed -n < "$help_file" \ + -e '1,/#help/d' \ + -e '/^'"$help_prefix_pat"'#end/q' \ + -e 's/^'"$help_prefix_pat"'//;p' + exit 0 +fi + +if test -z "$command" ; then + if test -n "$override_ext" ; then + case $selected_ext in + awk) $have_awk; exit $? ;; + bash) $have_bash; exit $? ;; + exp) $have_expect; exit $? ;; + gawk) $have_gawk; exit $? ;; + tcl) $have_tcl; exit $? ;; + sh) $have_sh; exit $? ;; + *) exit 2 ;; + esac + else + echo ERROR: no command given + exit 2 + fi +fi + +case $selected_ext in + awk) + if $have_gawk_as_awk ; then + exec "$awkbin" --posix -f "${commdir}/${command}.awk" -- ${1+"$@"} + else + exec "$awkbin" -f "${commdir}/${command}.awk" -- ${1+"$@"} + fi + ;; + bash) exec "$bashbin" -- "${commdir}/${command}.bash" ${1+"$@"} ;; + exp) exec "$expectbin" -- "${commdir}/${command}.exp" ${1+"$@"} ;; + gawk) exec "$gawkbin" -f "${commdir}/${command}.gawk" -- ${1+"$@"} ;; + tcl) exec "$tclbin" "${commdir}/${command}.tcl" ${1+"$@"} ;; + sh) exec /bin/sh "${commdir}/${command}.sh" ${1+"$@"} ;; + echo) + echo command: "${command}" + echo args: ${1+"$@"} + exit 0 + ;; + *) + echo ERROR: '(run-variant)' unrecognized variant "$selected_ext" + exit 2 + ;; +esac + +#EOF |