summaryrefslogtreecommitdiff
path: root/Master/tlpkg/bin/check-wrapper-consistency
blob: 47efde4ff8ff6eda0ea3e8e73bce2cdff9d7122a (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env perl
# $Id$
# Copyright 2008, 2009 TeX Users Group.
# This file is licensed under the GNU General Public License version 2
# or any later version.
# 
# Check that the same set of files are wrappers on w32 and symlinks on
# all others.

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

use Getopt::Long;
use Pod::Usage;

our $mydir;
my $help = 0;

GetOptions("help|?"       => \$help) or pod2usage(1);
pod2usage(-exitstatus => 0, -verbose => 2) if $help;

exit (&main ());


sub main
{
  my $err = 0;
  
  chomp (my $Master = `cd $mydir/../.. && pwd`);
  my $bindir = "$Master/bin";
  chdir ($bindir) || die "chdir($bindir) failed: $!";
  
  my %w = &unx_wrapper_entries ("i386-linux");

  # add some additional wrappers which are not found 
  # automatically since they are not .. symlinks on Unix.
  $w{'dvigif'} = 1;
  $w{'fmtutil-sys'} = 1;
  $w{'updmap'} = 1;
  $w{'updmap-sys'} = 1;

  chomp (my $srcdir = `cd $Master/../Build/source/texk/texlive && pwd`);
  $cww = "$srcdir/w32_wrapper/runscript.exe";
  $err += &check_w32 ("win32", $cww, %w);

  return $err;
}



# return all symlinks starting with ".." in DIR as a hash, with symlink
# targets as the values.  Check that targets are executable.
# 
sub unx_wrapper_entries
{
  my ($DIR) = @_;
  my %ret;
  
  chomp (my $olddir = `pwd`);
  chdir ($DIR) || die "chdir($DIR) failed: $!";

  local *DIR;
  opendir (DIR, ".") || die "opendir($DIR) failed: $!";
  while (my $ent = readdir (DIR)) {
    next unless -l $ent;  # skip all but symlinks

    my $target = readlink ($ent);
    die "readlink($ent) failed: $!" if !defined ($target);
    next unless $target =~ /^\.\./;  # skip all but .. symlinks
    
    # the target of the symlink should be executable.
    warn "$ent: target $target not executable\n" if ! -x $target;

    $ret{$ent} = $target;  # remember name and link target
  }
  closedir (DIR) || warn "closedir($DIR) failed: $!";
  chdir ($olddir) || die "chdir($olddir) failed: $!";

  return %ret;
}



# Windows is special, as usual.  Given the list of wrappers in UW, check
# that each of those entries exists in W32DIR as a .exe, and is a copy
# of the canonical w32 wrapper specified in W32CANONICAL.
# 
sub check_w32
{
  my ($w32dir, $w32canonical, %uw) = @_;
  my $diff = 0;

  for my $k (sort keys %uw) {
    my $target = $uw{$k};
    next if $target =~ /bibexport/;    # shell script
    next if $target =~ /context/;      # does things its own way
    next if $target =~ /listings-ext/; # shell script
    next if $target =~ /man/;          # no symlink
    next if $target =~ /ps4pdf/;       # has its own .bat
    next if $target =~ /simpdftex/;    # shell script
    next if $target =~ /tex4ht/;       # tex4ht has its own .bat's
    next if $target =~ /tlmgr/;        # does things its own way
    next if $target =~ /xasy/;         # no need
    #print "$k -> $uw{$k}\n";
    $diff += system ("cmp $w32dir/$k.exe $w32canonical");
  }

  opendir (DIR, $w32dir) || die "opendir($DIR) failed: $!";
  my @binfiles = readdir (DIR);
  closedir (DIR) || warn "closedir($DIR) failed: $!";
  
  foreach my $f (@binfiles) {
    my $cannonical = $w32canonical;
    #
    # .exe would prevent tlmgr update --self!
    next if ($f =~ /^tlmgr\.bat$/);
    #
    # no .exe stub for the universal wrapper:
    next if ($f =~ /^tl-w32-wrapper\.cmd$/);
    #
    # only if batch file:
    next unless ($f =~ s/\.(bat|cmd)$/\.exe/);
    #
    # dvigif.exe is now a copy of dvipng.exe
    $cannonical = "$w32dir/dvipng.exe" if ($f =~ /^dvigif\.exe$/);
    #
    # fmtutil-sys.exe is now a copy of fmtutil.exe
    $cannonical = "$w32dir/fmtutil.exe" if ($f =~ /^fmtutil-sys\.exe$/);

    $diff += system ("cmp $w32dir/$f $canonical");
  }
  
  return $diff;
}