diff --git a/autobuild.pl b/autobuild.pl index 06cf16165..b49502d78 100755 --- a/autobuild.pl +++ b/autobuild.pl @@ -35,7 +35,7 @@ my %data = (); my %command_table = (); my $cvs_tag; -my $starting_dir= getcwd (); +my $starting_dir = getcwd (); my $warn_nonfatal; ############################################################################## @@ -161,7 +161,7 @@ elsif ($ARGV[0] =~ m!^(-|/\?)!) { print "Error: Unknown option $ARGV[0]\n" if ($ARGV[0] !~ m!^(-|/)\?!); print - "Useage: $0 [-c][-cvs_tag ][-d][-k][-p][-v][-xml] files_to_process.xml [...]\n", + "Usage: $0 [-c][-cvs_tag ][-d][-k][-p][-v][-xml] files_to_process.xml [...]\n", "where:\n", " -c Parse and Check each command but don't execute any\n", " -cvs_tag Checkout operations use instead of HEAD\n", @@ -195,17 +195,17 @@ # because FindBin does not work on OpenVMS # sub which { - my($prog) = shift; - my($exec) = $prog; - my($part) = ''; + my $prog = shift; + my $exec = $prog; + my $part = ''; if (defined $ENV{'PATH'}) { - foreach $part (split(/$pathsep/, $ENV{'PATH'})) { - $part .= (( $^O eq 'VMS' ) ? "" : "/" ) . "$prog"; - if ( -x $part ) { - $exec = $part; - last; - } - } + foreach $part (split(/$pathsep/, $ENV{'PATH'})) { + $part .= (( $^O eq 'VMS' ) ? "" : "/" ) . "$prog"; + if ( -x $part ) { + $exec = $part; + last; + } + } } return $exec; } @@ -293,7 +293,7 @@ ($$) if (!defined $file_handle) { print STDERR __FILE__, ': ', ($warn_nonfatal ? 'Unable to set' : 'Error setting'), - " status to file ($status_file)", ($warn_nonfatal ? '' : ": $!"), "\n"; + " status to file ($status_file)", ($warn_nonfatal ? '' : ": $!"), "\n"; # Non fatal error, so just return. return; @@ -343,7 +343,7 @@ ($$) # string. In case of undefined variables, also needs the filename and line # number(s) where the definition of this string was found. # -sub subsituteVars ($;$$$) +sub substituteVars ($;$$$) { my ($inputString, $filename, $lineFrom, $lineTo) = @_; my $outputString= $inputString; @@ -451,7 +451,7 @@ (\%) $data{VARS}->{BUILD_CONFIG_FILE} = File::Basename::basename ($file); $data{VARS}->{BUILD_CONFIG_PATH} = File::Basename::dirname ($file); my $temp_file = $file; - $temp_file =~ s!\\!/!g; ## replace windows seperators with unix ones + $temp_file =~ s!\\!/!g; ## replace windows separators with unix ones $temp_file =~ s!^.*configs/autobuild!configs/autobuild!; $data{VARS}->{CVS_CONFIG_FILE} = $temp_file; @@ -465,7 +465,7 @@ (\%) $data{VARS}->{AUTOBUILD_PL_PATH} = $this_file; $data{VARS}->{AUTOBUILD_ROOT} = File::Basename::dirname ($this_file); - # Setup some other usefull variables before parsing the actual xml file. + # Setup some other useful variables before parsing the actual xml file. # $data{VARS}->{'cvs_tag'} = (defined $cvs_tag) ? $cvs_tag : 'HEAD'; # @@ -654,10 +654,10 @@ (\%) if (2 == $SUBVARS && defined $cmd_handler->{'substitute_vars_in_options'} && $cmd_handler->{'substitute_vars_in_options'} ) { - $command->{SUBVARS}= 1; # Record that we are subsituting + $command->{SUBVARS}= 1; # Record that we are substituting } - # We must change the environment BEFORE we attempt to subsituteVars + # We must change the environment BEFORE we attempt to substituteVars # as the function can substitute environment values in place of # environment names within the variable being substituted. # @@ -670,7 +670,7 @@ (\%) # if ("" ne $DIRECTORY) { $DIRECTORY= - subsituteVars ($DIRECTORY, $FILE, $LINE_FROM, $LINE_TO); + substituteVars ($DIRECTORY, $FILE, $LINE_FROM, $LINE_TO); if ($DIRECTORY =~ s/^\s*([^\s].*?)\s*$/$1/ && !File::Spec->file_name_is_absolute ($DIRECTORY)) { @@ -736,6 +736,7 @@ (\%) my $FILE = $command->{FILE}; my $LINE_FROM = $command->{LINE_FROM}; my $LINE_TO = $command->{LINE_FROM}; + my $CONTENTS = $command->{CONTENTS}; my $CMD = "Executing \"$NAME\" line"; if (!defined $LINE_TO || $LINE_FROM == $LINE_TO) { @@ -749,7 +750,7 @@ (\%) print "\n",'=' x 79,"\n===== $CMD\n" if (1 < $verbose); - # We must change the environment BEFORE we attempt to subsituteVars + # We must change the environment BEFORE we attempt to substituteVars # as the function can substitute environment values in place of # environment names within the variable being substituted. # @@ -766,7 +767,7 @@ (\%) # Work out if we are going to execute this command. # my $IF_result = - subsituteVars ($IF_TEXT, $FILE, $LINE_FROM, $LINE_TO); + substituteVars ($IF_TEXT, $FILE, $LINE_FROM, $LINE_TO); if ($IF_result !~ s/^\s*(?:true|)\s*$/1/i) { $IF_result = eval ($IF_result); $IF_result = 0 if (!defined $IF_result || @@ -777,9 +778,9 @@ (\%) # Substitute any in the command's options string IF desired. # $OPTIONS= - subsituteVars ($OPTIONS, $FILE, $LINE_FROM, $LINE_TO) if ($SUBVARS); + substituteVars ($OPTIONS, $FILE, $LINE_FROM, $LINE_TO) if ($SUBVARS); if ($OPTIONS ne $command->{OPTIONS}) { - print "===== subsitutions: $OPTIONS\n" if (1 < $verbose); + print "===== substitutions: $OPTIONS\n" if (1 < $verbose); } # Always substitute any in the command's directory string @@ -787,7 +788,7 @@ (\%) # if ("" ne $DIRECTORY) { $DIRECTORY= - subsituteVars ($DIRECTORY, $FILE, $LINE_FROM, $LINE_TO ); + substituteVars ($DIRECTORY, $FILE, $LINE_FROM, $LINE_TO ); if ($DIRECTORY =~ s/^\s*([^\s].*?)\s*$/$1/ && !File::Spec->file_name_is_absolute ($DIRECTORY)) { @@ -804,7 +805,7 @@ (\%) } } - if ($command_table{$NAME}->Run ($OPTIONS) == 0) { + if ($command_table{$NAME}->Run ($OPTIONS, $CONTENTS) == 0) { print STDERR "ERROR: While $CMD $CMD2:\n" if ($verbose <= 1); print STDERR " The command failed"; if (!$keep_going) { diff --git a/autobuild.txt b/autobuild.txt index 02b940092..84710f0e2 100644 --- a/autobuild.txt +++ b/autobuild.txt @@ -82,7 +82,7 @@ This command splices together two other named variables and stores the resultant All attributes must be in the order given above although both join and type are optional. This command splices together two other named autobuild variables and stores the resultant string in environment variable being created. The join attribute is optional (defaulting to a null string) and if given its text will be spliced between the two other variable's text to form the result). If the type is given it works just as for the environment tag above. -The tag can now have an optional if attribute that will be evaluated immediatly during the parse stage. +The tag can now have an optional if attribute that will be evaluated immediately during the parse stage. This can sit anywhere in the input file and causes the named file to be opened and parsed at the current point. This file must have it's own and optional sections to be processed and any variables, environment and commands will be added to the current file's already processed tags. .. @@ -156,8 +156,8 @@ joining characters between the original value and the newly defined value; environment variables do still get treated to the platform's path separating character. replace/set which simply resets or creates the environment variable with the value given, -prefix which appends the original value of the environment variable to the end of the string, joind with a "path" separating character as defined by the platform autobuild.pl is running on, -suffix/postfix which appends the value given to the end of the current value of the environment variable again seporated by a "path" character or +prefix which appends the original value of the environment variable to the end of the string, joined with a "path" separating character as defined by the platform autobuild.pl is running on, +suffix/postfix which appends the value given to the end of the current value of the environment variable again separated by a "path" character or ifundefined/default which will only create a new environment variable with the given value if it does not already exist. unset/delete/remove which will remove the variable. @@ -180,9 +180,9 @@ Join="text" the optional, defaulting to a single space, used to modify (possibly Root="dir" or directory="dir" optionally specify that this command should have a different root to that defined globally. -Substitute_variables or SubsVars, optionally used to over-ride the default for the individual command, indicating that the resultant options string should have any variables subsituted prior to use. +Substitute_variables or SubsVars, optionally used to over-ride the default for the individual command, indicating that the resultant options string should have any variables substituted prior to use. -NoSubsitute_variables or NoSubsVars, optionally used to over-ride the default for the individual command, indicating that the resultant options string should NOT have any variables susituted. +NoSubstitute_variables or NoSubsVars, optionally used to over-ride the default for the individual command, indicating that the resultant options string should NOT have any variables substituted. group="group" optionally states that the command should be using the named environment group, it defaults to "default" which is always created. diff --git a/command/file_manipulation.pm b/command/file_manipulation.pm index 8bba95880..f098ab9bf 100644 --- a/command/file_manipulation.pm +++ b/command/file_manipulation.pm @@ -594,6 +594,7 @@ sub Run ($) { my $self = shift; my $options = shift; + my $contents = shift; my $root = main::GetVariable ('root'); @@ -684,6 +685,11 @@ sub Run ($) my $include= []; ### Copytree Default include everything my $exclude= []; ### Copytree Default exclude nothing + # Use contents of the tags as output if given + if (defined $contents) { + $output = $contents; + } + foreach my $option (@splitOptions) { ### option from= diff --git a/common/betterparser.pm b/common/betterparser.pm index ef583cae8..8767851fa 100644 --- a/common/betterparser.pm +++ b/common/betterparser.pm @@ -41,7 +41,7 @@ sub ParseQuotes (\$) s/^(?:"(?:[^"\\]*(?:\\(?:0?[xX][[:xdigit:]]{0,2}|0[0-2]?[0-7]{0,2}|.))*)*")*//) { print STDERR "INTERNAL ERROR: ParseQuotes didn't match quoted string\n"; - # If this occures, it will be due to the original tag search + # If this occurs, it will be due to the original tag search # failing to match the same pattern, i.e. the two patterns are out-of- # sync with each other. @@ -240,7 +240,7 @@ sub ParseIfAttribute ($$$$$$$;$) $existingIF =~ s/^\s*(?:true|)\s*$/1/i; if ($processIF) { $existingIF = - main::subsituteVars ($existingIF, $file, $lineStart, $lineEnd); + main::substituteVars ($existingIF, $file, $lineStart, $lineEnd); if ($existingIF !~ s/^\s*(?:true|)\s*$/1/i) { chomp ($existingIF = eval ($existingIF)); $existingIF = 0 if (!defined $existingIF || @@ -325,6 +325,17 @@ sub NeverSelfClosedTag ($$$$\$) } } +############################################################################### +# CouldBeSelfClosedTag +# Return true if tag is self closing and remove the trailing / in attributes +# to match the other *SelfClosedTag functions. +# +sub CouldBeSelfClosedTag ($$$$\$) +{ + my ($filename, $lineStart, $lineEnd, $tag, $attributes) = @_; + return $$attributes =~ s/\s*\/$// ? 1 : 0; +} + ############################################################################### my $nestedLevel = 0; @@ -618,12 +629,12 @@ sub DealWithVariableTagAttributes ($$$$$\%$) #------------------------------------------------------------------------- if ($thisAttrib =~ m/^(?:(relative_)?val(?:ue)?)$/i) { # relative_value is an DEPRECATED prismtech form that implies this - # value should have variables sustituted. To avoid missing variable + # value should have variables substituted. To avoid missing variable # warnings this is only done if we are actually creating this variable. # if (defined $1 && $IF_TEXT) { $thisValue = - main::subsituteVars ($thisValue, $file, $lineStart, $lineEnd); + main::substituteVars ($thisValue, $file, $lineStart, $lineEnd); } if ('' eq $VALUE) { @@ -718,7 +729,7 @@ sub DealWithVariableTagAttributes ($$$$$\%$) # if ($IF_TEXT) { $thisValue= - main::subsituteVars ($thisValue, $file, $lineStart, $lineEnd); + main::substituteVars ($thisValue, $file, $lineStart, $lineEnd); if ($thisValue =~ m/^\s*(true|)\s*$/i) { $EVAL= 1; } @@ -740,9 +751,9 @@ sub DealWithVariableTagAttributes ($$$$$\%$) } #------------------------------------------------------------------------- elsif ($thisAttrib =~ - m/^(?:(no)?subs(?:itute)?(?:_?var(?:iable)?s)?)$/i) { + m/^(?:(no)?subs(?:t)?(?:itute)?(?:_?var(?:iable)?s)?)$/i) { if ($thisValue !~ s/^\s*(.+?)\s*$/$1/) { - # This is a signal to globally subsitute variables within the whole + # This is a signal to globally substitute variables within the whole # resultant value. # if (2 == $SUBVARS) { @@ -757,7 +768,7 @@ sub DealWithVariableTagAttributes ($$$$$\%$) "Ignoring the multiple attribute $thisAttrib" ); } } - elsif (defined $1) { ## nosubsitute_variables="value" doesn't make sense + elsif (defined $1) { ## nosubstitute_variables="value" doesn't make sense DisplayProblem ( $file, $lineStart, @@ -767,11 +778,11 @@ sub DealWithVariableTagAttributes ($$$$$\%$) " should not have a value" ); } elsif ($IF_TEXT) { - # Subsitute_variables for just this given part, assuming we are + # Substitute_variables for just this given part, assuming we are # actually creating the variable. # $thisValue = - main::subsituteVars ($thisValue, $file, $lineStart, $lineEnd); + main::substituteVars ($thisValue, $file, $lineStart, $lineEnd); if ('' eq $VALUE) { $VALUE = $thisValue } @@ -904,7 +915,7 @@ sub DealWithVariableTagAttributes ($$$$$\%$) } elsif ($IF_TEXT) { if (1 == $SUBVARS) { - $VALUE = main::subsituteVars ($VALUE, $file, $lineStart, $lineEnd); + $VALUE = main::substituteVars ($VALUE, $file, $lineStart, $lineEnd); } if ($EVAL) { $VALUE = 1 if ($VALUE =~ m/^\s*(true|)\s*$/i); @@ -1222,13 +1233,12 @@ sub DealWithCommandTag ($$$$$\%) { my ($file, $lineStart, $lineEnd, $tag, $attributes, $data) = @_; - ShouldBeSelfClosedTag ($file, $lineStart, $lineEnd, $tag, $attributes); my ($PAIRS, $NAME, $IF_TEXT) = FindNameIF ($file, $lineStart, $lineEnd, $tag, $attributes); my $OPTIONS = ''; my $DIRECTORY = ''; my $JOIN = ' '; - my $SUBVARS = 2; ## use default, if 0 don't subsitute, if 1 subsitute. + my $SUBVARS = 2; ## use default, if 0 don't substitute, if 1 substitute. my $GROUP; while (scalar @$PAIRS) { @@ -1314,7 +1324,7 @@ sub DealWithCommandTag ($$$$$\%) elsif ($thisAttrib =~ m/^(?:(no)?subs(?:itute)?(?:_?var(?:iable)?s)?)$/i) { if ($thisValue !~ s/^\s*(.+?)\s*$/$1/) { - # This is a signal to globally subsitute variables within the whole + # This is a signal to globally substitute variables within the whole # option string. # if (2 == $SUBVARS) { @@ -1329,7 +1339,7 @@ sub DealWithCommandTag ($$$$$\%) "Ignoring the multiple attribute $thisAttrib" ); } } - elsif (defined $1) { ## nosubsitute_variables="value" doesn't make sense + elsif (defined $1) { ## nosubstitute_variables="value" doesn't make sense DisplayProblem ( $file, $lineStart, @@ -1339,12 +1349,12 @@ sub DealWithCommandTag ($$$$$\%) "<$tag $thisAttrib=\"$thisValue\">" ); } elsif ($IF_autobuild) { - # Subsitute_variables for just this given bit of the option string + # Substitute_variables for just this given bit of the option string # We assume we are actually going to execute this command unless # the autobuild section tag is disabled. # $thisValue = - main::subsituteVars ($thisValue, $file, $lineStart, $lineEnd); + main::substituteVars ($thisValue, $file, $lineStart, $lineEnd); if ('' eq $OPTIONS) { $OPTIONS = $thisValue } @@ -1354,7 +1364,7 @@ sub DealWithCommandTag ($$$$$\%) } } #------------------------------------------------------------------------- - # We have an unknown attribute and possiable value, treat this as a + # We have an unknown attribute and possible value, treat this as a # command name with options, if we have not seen the name yet. # elsif ("" eq $NAME) { @@ -1458,7 +1468,7 @@ sub Parse ($$\%) my $file_handle = new FileHandle ($file, 'r'); if (!defined $file_handle) { print STDERR "ERROR: Could not open file <$file>: $!\n"; - return 0; ## effectivly $parsedOK= 0; + return 0; ## effectively $parsedOK= 0; } # Each file parsed updates the "date_string" variable for the timestamp of @@ -1472,18 +1482,38 @@ sub Parse ($$\%) my $lineNumberStartOfTag = 0; ## Line zero indicates not found yet. my $lineNumberEndOfTag = 1; ## Shows where the last processed tag ended + # In "pre" mode, collect the content in-between the tags as is, sorta like + #
 in html, expect this only does whole lines.
