2013-03-25 13:17:47 +00:00
|
|
|
#! /run/current-system/sw/bin/perl -w
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use DBI;
|
|
|
|
use DBD::SQLite;
|
2014-12-09 12:42:06 +00:00
|
|
|
use Nix::Manifest;
|
2015-09-02 16:36:17 +00:00
|
|
|
use List::Util qw(all);
|
2013-03-25 13:17:47 +00:00
|
|
|
|
|
|
|
my $nixExprs = $ARGV[0] or die;
|
|
|
|
my $dbPath = $ARGV[1] or die;
|
2014-12-09 12:42:06 +00:00
|
|
|
my $manifestPath = $ARGV[2] or die;
|
|
|
|
|
|
|
|
my (%narFiles, %patches);
|
|
|
|
readManifest("$manifestPath", \%narFiles, \%patches);
|
2013-03-25 13:17:47 +00:00
|
|
|
|
|
|
|
my $dbh = DBI->connect("dbi:SQLite:dbname=$dbPath", "", "")
|
|
|
|
or die "cannot open database `$dbPath'";
|
|
|
|
$dbh->{RaiseError} = 1;
|
|
|
|
$dbh->{PrintError} = 0;
|
|
|
|
|
|
|
|
$dbh->do(<<EOF);
|
|
|
|
create table if not exists Programs (
|
|
|
|
name text not null,
|
|
|
|
system text not null,
|
|
|
|
package text not null,
|
|
|
|
primary key (name, system, package)
|
|
|
|
);
|
|
|
|
EOF
|
|
|
|
|
|
|
|
my $insertProgram = $dbh->prepare("insert or replace into Programs(name, system, package) values (?, ?, ?)");
|
|
|
|
|
|
|
|
$dbh->begin_work;
|
|
|
|
|
|
|
|
sub process_dir {
|
|
|
|
my ($system, $pkgname, $dir) = @_;
|
|
|
|
return unless -d $dir;
|
2015-09-02 16:36:17 +00:00
|
|
|
#print STDERR "indexing $dir\n";
|
2013-03-25 13:17:47 +00:00
|
|
|
opendir DH, "$dir" or die "opening $dir";
|
|
|
|
for my $program (readdir DH) {
|
|
|
|
next if substr($program, 0, 1) eq ".";
|
|
|
|
$insertProgram->execute($program, $system, $pkgname);
|
|
|
|
}
|
|
|
|
closedir DH;
|
|
|
|
}
|
|
|
|
|
|
|
|
for my $system ("x86_64-linux", "i686-linux") {
|
|
|
|
print STDERR "indexing programs for $system...\n";
|
|
|
|
|
2015-09-02 16:06:27 +00:00
|
|
|
my $out = `nix-env -f $nixExprs -qaP \\* --drv-path --out-path --argstr system $system`;
|
2013-03-25 13:17:47 +00:00
|
|
|
die "cannot evaluate Nix expressions for $system" if $? != 0;
|
|
|
|
|
2015-09-02 16:06:27 +00:00
|
|
|
my %packages;
|
|
|
|
|
2013-03-25 13:17:47 +00:00
|
|
|
foreach my $line (split "\n", $out) {
|
2015-09-02 16:06:27 +00:00
|
|
|
my ($attrName, $name, $drvPath, $outPath) = split ' ', $line;
|
2015-09-02 15:39:05 +00:00
|
|
|
die unless $attrName && $name && $outPath;
|
2015-09-02 16:36:17 +00:00
|
|
|
|
|
|
|
my @outPaths = map { s/^[a-z]+=//; $_ } (split ";", $outPath);
|
|
|
|
|
|
|
|
next unless all { defined $narFiles{$_} } @outPaths;
|
|
|
|
next unless all { -d $_ } @outPaths;
|
|
|
|
|
2015-09-02 16:06:27 +00:00
|
|
|
# Prefer shorter attribute names.
|
2015-09-02 16:36:17 +00:00
|
|
|
my $prev = $packages{$drvPath};
|
2015-09-02 16:06:27 +00:00
|
|
|
next if defined $prev &&
|
|
|
|
(length($prev->{attrName}) < length($attrName) ||
|
|
|
|
(length($prev->{attrName}) == length($attrName) && $prev->{attrName} le $attrName));
|
2015-09-02 16:36:17 +00:00
|
|
|
|
|
|
|
$packages{$drvPath} = { attrName => $attrName, outPaths => [@outPaths] };
|
2015-09-02 16:06:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach my $drvPath (keys %packages) {
|
|
|
|
my $pkg = $packages{$drvPath};
|
2015-09-02 16:36:17 +00:00
|
|
|
process_dir($system, $pkg->{attrName}, "$_/bin")
|
|
|
|
foreach @{$pkg->{outPaths}};
|
2013-03-25 13:17:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$dbh->commit;
|