diff options
-rw-r--r-- | ChangeLog | 24 | ||||
-rw-r--r-- | modules/TemplateParser.pm | 56 | ||||
-rw-r--r-- | templates/vc10.mpd | 10 |
3 files changed, 90 insertions, 0 deletions
@@ -1,3 +1,27 @@ +Fri Jun 28 15:52:37 UTC 2019 Chad Elliott <elliottc@objectcomputing.com> + + * modules/TemplateParser.pm: + + Added a template function, is_custom_input, which takes a file + as the parameter and checks it against all custom input files. It + returns true/false when used in a <%if()%> context. + + * templates/vc10.mpd: + + Use the 'is_custom_input' function template to ensure that files + listed as custom type inputs are not listed under template_files, + header_files, inline_files, documentation_files, or resource_files. + If a custom type input is also listed under source_files, we will + leave it to the user to resolve this externally. + + This is technically only required for certain versions of vs2017 and + vs2019, but in order to provide this functionality for just those + two types would require a duplication of the vc10 template with a + few minor adjustments. Future fixes to the vc10 template would have + needed to have been propagated to the slightly different vs2017 + template. To simplify maintenance, I just made the changes to this + template file. + Mon Jun 17 14:17:49 UTC 2019 Chad Elliott <elliottc@objectcomputing.com> * modules/CommandHelper.pm: diff --git a/modules/TemplateParser.pm b/modules/TemplateParser.pm index 779b0750..33516751 100644 --- a/modules/TemplateParser.pm +++ b/modules/TemplateParser.pm @@ -93,6 +93,7 @@ my %keywords = ('if' => 0, 'set' => 0, 'is_relative' => $get_type|$doif_type|$get_combined_type, 'extension' => $get_type, + 'is_custom_input' => $get_type|$doif_type|$get_combined_type, ); my %target_type_vars = ('type_is_static' => 1, @@ -138,6 +139,7 @@ sub new { $self->{'keyname_used'} = {}; $self->{'scopes'} = {}; $self->{'aux_file'} = undef; + $self->{'custom_input_cache'} = {}; $self->{'foreach'} = {}; $self->{'foreach'}->{'count'} = -1; @@ -2015,6 +2017,60 @@ sub handle_is_relative { } +sub get_is_custom_input { + my($self, $name) = @_; + return $self->doif_is_custom_input($self->get_value_with_default($name)); +} + + +sub doif_is_custom_input { + my($self, $val) = @_; + + ## Create an array reference from the custom_types string value. + my $custom_types = $self->{'prjc'}->get_assignment('custom_types'); + my $ctypes = $self->create_array(defined $custom_types ? $custom_types : ''); + + foreach my $ctype (@$ctypes) { + ## Get the input files for each custom type. We cache it to avoid + ## generating the custom inputs for each and every call. This function + ## is usually called within a foreach context, so it will be called many + ## times per run. + my $inputs; + if (defined $self->{'custom_input_cache'}->{$ctype}) { + $inputs = $self->{'custom_input_cache'}->{$ctype}; + } + else { + $inputs = $self->{'prjc'}->get_custom_value('input_files', $ctype); + $self->{'custom_input_cache'}->{$ctype} = $inputs; + } + + ## Once we have the inputs, see if any of them match the current file + foreach my $input (@$inputs) { + ## There are various ways that the user could list files such that + ## a custom input could physically match a built-in file listing + ## but not be equal, in a string comparison sense. Resolving those + ## differences requires path traversal and that the files actually + ## exist (which isn't guaranteed at project generation time). So, + ## we do the minimal comparison using the file_sorter on the + ## ProjectCreator to handle case sensitivity automatically. + return 1 if ($self->{'prjc'}->file_sorter($input, $val)); + } + } + + ## There are either no custom types or there isn't a custom input file + ## that matches the one we're currently processing. + return undef; +} + + +sub handle_is_custom_input { + my($self, $name) = @_; + my $val = $self->get_value_with_default($name); + $self->append_current( + $self->doif_is_custom_input($val) ? '1' : '0') if (defined $val); +} + + sub get_extension { my($self, $name) = @_; my $val = $self->get_value_with_default($name); diff --git a/templates/vc10.mpd b/templates/vc10.mpd index 00b7bb9b..7c4358c2 100644 --- a/templates/vc10.mpd +++ b/templates/vc10.mpd @@ -787,6 +787,7 @@ <%if(template_files)%> <ItemGroup> <%foreach(uniq(template_files))%> +<%if(!is_custom_input(template_file))%> <ClCompile Include="<%template_file%>"> <%foreach(platforms)%> <%foreach(configurations)%> @@ -794,13 +795,16 @@ <%endfor%> <%endfor%> </ClCompile> +<%endif%> <%endfor%> </ItemGroup> <%endif%> <%if(header_files)%> <ItemGroup> <%foreach(uniq(header_files))%> +<%if(!is_custom_input(header_file))%> <ClInclude Include="<%header_file%>" /> +<%endif%> <%endfor%> </ItemGroup> <%endif%> @@ -831,13 +835,16 @@ <%if(inline_files)%> <ItemGroup> <%foreach(uniq(inline_files))%> +<%if(!is_custom_input(inline_file))%> <None Include="<%inline_file%>" /> +<%endif%> <%endfor%> </ItemGroup> <%endif%> <%if(documentation_files)%> <ItemGroup> <%foreach(uniq(documentation_files))%> +<%if(!is_custom_input(documentation_file))%> <CustomBuild Include="<%documentation_file%>"> <FileType>Document</FileType> <%foreach(platforms)%> @@ -846,13 +853,16 @@ <%endfor%> <%endfor%> </CustomBuild> +<%endif%> <%endfor%> </ItemGroup> <%endif%> <%if(resource_files && !type_is_static)%> <ItemGroup> <%foreach(uniq(resource_files))%> +<%if(!is_custom_input(resource_file))%> <<%if(ends_with(resource_file,\.rc))%>ResourceCompile<%else%>None<%endif%> Include="<%resource_file%>" /> +<%endif%> <%endfor%> </ItemGroup> <%endif%> |