summaryrefslogtreecommitdiff
path: root/Master/tlpkg/bin/check-duplicated-runfiles
blob: 05a518602832f66df7763edf0bbd86f07e4e0b0c (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
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env perl
# $Id$
# Copyright 2008 Manuel Pegourie-Gonnard.
# This file is licenced under the WTFPL version 2.
#
# Check there are no duplicated runtimes files.

BEGIN {
  $^W = 1;
  ($mydir = $0) =~ s,/[^/]*$,,;
  unshift (@INC, "$mydir/..");
}

use TeXLive::TLConfig qw/$RelocPrefix $RelocTree/;
use TeXLive::TLPOBJ;
use TeXLive::TLPDB;

use File::Basename;

# first, get and load the current texlive.tlpdb
#
chomp (my $Master = `cd $mydir/../.. && pwd`);
$tlpdb = TeXLive::TLPDB->new ("root" => "$Master");
die("Cannot find tlpdb in $Master!\n") unless defined($tlpdb);

# build a list of all runtime files associated to 'normal' packages
#
(my $non_normal = `ls $Master/bin`) =~ s/\n/\$|/g; # binaries
$non_normal .= '^0+texlive|^bin-|^collection-|^scheme-|^texlive-';
my @runtime_files = ();
foreach my $tlpn ($tlpdb->list_packages) {
  next if ($tlpn =~ /$non_normal/);
  my $tlp = $tlpdb->get_package($tlpn);
  my @files = $tlp->runfiles;
  if ($tlp->relocated) { for (@files) { s:^$RelocPrefix/:$RelocTree/:; } }
  push @runtime_files, @files;
}

# build the duplicates list
#
my @duplicates = (""); # just to use $duplicates[-1] freely
my $prev = "";
foreach my $f (sort map { basename($_) } @runtime_files) {
  push (@duplicates, $f) if (($f eq $prev) and not ($f eq $duplicates[-1]));
  $prev = $f;
}
shift @duplicates; # get rid of the fake 1st value

# @duplicates = ('8r-base.map', 'aer.sty', 'lm-ec.map'); # for debugging

# check if duplicates are different files
#
foreach my $f (@duplicates) {
  # assume tex4ht stuff is ok, and don't worry about Changes/README for now
  next if ($f =~ /(^Changes$|^README$|\.htf$|\.4hf$)/);
  # 
  my @copies = grep (/\/$f$/, @runtime_files);
  # map files can be duplicated as long as copies don't concern the same engine
  if ($f =~ /\.map$/) {
    my $need_check = 0;
    my $prev_dir = "";
    my @cop = @copies; # don't break the outside list
    map { s#^texmf-dist/fonts/map/(.*?)/.*#$1# } @cop;
    foreach my $dir (sort  @cop ) {
      last if ($need_check = ($dir eq $prev_dir)); 
      $prev_dir = $dir;
    }
    next unless $need_check;
  }
  # if all copies are identical, ok, else, complain
  my $diff = 0;
  for (my $i = 1; $i < scalar(@copies); $i++) {
    if ($diff = system ("diff -q --strip-trailing-cr "
        . "$Master/$copies[$i-1] $Master/$copies[$i] >/dev/null")) {
      print "# $f\ndiff $Master/$copies[$i-1] $Master/$copies[$i]\n";
      last;
    }
  }
  print join ("\n", @copies), "\n" if ($diff and (scalar(@copies) > 2));
}

### Local Variables:
### perl-indent-level: 2
### tab-width: 2
### indent-tabs-mode: nil
### End
# vim: set tabstop=2 shiftwidth=2 expandtab: