2008-04-09 11:06:16 +01:00
|
|
|
use strict;
|
|
|
|
use XML::Simple;
|
|
|
|
|
|
|
|
my $packagesFile = shift @ARGV;
|
|
|
|
my $urlPrefix = shift @ARGV;
|
|
|
|
my @toplevelPkgs = @ARGV;
|
|
|
|
|
2008-04-11 12:52:40 +01:00
|
|
|
my @archs = split ' ', ($ENV{'archs'} or "");
|
|
|
|
|
|
|
|
print STDERR "parsing packages...\n";
|
|
|
|
|
|
|
|
my $xml = XMLin($packagesFile, ForceArray => ['package', 'rpm:entry', 'file'], KeyAttr => []) or die;
|
2008-04-09 11:06:16 +01:00
|
|
|
|
|
|
|
print STDERR "file contains $xml->{packages} packages\n";
|
|
|
|
|
|
|
|
|
2008-04-11 12:52:40 +01:00
|
|
|
my %pkgs;
|
|
|
|
foreach my $pkg (@{$xml->{'package'}}) {
|
|
|
|
if (scalar @archs > 0) {
|
|
|
|
my $arch = $pkg->{arch};
|
|
|
|
my $found = 0;
|
|
|
|
foreach my $a (@archs) { $found = 1 if $arch eq $a; }
|
|
|
|
next if !$found;
|
|
|
|
}
|
|
|
|
if (defined $pkgs{$pkg->{name}}) {
|
|
|
|
print STDERR "WARNING: duplicate occurrence of package $pkg->{name}\n";
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
$pkgs{$pkg->{name}} = $pkg;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-09 11:06:16 +01:00
|
|
|
my %provides;
|
2008-04-11 12:52:40 +01:00
|
|
|
foreach my $pkgName (keys %pkgs) {
|
2008-04-09 13:51:54 +01:00
|
|
|
print STDERR "looking at $pkgName\n";
|
2008-04-11 12:52:40 +01:00
|
|
|
my $pkg = $pkgs{$pkgName};
|
|
|
|
|
|
|
|
#print STDERR keys %{$pkg->{format}}, "\n";
|
|
|
|
|
|
|
|
#print STDERR $pkg->{format}->{'rpm:provides'}, "\n";
|
|
|
|
|
|
|
|
my $provides = $pkg->{format}->{'rpm:provides'}->{'rpm:entry'} or die;
|
|
|
|
foreach my $req (@{$provides}) {
|
|
|
|
#print "$req->{name}\n";
|
|
|
|
#print STDERR " provides $req\n";
|
|
|
|
#die "multiple provides for $req" if defined $provides{$req};
|
|
|
|
$provides{$req->{name}} = $pkgName;
|
2008-04-09 11:06:16 +01:00
|
|
|
}
|
2008-04-11 12:52:40 +01:00
|
|
|
|
2008-04-09 11:06:16 +01:00
|
|
|
if (defined $pkg->{format}->{file}) {
|
|
|
|
foreach my $file (@{$pkg->{format}->{file}}) {
|
|
|
|
#print STDERR " provides file $file\n";
|
|
|
|
$provides{$file} = $pkgName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
my %donePkgs;
|
|
|
|
my @needed = ();
|
|
|
|
|
|
|
|
sub closePackage {
|
|
|
|
my $pkgName = shift;
|
|
|
|
|
|
|
|
return if defined $donePkgs{$pkgName};
|
|
|
|
$donePkgs{$pkgName} = 1;
|
|
|
|
|
|
|
|
print STDERR ">>> $pkgName\n";
|
|
|
|
|
2008-04-11 12:52:40 +01:00
|
|
|
my $pkg = $pkgs{$pkgName} or die "package $pkgName doesn't exist";
|
2008-04-09 11:06:16 +01:00
|
|
|
|
2008-11-26 11:14:39 +00:00
|
|
|
my $requires = $pkg->{format}->{'rpm:requires'}->{'rpm:entry'} || [];
|
2008-04-09 11:06:16 +01:00
|
|
|
|
|
|
|
my @deps = ();
|
2008-04-11 12:52:40 +01:00
|
|
|
foreach my $req (@{$requires}) {
|
|
|
|
next if $req->{name} =~ /^rpmlib\(/;
|
|
|
|
print STDERR " needs $req->{name}\n";
|
|
|
|
my $provider = $provides{$req->{name}};
|
2008-04-09 11:06:16 +01:00
|
|
|
if (!defined $provider) {
|
2008-04-11 12:52:40 +01:00
|
|
|
print STDERR " WARNING: no provider for $req->{name}\n";
|
2008-04-09 11:06:16 +01:00
|
|
|
next;
|
|
|
|
}
|
|
|
|
print STDERR " satisfied by $provider\n";
|
|
|
|
push @deps, $provider;
|
|
|
|
}
|
|
|
|
|
|
|
|
closePackage($_) foreach @deps;
|
|
|
|
|
|
|
|
push @needed, $pkgName;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach my $pkgName (@toplevelPkgs) {
|
|
|
|
closePackage $pkgName;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Generate the output Nix expression.
|
|
|
|
print "# This is a generated file. Do not modify!\n";
|
|
|
|
print "# Following are the RPM packages constituting the closure of: @toplevelPkgs\n\n";
|
|
|
|
print "{fetchurl}:\n\n";
|
|
|
|
print "[\n\n";
|
|
|
|
|
|
|
|
foreach my $pkgName (@needed) {
|
2008-04-11 12:52:40 +01:00
|
|
|
my $pkg = $pkgs{$pkgName};
|
2008-04-09 11:06:16 +01:00
|
|
|
print " (fetchurl {\n";
|
|
|
|
print " url = $urlPrefix/$pkg->{location}->{href};\n";
|
2009-06-09 15:25:45 +01:00
|
|
|
if ($pkg->{checksum}->{type} eq "sha") {
|
|
|
|
print " sha1 = \"$pkg->{checksum}->{content}\";\n";
|
|
|
|
} elsif ($pkg->{checksum}->{type} eq "sha256") {
|
|
|
|
print " sha256 = \"$pkg->{checksum}->{content}\";\n";
|
|
|
|
} else {
|
|
|
|
die "unsupported hash type";
|
|
|
|
}
|
2008-04-09 11:06:16 +01:00
|
|
|
print " })\n";
|
|
|
|
print "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
print "]\n";
|