PATCH: add --local_init and --global_init options to override use of site.exp [reissued]

Jacob Bachmeyer <[email protected]>
Newsgroups gmane.comp.sysutils.dejagnu.general
Message-ID <[email protected]>
This is the previous --{loc,glob}al_init patch regenerated against 
current master HEAD.  This version of the patch also adds 2018 to the 
copyright notices in runtest.exp and runtest.1, but there does not seem 
to be a copyright/permission notice in dejagnu.texi.  Did I miss it or 
is it missing?

ChangeLog entries:
----
	* doc/dejagnu.texi (Invoking runtest): Document new --local_init
	and --global_init command line options.
	* doc/runtest.1: Document same new command line options.

	* runtest.exp: Remove useless tests before setting default values
	for variables: all_flag, binpath, debug, options, outdir, reboot,
	tracelevel, verbose, log_dialog.  They are set before loading any
	files or parsing the command line.

	* runtest.exp: Add options --local_init and --global_init for
	selecting alternate testsuite configuration files.

	* runtest.exp: Split variable "configfile" into "local_init_file"
	and "global_init_file" in preparation for adding command-line
	options to specify these independently.  Defaults:  site.exp

	* runtest.exp (load_generic_config): Remove unused global variable.
	(load_board_description): Remove unused global variable.
	(load_base_board_description): Remove unused global variable.
----

patch:
----
diff --git a/doc/dejagnu.texi b/doc/dejagnu.texi
index 85a1730..0700182 100644
--- a/doc/dejagnu.texi
+++ b/doc/dejagnu.texi
@@ -554,6 +554,14 @@ output of the tool with the scripted patterns describing expected
 output.  The output generated with @code{--strace} also goes into
 @file{dbg.log}.
 
+@item @code{--global_init [name]}
+Use @emph{name} as the global init file instead of @file{site.exp} in
+@emph{libdir}.  The default is, of course, @file{site.exp}.  Note that
+this option accepts a relative file name, interpreted starting at
+@emph{libdir}, so a file in a subdirectory may be used.  This is
+probably less useful for most sites, but is orthogonal with the
+@code{--local_init} option and may be useful in large testing labs.
+
 @item @code{--help}
 Prints out a short summary of the @emph{runtest} options, then exits
 (even if you specify other options).
@@ -578,6 +586,12 @@ The host board to use.
 @item @code{--ignore [name(s)] }
 The name(s) of specific tests to ignore.
 
+@item @code{--local_init [name]}
+Use @emph{name} as the testsuite local init file instead of
+@file{site.exp} in the current directory and in @emph{objdir}.  The
+default is, of course, @file{site.exp}.  Note that this option accepts a
+relative file name, so a file in a subdirectory may be used.
+
 @item @code{--log_dialog}
 Emit Expect output to stdout.  The Expect output is usually only written
 to the @file{.log} file. By enabling this option, they are also printed
@@ -1354,6 +1368,17 @@ table describes the correspondence between command line options and
 variables you can set in @file{site.exp}.  @ref{Invoking runtest}, for
 explanations of the command-line options.
 
+The @code{--local_init} and @code{--global_init} options have
+associated Tcl variables, but they influence the search for
+configuration files and overriding them is unlikely to be useful
+because they are not used after the configuration files are loaded.
+Once the configuration file is opened, it is too late for a change to
+these variables to be effective.  However, the local init file name is
+used twice, once relative to @code{base_dir} (the directory in which
+runtest was started) and once relative to @code{objdir}.  While
+testsuites should not make assumptions about what global init files
+are available, the user could usefully write such a setting.
+
 @multitable @columnfractions 0.2 0.2 0.6
 @item
 @strong{Option}@tab @strong{Tcl variable}@tab @strong{Description}
@@ -1368,6 +1393,9 @@ explanations of the command-line options.
 --dir@tab cmdline_dir_to_run@tab run only tests in the specified directory
 
 @item
+--global_init@tab global_init_file@tab file name for global init file in @code{libdir}
+
+@item
 --host@tab host_triplet@tab system triplet for the host
 
 @item
@@ -1377,6 +1405,9 @@ explanations of the command-line options.
 --ignore@tab ignoretests @tab do not run the specified tests
 
 @item
+--local_init@tab local_init_file@tab file name for local init file in @code{objdir}
+
+@item
 --log_dialog@tab log_dialog@tab emit Expect output to standard output
 
 @item
@@ -5227,3 +5258,5 @@ This makes runtest exit. It is abbreviated as @emph{q}.
 @end table
 
 @bye
+
+@c  LocalWords:  subdirectory
diff --git a/doc/runtest.1 b/doc/runtest.1
index 5b70d35..39ebf4a 100644
--- a/doc/runtest.1
+++ b/doc/runtest.1
@@ -1,4 +1,4 @@
-.TH runtest 1 "2017-10-16"
+.TH runtest 1 "2018-11-18"
 .SH NAME
 runtest \- DejaGnu test driver
 .SH SYNOPSIS
