Skip to content

Commit d07b201

Browse files
committed
Fri May 17 14:42:45 UTC 2019 Chad Elliott <[email protected]>
* modules/Creator.pm: * modules/IARProjectCreator.pm: * modules/IARWorkspaceCreator.pm: If a project type requires relative paths, locate a relative path when replacing $() variables if at all possible. * modules/ProjectCreator.pm: * modules/TemplateParser.pm: * templates/iar.mpd: A new template function, 'extension', can be used to get the extension of a file. Additionally, non-template files can now be obtained through the custom input file interface.
1 parent 8c0ffa8 commit d07b201

File tree

7 files changed

+121
-9
lines changed

7 files changed

+121
-9
lines changed

ChangeLog

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
Fri May 17 14:42:45 UTC 2019 Chad Elliott <[email protected]>
2+
3+
* modules/Creator.pm:
4+
* modules/IARProjectCreator.pm:
5+
* modules/IARWorkspaceCreator.pm:
6+
7+
If a project type requires relative paths, locate a relative path
8+
when replacing $() variables if at all possible.
9+
10+
* modules/ProjectCreator.pm:
11+
* modules/TemplateParser.pm:
12+
* templates/iar.mpd:
13+
14+
A new template function, 'extension', can be used to get the
15+
extension of a file. Additionally, non-template files can now be
16+
obtained through the custom input file interface.
17+
118
Thu May 16 18:04:40 UTC 2019 Chad Elliott <[email protected]>
219

320
* templates/iar.mpd:

modules/Creator.pm

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,12 +1027,41 @@ sub get_outdir {
10271027
}
10281028

10291029

1030+
sub aggressively_replace {
1031+
my($self, $icwd, $val) = @_;
1032+
my $count = 0;
1033+
my $wd = $icwd;
1034+
my $ival = ($self->{'case_tolerant'} ? lc($val) : $val);
1035+
1036+
## Search back up the directories until we either find a match or we
1037+
## run out of directories.
1038+
while($wd =~ s/[^\/]+[\/]?$//) {
1039+
## We have gone up one directory
1040+
$count++;
1041+
1042+
## Make a regular expression and see if we have found a match
1043+
## with our provided directory value.
1044+
my $re = $self->escape_regex_special($wd);
1045+
if ($ival =~ /^($re)/) {
1046+
## We have found how it is relative. Now make the relative path
1047+
## and return it.
1048+
my $prefix = $1;
1049+
my $suffix = substr($val, length($prefix));
1050+
return ('../' x $count) . $suffix;
1051+
}
1052+
}
1053+
1054+
## We never found a match
1055+
return undef;
1056+
}
1057+
10301058
sub expand_variables {
10311059
my($self, $value, $rel, $expand_template, $scopes, $expand, $warn) = @_;
10321060
my $cwd = $self->getcwd();
10331061
my $start = 0;
10341062
my $forward_slashes = $self->{'convert_slashes'} ||
10351063
$self->{'requires_forward_slashes'};
1064+
my $aggrep = $self->aggressive_relative_replacement();
10361065

10371066
## Fix up the value for Windows switch the \\'s to /
10381067
$cwd =~ s/\\/\//g if ($forward_slashes);
@@ -1100,13 +1129,31 @@ sub expand_variables {
11001129
## instead of leaving it we will expand it. But, we will only
11011130
## get into this section if this is the secondary attempt to
11021131
## replace the variable (indicated by the $warn boolean).
1103-
$val =~ s/\//\\/g if ($self->{'convert_slashes'});
1104-
substr($value, $start) =~ s/\$\([^)]+\)/$val/;
1105-
$whole = $val;
1132+
my $aggressive_rel;
1133+
if ($aggrep &&
1134+
($aggressive_rel = $self->aggressively_replace($icwd, $val))) {
1135+
$aggressive_rel =~ s/\//\\/g if ($self->{'convert_slashes'});
1136+
substr($value, $start) =~ s/\$\([^)]+\)/$aggressive_rel/;
1137+
$whole = $aggressive_rel;
1138+
}
1139+
else {
1140+
$val =~ s/\//\\/g if ($self->{'convert_slashes'});
1141+
substr($value, $start) =~ s/\$\([^)]+\)/$val/;
1142+
$whole = $val;
1143+
}
11061144
}
11071145
else {
1108-
my $loc = index(substr($value, $start), $whole);
1109-
$start += $loc if ($loc > 0);
1146+
my $aggressive_rel;
1147+
if ($aggrep &&
1148+
($aggressive_rel = $self->aggressively_replace($icwd, $val))) {
1149+
$aggressive_rel =~ s/\//\\/g if ($self->{'convert_slashes'});
1150+
substr($value, $start) =~ s/\$\([^)]+\)/$aggressive_rel/;
1151+
$whole = $aggressive_rel;
1152+
}
1153+
else {
1154+
my $loc = index(substr($value, $start), $whole);
1155+
$start += $loc if ($loc > 0);
1156+
}
11101157
}
11111158
}
11121159
}
@@ -1285,6 +1332,12 @@ sub get_secondary_relative_values {
12851332
}
12861333

12871334

