From bb63ec232aff71a7ab670ce1a52c87d1d31439f2 Mon Sep 17 00:00:00 2001 From: Richard Tucker Date: Fri, 16 May 1997 15:29:05 +0100 Subject: [PATCH] Mend option processing Copied from Perforce Change: 18182 ServerID: perforce.ravenbrook.com --- mps/qa/test/qa | 73 ++++++++----------------------- mps/qa/test/script/commands/clib | 10 ++++- mps/qa/test/script/commands/index | 3 ++ mps/qa/test/script/commands/try | 8 ++++ mps/qa/test/script/compile | 4 +- 5 files changed, 40 insertions(+), 58 deletions(-) diff --git a/mps/qa/test/qa b/mps/qa/test/qa index 662529ec0c3..89bce76b8d8 100644 --- a/mps/qa/test/qa +++ b/mps/qa/test/qa @@ -16,19 +16,12 @@ $test_dir = $0; $0 = "qa testing"; # this will show up in ps -$test_dir =~ s/\/\w+$//; - -$script_dir = $test_dir."/script"; -$testlib_dir = $test_dir."/testlib"; &use($testlib_dir); - -$platform_class = `class`; -chop($platform_class); -$obj_dir = $test_dir."/obj/".$platform_class; -unless (-e $obj_dir) { - mkdir($obj_dir,0777) - || die "Couldn't find or create obj dir: $obj_dir."; +if ($test_dir eq "qa") { + $test_dir = "./qa" } -$report_dir = $test_dir."/report"; &use($report_dir); + +$test_dir =~ s/\/\w+$//; +$script_dir = $test_dir."/script"; foreach (@INC) { if ($_ ne '.') { push(@newINC, $_) } @@ -36,55 +29,25 @@ foreach (@INC) { push(@newINC, $script_dir); @INC = @newINC; -# Now we must process the command-line arguments -# to qa. These specify: -# 0: which qa command to run -# 1,2,3.. it's parameters -# except that -V, -I, -L (or lower-case) can be used to -# define $MMQA_VERSION, $MPS_LINK_OBJ and $MPS_INCLUDE_DIR -# which otherwise will be taken from environment variables. -# -# we'll set the relevant vars and pass the rest on in @qa_args +# other directories will be set when needed by requiring +# the 'dirs' file. This must be done after reading command-line +# options, so we don't try it now -@qa_args = (); +# Now we must process the command-line to qa +# Since options may be command-dependent, all we do now +# is get the command and run it -%qa_options = (); -$qa_options{"v"} = "MMQA_VERSION"; -$MMQA_VERSION = "MMQA_VERS_MO"; &use($MMQA_VERSION); -$qa_options{"i"} = "MPS_INCLUDE_DIR"; -$qa_options{"l"} = "MPS_LINK_OBJ"; +$qa_command = shift(@ARGV); -while ($_ = shift(@ARGV)) { - if (/^\-(.*)$/i) { - unless ($qa_options{$1}) { - die "Unrecognised option: $1.\n"; - } - $val = shift(@ARGV); &use($val); - $tetete="$".$qa_options{$1}." = \$val"; - eval $tetete; - } else { - push(@qa_args, $_); - } +unless ($qa_command) { + die "You must specify a command -- try 'qa help' for details.\n"; } - -$qa_command = shift(@qa_args); - -foreach (keys %qa_options) { - unless (eval("$".$qa_options{$_})) { - eval("$".$qa_options{$_}." = \$ENV{'".$qa_options{$_}."'}"); - unless (eval("$".$qa_options{$_})) { - die "Error: please specify $qa_options{$_} (use the -$_ option).\n"; - } - } -} - unless (-e "$script_dir/commands/".$qa_command) { - die "MM QA: unknown command '".$qa_command."'"; + die "Unknown command '".$qa_command."' -- 'qa help' for info.\n"; } + +require "optproc"; + do "commands/".$qa_command; if ($@) {print $@}; -################# - -sub use {} - diff --git a/mps/qa/test/script/commands/clib b/mps/qa/test/script/commands/clib index 0766b6ca3e6..514b9b7111e 100644 --- a/mps/qa/test/script/commands/clib +++ b/mps/qa/test/script/commands/clib @@ -4,7 +4,15 @@ # putting the resulting .o files in $obj_dir. # -print "Compiling test libraries in $testlib_dir.\n"; +&options( + "MPS_INCLUDE_DIR", + "INTERFACE_VERSION", + "PLATFORM" +); + +require "dirs"; + +print "Compiling test libraries from $testlib_dir.\n"; require "compile"; diff --git a/mps/qa/test/script/commands/index b/mps/qa/test/script/commands/index index 9b4859dac9d..2eb98a3460b 100644 --- a/mps/qa/test/script/commands/index +++ b/mps/qa/test/script/commands/index @@ -2,6 +2,9 @@ # # make an index of all the tests (all .c files) in the # current directory, and write it on stdout. +# + +&options(); require "headread"; diff --git a/mps/qa/test/script/commands/try b/mps/qa/test/script/commands/try index f8215a0c64c..009d1a8fa08 100644 --- a/mps/qa/test/script/commands/try +++ b/mps/qa/test/script/commands/try @@ -3,6 +3,14 @@ # run tests interactively (allows for user input, immediate results, # &c, but doesn't give results in standard format) +&options( + "MPS_INCLUDE_DIR", + "MPS_LINK_OBJ", + "INTERFACE_VERSION", + "PLATFORM" +); + +require "dirs"; require "headread"; require "compile"; diff --git a/mps/qa/test/script/compile b/mps/qa/test/script/compile index 2a19f830a4f..7f657f0e56f 100644 --- a/mps/qa/test/script/compile +++ b/mps/qa/test/script/compile @@ -18,8 +18,8 @@ sub compiler_settings { $cc_opts = "-ansi -pedantic -Wall -Wstrict-prototypes \\ -Winline -Waggregate-return -Wnested-externs -Wcast-qual \\ -Wshadow -Wmissing-prototypes -Wredundant-decls -Wcast-align \\ - -O -g -ggdb3 -D$MMQA_VERSION"; - $cc_link = "$obj_dir/platform.o $plat_link{$platform_class}"; + -O -g -ggdb3 -DMMQA_VERS_$INTERFACE_VERSION"; + $cc_link = "$obj_dir/platform.o $plat_link{$PLATFORM}"; $cc_include = "-I$testlib_dir -I$MPS_INCLUDE_DIR"; }