Skip to content

Commit 409ff5e

Browse files
Merge pull request #19 from iguessthislldo/igtd/embedtext
Make Creating a File More Friendly
2 parents 5cb79c5 + 6c84623 commit 409ff5e

File tree

5 files changed

+101
-54
lines changed

5 files changed

+101
-54
lines changed

autobuild.pl

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
my %data = ();
3636
my %command_table = ();
3737
my $cvs_tag;
38-
my $starting_dir= getcwd ();
38+
my $starting_dir = getcwd ();
3939
my $warn_nonfatal;
4040

4141
##############################################################################
@@ -161,7 +161,7 @@
161161
elsif ($ARGV[0] =~ m!^(-|/\?)!) {
162162
print "Error: Unknown option $ARGV[0]\n" if ($ARGV[0] !~ m!^(-|/)\?!);
163163
print
164-
"Useage: $0 [-c][-cvs_tag <tag>][-d][-k][-p][-v][-xml] files_to_process.xml [...]\n",
164+
"Usage: $0 [-c][-cvs_tag <tag>][-d][-k][-p][-v][-xml] files_to_process.xml [...]\n",
165165
"where:\n",
166166
" -c Parse and Check each command but don't execute any\n",
167167
" -cvs_tag <tag> Checkout operations use <tag> instead of HEAD\n",
@@ -195,17 +195,17 @@
195195
# because FindBin does not work on OpenVMS
196196
#
197197
sub which {
198-
my($prog) = shift;
199-
my($exec) = $prog;
200-
my($part) = '';
198+
my $prog = shift;
199+
my $exec = $prog;
200+
my $part = '';
201201
if (defined $ENV{'PATH'}) {
202-
foreach $part (split(/$pathsep/, $ENV{'PATH'})) {
203-
$part .= (( $^O eq 'VMS' ) ? "" : "/" ) . "$prog";
204-
if ( -x $part ) {
205-
$exec = $part;
206-
last;
207-
}
208-
}
202+
foreach $part (split(/$pathsep/, $ENV{'PATH'})) {
203+
$part .= (( $^O eq 'VMS' ) ? "" : "/" ) . "$prog";
204+
if ( -x $part ) {
205+
$exec = $part;
206+
last;
207+
}
208+
}
209209
}
210210
return $exec;
211211
}
@@ -293,7 +293,7 @@ ($$)
293293
if (!defined $file_handle) {
294294
print STDERR __FILE__,
295295
': ', ($warn_nonfatal ? 'Unable to set' : 'Error setting'),
296-
" status to file ($status_file)", ($warn_nonfatal ? '' : ": $!"), "\n";
296+
" status to file ($status_file)", ($warn_nonfatal ? '' : ": $!"), "\n";
297297

298298
# Non fatal error, so just return.
299299
return;
@@ -343,7 +343,7 @@ ($$)
343343
# string. In case of undefined variables, also needs the filename and line
344344
# number(s) where the definition of this string was found.
345345
#
346-
sub subsituteVars ($;$$$)
346+
sub substituteVars ($;$$$)
347347
{
348348
my ($inputString, $filename, $lineFrom, $lineTo) = @_;
349349
my $outputString= $inputString;
@@ -451,7 +451,7 @@ (\%)
451451
$data{VARS}->{BUILD_CONFIG_FILE} = File::Basename::basename ($file);
452452
$data{VARS}->{BUILD_CONFIG_PATH} = File::Basename::dirname ($file);
453453
my $temp_file = $file;
454-
$temp_file =~ s!\\!/!g; ## replace windows seperators with unix ones
454+
$temp_file =~ s!\\!/!g; ## replace windows separators with unix ones
455455
$temp_file =~ s!^.*configs/autobuild!configs/autobuild!;
456456
$data{VARS}->{CVS_CONFIG_FILE} = $temp_file;
457457

@@ -465,7 +465,7 @@ (\%)
465465
$data{VARS}->{AUTOBUILD_PL_PATH} = $this_file;
466466
$data{VARS}->{AUTOBUILD_ROOT} = File::Basename::dirname ($this_file);
467467

468-
# Setup some other usefull variables before parsing the actual xml file.
468+
# Setup some other useful variables before parsing the actual xml file.
469469
#
470470
$data{VARS}->{'cvs_tag'} = (defined $cvs_tag) ? $cvs_tag : 'HEAD';
471471
#
@@ -654,10 +654,10 @@ (\%)
654654
if (2 == $SUBVARS &&
655655
defined $cmd_handler->{'substitute_vars_in_options'} &&
656656
$cmd_handler->{'substitute_vars_in_options'} ) {
657-
$command->{SUBVARS}= 1; # Record that we are subsituting
657+
$command->{SUBVARS}= 1; # Record that we are substituting
658658
}
659659

660-
# We must change the environment BEFORE we attempt to subsituteVars
660+
# We must change the environment BEFORE we attempt to substituteVars
661661
# as the function can substitute environment values in place of
662662
# environment names within the variable being substituted.
663663
#
@@ -670,7 +670,7 @@ (\%)
670670
#
671671
if ("" ne $DIRECTORY) {
672672
$DIRECTORY=
673-
subsituteVars ($DIRECTORY, $FILE, $LINE_FROM, $LINE_TO);
673+
substituteVars ($DIRECTORY, $FILE, $LINE_FROM, $LINE_TO);
674674

675675
if ($DIRECTORY =~ s/^\s*([^\s].*?)\s*$/$1/ &&
676676
!File::Spec->file_name_is_absolute ($DIRECTORY)) {
@@ -736,6 +736,7 @@ (\%)
736736
my $FILE = $command->{FILE};
737737
my $LINE_FROM = $command->{LINE_FROM};
738738
my $LINE_TO = $command->{LINE_FROM};
739+
my $CONTENTS = $command->{CONTENTS};
739740

740741
my $CMD = "Executing \"$NAME\" line";
741742
if (!defined $LINE_TO || $LINE_FROM == $LINE_TO) {
@@ -749,7 +750,7 @@ (\%)
749750

750751
print "\n",'=' x 79,"\n===== $CMD\n" if (1 < $verbose);
751752

752-
# We must change the environment BEFORE we attempt to subsituteVars
753+
# We must change the environment BEFORE we attempt to substituteVars
753754
# as the function can substitute environment values in place of
754755
# environment names within the variable being substituted.
755756
#
@@ -766,7 +767,7 @@ (\%)
766767
# Work out if we are going to execute this command.
767768
#
768769
my $IF_result =
769-
subsituteVars ($IF_TEXT, $FILE, $LINE_FROM, $LINE_TO);
770+
substituteVars ($IF_TEXT, $FILE, $LINE_FROM, $LINE_TO);
770771
if ($IF_result !~ s/^\s*(?:true|)\s*$/1/i) {
771772
$IF_result = eval ($IF_result);
772773
$IF_result = 0 if (!defined $IF_result ||
@@ -777,17 +778,17 @@ (\%)
777778
# Substitute any <variables> in the command's options string IF desired.
778779
#
779780
$OPTIONS=
780-
subsituteVars ($OPTIONS, $FILE, $LINE_FROM, $LINE_TO) if ($SUBVARS);
781+
substituteVars ($OPTIONS, $FILE, $LINE_FROM, $LINE_TO) if ($SUBVARS);
781782
if ($OPTIONS ne $command->{OPTIONS}) {
782-
print "===== subsitutions: $OPTIONS\n" if (1 < $verbose);
783+
print "===== substitutions: $OPTIONS\n" if (1 < $verbose);
783784
}
784785

785786
# Always substitute any <variables> in the command's directory string
786787
# if a change of directory/root has been specified for the command.
787788
#
788789
if ("" ne $DIRECTORY) {
789790
$DIRECTORY=
790-
subsituteVars ($DIRECTORY, $FILE, $LINE_FROM, $LINE_TO );
791+
substituteVars ($DIRECTORY, $FILE, $LINE_FROM, $LINE_TO );
791792

792793
if ($DIRECTORY =~ s/^\s*([^\s].*?)\s*$/$1/ &&
793794
!File::Spec->file_name_is_absolute ($DIRECTORY)) {
@@ -804,7 +805,7 @@ (\%)
804805
}
805806
}
806807

807-
if ($command_table{$NAME}->Run ($OPTIONS) == 0) {
808+
if ($command_table{$NAME}->Run ($OPTIONS, $CONTENTS) == 0) {
808809
print STDERR "ERROR: While $CMD $CMD2:\n" if ($verbose <= 1);
809810
print STDERR " The command failed";
810811
if (!$keep_going) {

autobuild.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ This command splices together two other named variables and stores the resultant
8282
<relative_env name="environment" base_var="variable" suffix_var="variable" join="text" type="" />
8383
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.
8484

85-
The <include name="filename" if="test" /> tag can now have an optional if attribute that will be evaluated immediatly during the parse stage.
85+
The <include name="filename" if="test" /> tag can now have an optional if attribute that will be evaluated immediately during the parse stage.
8686
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 <autobuild> and optional <configuration> sections to be processed and any variables, environment and commands will be added to the current file's already processed tags.
8787

8888
<autobuild> .. <autobuild/>
@@ -156,8 +156,8 @@ joining characters between the original value and the newly defined value;
156156
environment variables do still get treated to the platform's path separating
157157
character.
158158
replace/set which simply resets or creates the environment variable with the value given,
159-
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,
160-
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
159+
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,
160+
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
161161
ifundefined/default which will only create a new environment variable with the given value if it does not already exist.
162162
unset/delete/remove which will remove the variable.
163163

@@ -180,9 +180,9 @@ Join="text" the optional, defaulting to a single space, used to modify (possibly
180180

181181
Root="dir" or directory="dir" optionally specify that this command should have a different root to that defined globally.
182182

183-
Substitute_variables or SubsVars, optionally used to over-ride the default for the individual command, indicating that the resultant options string should have any <Var> variables subsituted prior to use.
183+
Substitute_variables or SubsVars, optionally used to over-ride the default for the individual command, indicating that the resultant options string should have any <Var> variables substituted prior to use.
184184

185-
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 <Var> variables susituted.
185+
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 <Var> variables substituted.
186186

187187
group="group" optionally states that the command should be using the named environment group, it defaults to "default" which is always created.
188188

command/file_manipulation.pm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ sub Run ($)
594594
{
595595
my $self = shift;
596596
my $options = shift;
597+
my $contents = shift;
597598

598599
my $root = main::GetVariable ('root');
599600

@@ -684,6 +685,11 @@ sub Run ($)
684685
my $include= []; ### Copytree Default include everything
685686
my $exclude= []; ### Copytree Default exclude nothing
686687

688+
# Use contents of the tags as output if given
689+
if (defined $contents) {
690+
$output = $contents;
691+
}
692+
687693
foreach my $option (@splitOptions) {
688694

689695
### option from=

0 commit comments

Comments
 (0)