source: tags/arb-6.0.2/util/arb_srclst.pl

Last change on this file was 12717, checked in by epruesse, 12 years ago

add lib/desktop to package

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 21.4 KB
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6my $debug_matching = 0;
7my $ignore_unknown = 0;
8
9# ------------------------------------------------------------
10# override checks below and save strictly as checked-in in SVN
11
12my @strictly_as_in_svn_when_matchesDir = (
13                                           qr/\/GDE\/MAFFT\/mafft-[0-9\.]+-with[out]*-extensions/o,
14                                          );
15
16# ------------------------------------------------------------
17# skipped_directories and files inside are never examined:
18
19my @skipped_directories = (
20                           qr/\/.+\/bin$/o,
21                           qr/\/.+\/build$/o,
22                           qr/\/HELP_SOURCE\/Xml$/o,
23                           qr/\/GDE\/MUSCLE\/obj$/o,
24                           qr/\/GDE\/PHYML20130708\/phyml\/autom4te.cache$/o,
25                           qr/\/ignore\./o,
26                           qr/\/PERL2ARB\/blib$/o,
27                           qr/\/HEADERLIBS\/[^\/]+/o,
28                           qr/\/UNIT_TESTER\/logs$/o,
29                           qr/\/UNIT_TESTER\/tests$/o,
30                           qr/\/UNIT_TESTER\/run\/homefake\/.arb_prop\/(macros|cfgSave)$/o,
31                           qr/^\.\/ARB_SOURCE_DOC/o,
32                           qr/^\.\/dep_graphs/o,
33                           qr/^\.\/INCLUDE$/o,
34                           qr/^\.\/lib\/help$/o,
35                           qr/^\.\/lib\/help_html$/o,
36                           qr/^\.\/lib\/pts$/o,
37                           qr/^\.\/lib\/mafft$/o,
38                           qr/^\.\/patches.arb$/o,
39                           qr/^\.\/PERL5$/o,
40                           qr/_COM\/DUMP$/o,
41                           qr/_COM\/GEN[CH]$/o,
42                           qr/_COM\/O$/o,
43                           qr/_GEN$/o,
44                           qr/nbproject/o,
45                           # needed by ralf:
46                           qr/^\.\/test_arb_make_targets_logs/o,
47                           qr/\.dSYM$/o,
48                          );
49
50# first used/skipped match wins (exception see @3 below)
51
52my %used_files = map { $_ => 1; } (
53                                   '!BRANCH_STATE',
54                                   'AUTHORS',
55                                   'COPYING',
56                                   'demo.arb',
57                                   'Doxyfile',
58                                   'export2sub',
59                                   'Makefile',
60                                   'Makefile.org',
61                                   'Makefile.setup.include',
62                                   'Makefile.setup.template',
63                                   'Makefile.suite',
64                                   'Makefile.test',
65                                   'needs_libs',
66                                  );
67
68my %skipped_files = map { $_ => 1; } (
69                                      '.build.lst',
70                                      '.cvsignore',
71                                      '.depends',
72                                      'ChangeLog',
73                                      'config.makefile',
74                                      'helpfiles.lst',
75                                      'last.success',
76                                      'Makefile.setup.local',
77                                      'makeloc.here',
78                                      'makeloc.here',
79                                      'nt_date.h',
80                                      'postcompile.sav',
81                                      'TAGS',
82                                      '.DS_Store',
83                                      );
84
85my %used_extensions = map { $_ => 1; } (
86                                        'c', 'cpp', 'cxx', 'cc',
87                                        'h', 'hpp', 'hxx',
88
89                                        'aisc', 'pa',
90                                        'bitmap',
91                                        'dtd', 'xsl',
92                                        'f',
93                                        'footer',
94                                        'head', 'header',
95                                        'i',  # swig input
96                                        'inc',
97                                        'java', 'manifest',
98                                        'makefile',
99                                        'pl', 'pm', 'PL', 'cgi', 'xs',
100                                        'awk',
101                                        'py',
102                                        'script',
103                                        'sh',
104                                        'source', 'menu',
105                                        'template', 'default',
106                                        'txt', 'doc', 'ps', 'pdf',
107                                       );
108
109my %skipped_extensions = map { $_ => 1; } (
110                                           'a',
111                                           'bak',
112                                           'class',
113                                           'bundle', # Some file from XCode
114                                           'gcno',
115                                           'genmenu',
116                                           'jar',
117                                           'last_gcc',
118                                           'last_compiler',
119                                           'list',
120                                           'log',
121                                           'o',
122                                           'old',
123                                           'patch',
124                                           'rej',
125                                           'so',
126                                           'stamp',
127                                           'swp',
128                                           'yml', 'json', # perl2arb
129                                          );
130
131
132# used_when_matches, skipped_when_matches and used_when_matchesFull are only tested,
133# if above filters did not match:
134
135my @used_when_matches = (
136                         qr/^arb_.*\.txt$/o,
137                         qr/disclaimer/io,
138                         qr/license/io,
139                         qr/needs_libs\..*/io,
140                         qr/readme$/io,
141                         qr/typemap$/io,
142                         qr/unused.*source.*\.tgz$/io,
143                        );
144
145my @skipped_when_matches = (
146                            qr/.*~$/o, # backups
147                            qr/\#.*\#$/o,
148                            qr/\.\#.*$/o,
149                            qr/^arbsrc.*\.tgz$/o,
150                            qr/^arbsrc\.lst$/o,
151                            qr/^arbsrc\.lst\.tmp$/o,
152                            qr/^callgrind\./o,
153                           );
154
155my @used_when_matchesFull = (
156                             qr/\/AISC_COM\/AISC\/magic.lst$/o,
157                             qr/\/CLUSTALW\/.*$/o,
158                             qr/\/EISPACK\/rg\.html$/o,
159                             qr/\/GDE\/.*\.html$/o,
160                             qr/\/GDEHELP\/FASTA/o,
161                             qr/\/GDEHELP\/GDE.*/o,
162                             qr/\/GDEHELP\/HELP_PLAIN/o,
163                             qr/\/GDEHELP\/HELP_WRITTEN/o,
164                             qr/\/GDEHELP\/Makefile\.helpfiles/o,
165                             qr/\/HEADERLIBS\/.*COPYING$/o,
166                             qr/\/HEADERLIBS\/.*\.tgz$/o,
167                             qr/\/HELP_SOURCE\/.*\.gif$/o,
168                             qr/\/HELP_SOURCE\/oldhelp\/.*\.(ps|pdf)\.gz$/o,
169                             qr/\/HELP_SOURCE\/oldhelp\/.*\.hlp$/o,
170                             qr/\/HGL_SRC\/plot\.icon$/o,
171                             qr/\/PERL2ARB\/.*\.html$/o,
172                             qr/\/PERL2ARB\/Makefile.main$/o,
173                             qr/\/PHYLIP\/doc\//o,
174                             qr/\/PROBE_SERVER\/.*\.conf$/o,
175                             qr/\/READSEQ\/.*\.help$/o,
176                             qr/\/READSEQ\/Formats$/o,
177                             qr/\/SH\/[^\/\.]*$/o,
178                             qr/\/SOURCE_TOOLS\//o,
179                             qr/\/TREEPUZZLE\/.*\.gif$/o,
180                             qr/\/UNIT_TESTER\/run\/.*\.a00$/o,
181                             qr/\/UNIT_TESTER\/run\/.*\.arb$/o,
182                             qr/\/UNIT_TESTER\/run\/.*\.amc$/o,
183                             qr/\/UNIT_TESTER\/run\/.*\.expected$/o,
184                             qr/\/UNIT_TESTER\/run\/.*\.fig$/o,
185                             qr/\/UNIT_TESTER\/run\/.*\.in$/o,
186                             qr/\/UNIT_TESTER\/run\/.*\.inp$/o,
187                             qr/\/UNIT_TESTER\/run\/.*\.input$/o,
188                             qr/\/UNIT_TESTER\/run\/.*\.out$/o,
189                             qr/\/UNIT_TESTER\/run\/.*\.tree$/o,
190                             qr/\/UNIT_TESTER\/run\/help\//o,
191                             qr/\/UNIT_TESTER\/run\/impexp\/.*\.exported$/o,
192                             qr/\/UNIT_TESTER\/valgrind\/arb_valgrind_logged$/o,
193                             qr/^\.\/etc\//o,
194                             qr/^\.\/lib\/arb_default\/.*\.arb$/o,
195                             qr/^\.\/lib\/arb_tcp_org\.dat$/o,
196                             qr/^\.\/lib\/config\.[^\.]+$/io,
197                             qr/^\.\/lib\/desktop\/.*$/o,
198                             qr/^\.\/lib\/export\/.*\.eft$/o,
199                             qr/^\.\/lib\/import\/.*\.ift2?$/o,
200                             qr/^\.\/lib\/inputMasks\/.*\.mask$/o,
201                             qr/^\.\/lib\/macros\/.*\.amc$/o,
202                             qr/^\.\/lib\/macros\/.checks\/.*\.expected$/o,
203                             qr/^\.\/lib\/nas\/names\.dat\.template$/o,
204                             qr/^\.\/lib\/pictures\/.*\.(fig|vfont)$/o,
205                             qr/^\.\/lib\/pixmaps\/.*\.xpm$/o,
206                             qr/^\.\/lib\/protein_2nd_structure\/.*\.dat$/o,
207                             qr/^\.\/lib\/rna3d\/.*\.(pdb|data)$/o,
208                             qr/^\.\/lib\/rna3d\/images\/.*\.png$/o,
209                             qr/^\.\/lib\/sellists\/.*\.sellst$/o,
210                             qr/^\.\/lib\/submit\//o,
211                             qr/^\.\/lib\/BUGS\//o,
212                             qr/^\.\/util\/arb_.*$/o,
213                             qr/^\.\/util\/config\..*$/o,
214                             qr/\/GDE\/.*\/Makefile\.[^\/]+$/io,
215                             qr/\/GDE\/PHYML[^\/]+\/phyml\//o,
216                            );
217
218# skipped_when_matchesFull and forced_when_matchesFull are always tested! (@3)
219
220my @skipped_when_matchesFull = (
221                                qr/\/genhelp\/.*\.hlp$/o,
222                                qr/\/lib\/addlibs\/(lib.*\.so\..*)$/o,
223                                qr/^\.\/arb.*\.tgz$/o,
224                                qr/^\.\/bin\//o,
225                                qr/^\.\/GDE\/CORE\/functions.h$/o,
226                                qr/^\.\/GDE\/PHYML[^\/]+\/phyml\/(configure|config.h.in)$/o,
227                                qr/^\.\/lib\/ARB\.pm$/o,
228                                qr/^\.\/lib\/arb_tcp\.dat$/o,
229                                qr/^\.\/lib\/gde\/.*\.menu$/o,
230                                qr/^\.\/lib\/nas\/names.*\.dat$/o,
231                                qr/^\.\/lib\/macros\/\.checks\/.*\.ids$/o,
232                                qr/^\.\/lib\/motifHack\/pixmaps\/.*$/o,
233                                qr/^\.\/PERL2ARB\/.*\.h$/o,
234                                qr/^\.\/PERL2ARB\/ARB\.bs$/o,
235                                qr/^\.\/PERL2ARB\/ARB\.c$/o,
236                                qr/^\.\/PERL2ARB\/ARB\.xs$/o,
237                                qr/^\.\/PERL2ARB\/Makefile$/o,
238                                qr/^\.\/PERL2ARB\/Makefile.PL$/o,
239                                qr/^\.\/PERL2ARB\/perlmain.c$/o,
240                                qr/^\.\/PERL2ARB\/pm_to_blib$/o,
241                                qr/^\.\/SOURCE_TOOLS\/valgrind2grep\.lst$/o,
242                                qr/^\.\/SOURCE_TOOLS\/stamp\./o,
243                                qr/^\.\/TEMPLATES\/arb_build\.h$/o,
244                                qr/^\.\/UNIT_TESTER\/run\/TEST_g?pt\.arb$/o,
245                                qr/^\.\/UNIT_TESTER\/run\/.*\.ARM$/o,
246                                qr/^\.\/UNIT_TESTER\/run\/.*\.ARF$/o,
247                                qr/^\.\/UNIT_TESTER\/Makefile\.setup\.local\.last$/o,
248                                qr/date\.xsl$/o,
249                               );
250
251my @forced_when_matchesFull = (
252                               qr/^\.\/bin\/Makefile/o,
253                               qr/\/PROBE_WEB\/SERVER\/.*\.jar$/o,
254                               qr/\/GDE\/PHYML[^\/]+\/phyml\/.*\.log$/o,
255                              );
256
257# files that are even packed when generated and not in VC
258my @pack_fullGenerated = (
259                          qr/\/TEMPLATES\/svn_revision\.h$/o,
260                         );
261
262# ------------------------------------------------------------
263# sanity checks
264
265foreach (keys %used_extensions) {
266  if (exists $skipped_extensions{$_}) { die "'$_' in \$used_extensions and \$skipped_extensions"; }
267}
268foreach (keys %used_files) {
269  if (exists $skipped_files{$_}) { die "'$_' in \$used_files and \$skipped_files"; }
270}
271
272# ------------------------------------------------------------
273
274sub useDir($) {
275  my ($dir) = @_;
276
277  if ($dir =~ /.svn$/o) { return 0; }
278  if ($dir =~ /CVS$/o) { return 0; }
279  foreach (@skipped_directories) {
280    if ($dir =~ $_) { return 0; }
281  }
282  return 1;
283}
284
285sub matchingExpr($\@) {
286  # return 0 if no regexp matched, return index+1 otherwise
287  my ($str,$regexp_arr_r) = @_;
288
289  my $regexps = scalar(@$regexp_arr_r);
290  for (my $r=0; $r<$regexps; $r++) {
291    my $reg = $$regexp_arr_r[$r];
292    if ($str =~ $reg) {
293      return $r+1;
294    }
295  }
296  return 0;
297}
298
299sub useIfMatching($\@\$) {
300  my ($str,$regexp_arr_r,$use_r) = @_;
301  my $matches = matchingExpr($str,@$regexp_arr_r);
302  if ($matches>0) {
303    if ($debug_matching!=0) { print "'$str' matches '".$$regexp_arr_r[$matches-1]."' => use!\n"; }
304    $$use_r = 1;
305  }
306}
307sub dontUseIfMatching($\@\$) {
308  my ($str,$regexp_arr_r,$use_r) = @_;
309  my $matches = matchingExpr($str,@$regexp_arr_r);
310  if ($matches>0) {
311    if ($debug_matching!=0) { print "'$str' matches '".$$regexp_arr_r[$matches-1]."' => don't use!\n"; }
312    $$use_r = 0;
313  }
314}
315
316sub useFile($$) {
317  my ($dir,$file) = @_;
318
319  my $use = undef;
320  if (exists $used_files{$file}) { $use = 1; }
321  elsif (exists $skipped_files{$file}) { $use = 0; }
322
323  my $hasExt = 0;
324  if (not defined $use) {
325    if ($file =~ /\.([^\.]+)$/o) {
326      my $ext = $1;
327      $hasExt = 1;
328      if (exists $used_extensions{$ext}) { $use = 1; }
329      elsif (exists $skipped_extensions{$ext}) { $use = 0; }
330    }
331  }
332
333  if (not defined $use) {
334    useIfMatching($file,@used_when_matches, $use);
335  }
336
337  if (not defined $use) {
338    dontUseIfMatching($file,@skipped_when_matches, $use);
339  }
340
341  my $full;
342  if (not defined $use) {
343    $full = $dir.'/'.$file;
344
345    useIfMatching($full,@used_when_matchesFull, $use);
346    if (not defined $use) {
347      if (-X $full and $hasExt==0) { $use = 0; } # exclude binaries by default (wrong for scripts)
348    }
349  }
350
351  if (not defined $use or $use==1) {
352    if (not defined $full) { $full = $dir.'/'.$file; }
353
354    dontUseIfMatching($full,@skipped_when_matchesFull, $use);
355  }
356  if (not defined $use or $use==0) {
357    if (not defined $full) { $full = $dir.'/'.$file; }
358    useIfMatching($full,@forced_when_matchesFull, $use);
359  }
360
361  if (not defined $use) {
362    if ($ignore_unknown==0) {
363      die "Don't know whether to use or skip '$file' (in $dir)";
364    }
365    $use = 1;
366  }
367
368  return $use;
369}
370
371# ------------------------------------------------------------
372
373my $VC_FILE    = 1;
374my $VC_DIR     = 2;
375my $VC_UNKNOWN = 3; # in SVN, but unknown whether dir or file
376
377my $svn_entries_read = 0;
378my %all_svn_entries = ();
379
380sub isSVNcheckout($) {
381  my ($dir) = @_;
382  if (-f $dir.'/.svn/entries') { return 1; }
383  if (-f $dir.'/.svn/wc.db') { return 1; }
384  return 0;
385}
386
387sub getSVNEntries($\%) {
388  my ($dir,$SVN_r) = @_;
389
390  if ($svn_entries_read==0) { # first call
391    if (isSVNcheckout($dir)==0) { return 0; }
392
393    my $cmd = "svn status -v $dir";
394    open(SVNSTATUS, "$cmd|") || die "failed to execute '$cmd' (Reason: $!)";
395
396    eval {
397      my $reg_status_line = qr/^(.*)\s+[0-9]+\s+[0-9]+\s+[^\s]+\s+([^\s]+)$/;
398
399      my $line;
400      while (defined($line=<SVNSTATUS>)) {
401        chomp($line);
402        if ($line =~ $reg_status_line) {
403          my ($flags,$name) = ($1,$2);
404          if (-f $name) {
405            $all_svn_entries{$name} = $VC_FILE;
406          }
407          elsif (-d $name) {
408            $all_svn_entries{$name} = $VC_DIR;
409          }
410          else {
411            $all_svn_entries{$name} = $VC_UNKNOWN;
412          }
413        }
414        else {
415          if ($line =~ /^?/) {
416            ; # silently ignore unknown files
417          }
418          else {
419            die "Cant parse line '$line'";
420          }
421        }
422      }
423    };
424    if ($@) {
425      die "Failed to read svn status: $@";
426    }
427
428    close(SVNSTATUS);
429    $svn_entries_read = 1;
430  }
431
432  if ($dir eq '.') {
433    foreach (keys %all_svn_entries) {
434      if (not /\//) { # root entry
435        $$SVN_r{$_} = $all_svn_entries{$_};
436      }
437    }
438  }
439  else {
440    if (not $dir =~ /^\.\//) { die "expected '$dir' to start with './'"; }
441    my $sdir = $';
442    my $reg_matchdir = qr/^$sdir\//;
443    foreach (keys %all_svn_entries) {
444      if ($_ =~ $reg_matchdir) {
445        my $rest = $';
446        if (not $rest =~ /\//) { # in $dir (not below)
447          $$SVN_r{$rest} = $all_svn_entries{$_};
448        }
449      }
450    }
451  }
452
453  return 1;
454}
455
456sub getCVSEntries($\%) {
457  my ($dir,$CVS_r) = @_;
458
459  my $cvsentries = $dir.'/CVS/Entries';
460  if (-f $cvsentries) {
461    open(CVS,'<'.$cvsentries) || die "can't read '$cvsentries' (Reason: $!)";
462    eval {
463      foreach (<CVS>) {
464        chomp;
465        if (/^D\/([^\/]+)\//o) { # directory
466          $$CVS_r{$1} = $VC_DIR;
467        }
468        elsif (/^\/([^\/]+)\//o) { # file
469          $$CVS_r{$1} = $VC_FILE;
470        }
471        elsif (/^D$/o) {
472          ;
473        }
474        else {
475          die "can't parse line '$_'";
476        }
477      }
478    };
479    if ($@) { die "$@ while reading $cvsentries"; }
480    close(CVS);
481    return 1;
482  }
483  return 0;
484}
485
486my $VC = '<no VC>';
487
488sub getVCEntries($\%) {
489  my ($dir,$VC_r) = @_;
490
491  my $res = 1;
492  if (getSVNEntries($dir,%$VC_r)==0) {
493    if (getCVSEntries($dir,%$VC_r)==0) {
494      $VC = '<no VC>';
495      $res = 0;
496    }
497    else {
498      $VC = 'CVS';
499    }
500  }
501  else {
502    $VC = 'SVN';
503  }
504
505  if (0) {
506    print "$VC entries for $dir:\n";
507    foreach (sort keys %$VC_r) {
508      print " ".$$VC_r{$_}.": $_\n";
509    }
510  }
511
512  return $res;
513}
514
515# ------------------------------------------------------------
516
517sub expectVCmember($$\%) {
518  my ($full,$item,$VC_r) = @_;
519  if ((not defined $$VC_r{$item}) and ($ignore_unknown==0)) {
520    if (not matchingExpr($full,@pack_fullGenerated)) {
521      die "'$full' ($_) included, but not in $VC (seems to be generated)";
522    }
523  }
524}
525
526my %unpackedCVSmember = map { $_ => 1; } (
527                                          '.cvsignore',
528                                          'ChangeLog',
529                                         );
530
531sub unexpectVCmember($$\%) {
532  my ($full,$item,$VC_r) = @_;
533  if (defined $$VC_r{$item}) {
534    if ((not exists $unpackedCVSmember{$item}) and ($ignore_unknown==0)) {
535      die "'$full' excluded, but in $VC";
536    }
537  }
538}
539
540sub is_version_controlled($\%) {
541  my ($item,$VC_r) = @_;
542  if (defined $$VC_r{$item}) {
543    return 1;
544  }
545  return 0;
546}
547
548sub saveAsInSVNforDir($) {
549  my ($dir) = @_;
550  foreach my $reg (@strictly_as_in_svn_when_matchesDir) {
551    if ($dir =~ $reg) {
552      return 1;
553    }
554  }
555  return 0;
556}
557
558sub dumpFiles($);
559sub dumpFiles($) {
560  my ($dir) = @_;
561
562  eval {
563    my @subdirs;
564    my @files;
565
566    my %CVS;
567    if (!getVCEntries($dir,%CVS)) {
568      die "arb_srclst.pl only works in a SVN checkout";
569    }
570
571    my $as_in_svn = saveAsInSVNforDir($dir);
572
573    opendir(DIR,$dir) || die "can't read directory '$dir' (Reason: $!)";
574    foreach (readdir(DIR)) {
575      if ($_ ne '.' and $_ ne '..') {
576        my $full = $dir.'/'.$_;
577
578        # print STDERR "full='$full' (as_in_svn=$as_in_svn)\n";
579
580        if (not -l $full) {
581          if (-d $full) {
582            if ($as_in_svn==1) {
583              if (is_version_controlled($_,%CVS)==1) {
584                push @subdirs, $full;
585              }
586            }
587            else {
588              if (useDir($full)==1) {
589                expectVCmember($full,$_,%CVS);
590                push @subdirs, $full;
591              }
592              else { unexpectVCmember($full,$_,%CVS); }
593            }
594          }
595          elsif (-f $full) {
596            if ($as_in_svn==1) {
597              if (is_version_controlled($_,%CVS)==1) {
598                push @files, $full;
599              }
600            }
601            else {
602              if (useFile($dir,$_)==1) {
603                expectVCmember($full,$_,%CVS);
604                push @files, $full;
605              }
606              else { unexpectVCmember($full,$_,%CVS); }
607            }
608          }
609          else { die "Unknown (neighter link nor file nor directory): '$full'"; }
610        }
611      }
612    }
613    closedir(DIR);
614
615    foreach (@files) { print $_."\n"; }
616    foreach (@subdirs) { dumpFiles($_); }
617  };
618  if ($@) {
619    my $err = $@;
620    if ($err =~ /at\s(.*\.pl)\sline\s([0-9]+)/) {
621      $err = "$1:$2: Error: $`";
622    }
623    $err =~ s/\n//g;
624    die "$err\n";
625  }
626}
627
628my $args = scalar(@ARGV);
629if ($args==0) {
630  dumpFiles('.');
631}
632else {
633  my $arg = $ARGV[0];
634  if ($arg eq 'ignore') {
635    $ignore_unknown = 1;
636    dumpFiles('.');
637  }
638  elsif ($arg eq 'matching') {
639    $debug_matching = 1;
640    dumpFiles('.');
641  }
642  else {
643    die "Usage: arb_srclst.pl [ignore|matching]\n";
644  }
645}
Note: See TracBrowser for help on using the repository browser.