1335+
sub aggressive_relative_replacement {
1336+
#my $self = shift;
1337+
return 0;
1338+
}
1339+
1340+
12881341
sub convert_all_variables {
12891342
#my $self = shift;
12901343
return 0;

modules/IARProjectCreator.pm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,10 @@ sub get_cmdsep_symbol {
7575
}
7676

7777

78+
sub aggressive_relative_replacement {
79+
#my $self = shift;
80+
return 1;
81+
}
82+
83+
7884
1;

modules/IARWorkspaceCreator.pm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,10 @@ sub post_workspace {
7070
}
7171

7272

73+
sub aggressive_relative_replacement {
74+
#my $self = shift;
75+
return 1;
76+
}
77+
78+
7379
1;

modules/ProjectCreator.pm

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4617,6 +4617,22 @@ sub get_custom_value {
46174617
}
46184618
}
46194619
}
4620+
elsif ($cmd eq 'non_template_output_files') {
4621+
# Generate non-template output files based on $based
4622+
if (defined $self->{'custom_output_files'}) {
4623+
$value = [];
4624+
foreach my $file (@{$self->{'custom_output_files'}->{$based}}) {
4625+
my $template = 0;
4626+
foreach my $ext (@{$self->{'valid_components'}->{'template_files'}}) {
4627+
if ($file =~ /$ext$/) {
4628+
$template = 1;
4629+
last;
4630+
}
4631+
}
4632+
push(@$value, $file) if (!$template);
4633+
}
4634+
}
4635+
}
46204636
elsif ($cmd eq 'inputexts') {
46214637
my @array = @{$self->{'valid_components'}->{$based}};
46224638
foreach my $val (@array) {

modules/TemplateParser.pm

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ my %keywords = ('if' => 0,
9292
'deref' => 0,
9393
'set' => 0,
9494
'is_relative' => $get_type|$doif_type|$get_combined_type,
95+
'extension' => $get_type,
9596
);
9697

9798
my %target_type_vars = ('type_is_static' => 1,
@@ -388,7 +389,7 @@ sub get_value {
388389
if (!defined $value && $name =~ /^(.*)\->(\w+)/) {
389390
my $pre = $1;
390391
my $post = $2;
391-
my $base = $self->get_value($pre);
392+
my $base = $self->get_value($pre);
392393

393394
if (defined $base) {
394395
$value = $self->{'prjc'}->get_special_value(
@@ -2014,6 +2015,19 @@ sub handle_is_relative {
20142015
}
20152016

20162017

2018+
sub get_extension {
2019+
my($self, $name) = @_;
2020+
my $val = $self->get_value_with_default($name);
2021+
return ($val =~ /(\.[^\.]+)$/ ? $1 : '');
2022+
}
2023+
2024+
2025+
sub handle_extension {
2026+
my($self, $name) = @_;
2027+
$self->append_current($self->get_extension($name));
2028+
}
2029+
2030+
20172031
sub prepare_parameters {
20182032
my($self, $prefix) = @_;
20192033
my $input = $self->get_value($prefix . '->input_file');

templates/iar.mpd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,13 +1135,13 @@
11351135
<settings>
11361136
<name>CUSTOM</name>
11371137
<data>
1138-
<extensions><%foreach(custom_type->inputexts)%>.<%custom_type->inputext%><%fornotlast(",")%><%endfor%></extensions>
1138+
<extensions><%extension(custom_type->input_file)%><%foreach(custom_type->inputexts)%> .<%custom_type->inputext%><%endfor%></extensions>
11391139
<cmdline><%if(flag_overrides(custom_type->input_file, command))%><%flag_overrides(custom_type->input_file, command)%><%else%><%custom_type->command%><%endif%> <%if(flag_overrides(custom_type->input_file, commandflags))%><%flag_overrides(custom_type->input_file, commandflags)%><%else%><%custom_type->commandflags%><%endif%> <%custom_type->input_file%><%if(custom_type->output_option)%> <%custom_type->output_option%> <%foreach(custom_type->input_file->output_files)%><%if(flag_overrides(custom_type->input_file, gendir))%><%flag_overrides(custom_type->input_file, gendir)%>\<%basename(custom_type->input_file->output_file)%><%else%><%custom_type->input_file->output_file%><%endif%><%endfor%><%endif%></cmdline>
11401140
<hasPrio>0</hasPrio>
11411141
<outputs>
1142-
<%foreach(custom_type->input_file->output_files)%>
1142+
<%foreach(custom_type->input_file->non_template_output_files)%>
11431143
<file>
1144-
<name><%if(flag_overrides(custom_type->input_file, gendir))%><%flag_overrides(custom_type->input_file, gendir)%>\<%basename(custom_type->input_file->output_file)%><%else%><%custom_type->input_file->output_file%><%endif%></name>
1144+
<name><%if(flag_overrides(custom_type->input_file, gendir))%><%flag_overrides(custom_type->input_file, gendir)%>\<%basename(custom_type->input_file->non_template_output_file)%><%else%><%custom_type->input_file->non_template_output_file%><%endif%></name>
11451145
</file>
11461146
<%endfor%>
11471147
</outputs>

0 commit comments

Comments
 (0)