@@ -29,6 +29,10 @@ internal debugging output. The output is logged to a file called
 .BI --directory \ DIRECTORY
 Run only tests in the specified DIRECTORY.
 .TP
+.BI --global_init \ NAME
+The NAME to use for the global init file in libdir.
+The default is "site.exp" if this option is not given.
+.TP
 .B --help
 Prints a usage message and then exits.
 .TP
@@ -41,6 +45,11 @@ The host board definition to use.
 .BI --ignore \ test1.exp\ test2.exp\ ...
 Do not run the specified tests.
 .TP
+.BI --local_init \ NAME
+The NAME to use for the testsuite local init file in both the current
+directory and objdir.
+The default is "site.exp" if this option is not given.
+.TP
 .B --log_dialog
 Emit Expect output to standard output.
 .TP
@@ -125,7 +134,7 @@ Rob Savoye ([email protected])
 .SH "REPORTING BUGS"
 Report bugs to <bug\[email protected]>.
 .SH COPYRIGHT
-Copyright \(co 2005\-2016 Free Software Foundation, Inc.
+Copyright \(co 2005\-2016, 2018 Free Software Foundation, Inc.
 .PP
 This is free software.  You may redistribute copies of it under the terms of
 the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
diff --git a/runtest.exp b/runtest.exp
index be9f0e5..c7a6f26 100644
--- a/runtest.exp
+++ b/runtest.exp
@@ -1,5 +1,5 @@
 # runtest.exp -- Test framework driver
-# Copyright (C) 1992-2016 Free Software Foundation, Inc.
+# Copyright (C) 1992-2016, 2018 Free Software Foundation, Inc.
 #
 # This file is part of DejaGnu.
 #
@@ -63,7 +63,6 @@ set srcdir      "."		;# source directory containing the test suite
 set ignoretests ""		;# list of tests to not execute
 set objdir	"."		;# directory where test case binaries live
 set reboot      0
-set configfile  site.exp	;# (local to this file)
 set multipass   ""		;# list of passes and var settings
 set errno	"";		;#
 set exit_error  1		;# Toggle for whether to set the exit status
@@ -86,6 +85,12 @@ set target_cpu     ""		;# type of the cpu tests are running on
 set target_alias   ""		;# standard abbreviation of target
 set compiler_flags ""		;# the flags used by the compiler
 
+#
+# These set configuration file names and are local to this file.
+#
+set local_init_file	site.exp	;# testsuite-local init file name
+set global_init_file	site.exp	;# global init file name
+
 # Various ccache versions provide incorrect debug info such as ignoring
 # different current directory, breaking GDB testsuite.
 set env(CCACHE_DISABLE) 1
@@ -107,37 +112,18 @@ if {![info exists decimal]} {
 set base_dir [pwd]
 
 #
-# These are tested in case they are not initialized in $configfile. They are
-# tested here instead of the init module so they can be overridden by command
-# line options.
+# These are set here instead of the init module so they can be overridden
+# by command line options.
 #
-if {![info exists all_flag]} {
-    set all_flag 0
-}
-if {![info exists binpath]} {
-    set binpath ""
-}
-if {![info exists debug]} {
-    set debug 0
-}
-if {![info exists options]} {
-    set options ""
-}
-if {![info exists outdir]} {
-    set outdir "."
-}
-if {![info exists reboot]} {
-    set reboot 1
-}
-if {![info exists tracelevel]} {
-    set tracelevel 0
-}
-if {![info exists verbose]} {
-    set verbose 0
-}
-if {![info exists log_dialog]} {
-    set log_dialog 0
-}
+set all_flag	0
+set binpath	""
+set debug	0
+set options	""
+set outdir	"."
+set reboot	1
+set tracelevel	0
+set verbose	0
+set log_dialog	0
 
 #
 # verbose [-n] [-log] [--] message [level]
@@ -378,10 +364,12 @@ proc usage { } {
     send_user "\t--build \[triplet\]\tThe canonical triplet of the build machine\n"
     send_user "\t--debug\t\t\tSet expect debugging ON\n"
     send_user "\t--directory name\tRun only the tests in directory 'name'\n"
+    send_user "\t--global_init \[name\]\tThe file to load for global configuration\n"
     send_user "\t--help\t\t\tPrint help text\n"
     send_user "\t--host \[triplet\]\tThe canonical triplet of the host machine\n"
     send_user "\t--host_board \[name\]\tThe host board to use\n"
     send_user "\t--ignore \[name(s)\]\tThe names of specific tests to ignore\n"
+    send_user "\t--local_init \[name\]\tThe file to load for local configuration\n"
     send_user "\t--log_dialog\t\t\Emit Expect output on stdout\n"
     send_user "\t--mail \[name(s)\]\tWhom to mail the results to\n"
     send_user "\t--objdir \[name\]\t\tThe test suite binary directory\n"
@@ -412,9 +400,9 @@ proc usage { } {
 # parse them twice.  Things are complicated because:
 # - we want to parse --verbose early on
 # - we don't want config files to override command line arguments
-#   (eg: $base_dir/$configfile vs --host/--target)
+#   (eg: $base_dir/$local_init_file vs --host/--target)
 # - we need some command line arguments before we can process some config files
-#   (eg: --objdir before $objdir/$configfile, --host/--target before $DEJAGNU)
+#   (eg: --objdir before $objdir/$local_init_file, --host/--target before $DEJAGNU)
 # The use of `arg_host_triplet' and `arg_target_triplet' lets us avoid parsing
 # the arguments three times.
 #
@@ -441,8 +429,10 @@ for { set i 0 } { $i < $argc } { incr i } {
 	    regexp {^[^=]*=(.*)$} $option nil optarg
 	}
 	"--bu*" -
+	"--g*" -
 	"--ho*" -
 	"--ig*"  -
+	"--loc*" -
 	"--m*"  -
 	"--n*"  -
 	"--ob*" -
@@ -463,6 +453,11 @@ for { set i 0 } { $i < $argc } { incr i } {
 	    continue
 	}
 
+	"--g*" {			# (--global_init) the global init file name
+	    set global_init_file $optarg
+	    continue
+	}
+
 	"--host_bo*" {
 	    set host_board $optarg
 	    continue
@@ -473,6 +468,11 @@ for { set i 0 } { $i < $argc } { incr i } {
 	    continue
 	}
 
+	"--loc*" {			# (--local_init) the local init file name
+	    set local_init_file $optarg
+	    continue
+	}
+
 	"--ob*" {			# (--objdir) where the test case object code lives
 	    set objdir $optarg
 	    continue
@@ -611,25 +611,26 @@ verbose "Login name is $logname"
 # All are sourced in order.
 #
 # Search order:
-#	$base_dir/$configfile -> $objdir/$configfile ->
-#	installed -> $DEJAGNU -> $HOME/.dejagnurc
+#    (local)	$base_dir/$local_init_file -> $objdir/$local_init_file ->
+#    (global)	installed($global_init_file) -> $DEJAGNU -> $HOME/.dejagnurc
 #
-# For the normal case, we rely on $base_dir/$configfile to set
+# For the normal case, we expect $base_dir/$local_init_file to set
 # host_triplet and target_triplet.
 #
 
-load_file $base_dir/$configfile
+load_file [file join $base_dir $local_init_file]
 
 #
-# If objdir didn't get set in $base_dir/$configfile, set it to $base_dir.
-# Make sure we source $objdir/$configfile in case $base_dir/$configfile doesn't
-# exist and objdir was given on the command line.
+# If objdir didn't get set in $base_dir/$local_init_file, set it to
+# $base_dir.  Make sure we source $objdir/$local_init_file in case
+# $base_dir/$local_init_file doesn't exist and objdir was given on the
+# command line.
 #
 
 if {[expr {[string match "." $objdir] || [string match $srcdir $objdir]}]} {
     set objdir $base_dir
 } else {
-    load_file $objdir/$configfile
+    load_file [file join $objdir $local_init_file]
 }
 
 # Well, this just demonstrates the real problem...
@@ -853,7 +854,7 @@ proc setup_build_hook { name } {
 # These files assume the host and target have been set.
 #
 
-if { [load_file -- $libdir/$configfile] == 0 } {
+if { [load_file -- [file join $libdir $global_init_file]] == 0 } {
     # If $DEJAGNU isn't set either then there isn't any global config file.
     # Warn the user as there really should be one.
     if { ! [info exists env(DEJAGNU)] } {
@@ -997,8 +998,10 @@ for { set i 0 } { $i < $argc } { incr i } {
 	    regexp {^[^=]*=(.*)$} $option nil optarg
 	}
 	"--bu*" -
+	"--g*" -
 	"--ho*" -
 	"--ig*"  -
+	"--loc*" -
 	"--m*"  -
 	"--n*"  -
 	"--ob*" -
@@ -1027,6 +1030,16 @@ for { set i 0 } { $i < $argc } { incr i } {
 	    continue
 	}
 
+	"--g*" {			# (--global_init) the global init file name
+	    # Already parsed (and no longer useful).  The file has been loaded.
+	    continue
+	}
+
+	"--loc*" {			# (--local_init) the local init file name
+	    # Already parsed (and no longer useful).  The file has been loaded.
+	    continue
+	}
+
 	"--bu*" {			# (--build) the build host configuration
 	    # Already parsed (and don't set again).  Let $DEJAGNU rename it.
 	    continue
@@ -1247,7 +1260,6 @@ clone_output "\n\t\t=== $tool tests ===\n"
 
 proc load_generic_config { name } {
     global srcdir
-    global configfile
     global libdir
     global env
     global board
@@ -1323,7 +1335,6 @@ proc load_tool_target_config { name } {
 
 proc load_board_description { board_name args } {
     global srcdir
-    global configfile
     global libdir
     global env
     global board
@@ -1392,7 +1403,6 @@ proc load_board_description { board_name args } {
 
 proc load_base_board_description { board_name } {
     global srcdir
-    global configfile
     global libdir
     global env
     global board
----


-- Jacob
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.