| 1 |
# Copyright (C) 2008-2010 Modestas Vainius <[email protected]> |
| 2 |
# |
| 3 |
# This program is free software: you can redistribute it and/or modify |
| 4 |
# it under the terms of the GNU General Public License as published by |
| 5 |
# the Free Software Foundation, either version 3 of the License, or |
| 6 |
# (at your option) any later version. |
| 7 |
# |
| 8 |
# This program is distributed in the hope that it will be useful, |
| 9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
# GNU General Public License for more details. |
| 12 |
# |
| 13 |
# You should have received a copy of the GNU General Public License |
| 14 |
# along with this program. If not, see <http://www.gnu.org/licenses/> |
| 15 |
|
| 16 |
package Debian::PkgKde::SymbolsHelper::SymbolFileCollection; |
| 17 |
|
| 18 |
use strict; |
| 19 |
use warnings; |
| 20 |
|
| 21 |
use Dpkg::ErrorHandling; |
| 22 |
use Dpkg::Version; |
| 23 |
use Debian::PkgKde::SymbolsHelper::Substs; |
| 24 |
use Debian::PkgKde::SymbolsHelper::String; |
| 25 |
use Debian::PkgKde::SymbolsHelper::SymbolFile; |
| 26 |
|
| 27 |
sub new { |
| 28 |
my ($class, $orig_symfile) = @_; |
| 29 |
unless ($orig_symfile->get_confirmed_version()) { |
| 30 |
error("original symbol file template must have 'Confirmed' header set"); |
| 31 |
} |
| 32 |
return bless { orig_symfile => $orig_symfile, |
| 33 |
new_arches => {}, |
| 34 |
new_non_latest => [], |
| 35 |
confirmed_arches => [], |
| 36 |
symfiles => {}, |
| 37 |
versions => {}, |
| 38 |
latest => undef }, $class; |
| 39 |
} |
| 40 |
|
| 41 |
sub get_symfiles { |
| 42 |
my $self = shift; |
| 43 |
return values %{$self->{symfiles}}; |
| 44 |
} |
| 45 |
|
| 46 |
sub get_symfile { |
| 47 |
my ($self, $arch) = @_; |
| 48 |
if (defined $arch) { |
| 49 |
return $self->{symfiles}{$arch}; |
| 50 |
} else { |
| 51 |
return $self->{orig_symfile}; |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
# NOTE: latest may also include $orig fork()s if no symbol files with higher |
| 56 |
# confirmed version have been added. |
| 57 |
sub get_latest_version { |
| 58 |
my $self = shift; |
| 59 |
return $self->{latest}; |
| 60 |
} |
| 61 |
|
| 62 |
sub get_latest_arches { |
| 63 |
my $self = shift; |
| 64 |
return @{$self->{versions}{$self->{latest}}}; |
| 65 |
} |
| 66 |
|
| 67 |
sub get_new_arches { |
| 68 |
my $self = shift; |
| 69 |
return keys %{$self->{new_arches}}; |
| 70 |
} |
| 71 |
|
| 72 |
# This will NEVER include $orig fork()s |
| 73 |
sub get_new_non_latest_arches { |
| 74 |
my $self = shift; |
| 75 |
return @{$self->{new_non_latest}}; |
| 76 |
} |
| 77 |
|
| 78 |
sub is_arch_latest { |
| 79 |
my ($self, $arch) = @_; |
| 80 |
return $self->get_symfile($arch)->get_confirmed_version() eq $self->{latest}; |
| 81 |
} |
| 82 |
|
| 83 |
sub is_arch_new { |
| 84 |
my ($self, $arch) = @_; |
| 85 |
return exists $self->{new_arches}{$arch}; |
| 86 |
} |
| 87 |
|
| 88 |
sub add_symfiles { |
| 89 |
my ($self, @symfiles) = @_; |
| 90 |
my $latest = $self->get_latest_version(); |
| 91 |
foreach my $symfile (@symfiles) { |
| 92 |
my $arch = $symfile->get_arch(); |
| 93 |
my $ver = $symfile->get_confirmed_version(); |
| 94 |
unless ($ver) { |
| 95 |
internerr("problem with %s symbol file: it must have 'Confirmed' header", |
| 96 |
$arch); |
| 97 |
} |
| 98 |
if ($self->get_symfile($arch)) { |
| 99 |
error("you cannot add symbol file for the same arch (%s) more than once", |
| 100 |
$arch); |
| 101 |
} |
| 102 |
$self->{symfiles}{$arch} = $symfile; |
| 103 |
push @{$self->{versions}{$ver}}, $arch; |
| 104 |
if (!defined $latest || |
| 105 |
version_compare($ver, $latest) > 0) |
| 106 |
{ |
| 107 |
$latest = $ver; |
| 108 |
} |
| 109 |
} |
| 110 |
$self->{latest} = $latest; |
| 111 |
} |
| 112 |
|
| 113 |
sub add_confirmed_arches { |
| 114 |
my ($self, $version, @arches) = @_; |
| 115 |
$version = $self->get_symfile()->get_confirmed_version() unless $version; |
| 116 |
foreach my $arch (@arches) { |
| 117 |
if ($self->get_symfile($arch)) { |
| 118 |
error("new symbol file has already been added for arch (%s)", $arch); |
| 119 |
} |
| 120 |
} |
| 121 |
push @{$self->{versions}{$version}}, @arches; |
| 122 |
push @{$self->{confirmed_arches}}, @arches; |
| 123 |
$self->{latest} = $version unless defined $self->{latest}; |
| 124 |
} |
| 125 |
|
| 126 |
sub get_confirmed_arches { |
| 127 |
my ($self) = @_; |
| 128 |
return @{$self->{confirmed_arches}}; |
| 129 |
} |
| 130 |
|
| 131 |
sub add_new_symfiles { |
| 132 |
my ($self, @symfiles) = @_; |
| 133 |
$self->{new_arches} = { %{$self->{new_arches}}, |
| 134 |
map({ $_->{arch} => $_ } @symfiles) }; |
| 135 |
$self->add_symfiles(@symfiles); |
| 136 |
|
| 137 |
# Recalc new_non_latest |
| 138 |
my $ver = $self->get_latest_version(); |
| 139 |
my @new_non_latest; |
| 140 |
foreach my $arch ($self->get_new_arches()) { |
| 141 |
if (! $self->is_arch_latest($arch)) { |
| 142 |
push @new_non_latest, $arch; |
| 143 |
} |
| 144 |
} |
| 145 |
$self->{new_non_latest} = \@new_non_latest; |
| 146 |
} |
| 147 |
|
| 148 |
sub fork_orig_symfile { |
| 149 |
my ($self, @arches) = @_; |
| 150 |
my @symfiles = $self->get_symfile()->fork( |
| 151 |
map +{ arch => $_ }, @arches |
| 152 |
); |
| 153 |
return map { $_->{arch} => $_ } @symfiles; |
| 154 |
} |
| 155 |
|
| 156 |
sub calc_group_name { |
| 157 |
my ($self, $name, $arch, @substs) = @_; |
| 158 |
|
| 159 |
my $str = Debian::PkgKde::SymbolsHelper::String->new($name); |
| 160 |
foreach my $subst (@substs) { |
| 161 |
$subst->prep($str, $arch); |
| 162 |
$subst->neutralize($str, $arch); |
| 163 |
} |
| 164 |
return $str->get_string(); |
| 165 |
} |
| 166 |
|
| 167 |
sub get_symbols_regrouped_by_name { |
| 168 |
my ($self, $group) = @_; |
| 169 |
my $byname = $group->regroup_by_name(); |
| 170 |
my @byname; |
| 171 |
foreach my $grp (sort values %$byname) { |
| 172 |
if (my $sym = $grp->calc_properties($self)) { |
| 173 |
push @byname, $sym; |
| 174 |
} |
| 175 |
} |
| 176 |
return sort { $a->get_symboltempl() cmp $b->get_symboltempl() } @byname; |
| 177 |
} |
| 178 |
|
| 179 |
sub select_group { |
| 180 |
my ($self, $sym, $soname, $arch, $gsubsts, $gother) = @_; |
| 181 |
|
| 182 |
# Substitution detection is only supported for regular symbols and c++ |
| 183 |
# aliases. |
| 184 |
if (! $sym->is_pattern() || $sym->get_alias_type() eq "c++") { |
| 185 |
my $substs = ($sym->has_tag("c++")) ? \@CPP_TYPE_SUBSTS : \@TYPE_SUBSTS; |
| 186 |
my $groupname = $self->calc_group_name($sym->get_symbolname(), $arch, @$substs); |
| 187 |
|
| 188 |
unless (exists $gsubsts->{$soname}{$groupname}) { |
| 189 |
$gsubsts->{$soname}{$groupname} = |
| 190 |
Debian::PkgKde::SymbolsHelper::SymbolFileCollection::Group->new($substs); |
| 191 |
} |
| 192 |
return $gsubsts->{$soname}{$groupname}; |
| 193 |
} else { |
| 194 |
# Symbol of some other kind. Then just group by name |
| 195 |
my $name = $sym->get_symbolname(); |
| 196 |
unless (exists $gother->{$soname}{$name}) { |
| 197 |
$gother->{$soname}{$name} = |
| 198 |
Debian::PkgKde::SymbolsHelper::SymbolFileCollection::Group->new(); |
| 199 |
} |
| 200 |
return $gother->{$soname}{$name}; |
| 201 |
} |
| 202 |
} |
| 203 |
|
| 204 |
# Create a new template from the collection of symbol files |
| 205 |
sub create_template { |
| 206 |
my ($self, %opts) = @_; |
| 207 |
|
| 208 |
my $orig = $self->get_symfile(); |
| 209 |
my $orig_arch = $orig->get_arch(); |
| 210 |
my $template = $orig->fork_empty(); |
| 211 |
|
| 212 |
# Prepare original template and other arch specific symbol files (virtual |
| 213 |
# table stuff etc.). |
| 214 |
$orig->prepare_for_templating(); |
| 215 |
foreach my $symfile ($self->get_symfiles()) { |
| 216 |
$symfile->prepare_for_templating(); |
| 217 |
} |
| 218 |
|
| 219 |
# Group new symbols by fully arch-neutralized name or, if unsupported, |
| 220 |
# simply by name. |
| 221 |
my (%gsubsts, %gother); |
| 222 |
my %osymfiles = $self->fork_orig_symfile($self->get_new_arches()); |
| 223 |
|
| 224 |
foreach my $arch ($self->get_new_arches()) { |
| 225 |
my $nsymfile = $self->get_symfile($arch); |
| 226 |
my $osymfile = $osymfiles{$arch}; |
| 227 |
|
| 228 |
my @new = $nsymfile->get_new_symbols($osymfile, with_optional => 1); |
| 229 |
foreach my $n (@new) { |
| 230 |
my $soname = $n->{soname}; |
| 231 |
my $nsym = $n->{symbol}; |
| 232 |
# Get a reference in the orig symfile if any |
| 233 |
my $osym = $osymfile->get_symbol_object($nsym, $soname); |
| 234 |
|
| 235 |
my $group = $self->select_group($nsym, $soname, $arch, \%gsubsts, \%gother); |
| 236 |
|
| 237 |
# Add symbol to the group |
| 238 |
$group->add_symbol($nsym, $arch); |
| 239 |
$group->prep_substs($arch); |
| 240 |
|
| 241 |
if (defined $osym) { |
| 242 |
my $origin = $osym->{h_origin_symbol}; |
| 243 |
$group->add_symbol($origin); |
| 244 |
# "Touch" the origin symbol |
| 245 |
$origin->{h_touched} = 1; |
| 246 |
} |
| 247 |
} |
| 248 |
|
| 249 |
my @lost = $nsymfile->get_lost_symbols($osymfile, with_optional => 1); |
| 250 |
foreach my $l (@lost) { |
| 251 |
my $soname = $l->{soname}; |
| 252 |
my $sym = $l->{symbol}; |
| 253 |
my $origin = $sym->{h_origin_symbol}; |
| 254 |
my $group = $self->select_group($sym, $soname, $arch, \%gsubsts, \%gother); |
| 255 |
|
| 256 |
$group->add_lost_symbol($sym, $arch); |
| 257 |
$group->add_symbol($origin); |
| 258 |
# "Touch" the origin symbol |
| 259 |
$origin->{h_touched} = 1; |
| 260 |
} |
| 261 |
} |
| 262 |
|
| 263 |
# Fork confirmed symbols where it matters |
| 264 |
if (my @carches = $self->get_confirmed_arches()) { |
| 265 |
# Important for substs detection |
| 266 |
foreach my $soname (values %gsubsts) { |
| 267 |
foreach my $group (values %$soname) { |
| 268 |
if ($group->get_arches() && (my $osym = $group->get_symbol())) { |
| 269 |
foreach my $arch (@carches) { |
| 270 |
if ($osym->arch_is_concerned($arch)) { |
| 271 |
my $nsym = $orig->fork_symbol($osym, $arch); |
| 272 |
$group->add_symbol($nsym, $arch); |
| 273 |
$group->prep_substs($arch); |
| 274 |
} |
| 275 |
} |
| 276 |
} |
| 277 |
} |
| 278 |
} |
| 279 |
} |
| 280 |
|
| 281 |
# Readd all untouched symbols in $orig back to the $template |
| 282 |
foreach my $soname ($orig->get_sonames()) { |
| 283 |
foreach my $sym ($orig->get_symbols($soname), |
| 284 |
$orig->get_patterns($soname)) |
| 285 |
{ |
| 286 |
if (!exists $sym->{h_touched}) { |
| 287 |
$template->add_symbol($sym, $soname); |
| 288 |
} |
| 289 |
} |
| 290 |
} |
| 291 |
|
| 292 |
# Process substs groups (%gsubsts) first |
| 293 |
foreach my $soname (keys %gsubsts) { |
| 294 |
my $groups = $gsubsts{$soname}; |
| 295 |
|
| 296 |
foreach my $groupname (keys %$groups) { |
| 297 |
my $group = $groups->{$groupname}; |
| 298 |
|
| 299 |
# print "group: $groupname", "\n"; |
| 300 |
|
| 301 |
# Take care of ambiguous groups |
| 302 |
if ($group->is_ambiguous()) { |
| 303 |
if (my @byname = $self->get_symbols_regrouped_by_name($group)) { |
| 304 |
$template->add_symbol($_, $soname) foreach @byname; |
| 305 |
info("ambiguous symbols for subst detection (%s). Processed by name:\n" . |
| 306 |
" %s", "$groupname/$soname", |
| 307 |
join("\n ", map { $_->get_symbolspec(1) } @byname)); |
| 308 |
} |
| 309 |
next; |
| 310 |
} |
| 311 |
# Calculate properties and detect substs. |
| 312 |
if (my $sym = $group->calc_properties($self)) { |
| 313 |
# Then detect substs (we need two or more arch specific symbols for that) |
| 314 |
my $substs_ok = 0; |
| 315 |
if (scalar($group->get_arches()) > 1 && ! $group->are_symbols_equal()) { |
| 316 |
my $substs_arch = ($group->has_symbol($orig_arch)) ? |
| 317 |
$orig_arch : ($group->get_arches())[0]; |
| 318 |
if ($group->detect_substs($substs_arch)) { |
| 319 |
my $substs_sym = $group->get_symbol($substs_arch); |
| 320 |
$sym->add_tag("subst"); |
| 321 |
$sym->reset_h_name($substs_sym->get_h_name()); |
| 322 |
# Properly handle the case when *some substs have been* |
| 323 |
# detected but symbols in the group still differ. Since |
| 324 |
# the symbols will be grouped, we need to add a subst |
| 325 |
# tag to all of them and reset h_name of the orig |
| 326 |
# symbol since it is not touched by substs detection. |
| 327 |
unless ($substs_ok = $group->verify_substs()) { |
| 328 |
foreach my $sym ($group->get_symbols()) { |
| 329 |
$sym->add_tag("subst"); |
| 330 |
} |
| 331 |
if ($orig_arch eq $substs_arch) { |
| 332 |
$group->get_symbol()->add_tag("subst"); |
| 333 |
$group->get_symbol()->reset_h_name( |
| 334 |
$substs_sym->get_h_name() |
| 335 |
); |
| 336 |
} |
| 337 |
} |
| 338 |
} |
| 339 |
} else { |
| 340 |
$substs_ok = 1; |
| 341 |
} |
| 342 |
|
| 343 |
if ($substs_ok) { |
| 344 |
# Finally add to template |
| 345 |
$template->add_symbol($sym, $soname); |
| 346 |
} else { |
| 347 |
# Substitutions do not verify. Regroup by name what remains |
| 348 |
foreach my $sym ($group->get_symbols()) { |
| 349 |
$sym->resync_name_with_h_name(); |
| 350 |
} |
| 351 |
$group->get_symbol()->resync_name_with_h_name() if $group->get_symbol(); |
| 352 |
if (my @byname = $self->get_symbols_regrouped_by_name($group)) { |
| 353 |
$template->add_symbol($_, $soname) foreach @byname; |
| 354 |
info("possible incomplete subst detection (%s). Processed by name:\n" . |
| 355 |
" %s", "$groupname/$soname", |
| 356 |
join("\n ", map { $_->get_symbolspec(1) } @byname)); |
| 357 |
} |
| 358 |
} |
| 359 |
} |
| 360 |
} |
| 361 |
} |
| 362 |
|
| 363 |
# Now process others groups (%gother). Just calculate properties (arch |
| 364 |
# tags) and add to the template. |
| 365 |
foreach my $soname (keys %gother) { |
| 366 |
my $groups = $gother{$soname}; |
| 367 |
foreach my $groupname (keys %$groups) { |
| 368 |
my $group = $groups->{$groupname}; |
| 369 |
if (my $sym = $group->calc_properties($self)) { |
| 370 |
$template->add_symbol($sym, $soname); |
| 371 |
} |
| 372 |
} |
| 373 |
} |
| 374 |
|
| 375 |
# Finally, resync h_names |
| 376 |
foreach my $soname ($template->get_sonames()) { |
| 377 |
$template->resync_soname_with_h_name($soname); |
| 378 |
} |
| 379 |
|
| 380 |
return $template; |
| 381 |
} |
| 382 |
|
| 383 |
package Debian::PkgKde::SymbolsHelper::SymbolFileCollection::Group; |
| 384 |
|
| 385 |
use Dpkg::Arch qw(debarch_is); |
| 386 |
|
| 387 |
sub new { |
| 388 |
my ($class, $substs) = @_; |
| 389 |
return bless { |
| 390 |
arches => {}, |
| 391 |
lost => {}, |
| 392 |
orig => undef, |
| 393 |
result => undef, |
| 394 |
substs => $substs}, $class; |
| 395 |
} |
| 396 |
|
| 397 |
sub has_symbol { |
| 398 |
my ($self, $arch) = @_; |
| 399 |
return (defined $arch) ? exists $self->{arches}{$arch} : $self->{orig}; |
| 400 |
} |
| 401 |
|
| 402 |
sub get_symbol { |
| 403 |
my ($self, $arch) = @_; |
| 404 |
return (defined $arch) ? $self->{arches}{$arch} : $self->{orig}; |
| 405 |
} |
| 406 |
|
| 407 |
sub get_arches { |
| 408 |
my $self = shift; |
| 409 |
return keys %{$self->{arches}}; |
| 410 |
} |
| 411 |
|
| 412 |
sub get_symbols { |
| 413 |
my $self = shift; |
| 414 |
return values %{$self->{arches}}; |
| 415 |
} |
| 416 |
|
| 417 |
sub get_result { |
| 418 |
my $self = shift; |
| 419 |
return $self->{result}; |
| 420 |
} |
| 421 |
|
| 422 |
# There might be a new version available (e.g. with corrected substs). |
| 423 |
sub is_lost { |
| 424 |
my ($self, $arch) = @_; |
| 425 |
return exists $self->{lost}{$arch} && ! $self->has_symbol($arch); |
| 426 |
} |
| 427 |
|
| 428 |
sub is_new { |
| 429 |
my ($self, $arch) = @_; |
| 430 |
if (my $osym = $self->get_symbol()) { |
| 431 |
return ! $osym->is_legitimate($arch); |
| 432 |
} else { |
| 433 |
return 1; |
| 434 |
} |
| 435 |
} |
| 436 |
|
| 437 |
sub init_result { |
| 438 |
my ($self, $based_on_arch) = @_; |
| 439 |
$self->{result} = $self->get_symbol($based_on_arch)->clone(); |
| 440 |
return $self->{result}; |
| 441 |
} |
| 442 |
|
| 443 |
sub add_symbol { |
| 444 |
my ($self, $sym, $arch, $lost) = @_; |
| 445 |
my $status = ($lost) ? "lost" : "arches"; |
| 446 |
|
| 447 |
if (my $esym = ($lost) ? $self->{lost}{$arch} : $self->get_symbol($arch)) { |
| 448 |
if ($esym != $sym) { |
| 449 |
# Another symbol already exists in this group for $arch. |
| 450 |
# Add to other syms |
| 451 |
push @{$self->{ambiguous}{$status}{$arch || ''}}, $sym; |
| 452 |
} |
| 453 |
# Otherwise, don't do anything. This symbol has already been added. |
| 454 |
return 0; |
| 455 |
} else { |
| 456 |
if (defined $arch) { |
| 457 |
$self->{$status}{$arch} = $sym; |
| 458 |
} else { |
| 459 |
$self->{orig} = $sym; |
| 460 |
} |
| 461 |
return 1; |
| 462 |
} |
| 463 |
} |
| 464 |
|
| 465 |
sub add_lost_symbol { |
| 466 |
my ($self, $sym, $arch) = @_; |
| 467 |
return $self->add_symbol($sym, $arch, 1); |
| 468 |
} |
| 469 |
|
| 470 |
sub dump { |
| 471 |
my ($self, $fh) = @_; |
| 472 |
$fh = \*STDERR unless defined $fh; |
| 473 |
if (my $sym = $self->get_symbol()) { |
| 474 |
print $fh "orig:", $sym->get_symbolspec(1), "\n"; |
| 475 |
} |
| 476 |
foreach my $arch ($self->get_arches()) { |
| 477 |
my $sym = $self->get_symbol($arch); |
| 478 |
print $fh "arches{$arch}:", $sym->get_symbolspec(1), "\n"; |
| 479 |
} |
| 480 |
foreach my $arch (keys %{$self->{lost}}) { |
| 481 |
my $sym = $self->{lost}{$arch}; |
| 482 |
print $fh "lost{$arch}:", $sym->get_symbolspec(1), "\n"; |
| 483 |
} |
| 484 |
if ($self->is_ambiguous()) { |
| 485 |
foreach my $status (sort keys %{$self->{ambiguous}}) { |
| 486 |
my $arches = $self->{ambiguous}{$status}; |
| 487 |
foreach my $arch (keys %$arches) { |
| 488 |
foreach my $sym (@{$arches->{$arch}}) { |
| 489 |
print $fh "ambiguous{$status}{$arch}:", $sym->get_symbolspec(1), "\n"; |
| 490 |
} |
| 491 |
} |
| 492 |
} |
| 493 |
} |
| 494 |
} |
| 495 |
|
| 496 |
sub is_ambiguous { |
| 497 |
my $self = shift; |
| 498 |
return exists $self->{ambiguous}; |
| 499 |
} |
| 500 |
|
| 501 |
# Regroup ambiguous symbols by symbol name |
| 502 |
sub regroup_by_name { |
| 503 |
my $self = shift; |
| 504 |
my %groups; |
| 505 |
|
| 506 |
foreach my $arch (undef, $self->get_arches()) { |
| 507 |
my $sym = $self->get_symbol($arch); |
| 508 |
if (defined $sym) { |
| 509 |
my $name = $sym->get_symbolname(); |
| 510 |
unless (exists $groups{$name}) { |
| 511 |
$groups{$name} = ref($self)->new(); |
| 512 |
} |
| 513 |
my $group = $groups{$name}; |
| 514 |
$group->add_symbol($sym, $arch, defined $arch && |
| 515 |
$self->is_lost($arch)); |
| 516 |
} |
| 517 |
} |
| 518 |
foreach my $arch (keys %{$self->{lost}}) { |
| 519 |
my $sym = $self->{lost}{$arch}; |
| 520 |
my $name = $sym->get_symbolname(); |
| 521 |
unless (exists $groups{$name}) { |
| 522 |
$groups{$name} = ref($self)->new(); |
| 523 |
} |
| 524 |
my $group = $groups{$name}; |
| 525 |
$group->add_lost_symbol($sym, $arch); |
| 526 |
} |
| 527 |
if ($self->is_ambiguous()) { |
| 528 |
foreach my $status (keys %{$self->{ambiguous}}) { |
| 529 |
my $arches = $self->{ambiguous}{$status}; |
| 530 |
my $lost = ($status eq "lost"); |
| 531 |
foreach my $arch (keys %$arches) { |
| 532 |
foreach my $sym (@{$arches->{$arch}}) { |
| 533 |
$arch = undef if ! $arch; |
| 534 |
my $name = $sym->get_symbolname(); |
| 535 |
unless (exists $groups{$name}) { |
| 536 |
$groups{$name} = ref($self)->new(); |
| 537 |
} |
| 538 |
my $group = $groups{$name}; |
| 539 |
$group->add_symbol($sym, $arch, $lost); |
| 540 |
} |
| 541 |
} |
| 542 |
} |
| 543 |
} |
| 544 |
|
| 545 |
return \%groups; |
| 546 |
} |
| 547 |
|
| 548 |
sub are_symbols_equal { |
| 549 |
my $self = shift; |
| 550 |
my @arches = $self->get_arches(); |
| 551 |
my $name; |
| 552 |
|
| 553 |
$name = ($self->get_symbol()) ? |
| 554 |
$self->get_symbol() : $self->get_symbol(shift @arches); |
| 555 |
$name = $name->get_symbolname(); |
| 556 |
foreach my $arch (@arches) { |
| 557 |
if ($self->get_symbol($arch)->get_symbolname() ne $name) { |
| 558 |
return 0; |
| 559 |
} |
| 560 |
} |
| 561 |
return 1; |
| 562 |
} |
| 563 |
|
| 564 |
# Verify if all substs have been replaced (i.e. hint-neutralized) |
| 565 |
sub verify_substs { |
| 566 |
my $self = shift; |
| 567 |
my @arches = $self->get_arches(); |
| 568 |
my $str = $self->get_symbol(shift @arches)->get_h_name()->get_string(); |
| 569 |
foreach my $arch (@arches) { |
| 570 |
if ($self->get_symbol($arch)->get_h_name()->get_string() ne $str) { |
| 571 |
return 0; |
| 572 |
} |
| 573 |
} |
| 574 |
return 1; |
| 575 |
} |
| 576 |
|
| 577 |
sub verify_result_arches { |
| 578 |
my ($self, $add, $deprecate) = @_; |
| 579 |
my $result = $self->get_result(); |
| 580 |
my $ok = 1; |
| 581 |
foreach my $arch (keys %$add) { |
| 582 |
unless ($result->arch_is_concerned($arch)) { |
| 583 |
$ok = 0; |
| 584 |
last; |
| 585 |
} |
| 586 |
} |
| 587 |
if ($ok) { |
| 588 |
foreach my $arch (keys %$deprecate) { |
| 589 |
if ($result->arch_is_concerned($arch)) { |
| 590 |
$ok = 0; |
| 591 |
last; |
| 592 |
} |
| 593 |
} |
| 594 |
} |
| 595 |
return $ok; |
| 596 |
} |
| 597 |
|
| 598 |
# Gets symbol status on $arch: |
| 599 |
# -2 - if symbol got LOST; |
| 600 |
# -1 - if symbol is deprecated and has been such (status hasn't changed); |
| 601 |
# 0 - symbol is NOT present on $arch and original symbol is not available; |
| 602 |
# 1 - symbol is present and has been been such (status hasn't changed); |
| 603 |
# 2 - symbol is NEW. |
| 604 |
sub get_symbol_arch_status { |
| 605 |
my ($self, $arch) = @_; |
| 606 |
my $status; |
| 607 |
|
| 608 |
# If $self->is_lost($arch) returns true, it means a symbol is really |
| 609 |
# NOT (or no longer) present on that arch in comparision to original |
| 610 |
# symbol file. If $self->has_symbol($arch) returns true, the symbol is |
| 611 |
# KNOWN to be have BEEN present on that arch (and it still is if it is |
| 612 |
# not deprecated). Otherwise, the symbol the symbols status has not changed |
| 613 |
# so it is is either: 1) present on $arch if $osym is legitimate on $arch; |
| 614 |
# 2) absent on $arch otherwise. |
| 615 |
if ($self->is_lost($arch)) { |
| 616 |
$status = -2; |
| 617 |
} elsif ($self->has_symbol($arch)) { |
| 618 |
if ($self->get_symbol($arch)->{deprecated}) { |
| 619 |
$status = -1; |
| 620 |
} else { |
| 621 |
$status = ($self->is_new($arch)) ? 2 : 1; |
| 622 |
} |
| 623 |
} elsif ($self->has_symbol()) { |
| 624 |
$status = ($self->get_symbol()->is_legitimate($arch)) ? 1 : -1; |
| 625 |
} else { |
| 626 |
$status = 0; |
| 627 |
} |
| 628 |
return $status; |
| 629 |
} |
| 630 |
|
| 631 |
sub is_arch_in_db { |
| 632 |
my ($self, $arch, $db) = @_; |
| 633 |
if ($arch =~ /any/) { # Might be a wildcard |
| 634 |
foreach my $adb ((ref $db eq 'ARRAY') ? @$db : keys %$db) { |
| 635 |
return 2 if debarch_is($adb, $arch); |
| 636 |
} |
| 637 |
} elsif (ref $db eq 'ARRAY') { |
| 638 |
return 1 if grep { $arch eq $_ } @$db; |
| 639 |
} else { |
| 640 |
return exists $db->{$arch}; |
| 641 |
} |
| 642 |
return 0; |
| 643 |
} |
| 644 |
|
| 645 |
# Calculate group properties and instantiates 'result'. At the moment, this |
| 646 |
# method will take care of arch tags and deprecated status. "Result" symbol is |
| 647 |
# returned if symbol is not useless in the group. |
| 648 |
sub calc_properties { |
| 649 |
my ($self, $collection) = @_; |
| 650 |
|
| 651 |
my @latest = $collection->get_latest_arches(); |
| 652 |
my @non_latest = $collection->get_new_non_latest_arches(); |
| 653 |
my $total_arches = scalar(@latest) + scalar(@non_latest); |
| 654 |
my (%present, %absent); |
| 655 |
my (@oarches, @narches, $arch_neg); |
| 656 |
my $arch_added = 0; |
| 657 |
my $osym = $self->get_symbol(); |
| 658 |
my $result; |
| 659 |
|
| 660 |
if (defined $osym) { |
| 661 |
# The symbol exists in the template. This might complicate things a lot. |
| 662 |
if ($osym->has_tag("arch")) { |
| 663 |
@oarches = split(/[\s,]+/, $osym->get_tag_value("arch")) |
| 664 |
} |
| 665 |
} |
| 666 |
|
| 667 |
# Calculate status of @latest arches |
| 668 |
foreach my $arch (@latest) { |
| 669 |
my $status = $self->get_symbol_arch_status($arch); |
| 670 |
if ($status > 0) { |
| 671 |
$present{$arch} = $status; |
| 672 |
} else { |
| 673 |
$absent{$arch} = $status; |
| 674 |
} |
| 675 |
} |
| 676 |
|
| 677 |
# Initialize $result |
| 678 |
if (defined $osym) { |
| 679 |
$result = $self->init_result(); # base result on original |
| 680 |
} elsif (keys %present) { |
| 681 |
$result = $self->init_result((keys %present)[0]); |
| 682 |
} else { |
| 683 |
return undef; |
| 684 |
} |
| 685 |
|
| 686 |
if (scalar(keys %absent) == scalar(@latest) && |
| 687 |
(grep { $absent{$_} == -2 } keys %absent)) |
| 688 |
{ |
| 689 |
if (!$osym->{deprecated} || $osym->is_optional()) { |
| 690 |
$result->{deprecated} = $collection->get_latest_version(); |
| 691 |
} |
| 692 |
} elsif (scalar(keys %present) == scalar(@latest) && |
| 693 |
(@oarches == 0 || @latest > 1)) |
| 694 |
{ |
| 695 |
# Do not remove arch tag if we based our findings only on a single |
| 696 |
# arch. |
| 697 |
$result->{deprecated} = 0; |
| 698 |
if (@oarches > 0) { |
| 699 |
$result->delete_tag("arch"); |
| 700 |
$arch_added += scalar(keys %present); |
| 701 |
} |
| 702 |
} else { |
| 703 |
# We will need to add appropriate arch tag. But in addition, |
| 704 |
# collect info from NEW non-latest arches (provided we had |
| 705 |
# info about them from latest) |
| 706 |
foreach my $arch (@non_latest) { |
| 707 |
my $status = $self->get_symbol_arch_status($arch); |
| 708 |
if ($status > 0) { |
| 709 |
$present{$arch} = $status if keys(%present) > 0 && |
| 710 |
! exists $absent{$arch}; |
| 711 |
} else { |
| 712 |
$absent{$arch} = $status if keys(%absent) > 0 && |
| 713 |
! exists $present{$arch}; |
| 714 |
} |
| 715 |
} |
| 716 |
|
| 717 |
if (keys %present || keys %absent) { |
| 718 |
$result->{deprecated} = 0 if keys %present; |
| 719 |
if (@oarches > 0) { |
| 720 |
# We need to combine original and new data. Filter out hits |
| 721 |
# (exact and wildcards) in @oarches first. |
| 722 |
my $fail; |
| 723 |
foreach my $arch (@oarches) { |
| 724 |
my $not_arch = $1 if $arch =~ /^!+(.*)$/; |
| 725 |
if (! defined $arch_neg) { |
| 726 |
$arch_neg = ($not_arch) ? '!' : ''; |
| 727 |
} elsif ($arch_neg ne (($not_arch) ? '!' : '')) { |
| 728 |
$fail = 1; |
| 729 |
$osym->add_tag("helper-arch", "mixed-arch-tag-not-supported"); |
| 730 |
last; |
| 731 |
} |
| 732 |
if ($not_arch) { |
| 733 |
if (! $self->is_arch_in_db($not_arch, \%present)) { |
| 734 |
push @narches, $not_arch; |
| 735 |
} else { |
| 736 |
$arch_added++; |
| 737 |
} |
| 738 |
} else { |
| 739 |
if (! $self->is_arch_in_db($arch, \%absent)) { |
| 740 |
push @narches, $arch; |
| 741 |
} |
| 742 |
} |
| 743 |
} |
| 744 |
|
| 745 |
return $result if $fail; |
| 746 |
} |
| 747 |
|
| 748 |
if (@narches) { |
| 749 |
# Now add new arches of the specified type |
| 750 |
foreach my $arch (($arch_neg) ? (keys %absent) : (keys %present)) { |
| 751 |
if (! $self->is_arch_in_db($arch, \@narches)) { |
| 752 |
push @narches, $arch; |
| 753 |
$arch_added++ if ! $arch_neg; |
| 754 |
} |
| 755 |
} |
| 756 |
|
| 757 |
# Finally set arch tag |
| 758 |
$result->add_tag("arch", join(" ", map { "${arch_neg}$_" } sort(@narches))); |
| 759 |
} else { # Original symbol has no more valid arch tags |
| 760 |
$arch_added += scalar(keys %present); |
| 761 |
if ($total_arches > 2 && keys(%present) == $total_arches - 1) { |
| 762 |
# Use !missing_arch if only a single arch is missing |
| 763 |
my $missarch; |
| 764 |
if (keys(%absent) == 1) { |
| 765 |
$missarch = (keys %absent)[0]; |
| 766 |
} else { |
| 767 |
foreach my $arch (@latest, @non_latest) { |
| 768 |
if (!exists $present{$arch}) { |
| 769 |
$missarch = $arch; |
| 770 |
last; |
| 771 |
} |
| 772 |
} |
| 773 |
} |
| 774 |
$result->add_tag("arch", "!$missarch"); |
| 775 |
} elsif ($total_arches > 2 && keys(%absent) == $total_arches - 1) { |
| 776 |
# Use arch if only present on a single arch |
| 777 |
my $okarch; |
| 778 |
if (keys(%present) == 1) { |
| 779 |
$okarch = (keys %present)[0]; |
| 780 |
} else { |
| 781 |
foreach my $arch (@latest, @non_latest) { |
| 782 |
if (!exists $absent{$arch}) { |
| 783 |
$okarch = $arch; |
| 784 |
last; |
| 785 |
} |
| 786 |
} |
| 787 |
} |
| 788 |
$result->add_tag("arch", $okarch); |
| 789 |
} elsif (scalar(keys %present) <= scalar(keys %absent)) { |
| 790 |
$result->add_tag("arch", join(" ", sort keys %present)); |
| 791 |
} else { |
| 792 |
$result->add_tag("arch", join(" ", map { "!$_" } sort(keys %absent))); |
| 793 |
} |
| 794 |
} |
| 795 |
} |
| 796 |
} |
| 797 |
|
| 798 |
# Bump symbol minver if new arches added or there is no original symbol |
| 799 |
if (defined $result && keys(%present) && (!defined $osym || $arch_added) && |
| 800 |
! $result->is_optional()) |
| 801 |
{ |
| 802 |
$result->{minver} = $collection->get_latest_version(); |
| 803 |
} |
| 804 |
|
| 805 |
return $result; |
| 806 |
} |
| 807 |
|
| 808 |
sub prep_substs { |
| 809 |
my ($self, $arch) = @_; |
| 810 |
my $sym = $self->get_symbol($arch); |
| 811 |
my $h_name = $sym->get_h_name(); |
| 812 |
foreach my $subst (@{$self->{substs}}) { |
| 813 |
$subst->prep($h_name, $arch); |
| 814 |
} |
| 815 |
} |
| 816 |
|
| 817 |
sub detect_substs { |
| 818 |
my ($self, $main_arch) = @_; |
| 819 |
|
| 820 |
my %h_names = map { $_ => $self->get_symbol($_)->get_h_name() } $self->get_arches(); |
| 821 |
my $h_name = $h_names{$main_arch}; |
| 822 |
|
| 823 |
my $detected = 0; |
| 824 |
foreach my $subst (@{$self->{substs}}) { |
| 825 |
if ($subst->detect($h_name, $main_arch, \%h_names)) { |
| 826 |
$detected++; |
| 827 |
# Make other h_names arch independent with regard to this handler. |
| 828 |
foreach my $arch (keys %h_names) { |
| 829 |
$subst->hinted_neutralize($h_names{$arch}, $h_name); |
| 830 |
} |
| 831 |
} |
| 832 |
} |
| 833 |
return $detected; |
| 834 |
} |
| 835 |
|
| 836 |
1; |