Simplify line ending management and make it work on Windows
Instead of manipulating CR explicitly to cope with CRLF (Windows) line endings in input and produce output with CRLF line endings, just convert files from/to CRLF line endings when reading/writing. The minimum required Perl version remains 5.8, since this both the version that introduced Digest::MD5 (which was used before this patch) and the version that introduced open "<:crlf" (which this patch introduces). Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
b0fa9d209d
commit
6e245c6e95
1 changed files with 25 additions and 26 deletions
|
@ -79,31 +79,30 @@ my @excluded_files = qw(
|
|||
my %excluded_files = ();
|
||||
foreach (@excluded_files) { $excluded_files{$_} = 1 }
|
||||
|
||||
# Need windows line endings!
|
||||
my $vsx_hdr_tpl = <<EOT;
|
||||
<ClInclude Include="..\\..\\{NAME}" />\r
|
||||
<ClInclude Include="..\\..\\{NAME}" />
|
||||
EOT
|
||||
my $vsx_src_tpl = <<EOT;
|
||||
<ClCompile Include="..\\..\\{NAME}" />\r
|
||||
<ClCompile Include="..\\..\\{NAME}" />
|
||||
EOT
|
||||
|
||||
my $vsx_sln_app_entry_tpl = <<EOT;
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "{APPNAME}", "{APPNAME}.vcxproj", "{GUID}"\r
|
||||
ProjectSection(ProjectDependencies) = postProject\r
|
||||
{46CF2D25-6A36-4189-B59C-E4815388E554} = {46CF2D25-6A36-4189-B59C-E4815388E554}\r
|
||||
EndProjectSection\r
|
||||
EndProject\r
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "{APPNAME}", "{APPNAME}.vcxproj", "{GUID}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{46CF2D25-6A36-4189-B59C-E4815388E554} = {46CF2D25-6A36-4189-B59C-E4815388E554}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
EOT
|
||||
|
||||
my $vsx_sln_conf_entry_tpl = <<EOT;
|
||||
{GUID}.Debug|Win32.ActiveCfg = Debug|Win32\r
|
||||
{GUID}.Debug|Win32.Build.0 = Debug|Win32\r
|
||||
{GUID}.Debug|x64.ActiveCfg = Debug|x64\r
|
||||
{GUID}.Debug|x64.Build.0 = Debug|x64\r
|
||||
{GUID}.Release|Win32.ActiveCfg = Release|Win32\r
|
||||
{GUID}.Release|Win32.Build.0 = Release|Win32\r
|
||||
{GUID}.Release|x64.ActiveCfg = Release|x64\r
|
||||
{GUID}.Release|x64.Build.0 = Release|x64\r
|
||||
{GUID}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{GUID}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{GUID}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{GUID}.Debug|x64.Build.0 = Debug|x64
|
||||
{GUID}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{GUID}.Release|Win32.Build.0 = Release|Win32
|
||||
{GUID}.Release|x64.ActiveCfg = Release|x64
|
||||
{GUID}.Release|x64.Build.0 = Release|x64
|
||||
EOT
|
||||
|
||||
exit( main() );
|
||||
|
@ -127,7 +126,7 @@ sub slurp_file {
|
|||
my ($filename) = @_;
|
||||
|
||||
local $/ = undef;
|
||||
open my $fh, '<', $filename or die "Could not read $filename\n";
|
||||
open my $fh, '<:crlf', $filename or die "Could not read $filename\n";
|
||||
my $content = <$fh>;
|
||||
close $fh;
|
||||
|
||||
|
@ -137,7 +136,7 @@ sub slurp_file {
|
|||
sub content_to_file {
|
||||
my ($content, $filename) = @_;
|
||||
|
||||
open my $fh, '>', $filename or die "Could not write to $filename\n";
|
||||
open my $fh, '>:crlf', $filename or die "Could not write to $filename\n";
|
||||
print $fh $content;
|
||||
close $fh;
|
||||
}
|
||||
|
@ -161,17 +160,17 @@ sub gen_app {
|
|||
my $srcs = "<ClCompile Include=\"..\\..\\programs\\$path.c\" \/>";
|
||||
if( $appname eq "ssl_client2" or $appname eq "ssl_server2" or
|
||||
$appname eq "query_compile_time_config" ) {
|
||||
$srcs .= "\r\n <ClCompile Include=\"..\\..\\programs\\test\\query_config.c\" \/>";
|
||||
$srcs .= "\n <ClCompile Include=\"..\\..\\programs\\test\\query_config.c\" \/>";
|
||||
}
|
||||
if( $appname eq "ssl_client2" or $appname eq "ssl_server2" ) {
|
||||
$srcs .= "\r\n <ClCompile Include=\"..\\..\\programs\\ssl\\ssl_test_lib.c\" \/>";
|
||||
$srcs .= "\n <ClCompile Include=\"..\\..\\programs\\ssl\\ssl_test_lib.c\" \/>";
|
||||
}
|
||||
|
||||
my $content = $template;
|
||||
$content =~ s/<SOURCES>/$srcs/g;
|
||||
$content =~ s/<APPNAME>/$appname/g;
|
||||
$content =~ s/<GUID>/$guid/g;
|
||||
$content =~ s/INCLUDE_DIRECTORIES\r\n/$include_directories/g;
|
||||
$content =~ s/INCLUDE_DIRECTORIES\n/$include_directories/g;
|
||||
|
||||
content_to_file( $content, "$dir/$appname.$ext" );
|
||||
}
|
||||
|
@ -214,9 +213,9 @@ sub gen_main_file {
|
|||
my $source_entries = gen_entry_list( $src_tpl, @$sources );
|
||||
|
||||
my $out = slurp_file( $main_tpl );
|
||||
$out =~ s/SOURCE_ENTRIES\r\n/$source_entries/m;
|
||||
$out =~ s/HEADER_ENTRIES\r\n/$header_entries/m;
|
||||
$out =~ s/INCLUDE_DIRECTORIES\r\n/$library_include_directories/g;
|
||||
$out =~ s/SOURCE_ENTRIES\n/$source_entries/m;
|
||||
$out =~ s/HEADER_ENTRIES\n/$header_entries/m;
|
||||
$out =~ s/INCLUDE_DIRECTORIES\n/$library_include_directories/g;
|
||||
|
||||
content_to_file( $out, $main_out );
|
||||
}
|
||||
|
@ -242,8 +241,8 @@ sub gen_vsx_solution {
|
|||
}
|
||||
|
||||
my $out = slurp_file( $vsx_sln_tpl_file );
|
||||
$out =~ s/APP_ENTRIES\r\n/$app_entries/m;
|
||||
$out =~ s/CONF_ENTRIES\r\n/$conf_entries/m;
|
||||
$out =~ s/APP_ENTRIES\n/$app_entries/m;
|
||||
$out =~ s/CONF_ENTRIES\n/$conf_entries/m;
|
||||
|
||||
content_to_file( $out, $vsx_sln_file );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue