Make pkgbuild use packages.xml to set ips_package_name; stop it from packaging sources
--- 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);