#!/usr/bin/env perl =begin comment README This script removes wolfSSL configurations from the legacy Visual Studio curl projects in the projects directory. Copyright (C) 2024 Jay Satiro https://curl.se/docs/copyright.html https://gist.github.com/jay/5f6d8d5ba15c12c7457e3216a94da72d =end comment =cut use strict; use warnings; use Config; use File::Spec; use File::Spec::Win32; use Getopt::Long; use IO::File; sub strlen($) { defined($_[0]) ? length($_[0]) : 0; } sub modify(@) { local (*IN, *OUT); my ($version, $infile, $outfile) = @_; open(IN, "<:raw", $infile) or return "Can't open $infile : $!"; open(OUT, ">:raw", $outfile) or return "Can't open $outfile : $!"; my $content; { local $/; $content = ; } if($infile =~ /\.sln$/) { $content =~ s/^.+wolfssl.+\n//gmi; } elsif($infile =~ /\.tmpl$/) { my @tags = ( "ProjectConfiguration", "PropertyGroup", "ImportGroup", "OutDir", "IntDir", "LinkIncremental", "TargetName", "ItemDefinitionGroup" ); for my $tag (@tags) { $content =~ s/^\s*<\Q$tag\E[^>\n]+wolfssl.+?> .*? <\/\Q$tag\E>(?:\r?\n)? //gmsix; } } else { return "FATAL: Unrecognized file $infile"; } if($content =~ /wolfssl/i) { return "FATAL: Could not eliminate all of wolfssl in $infile"; } print OUT $content or return "Can't write $outfile : $!"; close(IN) or return "Can't close $infile : $!"; close(OUT) or return "Can't close $outfile : $!"; return undef; } # This is the max times to retry modifying each file. # Modification fails if Microsoft dev git detects file changes and opens # the file at the same time as this script is attempting to modify. my $max_retries = 10; my @versions = (10, 11, 12); my @filenames = ( "curl-all.sln", "src/curl.sln", "src/curl.tmpl", "lib/libcurl.sln", "lib/libcurl.tmpl" ); for my $version (@versions) { for my $name (@filenames) { my $infile = "x:/j/curl/curl/projects/Windows/VC$version/$name"; my $outfile = "$infile.tmp"; for(my $i = 0; $i < $max_retries; sleep($i++)) { my $errmsg = modify($version, $infile, $outfile); last if !defined($errmsg); $errmsg =~ s/[\r\n]+$//g; die $errmsg if $errmsg =~ /^FATAL: /; die "FATAL: $errmsg" if $i+1 == $max_retries; print STDERR "[Retrying in ${i}s] $errmsg\n"; } for(my $i = 0; $i < $max_retries; sleep($i++)) { my $result = rename($outfile, $infile); last if $result; my $errmsg = "Can't rename $outfile => $infile: $!"; die "FATAL: $errmsg" if $i+1 == $max_retries; print STDERR "[Retrying in ${i}s] $errmsg\n"; } print "Updated $infile\n"; } }