aboutsummaryrefslogtreecommitdiff
path: root/scripts/maintenance/shrink-manifest.pl
blob: 9ceb4af90cde2db9ab81949bc43b8873b1146059 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#! /usr/bin/perl -w -I. -I..

use strict;
use readmanifest;
use readcache;


my %allNarFiles;
my %allPatches;
my %allSuccessors;

foreach my $manifest (glob "/data/webserver/dist/*/*/MANIFEST") {
    print STDERR "loading $manifest\n";
    readManifest($manifest, \%allNarFiles, \%allPatches, \%allSuccessors, 1);
}



foreach my $manifest (@ARGV) {

    print STDERR "shrinking manifest $manifest...\n";

    my %narFiles;
    my %patches;
    my %successors;

    if (readManifest($manifest, \%narFiles, \%patches, \%successors, 1) < 3) {
        print STDERR "manifest `$manifest' is too old (i.e., for Nix <= 0.7)\n";
	next;
    }

    my %done;

    sub traverse {
	my $p = shift;
	my $prefix = shift;
	print "$prefix$p\n";

	my $reachesNAR = 0;

	foreach my $patch (@{$patches{$p}}) {
	    next if defined $done{$patch->{url}};
	    $done{$patch->{url}} = 1;
	    $reachesNAR = 1 if traverse ($patch->{basePath}, $prefix . "  ");
	}

	$reachesNAR = 1 if defined $allNarFiles{$p};

	print "  $prefix$reachesNAR\n";
	return $reachesNAR;
    }

#    foreach my $p (keys %narFiles) {
#	traverse ($p, "");
#    }

    my %newPatches;

    foreach my $p (keys %patches) {
	my $patchList = $patches{$p};
	my @newList;
	foreach my $patch (@{$patchList}) {
	    if (! defined $allNarFiles{$patch->{basePath}} || 
		! defined $allNarFiles{$p} ) 
	    {
#		print "REMOVING PATCH ", $patch->{basePath}, " -> ", $p, "\n";
	    } else {
#		print "KEEPING PATCH ", $patch->{basePath}, " -> ", $p, "\n";
		push @newList, $patch;
	    }
	}
	$newPatches{$p} = \@newList;
    }

    writeManifest ($manifest, \%narFiles, \%newPatches);
}