Last active
November 1, 2024 17:43
-
-
Save jay/5f6d8d5ba15c12c7457e3216a94da72d to your computer and use it in GitHub Desktop.
This script removes wolfSSL configurations from the legacy Visual Studio curl projects in the projects directory.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 <[email protected]> | |
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 = <IN>; | |
} | |
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"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment