summaryrefslogtreecommitdiff
path: root/Build/cdbuild/place
blob: 60381aa411d3c0459c143c216ad7613c4febc858 (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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/usr/bin/env perl
# $Id$
# License: public domain.  Originally written by Sebastian Rahtz.
# 
# Process a tree in the Build/cdbuild/cooked directory (probably created
# by ctan2tds.pl) and integrate into the main texmf trees.
# 
# Basic usage: place PKG
# to process Build/cdbuild/cooked/PKG.

use File::Basename;
use File::Find;
use Cwd;

$newpackage = 0;
%dirs = ();  # dirs we make changes in

if ($ARGV[0] eq "-n") {
  $chicken = 1;
  shift;
} else {
  $chicken = 0;
}
print "place: chicken mode = $chicken\n";

die "usage: $0 PKGNAME\n" unless @ARGV == 1;
$package = $ARGV[0];

xchdir (dirname($0) . "/cooked");
$mydir = getcwd();
-d "$mydir/$package" || die "$0: No such package in $mydir: $package\n";

xchdir ("../../../Master");
$M = getcwd();

xchdir ("$mydir/$package");
if    (-d "texmf-dist") {$Root="texmf-dist"; }
elsif (-d "texmf-doc")  {$Root="texmf-doc"; }
elsif (-d "texmf")      {$Root="texmf"; }


# get list of existing files
my $listsfile = "$M/texmf/lists/$package";
if (-f $listsfile) {
  open (LIST, $listsfile) || die "open($listsfile) failed: $!";
  while (<LIST>) { 
    chomp; 
    s/\r$//;
    $Old{$_} = 1 if /^[A-z]/;
  }
  close (LIST);
}
else {
  $newpackage=1;
}

&xchdir ("$mydir/$package");
find (\&files,".");
foreach $file (sort keys %Old) {
  print "* $file: [retained=$New{$file}]\n";

  # and if the file does not exist, don't try to remove it -- we
  # probably did so by hand and didn't bother to update the tpm.
  next unless -f "$M/$file";
  
  # don't remove tpm or lists file, they won't be in the new package.
  if (! $New{$file} && $file !~ /\.tpm$/ && $file !~ m,/lists/[^/]+$,) {
    &my_system ("svn remove $M/$file"); 
  }
  $dirs{dirname ("$M/$file")}++;
}

# copy files
my $Job = "tar cf - . | (cd $M && tar xf - )";
&my_system ($Job);

# sort so dirs will be added before subdirs.
foreach $file (sort keys %New) {
  if (! $Old{$file}) { 
    &add_file ("$M/$file");
  }
}

my $tpmdir = "$M/$Root/tpm";

xchdir ($mydir);
&my_system ("mv $package $package.done");

if ($Root eq 'texmf-doc') {
  $Type = 'Documentation';
} elsif ($Root eq 'texmf-dist') { 
  $Type = 'Package'; 
} else {
  die "cannot handle Root=$Root";
}

chomp (my $tools = `cd $mydir/../../tools && pwd`);

$SETUP = "$tools/tpm-factory.pl --master=$M --tpm_dir=$tpmdir"
         . " --ftp_dir=/var/tmp --arch=all --patterns=auto"
         . " --name=$Type/$package";

# create tpm if needed
&my_system ("perl $SETUP --new") unless -f "$tpmdir/$package.tpm";

# update tpm
&my_system ("perl $SETUP --clean");

# create/update lists file
&my_system ("xsltproc --stringparam ROOT $M"
            . " $tools/tpm2list.xsl $M/$Root/tpm/$package.tpm");


# add tpm and lists files after they are created.
if ($newpackage) {
  &add_file ($listsfile);
  &add_file ("$tpmdir/$package.tpm");
}

# these two dirs will essentially always change, so just list them.
$dirs{$tpmdir}++;
$dirs{"$M/texmf/lists"}++;

# print dirs with changed files, for svn commit purposes.
# if other files have been modified in those same dirs, though, this
# won't detect it.  It would be better to list exactly the *files* which
# should be committed, but ... lazy.
# 
# also write dir list to a separate file, for easy passing to a commit.
# 
$DIRLIST = ">" . ($ENV{"TMPDIR"} || "/tmp") . "/tlplace.dirs";
open (DIRLIST) || die "open($DIRLIST) failed: $!";
#
for my $dir (sort keys %dirs) {
  print "$dir\n";
  print DIRLIST "$dir\n";
}
#
close (DIRLIST) || warn "close($DIRLIST) failed: $!";

exit (0);



#--------------------------------------
sub dirs
{
    local @filenames;
   if (-d) { 
       @filenames=&buildfilelist($File::Find::name);
    if (!@filenames) { rmdir $File::Find::name;}
  }}

sub buildfilelist
{
    my($me) = @_;
    my @files;
    opendir(DIR,$me) || cleanup ("cannot open directory $me");
    @files =grep(!/^\.\.?/,readdir(DIR));
    closedir(DIR);  
    return @files;
}


sub files
{
  if (-f) {
    $This=$File::Find::name;
    $This =~ s/^\.\///;
    $New{$This}=1;
 }
}


# add a file to the repository.  for svn, we also have to add the
# containing dir, and the parent of that dir, if they are new.
# (Should really just traverse )
# 
sub add_file
{
  my ($newfile) = @_;
  
  my $newdir = dirname ($newfile);
  
  # when it's needed, parent must come first, else have svn "not working copy".
  my $parentdir = dirname ($newdir);
  unless (-d "$parentdir/.svn") {
    &my_system ("svn add -N $parentdir");
    $dirs{$parentdir}++;
  }
  
  unless (-d "$newdir/.svn") {
    &my_system ("svn add -N $newdir");
  }
  
  &my_system ("svn add $newfile");
  
  # remember that we changed this directory.
  $dirs{$newdir}++;
}


sub xchdir
{
  my ($dir) = @_;
  chdir ($dir) || die "chdir($dir) failed: $!";
  print "place: chdir($dir)\n";
}


sub my_system
{
  my ($cmd) = @_;
  
  print "place: SYSTEM $cmd\n";

  unless ($chicken) {
    my $ret = system ($cmd);
    die "`$cmd' failed, status=$ret, goodbye\n" if $ret != 0;
  }
}