+  #
+  my $preMode = 0;
+  my $preModeText = '';
+
   # This while loop reads each line of the file into $_ one by one until EOF.
   #
   while (<$file_handle>) {
     ++$lineNumberCurrent;
 
+    # Collect lines that aren't closing tags
+    if ($preMode) {
+      if ($_ =~ /\/>/ || $_ =~ /<\//) {
+        $preMode = 0;
+      } else {
+        # Replace Entity References
+        $_ =~ s/<//g;
+        $_ =~ s/&/&/g;
+        $preModeText .= $_;
+        next;
+      }
+    }
+
     # Remove leading and trailing spaces from the current line just read in,
     # and if now blank read in another to replace it.
     #
     next if ($_ !~ s/^\s*(.+?)\s*$/$1/);
 
     # Keep appending each new line to the line(s) we are currently processing;
-    # this is kept as a single line seporated by a single space instead of
+    # this is kept as a single line separated by a single space instead of
     # multiple whitespace and new-line marks.
     #
     $inputFromFile .= ' ' . $_;
@@ -1491,7 +1521,7 @@ sub Parse ($$\%)
     # Remove anything up to the start of the first < character as these are to
     # be ignored. (These are just noise within the input stream into which the
     # XML tags are placed.) NOTE that quotes do NOT hide the start of XML tags,
-    # as these quotes could be used unballanced within the non-tag text.
+    # as these quotes could be used unbalanced within the non-tag text.
     #
     $inputFromFile =~ s/^[^<]+//;
     next if ("" eq $inputFromFile);
@@ -1578,7 +1608,7 @@ sub Parse ($$\%)
         # ignore any quoted > we find along the way as the optional value
         # strings to any attributes for this tag may have this character
         # embedded. Quoted strings may be surrounded by "" pairs and it
-        # is also complicated by the possiability that within these there can
+        # is also complicated by the possibility that within these there can
         # be escaped quotes.
         #
         my $tag = $inputFromFile;  ## Trimmed down if the end of tag is found.
@@ -1861,6 +1891,8 @@ sub Parse ($$\%)
             # -------------------------------------
             #
             if ($tag =~ m/^command$/i) {
+              $preMode = !CouldBeSelfClosedTag (
+                $file, $lineNumberStartOfTag, $lineNumberEndOfTag, $tag, $attributes);
               DealWithCommandTag (
                 $file,
                 $lineNumberStartOfTag,
@@ -1869,6 +1901,10 @@ sub Parse ($$\%)
                 $attributes,
                 %$data );
             }
+            elsif ($tag =~ m!^/command$!i) {
+              $data->{COMMANDS}[-1]{CONTENTS} = $preModeText;
+              $preModeText = '';
+            }
             else {
               DisplayProblem (
                 $file,
diff --git a/docs/autobuild.txt b/docs/autobuild.txt
index 3725295ab..8c21d031b 100644
--- a/docs/autobuild.txt
+++ b/docs/autobuild.txt
@@ -38,6 +38,10 @@ file_manipulation - This command provides the ability to append, create,
   update, delete, and copy files.  It also allows the recursive removal of
   directories (rmtree) and can be used to ensure that a particular file not
   exist (mustnotexist).
+   - If the tag isn't self closing, all WHOLE lines between the ``
+     and `` tags will be treated as an almost raw `output` option.
+     It's almost raw because like in standard XML and HTML, you should replace
+     `>` with `>`, `<` with `<`, and `&` with `&`.
 generate_workspace - Runs MPC in the "project_root" directory with the
   options provided.  It attempts to run bin/mwc.pl from the "project_root"
   directory.  If that fails, it uses $MPC_ROOT/mwc.pl.
@@ -51,11 +55,11 @@ make - Runs the make program, optionally specified by the "make_program"
   a makefile name to use by using the 'find' sub-command.  The 'find'
   sub-command uses the name or wild-card specification to locate the
   makefile.
-notify - Scans the log file for compile amd test errors and notifies the
+notify - Scans the log file for compile and test errors and notifies the
   user via email.  This command uses three variables;
   - 'mail_prog' (which defaults to /bin/mail) to send email on *nix;
   - 'mail_host' (SMTP server hostname, defaults to 'localhost') to send email
-  on Windoze;
+  on Windows;
   - and 'mail_map'.  The 'mail_map' variable, if used, should point to a file
   that contains a username and email address per line.  If a 'mail_map' is
   not provided, it will create email addresses in the form of