summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorChad Elliott <elliottc@objectcomputing.com>2022-11-11 06:23:32 -0600
committerChad Elliott <elliottc@objectcomputing.com>2022-11-11 06:23:32 -0600
commit803712a150de62cf8c8427a775c7e5587a59fa7f (patch)
tree62508ff7ec4c2c1b08b33faca1fb4e6145fad521 /modules
parenta91abb9c996317753d7c0302bb6eb87cbad7cfca (diff)
parent5aad93c4292b7aa33395dd2bb96c5599c73bdf5a (diff)
downloadMPC-803712a150de62cf8c8427a775c7e5587a59fa7f.tar.gz
Merge branch 'master' into elliottc/cmake-support
Diffstat (limited to 'modules')
-rw-r--r--modules/ProjectCreator.pm60
-rw-r--r--modules/TemplateParser.pm1
2 files changed, 50 insertions, 11 deletions
diff --git a/modules/ProjectCreator.pm b/modules/ProjectCreator.pm
index de7ff8f5..5776ea72 100644
--- a/modules/ProjectCreator.pm
+++ b/modules/ProjectCreator.pm
@@ -353,6 +353,7 @@ sub new {
$self->{'escape_spaces'} = $self->escape_spaces();
$self->{'current_template'} = undef;
$self->{'make_coexistence'} = $makeco;
+ $self->{'forcount'} = 0;
$self->add_default_matching_assignments();
$self->reset_generating_types();
@@ -4674,15 +4675,24 @@ sub get_custom_value {
}
elsif ($cmd eq 'commands') { # only used with 'combined_custom'
$value = [];
+
+ ## Clear out the previous custom_multi_details hash map so that we don't
+ ## have extraneous data associated with commands from previous iterations.
+ $self->{'custom_multi_details'} = {};
+
my %details = ('flags' => 'commandflags',
'outopt' => 'output_option',
'gdir' => 'gendir');
for my $tag (@{$self->{'custom_multi_cmd'}->{$based}}) {
my $command = $self->get_custom_assign_or_override('command', $tag,
$based, @params);
- push(@$value, $command);
- my $det = $self->{'custom_multi_details'}->{$command} = {'type' => $tag,
- 'outfile' => ''};
+
+ ## Use $tag as the key for custom_multi_details and store the command as
+ ## a data member that we can access later. $command shouldn't be used
+ ## as the key because it is not guaranteed to be unique.
+ my $det = $self->{'custom_multi_details'}->{$tag} = {'_cmd' => $command,
+ 'type' => $tag,
+ 'outfile' => ''};
for my $k (keys %details) {
$det->{$k} = $self->get_custom_assign_or_override($details{$k}, $tag,
$based, @params);
@@ -4705,15 +4715,15 @@ sub get_custom_value {
}
}
- ## Sort the list of commands based on the original type so that generated
- ## projects are reproducable.
+ ## Sort the list of types so that generated projects are reproducable.
+ ## Additionally, we need them to be ordered (and numbered) so that we can
+ ## match the command with the right tag when iterating in the template.
my $det = $self->{'custom_multi_details'};
- my @sorted = sort { $det->{$a}->{'type'} cmp $det->{$b}->{'type'} } @$value;
- $value = \@sorted;
- }
- elsif (exists $self->{'custom_multi_details'}->{$based}->{$cmd}) {
- # only used with 'combined_custom'
- $value = $self->{'custom_multi_details'}->{$based}->{$cmd};
+ my $i = 0;
+ foreach my $key (sort { $a cmp $b } keys %$det) {
+ $det->{$key}->{'_order'} = $i++;
+ push(@$value, $det->{$key}->{'_cmd'});
+ }
}
elsif (defined $customDefined{$cmd}) {
$value = $self->get_assignment($cmd,
@@ -4722,6 +4732,30 @@ sub get_custom_value {
$value = $self->convert_command_parameters($based, $value, @params);
}
}
+ else {
+ ## This is only used with 'combined_custom'.
+ ##
+ ## $based - The command for the original define custom.
+ ## $cmd - The member after the arrow operator.
+ ##
+ ## We cannot use a direct lookup because the command is no longer the
+ ## key for custom_multi_details. It is possible to have two or more custom
+ ## types that use the same command. Therefore, we have to use the custom
+ ## type name ($tag) as the key. Since this code can only be called within
+ ## a foreach, we have to rely on the fact that the values created above
+ ## (during the processing of 'commands') are sorted to correlate the
+ ## command, stored in $base, with the correct tag in order to get the
+ ## correct command flags and other associated values.
+ foreach my $tag (keys %{$self->{'custom_multi_details'}}) {
+ my $det = $self->{'custom_multi_details'}->{$tag};
+ if ($det->{'_cmd'} eq $based && $det->{'_order'} == $self->{'forcount'}) {
+ if (exists $det->{$cmd}) {
+ $value = $det->{$cmd};
+ }
+ last;
+ }
+ }
+ }
return $value;
}
@@ -5890,6 +5924,10 @@ sub combine_custom_types {
return 1;
}
+sub set_forcount {
+ my($self, $count) = @_;
+ $self->{'forcount'} = $count;
+}
# ************************************************************
# Accessors used by support scripts
diff --git a/modules/TemplateParser.pm b/modules/TemplateParser.pm
index f447b175..f8fddaef 100644
--- a/modules/TemplateParser.pm
+++ b/modules/TemplateParser.pm
@@ -631,6 +631,7 @@ sub process_foreach {
## Now parse the line of text, each time
## with different values
++$self->{'foreach'}->{'processing'};
+ $self->{'prjc'}->set_forcount($i);
my($status, $error) = $self->parse_line(undef, $text);
--$self->{'foreach'}->{'processing'};
return $error if (defined $error);