Explorar el Código

Dpkg::Shlibs::SymbolFile::merge_symbols(): factorize some code

Split off some code from SymbolFile::merge_symbols() to
Symbol::mark_found_in_library() and Symbol::mark_not_found_in_library()
methods. Methods do sanitizing of the Symbol object when the symbol is / isn't
found in the library respectively. This simplifies readability of
merge_symbols() and allows reusability of the code blocks (for the future).

Signed-off-by: Modestas Vainius <modax@debian.org>
Signed-off-by: Raphaël Hertzog <hertzog@debian.org>
Modestas Vainius hace 16 años
padre
commit
8ad712068d
Se han modificado 2 ficheros con 45 adiciones y 29 borrados
  1. 42 0
      scripts/Dpkg/Shlibs/Symbol.pm
  2. 3 29
      scripts/Dpkg/Shlibs/SymbolFile.pm

+ 42 - 0
scripts/Dpkg/Shlibs/Symbol.pm

@@ -21,6 +21,7 @@ use warnings;
 use Dpkg::Gettext;
 use Dpkg::Deps;
 use Dpkg::ErrorHandling;
+use Dpkg::Version;
 use Storable qw();
 use Dpkg::Shlibs::Cppfilt;
 
@@ -394,4 +395,45 @@ sub get_symbolspec {
     return $spec;
 }
 
+# Sanitize the symbol when it is confirmed to be found in
+# the respective library.
+sub mark_found_in_library {
+    my ($self, $minver, $arch) = @_;
+
+    if ($self->{deprecated}) {
+	# Symbol reappeared somehow
+	$self->{deprecated} = 0;
+	$self->{minver} = $minver if (not $self->is_optional());
+    } else {
+	# We assume that the right dependency information is already
+	# there.
+	if (version_compare($minver, $self->{minver}) < 0) {
+	    $self->{minver} = $minver;
+	}
+    }
+    if (not $self->arch_is_concerned($arch)) {
+	# Remove arch tag because it is incorrect.
+	$self->delete_tag('arch');
+    }
+}
+
+# Sanitize the symbol when it is confirmed to be NOT found in
+# the respective library.
+# Mark as deprecated those that are no more provided (only if the
+# minver is bigger than the version where the symbol was introduced)
+sub mark_not_found_in_library {
+    my ($self, $minver, $arch) = @_;
+
+    # Ignore symbols from foreign arch
+    return if not $self->arch_is_concerned($arch);
+
+    if ($self->{deprecated}) {
+	# Bump deprecated if the symbol is optional so that it
+	# keeps reappering in the diff while it's missing
+	$self->{deprecated} = $minver if $self->is_optional();
+    } elsif (version_compare($minver, $self->{minver}) > 0) {
+	$self->{deprecated} = $minver;
+    }
+}
+
 1;

+ 3 - 29
scripts/Dpkg/Shlibs/SymbolFile.pm

@@ -301,21 +301,7 @@ sub merge_symbols {
 	if (exists $obj->{syms}{$name}) {
 	    # If the symbol is already listed in the file
 	    $sym = $obj->{syms}{$name};
-	    if ($sym->{deprecated}) {
-		# Symbol reappeared somehow
-		$sym->{deprecated} = 0;
-		$sym->{minver} = $minver if (not $sym->is_optional());
-	    } else {
-		# We assume that the right dependency information is already
-		# there.
-		if (version_compare($minver, $sym->{minver}) < 0) {
-		    $sym->{minver} = $minver;
-		}
-	    }
-	    if (not $sym->arch_is_concerned($self->{arch})) {
-		# Remove arch tag because it is incorrect.
-		$sym->delete_tag('arch');
-	    }
+	    $sym->mark_found_in_library($minver, $self->{arch});
 	} else {
 	    # The symbol is new and not present in the file
 	    my $symobj = $dynsyms{$name};
@@ -329,23 +315,11 @@ sub merge_symbols {
 	}
     }
 
-    # Scan all symbols in the file and mark as deprecated those that are
-    # no more provided (only if the minver is bigger than the version where
-    # the symbol was introduced)
+    # Process all symbols which could not be found in the library.
     foreach my $name (keys %{$self->{objects}{$soname}{syms}}) {
 	if (not exists $dynsyms{$name}) {
 	    my $sym = $self->{objects}{$soname}{syms}{$name};
-
-	    # Ignore symbols from foreign arch
-	    next if not $sym->arch_is_concerned($self->{arch});
-
-	    if ($sym->{deprecated}) {
-		# Bump deprecated if the symbol is optional so that it
-                # keeps reappering in the diff while it's missing
-		$sym->{deprecated} = $minver if $sym->is_optional();
-	    } elsif (version_compare($minver, $sym->{minver}) > 0) {
-		$sym->{deprecated} = $minver;
-	    }
+	    $sym->mark_not_found_in_library($minver, $self->{arch});
 	}
     }
 }