pkgbuild/patches/distro-redefine-tags.diff
author Alex Viskovatoff <herzen@imap.cc>
Wed, 06 Jul 2011 03:54:09 +0100
changeset 10 013ce4d15ea3
parent 7 f5f12f417d49
child 11 7002e18f9aec
permissions -rw-r--r--
Make pkgtool resolve build dependency on SFEgcc The reason this patch is required is that the name of the gcc devel package (SFEgcc) is different from the name of the main package of that spec (SFEgccruntime). That naming scheme is utterly anomalous.

--- pkgbuild-1.3.103/rpm_spec.pm.in.orig	2011-05-30 03:08:52.363950094 +0100
+++ pkgbuild-1.3.103/rpm_spec.pm.in	2011-06-20 10:45:55.986089124 +0100
@@ -35,6 +35,7 @@
 #use strict;
 
 use warnings;
+use XML::XPath;
 use rpm_package;
 use rpm_file;
 use packagebase;
@@ -64,6 +65,12 @@
 my $all_block_names = "prep|build|install|clean|check|changelog|$all_script_names";
 my $all_keywords = "$all_block_names|define|patch|setup|files|description|package|iclass|rclass|use|actions";
 
+my $distro_file_name = "${_homedir}/packages.xml";
+# Tags from the XML file relevant to pkgbuild, which we prevent the spec from redefining
+# Don't use the exists function on an array because that is deprecated; define a hash instead
+my %distro_tag_names = ("ips_package_name", 0, "group", 0, "summary", 0);
+my $xpath;
+
 sub get_version () {
     my $version = "1.3.103";
     return $version;
@@ -138,6 +145,25 @@
     `mkdir -p /var/tmp/pkgbuild-${logname}`;
 }
 
+# Get redefinitions for some tags from the XML file for that purpose, using the
+# XPath location path supplied as our argument that tells us how to find them
+sub get_distro_tags ($) {
+    return () unless (defined($xpath));
+    my @nodes = $xpath->findnodes(shift);
+    my @tags = ();
+    foreach my $node (@nodes) {
+	my $name = $node->getName;
+#	Create an association list of tag name/value pairs
+#	Our XML file uses some tags unknown to pkgbuild, so make sure the tag is relevant
+	push @tags, $name, $node->getChildNode(1)->getValue
+	    if (exists $distro_tag_names{$name});
+    }
+#   Return a reference to the list instead of the list itself, in case we will want
+#   this function to also handle Meta tags, in which case we will return two lists.
+#   (It is not possible to return more than one list in Perl other than by reference.)
+    return \@tags;
+}
+
 # Create a new rpm_spec object.
 # Return undef if the spec_file is not found
 # args:
@@ -157,7 +183,11 @@
     if (! -r $spec_file) {
 	return (undef);
     }
-    
+
+#   If there is a distribution-specific XML file which redefines some tags, process it
+    $xpath = XML::XPath->new(filename => $distro_file_name)
+	if (-f $distro_file_name);
+
     if (not $spec_file =~ /^\//) {
 	my $current_dir=`pwd`;
 	chomp ($current_dir);
@@ -1285,7 +1315,17 @@
 		    $package_ref->set_subpkg($is_subpkg);
 		}
 	    }
-	    $package_ref->set_tag ($tagname, $value);
+	    if ($tagname eq "name" ) {
+		# set tags defined by distro in xml file for that purpose
+		# @$distro_tags is an association list of tag names and values
+		my $distro_tags = get_distro_tags ("pkgs/pkg[string(name)=\'$value\']/child::*");
+		$package_ref->set_tag (shift @$distro_tags, shift @$distro_tags)
+		    while (@$distro_tags);
+	    }
+#	    Ignore tag specified by spec if the tag was set using get_distro_tags
+	    $package_ref->set_tag ($tagname, $value)
+		unless (defined $package_ref->get_tag ($tagname) &&
+			exists $distro_tag_names{$tagname});
 	    return 1;
 	}
     }
@@ -1428,6 +1468,13 @@
     my $packagebase = new packagebase;
     $packagebase->add_package ($new_package);
 
+#   Get IPS_package_name and other tags from distribution-specific XML file
+    unless ($is_subpkg) {
+	my $distro_tags = get_distro_tags ("pkgs/pkg/pkg[string(name)=\'$package_name\']/child::*");
+	$new_package->set_tag (shift @$distro_tags, shift @$distro_tags)
+	    while (@$distro_tags)
+    }
+
     $line = $self->_get_next_line ($fhandle);
     if (defined ($line)) {
 	return $self->_process_top_level ($fhandle, $line);
--- pkgbuild-1.3.103/pkgdb.pm.in.orig	2010-06-28 01:21:14.000000000 +0100
+++ pkgbuild-1.3.103/pkgdb.pm.in	2011-06-28 03:39:54.793511431 +0100
@@ -392,6 +392,15 @@
 	return $self->{ips_pkgname_cache}->{$pkg};
     }
 
+    # See if the package name is redefined in packages.xml
+    {
+	my $tags = rpm_spec::get_distro_tags "pkgs/pkg[string(name)=\'$pkg\']/ips_package_name";
+	if (@$tags) {
+	    $self->msg_info (0, "Package $pkg was renamed to @$tags[1]");
+	    return @$tags[1];
+	}
+    }
+
     # search for local or remote matches using pkg search
 
     # file2pkgs works for package names, too
--- pkgbuild-1.3.103/pkgtool.pl.orig	2010-07-14 12:03:12.000000000 +0100
+++ pkgbuild-1.3.103/pkgtool.pl	2011-07-05 23:15:28.904754627 +0100
@@ -1787,7 +1787,17 @@
 	@this_pkg_requires = $pkg->get_array ('buildrequires');
 	next if not @this_pkg_requires or not defined $this_pkg_requires[0];
 	msg_debug (3, "adding \"@this_pkg_requires\" to the dependencies of $spec");
-	push (@dependencies, @this_pkg_requires);
+	# OpenIndiana names SFEgcc sanely
+	my @real_deps = map {
+	    if ($_ eq "SFEgcc") {
+		"runtime/gcc"
+	    }
+	    elsif ($_ eq "SFEgcc-46") {
+		"runtime/gcc-46"
+	    }
+	    else { $_ }
+	} @this_pkg_requires ;
+	push (@dependencies, @real_deps);
     }
 
     if (not $build_only) {