From 595ffe4dee1d88ed9b1998dbb4fcd2acf0484c2e Mon Sep 17 00:00:00 2001 From: eschnett Date: Fri, 18 Jan 2013 02:02:00 +0000 Subject: Introduce OPTIONAL_IFACTIVE Following up on a discussion on the Cactus developers mailing list, this patch introduces a third way of indicating a desired capability: in addition to REQUIRES and OPTIONAL there is OPTIONAL_IFACTIVE. This behaves like OPTIONAL, except that the capability relationship only exists if the thorn providing the capability is active. git-svn-id: http://svn.cactuscode.org/flesh/trunk@4938 17b73243-c579-4c4c-a9d2-2d5706c11dac --- lib/sbin/ConfigurationParser.pl | 78 +++++++++++++++++++++++++++----- lib/sbin/CreateImplementationBindings.pl | 20 +++++++- 2 files changed, 86 insertions(+), 12 deletions(-) diff --git a/lib/sbin/ConfigurationParser.pl b/lib/sbin/ConfigurationParser.pl index 59ebba53..19af291a 100644 --- a/lib/sbin/ConfigurationParser.pl +++ b/lib/sbin/ConfigurationParser.pl @@ -38,12 +38,14 @@ sub CreateConfigurationDatabase # if($debug) # { # print " $thorn\n"; -# print " Provides: ", $cfg{"\U$thorn\E PROVIDES"}, "\n" +# print " Provides: ", $cfg{"\U$thorn\E PROVIDES"}, "\n" # if ($cfg{"\U$thorn\E PROVIDES"}); -# print " Requires: ", $cfg{"\U$thorn\E REQUIRES"}, "\n" +# print " Requires: ", $cfg{"\U$thorn\E REQUIRES"}, "\n" # if ($cfg{"\U$thorn\E REQUIRES"}); -# print " Optional: ", $cfg{"\U$thorn\E OPTIONAL"}, "\n" +# print " Optional: ", $cfg{"\U$thorn\E OPTIONAL"}, "\n" # if ($cfg{"\U$thorn\E OPTIONAL"}); +# print " Optional-ifactive: ", $cfg{"\U$thorn\E OPTIONAL_IFACTIVE"}, "\n" +# if ($cfg{"\U$thorn\E OPTIONAL_IFACTIVE"}); # } $cfg{"\U$thorn\E USES THORNS"} = ''; @@ -88,6 +90,16 @@ sub CreateConfigurationDatabase } } foreach my $thorn (sort keys %thorns) + { + if ($cfg{"\U$thorn\E REQUIRES"}) + { + foreach my $requiredcap (split (' ', $cfg{"\U$thorn\E REQUIRES"})) + { + $cfg{"\U$thorn\E ACTIVATES"} .= "$requiredcap "; + } + } + } + foreach my $thorn (sort keys %thorns) { if ($cfg{"\U$thorn\E OPTIONAL"}) { @@ -96,6 +108,18 @@ sub CreateConfigurationDatabase if ($providedcaps{$optionalcap}) { $cfg{"\U$thorn\E REQUIRES"} .= "$optionalcap "; + $cfg{"\U$thorn\E ACTIVATES"} .= "$optionalcap "; + } + } + } + if ($cfg{"\U$thorn\E OPTIONAL_IFACTIVE"}) + { + foreach my $optionalcap (split (' ', $cfg{"\U$thorn\E OPTIONAL_IFACTIVE"})) + { + if ($providedcaps{$optionalcap}) + { + $cfg{"\U$thorn\E REQUIRES"} .= "$optionalcap "; + # nothing is activated } } } @@ -140,8 +164,29 @@ sub CreateConfigurationDatabase } } -# Check for cyclic dependencies -# create a hash with thorn-> used thorns (no prefix) + # Translate capability to thorn names + my %capabilities; + foreach my $thorn (sort keys %thorns) + { + next if ! $cfg{"\U$thorn\E PROVIDES"}; + foreach my $cap (split (' ', $cfg{"\U$thorn\E PROVIDES"})) + { + $capabilities{"\U$cap\E"} = $thorn; + } + } + foreach my $thorn (sort keys %thorns) + { + my $activates = ''; + foreach my $cap (split (' ', $cfg{"\U$thorn\E ACTIVATES"})) + { + my $cap_thorn = $capabilities{"\U$cap\E"}; + $activates .= " $cap_thorn"; + } + $cfg{"\U$thorn\E ACTIVATES THORNS"} = $activates; + } + + # Check for cyclic dependencies + # create a hash with thorn-> used thorns (no prefix) foreach my $thorn (sort keys %thorns) { $thorn_dependencies{uc($thorn)}=$cfg{"\U$thorn\E USES THORNS"}; @@ -151,10 +196,10 @@ sub CreateConfigurationDatabase my $message = &find_dep_cycles(%thorn_dependencies); if ("" ne $message) { - $message =~ s/^\s*//g; - $message =~ s/\s*$//g; + $message =~ s/^\s*//g; + $message =~ s/\s*$//g; $message =~ s/\s+/->/g; - $message = "Found a cyclic dependency in configuration requirements:".$message."\n"; + $message = "Found a cyclic dependency in configuration requirements:$message\n"; &CST_error(0, $message); } @@ -184,6 +229,8 @@ sub ParseConfigurationCCL $cfg->{"\U$thorn\E REQUIRES"} = ''; $cfg->{"\U$thorn\E REQUIRES THORNS"} = ''; $cfg->{"\U$thorn\E OPTIONAL"} = ''; + $cfg->{"\U$thorn\E OPTIONAL_IFACTIVE"} = ''; + $cfg->{"\U$thorn\E ACTIVATES"} = ''; $cfg->{"\U$thorn\E OPTIONS"} = ''; # Read the data @@ -260,6 +307,15 @@ re.ccl of thorn '$thorn'"); $cfg->{"\U$thorn\E OPTIONAL"} .= "$optional "; $cfg->{"\U$thorn\E OPTIONAL \U$optional\E DEFINE"} = $define; } + elsif($line =~ m/^\s*OPTIONAL_IFACTIVE\s*/i) + { + ($optional, $define, $line_number) = &ParseOptionalBlock($filename, $line_number, \@data); + if ($optional !~ m{^[A-Za-z0-9_. ]+$}) { + &CST_error (0, "Illegal optional capability '$optional' line '$line' in configure.ccl of thorn '$thorn'"); + } + $cfg->{"\U$thorn\E OPTIONAL_IFACTIVE"} .= "$optional "; + $cfg->{"\U$thorn\E OPTIONAL_IFACTIVE \U$optional\E DEFINE"} = $define; + } elsif($line =~ m/^\s*NO_SOURCE\s*/i) { $cfg->{"\U$thorn\E OPTIONS"} .= "NO_SOURCE"; @@ -343,7 +399,7 @@ sub ParseProvidesBlock # @date Mon May 8 15:52:40 2000 # @author Tom Goodale # @desc -# Parses the OPTIONAL block in a configuration.ccl file. +# Parses the OPTIONAL or OPTIONAL_IFACTIVE block in a configuration.ccl file. # @enddesc #@@*/ sub ParseOptionalBlock @@ -351,9 +407,9 @@ sub ParseOptionalBlock my ($file_name, $line_number, $data) = @_; my ($optional, $define); - $data->[$line_number] =~ m/^\s*OPTIONAL\s*(.*)/i; + $data->[$line_number] =~ m/^\s*OPTIONAL(_IFACTIVE)?\s*(.*)/i; - $optional = $1; + $optional = $2; $define = ""; diff --git a/lib/sbin/CreateImplementationBindings.pl b/lib/sbin/CreateImplementationBindings.pl index 64c45cad..af423aac 100644 --- a/lib/sbin/CreateImplementationBindings.pl +++ b/lib/sbin/CreateImplementationBindings.pl @@ -11,7 +11,7 @@ sub CreateImplementationBindings { my($bindings_dir, $rhparameter_db, $rhinterface_db, $configuration_db) = @_; my($i, $start_dir, $thorn); - my(@data, @thorns, @ancestors, @friends, @requires_thorns); + my(@data, @thorns, @ancestors, @friends, @requires_thorns, @activates_thorns); if(! $build_dir) { @@ -87,6 +87,7 @@ sub CreateImplementationBindings @ancestors = map { " \"$_\"," } split (' ', $rhinterface_db->{"IMPLEMENTATION \U$myimp\E ANCESTORS"}); @friends = map { " \"$_\"," } split (' ', $rhinterface_db->{"\U$thorn\E FRIEND"}); @requires_thorns = map { " \"$_\"," } split (' ', $configuration_db->{"\U$thorn\E REQUIRES THORNS"}); + @activates_thorns = map { " \"$_\"," } split (' ', $configuration_db->{"\U$thorn\E ACTIVATES THORNS"}); @data = (); push(@data, '#include '); @@ -134,6 +135,17 @@ sub CreateImplementationBindings $i++; } + if (@activates_thorns) + { + push(@data, ' const char *activates_thorns[] ='); + push(@data, ' {'); + push(@data, @activates_thorns); + push(@data, ' 0,'); + push(@data, ' };'); + push(@data, ''); + $i++; + } + push(@data, ' /*'); push(@data, ' * Should be able to do below with a constant initializer'); push(@data, ' * but sr8000 compiler doesn\'t like it.'); @@ -164,6 +176,12 @@ sub CreateImplementationBindings push(@data, " attributes[$i].AttributeData.StringList = requires_thorns;"); $i++; } + if (@activates_thorns) + { + push(@data, " attributes[$i].attribute = \"activates thorns\";"); + push(@data, " attributes[$i].AttributeData.StringList = activates_thorns;"); + $i++; + } push(@data, " attributes[$i].attribute = 0;"); push(@data, " attributes[$i].AttributeData.StringList = 0;"); push(@data, ''); -- cgit v1.2.3