| 1 | package Makefile::Update::VCProj; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Update list of sources and headers in Visual C++ projects. | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Exporter qw(import); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | our @EXPORT = qw(update_vcproj); | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | our $VERSION = '0.4'; # VERSION | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | sub update_vcproj | ||||||||||||||||||||||||||||
| 15 | 6 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
update_vcproj: called CC=26 SCAR=32.7
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | 6 | my ($in, $out, $sources, $headers, $filter_cb) = @_; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # Use standard/default classifier for the files if none is explicitly | ||||||||||||||||||||||||||||
| 19 | # specified. | ||||||||||||||||||||||||||||
| 20 | 6 | ▶ | if (!defined $filter_cb) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | 11 | ▶ | $filter_cb = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 22 | 11 | my ($file) = @_; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 11 | ▶ | return 'Source Files' if $file =~ q{\.c(c|pp|xx|\+\+)?$}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 4 | ▶ | return 'Header Files' if $file =~ q{\.h(h|pp|xx|\+\+)?$}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 1 | warn qq{No filter defined for the file "$file".\n}; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | undef | ||||||||||||||||||||||||||||
| 30 | 1 | } | |||||||||||||||||||||||||||
| 31 | 6 | } | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | # Hash mapping the filter to all the files using it (whether sources or | ||||||||||||||||||||||||||||
| 34 | # headers). | ||||||||||||||||||||||||||||
| 35 | 6 | my %files_by_filter; | |||||||||||||||||||||||||||
| 36 | 6 | foreach my $file (@$sources, @$headers) { | |||||||||||||||||||||||||||
| 37 | 11 | my $filter = $filter_cb->($file); | |||||||||||||||||||||||||||
| 38 | 11 | ▶ | if (defined $filter) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 10 | push @{$files_by_filter{$filter}}, $file | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | # Name of the current filter, if any. | ||||||||||||||||||||||||||||
| 44 | 6 | my $filter; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | # Hash containing 0 or 1 for each file using the current filter. | ||||||||||||||||||||||||||||
| 47 | my %seen; | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | # Indicates whether the closing angle bracket of "<File>" tags is on its | ||||||||||||||||||||||||||||
| 50 | # own line (which is how MSVS 2005 and 2008 format their files) or on the | ||||||||||||||||||||||||||||
| 51 | # same line as "RelativePath" attribute (which is how MSVS 2003 does it). | ||||||||||||||||||||||||||||
| 52 | 6 | my $angle_bracket_on_same_line = 0; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | # Set to 1 if we made any changes. | ||||||||||||||||||||||||||||
| 55 | 6 | my $changed = 0; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 6 | ▶ | while (defined (my $line_with_eol = <$in>)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 133 | (my $line = $line_with_eol) =~ s/\r?\n$//; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 133 | ▶ | if ($line =~ /^\s*<Filter$/) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 61 | 8 | ▶ | if (defined($filter)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 1 | warn qq{Nested <Filter> tag at line $. while parsing filter } . | |||||||||||||||||||||||||||
| 63 | qq{"$filter" is not supported.\n}; | ||||||||||||||||||||||||||||
| 64 | 1 | next; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 7 | print $out $line_with_eol; | |||||||||||||||||||||||||||
| 68 | 7 | $line_with_eol = <$in>; | |||||||||||||||||||||||||||
| 69 | 7 | ▶ | if (defined $line_with_eol && | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $line_with_eol and $line_with_eol =~ /^\s*Name="(.*)"\r?\n$/
MC/DC50%1/2
defined $line_with_eol and $line_with_eol =~ /^\s*Name="(.*)"\r?\n$/
defined $line_with_eol
$line_with_eol =~ /^\s*Name="(.*)"\r?\n$/
Truth table66%2/3
A and B
A= defined $line_with_eolB= $line_with_eol =~ /^\s*Name="(.*)"\r?\n$/
| |||||||||||||||||||||||||||||
| 70 | $line_with_eol =~ /^\s*Name="(.*)"\r?\n$/) { | ||||||||||||||||||||||||||||
| 71 | 6 | $filter = $1; | |||||||||||||||||||||||||||
| 72 | 6 | ▶ | if (!exists $files_by_filter{$filter}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | # If we don't have any files for this filter, don't remove | ||||||||||||||||||||||||||||
| 74 | # all the files from it, just skip it entirely instead. | ||||||||||||||||||||||||||||
| 75 | 1 | undef $filter; | |||||||||||||||||||||||||||
| 76 | } else { | ||||||||||||||||||||||||||||
| 77 | 5 | %seen = map { $_ => 0 } @{$files_by_filter{$filter}}; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | } else { | ||||||||||||||||||||||||||||
| 80 | 1 | warn qq{Unrecognized format for <Filter> tag at line $..\n}; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | } elsif (defined $filter) { | ||||||||||||||||||||||||||||
| 83 | 33 | ▶ | if ($line =~ /^\s*<File$/) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 84 | 11 | my $line_file_start = $line_with_eol; | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 11 | $line_with_eol = <$in>; | |||||||||||||||||||||||||||
| 87 | 11 | ▶ | if (defined $line_with_eol && | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $line_with_eol and $line_with_eol =~ /^\s*RelativePath="(.*)"(>?)\r?\n$/
MC/DC50%1/2
defined $line_with_eol and $line_with_eol =~ /^\s*RelativePath="(.*)"(>?)\r?\n$/
defined $line_with_eol
$line_with_eol =~ /^\s*RelativePath="(.*)"(>?)\r?\n$/
Truth table66%2/3
A and B
A= defined $line_with_eolB= $line_with_eol =~ /^\s*RelativePath="(.*)"(>?)\r?\n$/
| |||||||||||||||||||||||||||||
| 88 | $line_with_eol =~ /^\s*RelativePath="(.*)"(>?)\r?\n$/) { | ||||||||||||||||||||||||||||
| 89 | 10 | $angle_bracket_on_same_line = $2 eq '>'; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | # Normalize path separators to Unix and remove the leading | ||||||||||||||||||||||||||||
| 92 | # dot which MSVC likes to use for some reason. | ||||||||||||||||||||||||||||
| 93 | 10 | (my $file = $1) =~ s@\\@/@g; | |||||||||||||||||||||||||||
| 94 | 10 | $file =~ s@^\./@@; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | # Special hack for resource files that sometimes occur in | ||||||||||||||||||||||||||||
| 97 | # the "Source Files" section of MSVC projects too: don't | ||||||||||||||||||||||||||||
| 98 | # remove them, even if they don't appear in the master | ||||||||||||||||||||||||||||
| 99 | # files list, because they are never going to appear in it. | ||||||||||||||||||||||||||||
| 100 | 10 | ▶ | if ($file !~ /\.rc$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 9 | ▶ | if (!exists $seen{$file}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | # This file is not in the master file list any | ||||||||||||||||||||||||||||
| 103 | # more, delete it from the project file as well by | ||||||||||||||||||||||||||||
| 104 | # not copying the lines corresponding to it to the | ||||||||||||||||||||||||||||
| 105 | # output. | ||||||||||||||||||||||||||||
| 106 | 3 | $changed = 1; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | # Skip the next line unless we had already seen | ||||||||||||||||||||||||||||
| 109 | # the angle bracket. | ||||||||||||||||||||||||||||
| 110 | 3 | ▶ | if (!$angle_bracket_on_same_line) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 1 | ▶ | if (<$in> !~ /^\s*>\r?\n$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | 0 | warn qq{Expected closing '>' on the line $.\n} | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | # And skip everything up to and including the | ||||||||||||||||||||||||||||
| 117 | # closing </File> tag in any case. | ||||||||||||||||||||||||||||
| 118 | 3 | ▶ | while (<$in>) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 3 | ▶ | last if qr{^\s*</File>\r?\n$} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 3 | next; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | # This file is still in the files list, mark it as seen. | ||||||||||||||||||||||||||||
| 126 | 6 | ▶ | if ($seen{$file}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 1 | warn qq{Duplicate file "$file" in the project at line $.\n}; | |||||||||||||||||||||||||||
| 128 | } else { | ||||||||||||||||||||||||||||
| 129 | 5 | $seen{$file} = 1; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | } else { | ||||||||||||||||||||||||||||
| 133 | 1 | warn qq{Unrecognized format for <File> tag inside filter } . | |||||||||||||||||||||||||||
| 134 | qq{"$filter" at line $..\n}; | ||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | # Don't lose the original line, it won't be printed at the | ||||||||||||||||||||||||||||
| 138 | # end of the loop any more. | ||||||||||||||||||||||||||||
| 139 | 8 | print $out $line_file_start; | |||||||||||||||||||||||||||
| 140 | } elsif ($line =~ qr{^\s*</Filter>$}) { | ||||||||||||||||||||||||||||
| 141 | 5 | ▶ | my $angle_bracket = $angle_bracket_on_same_line | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | ? '>' | ||||||||||||||||||||||||||||
| 143 | : "\n\t\t\t\t>"; | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | # Add new files, if any. | ||||||||||||||||||||||||||||
| 146 | # | ||||||||||||||||||||||||||||
| 147 | # TODO Insert them in alphabetical order. | ||||||||||||||||||||||||||||
| 148 | 5 | ▶ | while (my ($file, $seen) = each(%seen)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | 9 | ▶ | if (!$seen) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | # Convert path separator to the one used by MSVC. | ||||||||||||||||||||||||||||
| 151 | 4 | $file =~ s@/@\\@g; | |||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | # And use path even for the files in this directory. | ||||||||||||||||||||||||||||
| 154 | 4 | ▶ | $file = ".\\$file" if $file !~ /\\/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 4 | print $out <<END | |||||||||||||||||||||||||||
| 157 | \t\t\t<File | ||||||||||||||||||||||||||||
| 158 | \t\t\t\tRelativePath="$file"$angle_bracket | ||||||||||||||||||||||||||||
| 159 | \t\t\t</File> | ||||||||||||||||||||||||||||
| 160 | END | ||||||||||||||||||||||||||||
| 161 | ; | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 4 | $changed = 1; | |||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 5 | undef $filter; | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 129 | print $out $line_with_eol; | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | $changed | ||||||||||||||||||||||||||||
| 175 | 6 | } | |||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | __END__ | ||||||||||||||||||||||||||||