summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorgoodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac>2004-08-27 03:20:39 +0000
committergoodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac>2004-08-27 03:20:39 +0000
commitae1087d19f3f5fa38beebe3513c911b3f66fe355 (patch)
tree7fca87834110699068c6f5c9fa29b60b091baeae /lib
parent0f32894d78d29b9d205ecfe4ee319a0f9112abee (diff)
Added tracking of options for thorn configuration scripts. Now a thorn
may specify OPTIONS a b c in a PROVIDES block in its configuration.ccl and these options will be tracked and stored in the configuration's config-info file. The config-info file, and any options file specified on the command line are now used to setup the environment before a configuration script is run by the CST. Note that the only options stored to the config-info file by the CST are ones specified in the configuration.ccl files, and configuration scripts are invoked each time the CST is run, so any option used by a thorn's configuration script MUST be mentioned in the configuration.ccl file to be remembered the next time the CST is invoked. git-svn-id: http://svn.cactuscode.org/flesh/trunk@3855 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'lib')
-rw-r--r--lib/sbin/CST7
-rw-r--r--lib/sbin/CSTUtils.pl294
-rw-r--r--lib/sbin/ConfigScriptParser.pl5
-rw-r--r--lib/sbin/ConfigurationParser.pl40
-rw-r--r--lib/sbin/ProcessConfiguration.pl99
5 files changed, 426 insertions, 19 deletions
diff --git a/lib/sbin/CST b/lib/sbin/CST
index d9e2c401..f15383e9 100644
--- a/lib/sbin/CST
+++ b/lib/sbin/CST
@@ -6,7 +6,7 @@
# @desc
# Parses the the configuration files for thorns.
# @enddesc
-# @version $Header: /mnt/data2/cvs2svn/cvs-repositories/Cactus/lib/sbin/CST,v 1.71 2004-08-17 18:38:32 goodale Exp $
+# @version $Header: /mnt/data2/cvs2svn/cvs-repositories/Cactus/lib/sbin/CST,v 1.72 2004-08-27 03:20:39 goodale Exp $
#@@*/
# Global parameter to track the number of errors from the CST
@@ -109,6 +109,11 @@ print "Parsing parameter files...\n";
print "Parsing schedule files...\n";
%schedule_database = &create_schedule_database(%source_thorns);
+# Run any configuration scripts.
+print "Running any thorn-privided configuration scripts...\n";
+
+&ProcessConfiguration($config_dir, $configuration_database,\%thorns,"$top/config-info");
+
print "Checking consistency...\n";
&check_schedule_database(\%schedule_database, %source_thorns);
diff --git a/lib/sbin/CSTUtils.pl b/lib/sbin/CSTUtils.pl
index ae01571e..c7043647 100644
--- a/lib/sbin/CSTUtils.pl
+++ b/lib/sbin/CSTUtils.pl
@@ -455,4 +455,298 @@ sub RemoveComments
return $nocomment;
}
+#/*@@
+# @routine TestConfigEnv
+# @date Thu Aug 26 15:59:41 2004
+# @author Tom Goodale
+# @desc
+# Tests the routines for finding the new configuration environment
+# and updating the config-info file.
+# @enddesc
+# @calls
+# @calledby
+# @history
+#
+# @endhistory
+#
+#@@*/
+sub TestConfigEnv
+{
+ my ($in,$out) = @_;
+
+ my @allowed_opts = ("foo", "bar", "baz");
+
+ my $env;
+ my $optfile;
+ my $configinfo;
+ my $headers;
+
+ ($configinfo,$headers) = ParseConfigInfo($in);
+
+ if($ENV{"options"})
+ {
+ $optfile = ParseOptionsFile($ENV{"options"})
+ }
+ else
+ {
+ $optfile = {};
+ }
+
+ $env = GetOptionsFromEnv(\%ENV, \@allowed_opts);
+
+ my $modified = AmalgamateOptions($env,$optfile,$configinfo,\@allowed_opts);
+
+ if($modified)
+ {
+ print "Configuration was modified\n\n";
+ }
+
+ my $option;
+
+ foreach $option (sort keys %$configinfo)
+ {
+ print "$option=$configinfo->{$option}\n"
+ }
+
+ WriteNewConfigInfo($out,$headers,$configinfo);
+
+}
+
+
+#/*@@
+# @routine WriteNewConfigInfo
+# @date Thu Aug 26 15:53:30 2004
+# @author Tom Goodale
+# @desc
+# Writes a new configuration file
+# @enddesc
+# @calls
+# @calledby
+# @history
+#
+# @endhistory
+#
+#@@*/
+sub WriteNewConfigInfo
+{
+ my ($file,$headers,$options) = @_;
+ my $line;
+ my $option;
+
+ open(OUTFILE, "> $file") || CST_error(0,"Cannot open config-info file '$file' for writing\n",
+ "",__LINE__,__FILE__);
+
+ foreach $line (@$headers)
+ {
+ if($line ne "# CONFIG-OPTIONS :")
+ {
+ print OUTFILE "$line\n";
+ }
+ }
+
+ print OUTFILE "# CONFIG-MODIFIED: " . gmtime(time()) . " (GMT)\n";
+ print OUTFILE "# CONFIG-OPTIONS :\n";
+
+ foreach $option (sort keys %$options)
+ {
+ print OUTFILE "$option=$options->{$option}\n";
+ }
+
+ close(OUTFILE);
+}
+
+#/*@@
+# @routine AmalgamateOptions
+# @date Thu Aug 26 15:53:30 2004
+# @author Tom Goodale
+# @desc
+# Creates a hash table of option settings, giving
+# priority to ones from the environment, then to
+# ones from an options file, and finally to ones
+# which already exist in a config-info file.
+#
+# It only adds or replaces options from a defined list.
+# @enddesc
+# @calls
+# @calledby
+# @history
+#
+# @endhistory
+#
+#@@*/
+sub AmalgamateOptions
+{
+ my($env,$optfile,$configinfo,$allowed_options) = @_;
+
+ my $option;
+
+ my $modified = 0;
+
+ foreach $option (@$allowed_options)
+ {
+ if($env->{$option})
+ {
+ # Environment (command line) has highest priority
+ $configinfo->{$option} = $env->{$option};
+ $modified = 1;
+ }
+ elsif($optfile->{$option})
+ {
+ # Then a new options file
+ $configinfo->{$option} = $optfile->{$option};
+ $modified = 1;
+ }
+ }
+
+ return $modified;
+}
+
+#/*@@
+# @routine ParseConfigInfo
+# @date Thu Aug 26 15:56:15 2004
+# @author Tom Goodale
+# @desc
+# Parses a config-info file. Returns a hash of the options
+# and an array containing pre-existing header lines.
+# @enddesc
+# @calls
+# @calledby
+# @history
+#
+# @endhistory
+#
+#@@*/
+sub ParseConfigInfo
+{
+ my($file) = @_;
+ my(%options);
+ my @headers = ();
+ my $line_number = 0;
+
+ open(INFILE, "< $file") || CST_error(0,"Cannot open config-info file '$file' for reading\n",
+ "",__LINE__,__FILE__);
+
+ while(<INFILE>)
+ {
+ chomp;
+
+ $line_number++;
+
+ if(m/^#/)
+ {
+ push(@headers,$_);
+ }
+ elsif (m/^\s*(\w+)[=\s]+(.*)\s*/)
+ {
+ if(! $options{$1})
+ {
+ $options{$1} = $2;
+ }
+ else
+ {
+ CST_error(0,"corrupt config-info file; duplicate entry on line $line_number",
+ "",__LINE__,__FILE__);
+ }
+ }
+ }
+
+ close(INFILE);
+
+ return \%options, \@headers;
+}
+
+#/*@@
+# @routine ParseOptionsFile
+# @date Thu Aug 26 15:57:58 2004
+# @author Tom Goodale
+# @desc
+# Parses a configuration options file.
+# @enddesc
+# @calls
+# @calledby
+# @history
+#
+# @endhistory
+#
+#@@*/
+sub ParseOptionsFile
+{
+ my($file) = @_;
+ my $line_number = 0;
+ my %options;
+
+ open(INFILE, "< $file") || CST_error(0,"Cannot open configuration options file '$file'\n",
+ "",__LINE__,__FILE__);
+
+ while(<INFILE>)
+ {
+ $line_number++;
+
+ chomp;
+
+ #Ignore comments.
+ s/\#(.*)$//g;
+
+ #Remove spaces at end of lines
+ s/\s*$//;
+
+ #Ignore blank lines
+ next if (m:^\s*$:);
+
+ # Match lines of the form
+ # keyword value
+ # or keyword = value
+ if (/^\s*(\w+)[=\s]+(.*)\s*/)
+ {
+ # only set it if it wasn't already
+ if(! $options{$1})
+ {
+ # Remember it for writing to config-info
+ $options{$1} = $2;
+ }
+ }
+ else
+ {
+ CST_error(0,"Could not parse configuration line $file:$line_number...\n'$_'\n",
+ "",__LINE__,__FILE__);
+
+ }
+ }
+ close(INFILE);
+
+ return \%options;
+}
+
+#/*@@
+# @routine GetOptionsFromEnv
+# @date Thu Aug 26 15:58:26 2004
+# @author Tom Goodale
+# @desc
+# Gets options from the environment.
+# @enddesc
+# @calls
+# @calledby
+# @history
+#
+# @endhistory
+#
+#@@*/
+sub GetOptionsFromEnv
+{
+ my($env, $allowed_options) = @_;
+ my %options;
+
+ my $option;
+
+ foreach $option (@$allowed_options)
+ {
+ if($env->{$option})
+ {
+ $options{$option} = $env->{$option};
+ }
+ }
+
+ return \%options;
+}
+
1;
diff --git a/lib/sbin/ConfigScriptParser.pl b/lib/sbin/ConfigScriptParser.pl
index 7f2551f8..fb08f2d4 100644
--- a/lib/sbin/ConfigScriptParser.pl
+++ b/lib/sbin/ConfigScriptParser.pl
@@ -19,7 +19,7 @@
#@@*/
sub ParseConfigScript
{
- my($config_dir, $provides, $lang, $script, $thorn, $cfg, $thorns, $filename)=@_;
+ my($config_dir, $provides, $lang, $script, $thorn, $cfg)=@_;
my($line_number, $line, $temp);
my($exit_value, $signal_num, $dumped_core);
@@ -29,7 +29,7 @@ sub ParseConfigScript
# Run the configuration script in the config_dir folder
if ($lang ne '' && $script ne '')
{
- @data=`$lang $thorns->{$thorn}/$script`;
+ @data=`$lang $script`;
}
$exit_value = $? >> 8;
$signal_num = $? & 127;
@@ -140,7 +140,6 @@ sub ParseConfigScript
&CST_error (0, $msg . "dumped core\n$error_msg")
if ($dumped_core);
- return ($cfg);
}
1;
diff --git a/lib/sbin/ConfigurationParser.pl b/lib/sbin/ConfigurationParser.pl
index dd6b48a9..346b4c75 100644
--- a/lib/sbin/ConfigurationParser.pl
+++ b/lib/sbin/ConfigurationParser.pl
@@ -44,7 +44,7 @@ sub CreateConfigurationDatabase
# if ($cfg{"\U$thorn\E REQUIRES"});
# }
- $cfg->{"\U$thorn\E USES THORNS"} = '';
+ $cfg{"\U$thorn\E USES THORNS"} = '';
# verify that all required thorns are there in the ThornList
next if (! $cfg{"\U$thorn\E REQUIRES THORNS"});
@@ -136,7 +136,7 @@ sub ParseConfigurationCCL
my($config_dir, $thorn, $cfg, $thorns, $filename) = @_;
my(@data);
my($line_number, $line);
- my($provides, $script, $lang);
+ my($provides, $script, $lang, $options);
my($optional, $define);
# Initialise some stuff to prevent perl -w from complaining.
@@ -157,19 +157,23 @@ sub ParseConfigurationCCL
if($line =~ m/^\s*PROVIDES\s*/i)
{
$lang = $script = '';
- ($provides, $script, $lang, $line_number) = &ParseProvidesBlock($line_number, \@data);
+ ($provides, $script, $lang, $options, $line_number) = &ParseProvidesBlock($line_number, \@data);
$cfg->{"\U$thorn\E PROVIDES"} .= "$provides ";
- $cfg->{"\U$thorn\E PROVIDES \U$provides\E SCRIPT"} = $script;
- $cfg->{"\U$thorn\E PROVIDES \U$provides\E LANG"} = $lang;
-
- if ($script)
+ if($script)
{
- print "Running configuration script '$script'\n";
-
- $cfg = &ParseConfigScript($config_dir, $provides, $lang, $script,
- $thorn, $cfg, $thorns, $filename);
- print "\n";
+ $cfg->{"\U$thorn\E PROVIDES \U$provides\E SCRIPT"} = "$thorns->{$thorn}/$script";
}
+ $cfg->{"\U$thorn\E PROVIDES \U$provides\E LANG"} = $lang;
+ $cfg->{"\U$thorn\E PROVIDES \U$provides\E OPTIONS"} = $options;
+
+# if ($script)
+# {
+# print "Running configuration script '$script'\n";
+#
+# &ParseConfigScript($config_dir, $provides, $lang, $script,
+# $thorn, $cfg);
+# print "\n";
+# }
next;
}
@@ -215,11 +219,12 @@ sub ParseConfigurationCCL
sub ParseProvidesBlock
{
my ($line_number, $data) = @_;
- my ($provides, $script, $lang);
+ my ($provides, $script, $lang, $options);
$provides = "";
$script = "";
$lang = "";
+ $options = [];
$data->[$line_number] =~ m/^\s*PROVIDES\s*(.*)/i;
@@ -230,7 +235,7 @@ sub ParseProvidesBlock
{
&CST_error (0, "Error parsing provides block line '$data->[$line_number]'.".
'Missing { at start of block');
- $line_number++ while($data[$line_number] !~ m:\s*\}\s*:);
+ $line_number++ while($data->[$line_number] !~ m:\s*\}\s*:);
}
else
{
@@ -247,6 +252,11 @@ sub ParseProvidesBlock
$lang = $1;
next;
}
+ elsif($data->[$line_number] =~ m/^\s*OPTIONS[^\s]*\s*(.*)$/i)
+ {
+ push(@$options, split(' ',$1));
+ next;
+ }
elsif($data->[$line_number] =~ m:\s*\}\s*:)
{
# do nothing.
@@ -259,7 +269,7 @@ sub ParseProvidesBlock
}
}
- return ($provides, $script, $lang, $line_number);
+ return ($provides, $script, $lang, $options, $line_number);
}
diff --git a/lib/sbin/ProcessConfiguration.pl b/lib/sbin/ProcessConfiguration.pl
index 4be4f7d3..d0a1e898 100644
--- a/lib/sbin/ProcessConfiguration.pl
+++ b/lib/sbin/ProcessConfiguration.pl
@@ -38,6 +38,105 @@ sub SplitThorns
}
}
+#/*@@
+# @routine ProcessConfiguration
+# @date Thu Aug 26 22:09:26 2004
+# @author Tom Goodale
+# @desc
+# Runs all the configuration scripts belonging to thorns.
+# Has to setup the environment correctly, and as a result
+# modifies the config-info file for future reference.
+# @enddesc
+# @calls
+# @calledby
+# @history
+#
+# @endhistory
+#
+#@@*/
+sub ProcessConfiguration
+{
+ my($config_dir,$config_database, $thorns, $config_file) = @_;
+
+ my $thorn;
+ my $provides;
+ my @allowed_opts;
+
+ # Find the master list of allowed options
+ foreach $thorn (sort keys %thorns)
+ {
+# print "DEBUG: Thorn $thorn\n";
+
+ foreach $provides (split(' ',$config_database->{"\U$thorn\E PROVIDES"}))
+ {
+# print "DEBUG: Provides $provides\n";
+
+ if(@{$config_database->{"\U$thorn\E PROVIDES \U$provides\E OPTIONS"}} != 0)
+ {
+# print "DEBUG: $thorn provides $provides with options\n";
+ push(@allowed_opts, @{$config_database->{"\U$thorn\E PROVIDES \U$provides\E OPTIONS"}});
+ }
+ }
+ }
+
+# print "DEBUG: allowed options are @allowed_opts\n";
+
+ # Now get all the configuration options.
+ my $env;
+ my $optfile;
+ my $configinfo;
+ my $headers;
+
+ ($configinfo,$headers) = ParseConfigInfo($config_file);
+ if($ENV{"options"})
+ {
+ $optfile = ParseOptionsFile($ENV{"options"})
+ }
+ else
+ {
+ $optfile = {};
+ }
+
+ $env = GetOptionsFromEnv(\%ENV, \@allowed_opts);
+
+ my $modified = AmalgamateOptions($env,$optfile,$configinfo,\@allowed_opts);
+
+ # Write a new config-info file if anything has changed
+ if($modified)
+ {
+ WriteNewConfigInfo($config_file,$headers,$configinfo);
+ }
+
+ # Now setup the environment
+ # FIXME: Would like to restrict this to just the @allowed_opts, but then
+ # flesh configuration options like MPI or arch specific ones like
+ # IRIX_BITS would not be propogated 8-(
+
+ foreach $option (keys %$configinfo)
+ {
+ $ENV{$option} = $configinfo->{$option};
+ }
+
+ # Ok, can now run the configuration scripts.
+
+ foreach $thorn (sort keys %thorns)
+ {
+ foreach $provides (split(' ',$config_database->{"\U$thorn\E PROVIDES"}))
+ {
+ my $script = $config_database->{"\U$thorn\E PROVIDES \U$provides\E SCRIPT"};
+ my $lang = $config_database->{"\U$thorn\E PROVIDES \U$provides\E LANG"};
+
+ if ($script)
+ {
+ print "Running configuration script '$script'\n";
+
+ &ParseConfigScript($config_dir, $provides, $lang, $script,
+ $thorn, $config_database);
+ print "\n";
+ }
+ }
+ }
+}
1;