source: tags/ms_ra2q1/SOURCE_TOOLS/remake_after_change.pl

Last change on this file was 16763, checked in by westram, 6 years ago
  • Property svn:executable set to *
File size: 8.6 KB
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6# ----------------------------------------
7
8my @shared = (
9              'AWT',
10              'ARBDB',
11              'CORE',
12              'WINDOW',
13             );
14my %shared = map { $_ => 1; } @shared;
15
16# ----------------------------------------
17
18my %dir2dirs = (
19
20                'AISC'     => 'NAMES_COM PROBE_COM',
21                'AISC_COM' => 'AISC',
22                'GL'       => 'GL/glAW GL/glpng',
23
24               );
25
26my %dir2libs = (
27
28                'NAMES_COM' => 'NAMES_COM/client.a NAMES_COM/common.a NAMES_COM/server.a',
29                'PROBE_COM' => 'PROBE_COM/client.a PROBE_COM/common.a PROBE_COM/server.a',
30                'GL/glAW'   => 'GL/glAW/libglAW.a',
31                'GL/glpng'  => 'GL/glpng/libglpng_arb.a',
32                'ptpan'     => 'ptpan/PROBE.a',
33
34               );
35
36my %dir2targets = (
37
38                   'AISC_MKPTPS'  => 'all',
39                   'bin'          => 'all',
40                   'BINDEP'       => 'all',
41                   'BUGEX'        => 'all',
42                   'dep_graphs'   => 'dep_graph',
43                   'GDE'          => 'gde',
44                   'GDEHELP'      => 'help menus',
45                   'HELP_SOURCE'  => 'help',
46                   'INCLUDE'      => 'all',
47                   'lib'          => 'help libs perl',
48                   'PERL2ARB'     => 'perl',
49                   'PERL_SCRIPTS' => 'testperlscripts',
50                   'PROBE_SET'    => 'pst',
51                   'READSEQ'      => 'readseq',
52                   'SL'           => 'all',
53                   'SOURCE_TOOLS' => 'links valgrind_update',
54                   'TEMPLATES'    => 'all',
55                   'TOOLS'        => 'tools',
56                   'UNIT_TESTER'  => 'ut',
57
58                  );
59
60# ----------------------------------------
61
62my $ARBHOME = $ENV{ARBHOME};
63if ((not defined $ARBHOME) or (not -d $ARBHOME)) {
64  die "Need correct \$ARBHOME";
65}
66my $SOURCE_TOOLS = $ARBHOME.'/SOURCE_TOOLS';
67
68sub dir2name($$$) {
69  my ($dir,$prefix,$suffix) = @_;
70
71  if ($dir eq '') { return undef; }
72
73  my $lastname = $dir;
74  if ($dir =~ /\/([^\/]+)$/) { $lastname = $1; }
75
76  my $useddir = ($suffix eq '.so') ? 'lib' : $dir;
77  my $name    = $useddir.'/'.$prefix.$lastname.$suffix;
78
79  return $name;
80}
81
82sub dirs2changedlibs($);
83sub dirs2changedlibs($) {
84  my ($dirs) = @_;
85
86  my @dir = split / /,$dirs;
87  my %libs = ();
88
89  foreach my $dir (@dir) {
90    if (defined $dir2dirs{$dir}) {
91      my $dirs2 = $dir2dirs{$dir};
92      my $libs2 = dirs2changedlibs($dirs2);
93      foreach (split / /,$libs2) { $libs{$_} = 1; }
94    }
95    elsif (defined $dir2libs{$dir}) {
96      my $libs = $dir2libs{$dir};
97      foreach (split / /,$libs) { $libs{$_} = 1; }
98    }
99    else {
100      my $prefix = '';
101      my $suffix = '.a';
102
103      if (defined $shared{$dir}) {
104        $prefix = 'lib';
105        $suffix = '.so';
106      }
107
108      my $libname = dir2name($dir,$prefix,$suffix);
109      $libs{$libname} = 1;
110    }
111  }
112
113  return join(' ',keys %libs);
114}
115
116sub changedlibs2targets($) {
117  my ($changed_lib) = @_;
118
119  my %targets = ();
120  foreach (split / /,$changed_lib) {
121    # all client.a and common.a libs are identical (the libs in PROBE_COM are used in dependencies)
122    if ($_ eq 'NAMES_COM/client.a') { $_ = 'PROBE_COM/client.a'; }
123    if ($_ eq 'NAMES_COM/common.a') { $_ = 'PROBE_COM/common.a'; }
124
125    my $cmd = $SOURCE_TOOLS.'/needed_libs.pl -F -U -I -T '.$_;
126    my $base_targets = `$cmd`;
127    chomp($base_targets);
128    foreach (split / /,$base_targets) { $targets{$_} = 1; }
129  }
130
131  # modify targets
132  my @targets = map {
133    if ($_ =~ /\//) {
134      if ($_ =~ /\.a$/o) {
135        $`.'.dummy';
136      }
137      elsif ($_ =~ /\/([^\/]+)\.o$/o) {
138        my $dir = $`;
139        dir2name($dir,'','.dummy');
140      }
141      else {
142        $_;
143      }
144    }
145    else {
146      'rac_'.$_;
147    }
148  } keys %targets;
149
150  return(join(' ', @targets));
151}
152
153sub dirs2targets($) {
154  my ($dirs) = @_;
155  my %targets = ();
156  foreach (split / /,$dirs) {
157    if (defined $dir2targets{$_}) {
158      my $targets = $dir2targets{$_};
159      foreach (split / /,$targets) { $targets{$_} = 1; }
160    }
161  }
162  return join(' ',keys %targets);
163}
164
165sub config2env() {
166  my $conf = $ARBHOME.'/config.makefile';
167
168  if (not -f $conf) {
169    print "$conf not found.. generating\n";
170    my $cmd = "cd $ARBHOME;make";
171    system($cmd);
172    exit(1);
173  }
174
175  open(CONF,'<'.$conf) || die "can't read '$conf' (Reason: $!)";
176
177  my $OPENGL     = 0;
178  my $PTPAN      = 0;
179  my $UNIT_TESTS = 0;
180
181  foreach (<CONF>) {
182    chomp;
183    if (/^OPENGL\s*:=\s*([0-9]+)/) { $OPENGL = $1; }
184    if (/^PTPAN\s*:=\s*([0-9]+)/) { $PTPAN = $1; }
185    if (/^UNIT_TESTS\s*:=\s*([0-9]+)/) { $UNIT_TESTS = $1; }
186  }
187  close(CONF);
188
189  print "Using:\n";
190  print "- OPENGL=$OPENGL\n";
191  print "- PTPAN=$PTPAN\n";
192  print "- UNIT_TESTS=$UNIT_TESTS\n";
193
194  if ($OPENGL==1) {
195    $ENV{RNA3D_LIB} = 'RNA3D/RNA3D.a';
196  }
197  if ($PTPAN==1) { $ENV{ARCHS_PT_SERVER_LINK} = 'ptpan/PROBE.a'; }
198  else { $ENV{ARCHS_PT_SERVER_LINK} = 'PROBE/PROBE.a'; }
199
200  return $UNIT_TESTS;
201}
202
203sub dump_log($) {
204  my ($log) = @_;
205  print "---------------------------------------- [$log start]\n";
206  open(LOG,'<'.$log) || die "can't read '$log' (Reason: $!)";
207  print <LOG>;
208  close(LOG);
209  print "---------------------------------------- [$log end]\n";
210}
211
212sub system_no_error_or_die($) {
213  my ($cmd) = @_;
214  if (system($cmd)!=0) { die "could not execute '$cmd'"; }
215  if ($? == -1) { die "could not execute '$cmd'"; }
216  if ($? & 127) { die sprintf("child died with signal %d", ($? & 127)); }
217  my $exitcode = ($? >> 8);
218  if ($exitcode!=0) { die "command '$cmd' failed (exitcode=$exitcode)"; }
219}
220
221sub main() {
222  my $dir = `pwd`;
223  chomp($dir);
224
225  if (not defined $ENV{LINK_STATIC}) {
226    print "Warning: LINK_STATIC not defined (assuming 0 - which is wrong for OSX)\n";
227    $ENV{LINK_STATIC} = '0'; # wrong for OSX
228  }
229
230  my $UNIT_TESTS = config2env();
231
232  if (not $dir =~ /^$ARBHOME/) {
233    print "Usage: simply call in any directory inside ARBHOME\n";
234    print "It will assume you changed something there and remake all depending executables\n";
235    print "(In fact this is a lie, it won't work everywhere:)\n";
236
237    die "Not called from inside $ARBHOME";
238  }
239
240  print "remake[3]: Entering directory `$ARBHOME'\n";
241  chdir($ARBHOME);
242
243  $dir = $';
244  $dir =~ s/^\///;
245
246  my $changed_libs = dirs2changedlibs($dir);
247  my $targets;
248  if ($changed_libs eq '') {
249    print "Called in ARBHOME\n";
250    $targets = 'all';
251  }
252  else {
253    $targets = '';
254    while ($targets eq '') {
255      print "Assuming $changed_libs changed\n";
256      $targets = changedlibs2targets($changed_libs);
257      if ($targets eq '') { $targets = dirs2targets($dir); }
258
259      if ($targets eq '') {
260        if ($dir =~ /\//) {
261          my $updir = $`;
262          print "No known targets for $dir - trying $updir\n";
263          $dir = $updir;
264          $changed_libs = dirs2changedlibs($dir);
265        }
266        else {
267          die "No idea what to remake for '$dir'\n ";
268        }
269      }
270    }
271  }
272
273  if ($targets ne '') {
274    my $cores = `cat /proc/cpuinfo | grep processor | wc -l`;
275    if ($cores<1) { $cores = 1; }
276    my $jobs = $cores+1;
277    print "Remaking\n";
278
279    foreach (split / /,$targets) { print " - $_\n"; }
280
281    print "\n";
282
283    my $premake = "make -j$jobs up_by_remake";
284    print "Silent premake: '$premake'\n";
285    my $log = 'silent_premake.log';
286    $premake = "cd $ARBHOME;$premake > $log 2>&1";
287    print "Silent premake: '$premake' (real)\n";
288
289    eval {
290      system_no_error_or_die($premake);
291    };
292    if ($@) {
293      my $err = "Silent premake failed (".$@.")";
294      print "\nError: $err\n";
295      dump_log($log);
296      die $err;
297    }
298    else {
299      open(LOG,'<'.$log) || die "can't read '$log' (Reason: $!)";
300      my @warnings = grep /:\swarning:\s/, <LOG>;
301      close(LOG);
302      if (scalar(@warnings)) {
303        print "\nWarnings detected:\n";
304        dump_log($log);
305      }
306    }
307    print "\n";
308
309    my $targets_contain_unittests = 0;
310    my $targets_are_timed = 0;
311
312    my %targets = map { $_ => 1; } split / /,$targets;
313    if (defined $targets{all}) {
314      $targets_contain_unittests = 1;
315      $targets_are_timed         = 1;
316    }
317    if (defined $targets{ut}) {
318      $targets_contain_unittests = 1;
319    }
320
321    my $makecmd;
322    if ($targets_are_timed==1) {
323      $makecmd = "cd $ARBHOME;make -j$jobs $targets";
324    }
325    else {
326      my $timed_target = (($UNIT_TESTS==0) or ($targets_contain_unittests==1)) ? 'timed_target' : 'timed_target_tested';
327      $makecmd = "cd $ARBHOME;make \"TIMED_TARGET=$targets\" -j$jobs $timed_target";
328    }
329
330    print "[Make: '$makecmd']\n";
331    system($makecmd)==0 || die "error executing '$makecmd' (exitcode=$?)\n";
332    print "remake[3]: Leaving directory `$ARBHOME'\n";
333
334    unlink($log);
335  }
336}
337
338main();
Note: See TracBrowser for help on using the repository browser.