Skip to content

Commit c8e2f48

Browse files
committed
Fri Jun 28 15:52:37 UTC 2019 Chad Elliott <elliottc@objectcomputing.com>
1 parent 3a06d56 commit c8e2f48

3 files changed

Lines changed: 90 additions & 0 deletions

File tree

ChangeLog

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
Fri Jun 28 15:52:37 UTC 2019 Chad Elliott <elliottc@objectcomputing.com>
2+
3+
* modules/TemplateParser.pm:
4+
5+
Added a template function, is_custom_input, which takes a file
6+
as the parameter and checks it against all custom input files. It
7+
returns true/false when used in a <%if()%> context.
8+
9+
* templates/vc10.mpd:
10+
11+
Use the 'is_custom_input' function template to ensure that files
12+
listed as custom type inputs are not listed under template_files,
13+
header_files, inline_files, documentation_files, or resource_files.
14+
If a custom type input is also listed under source_files, we will
15+
leave it to the user to resolve this externally.
16+
17+
This is technically only required for certain versions of vs2017 and
18+
vs2019, but in order to provide this functionality for just those
19+
two types would require a duplication of the vc10 template with a
20+
few minor adjustments. Future fixes to the vc10 template would have
21+
needed to have been propagated to the slightly different vs2017
22+
template. To simplify maintenance, I just made the changes to this
23+
template file.
24+
125
Mon Jun 17 14:17:49 UTC 2019 Chad Elliott <elliottc@objectcomputing.com>
226

327
* modules/CommandHelper.pm:

modules/TemplateParser.pm

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ my %keywords = ('if' => 0,
9393
'set' => 0,
9494
'is_relative' => $get_type|$doif_type|$get_combined_type,
9595
'extension' => $get_type,
96+
'is_custom_input' => $get_type|$doif_type|$get_combined_type,
9697
);
9798

9899
my %target_type_vars = ('type_is_static' => 1,
@@ -138,6 +139,7 @@ sub new {
138139
$self->{'keyname_used'} = {};
139140
$self->{'scopes'} = {};
140141
$self->{'aux_file'} = undef;
142+
$self->{'custom_input_cache'} = {};
141143

142144
$self->{'foreach'} = {};
143145
$self->{'foreach'}->{'count'} = -1;
@@ -2015,6 +2017,60 @@ sub handle_is_relative {
20152017
}
20162018

20172019

2020+
sub get_is_custom_input {
2021+
my($self, $name) = @_;
2022+
return $self->doif_is_custom_input($self->get_value_with_default($name));
2023+
}
2024+
2025+
2026+
sub doif_is_custom_input {
2027+
my($self, $val) = @_;
2028+
2029+
## Create an array reference from the custom_types string value.
2030+
my $custom_types = $self->{'prjc'}->get_assignment('custom_types');
2031+
my $ctypes = $self->create_array(defined $custom_types ? $custom_types : '');
2032+
2033+
foreach my $ctype (@$ctypes) {
2034+
## Get the input files for each custom type. We cache it to avoid
2035+
## generating the custom inputs for each and every call. This function
2036+
## is usually called within a foreach context, so it will be called many
2037+
## times per run.
2038+
my $inputs;
2039+
if (defined $self->{'custom_input_cache'}->{$ctype}) {
2040+
$inputs = $self->{'custom_input_cache'}->{$ctype};
2041+
}
2042+
else {
2043+
$inputs = $self->{'prjc'}->get_custom_value('input_files', $ctype);
2044+
$self->{'custom_input_cache'}->{$ctype} = $inputs;
2045+
}
2046+
2047+
## Once we have the inputs, see if any of them match the current file
2048+
foreach my $input (@$inputs) {
2049+
## There are various ways that the user could list files such that
2050+
## a custom input could physically match a built-in file listing
2051+
## but not be equal, in a string comparison sense. Resolving those
2052+
## differences requires path traversal and that the files actually
2053+
## exist (which isn't guaranteed at project generation time). So,
2054+
## we do the minimal comparison using the file_sorter on the
2055+
## ProjectCreator to handle case sensitivity automatically.
2056+
return 1 if ($self->{'prjc'}->file_sorter($input, $val));
2057+
}
2058+
}
2059+
2060+
## There are either no custom types or there isn't a custom input file
2061+
## that matches the one we're currently processing.
2062+
return undef;
2063+
}
2064+
2065+
2066+
sub handle_is_custom_input {
2067+
my($self, $name) = @_;
2068+
my $val = $self->get_value_with_default($name);
2069+
$self->append_current(
2070+
$self->doif_is_custom_input($val) ? '1' : '0') if (defined $val);
2071+
}
2072+
2073+
20182074
sub get_extension {
20192075
my($self, $name) = @_;
20202076
my $val = $self->get_value_with_default($name);

templates/vc10.mpd

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,20 +787,24 @@
787787
<%if(template_files)%>
788788
<ItemGroup>
789789
<%foreach(uniq(template_files))%>
790+
<%if(!is_custom_input(template_file))%>
790791
<ClCompile Include="<%template_file%>">
791792
<%foreach(platforms)%>
792793
<%foreach(configurations)%>
793794
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='<%configuration%>|<%platform%>'">true</ExcludedFromBuild>
794795
<%endfor%>
795796
<%endfor%>
796797
</ClCompile>
798+
<%endif%>
797799
<%endfor%>
798800
</ItemGroup>
799801
<%endif%>
800802
<%if(header_files)%>
801803
<ItemGroup>
802804
<%foreach(uniq(header_files))%>
805+
<%if(!is_custom_input(header_file))%>
803806
<ClInclude Include="<%header_file%>" />
807+
<%endif%>
804808
<%endfor%>
805809
</ItemGroup>
806810
<%endif%>
@@ -831,13 +835,16 @@
831835
<%if(inline_files)%>
832836
<ItemGroup>
833837
<%foreach(uniq(inline_files))%>
838+
<%if(!is_custom_input(inline_file))%>
834839
<None Include="<%inline_file%>" />
840+
<%endif%>
835841
<%endfor%>
836842
</ItemGroup>
837843
<%endif%>
838844
<%if(documentation_files)%>
839845
<ItemGroup>
840846
<%foreach(uniq(documentation_files))%>
847+
<%if(!is_custom_input(documentation_file))%>
841848
<CustomBuild Include="<%documentation_file%>">
842849
<FileType>Document</FileType>
843850
<%foreach(platforms)%>
@@ -846,13 +853,16 @@
846853
<%endfor%>
847854
<%endfor%>
848855
</CustomBuild>
856+
<%endif%>
849857
<%endfor%>
850858
</ItemGroup>
851859
<%endif%>
852860
<%if(resource_files && !type_is_static)%>
853861
<ItemGroup>
854862
<%foreach(uniq(resource_files))%>
863+
<%if(!is_custom_input(resource_file))%>
855864
<<%if(ends_with(resource_file,\.rc))%>ResourceCompile<%else%>None<%endif%> Include="<%resource_file%>" />
865+
<%endif%>
856866
<%endfor%>
857867
</ItemGroup>
858868
<%endif%>

0 commit comments

Comments
 (0)