Check whether the addon needs to be updated before any update method is called. Since _IsAddOnBad() needs all the information required to locate the addon it now stores it in the architecture-specific structure for reuse by the update methods such as _UpdateMSIAddOn().
Signed-off-by: Francois Gouget fgouget@codeweavers.com --- testbot/lib/Build/Utils.pm | 77 +++++++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 30 deletions(-)
diff --git a/testbot/lib/Build/Utils.pm b/testbot/lib/Build/Utils.pm index 17addeede8..a6d38fc7f5 100644 --- a/testbot/lib/Build/Utils.pm +++ b/testbot/lib/Build/Utils.pm @@ -1,5 +1,5 @@ # -*- Mode: Perl; perl-indent-level: 2; indent-tabs-mode: nil -*- -# Copyright 2018 Francois Gouget +# Copyright 2018-2020 Francois Gouget # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -360,23 +360,56 @@ sub BuildWine($$$$;$) # Wine addons updates #
+my $ADDONS_URL = "http://dl.winehq.org/wine"; + sub _IsAddOnBad($$) { my ($AddOn, $Arch) = @_;
+ my $AddOnArch = $AddOn->{$Arch}; + if (!$AddOnArch->{msifile}) + { + $AddOn->{basedir} = "$DataDir/$AddOn->{name}"; + my $Basename = "wine-$AddOn->{name}-$AddOn->{version}"; + my $ArchSuffix = $Arch eq "" ? "" : "-$Arch"; + $AddOnArch->{msifile} = "$Basename$ArchSuffix.msi"; + mkdir "$AddOn->{basedir}"; + } + my $Sha256 = Digest::SHA->new(256); - eval { $Sha256->addfile("$DataDir/$AddOn->{name}/$AddOn->{filename}") }; + eval { $Sha256->addfile("$AddOn->{basedir}/$AddOnArch->{msifile}") }; return "$@" if ($@);
my $Checksum = $Sha256->hexdigest(); - return undef if ($Checksum eq $AddOn->{$Arch}); - return "Bad checksum for '$AddOn->{filename}'"; + return undef if ($Checksum eq $AddOnArch->{checksum}); + return "Bad checksum for '$AddOnArch->{msifile}'"; +} + +sub _UpdateMSIAddOn($$) +{ + my ($AddOn, $Arch) = @_; + + my $AddOnArch = $AddOn->{$Arch}; + InfoMsg "Downloading $AddOnArch->{msifile}\n"; + my $Url="$ADDONS_URL/wine-$AddOn->{name}/$AddOn->{version}/$AddOnArch->{msifile}"; + my $ErrMessage; + for (1..3) + { + system("cd '$AddOn->{basedir}' && set -x && ". + "wget --no-verbose -O- '$Url' >'$AddOnArch->{msifile}'"); + $ErrMessage = _IsAddOnBad($AddOn, $Arch); + return 1 if (!defined $ErrMessage); + unlink "$AddOn->{basedir}/$AddOnArch->{msifile}"; + } + LogMsg "$ErrMessage\n"; + return 0; }
sub _UpdateAddOn($$$) { - my ($AddOn, $Name, $Arch) = @_; + my ($AddOns, $Name, $Arch) = @_;
+ my $AddOn = $AddOns->{$Name}; if (!defined $AddOn) { LogMsg "Could not get information on the $Name addon\n"; @@ -389,33 +422,17 @@ sub _UpdateAddOn($$$) } if (!$AddOn->{$Arch}) { - LogMsg "Could not get the $Name $Arch checksum\n"; + LogMsg "Could not get the $Name $Arch MSI checksum\n"; return 0; }
- $AddOn->{filename} = "wine-$Name-$AddOn->{version}". - ($Arch eq "" ? "" : "-$Arch") .".msi"; return 1 if (!_IsAddOnBad($AddOn, $Arch)); - - InfoMsg "Downloading $AddOn->{filename}\n"; - mkdir "$DataDir/$Name"; - - my $Url="http://dl.winehq.org/wine/wine-$Name/$AddOn-%3E%7Bversion%7D/$AddOn-%3E%7Bfi..."; - for (1..3) - { - system("cd '$DataDir/$Name' && set -x && ". - "wget --no-verbose -O- '$Url' >'$AddOn->{filename}'"); - last if ($? == 0); - } - my $ErrMessage = _IsAddOnBad($AddOn, $Arch); - return 1 if (!defined $ErrMessage); - LogMsg "$ErrMessage\n"; - return 0; + return _UpdateMSIAddOn($AddOn, $Arch); }
sub UpdateAddOns() { - my %AddOns; + my $AddOns; my $AddonSrc = "wine/dlls/appwiz.cpl/addons.c"; if (open(my $fh, "<", "$DataDir/$AddonSrc")) { @@ -434,14 +451,14 @@ sub UpdateAddOns() { my ($AddOn, $Version) = ($1, $2); $AddOn =~ tr/A-Z/a-z/; - $AddOns{$AddOn}->{name} = $AddOn; - $AddOns{$AddOn}->{version} = $Version; + $AddOns->{$AddOn}->{name} = $AddOn; + $AddOns->{$AddOn}->{version} = $Version; } elsif ($Line =~ /^\s*#\s*define\s*(GECKO|MONO)_SHA\s*"([^"]+)"/) { my ($AddOn, $Checksum) = ($1, $2); $AddOn =~ tr/A-Z/a-z/; - $AddOns{$AddOn}->{$Arch} = $Checksum; + $AddOns->{$AddOn}->{$Arch}->{checksum} = $Checksum; $Arch = ""; } } @@ -453,9 +470,9 @@ sub UpdateAddOns() return 0; }
- return _UpdateAddOn($AddOns{gecko}, "gecko", "x86") && - _UpdateAddOn($AddOns{gecko}, "gecko", "x86_64") && - _UpdateAddOn($AddOns{mono}, "mono", "x86"); + return _UpdateAddOn($AddOns, "gecko", "x86") && + _UpdateAddOn($AddOns, "gecko", "x86_64") && + _UpdateAddOn($AddOns, "mono", "x86"); }