]> git.saurik.com Git - apple/ld64.git/blob - unit-tests/bin/make-recursive-newtest.pl
ld64-409.12.tar.gz
[apple/ld64.git] / unit-tests / bin / make-recursive-newtest.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use Data::Dumper;
5 use File::Find;
6 use Cwd qw(realpath);
7
8 my @args = @ARGV;
9
10 $ENV{'LD_NO_CLASSSIC_LINKER'} = '1';
11 $ENV{'LD_NO_CLASSSIC_LINKER_STATIC'} = '1';
12
13 my $makefiles =
14 {
15 'makefile' => undef,
16 'Makefile' => undef,
17 'makefile.newtest' => undef,
18 'Makefile.newtest' => undef,
19 };
20
21 my $find_opts =
22 {
23 'wanted' => \&find_callback,
24 };
25
26 my $keywords =
27 {
28 'root' => '',
29 'cwd' => '',
30 'cmd' => '',
31 'exit' => '',
32 'stdout' => [],
33 'stderr' => [],
34 };
35
36 my $keyword;
37 my $max_keyword_len = 0;
38 foreach $keyword (keys %$keywords)
39 { if($max_keyword_len < length($keyword)) { $max_keyword_len = length($keyword); } }
40 my $delim = ':';
41 $max_keyword_len += length($delim) + length(' ');
42
43 my $last_keyword = '';
44
45 sub print_line
46 {
47 my ($keyword, $val) = @_;
48
49 if(!exists($$keywords{$keyword}))
50 {
51 print STDERR "error: keyword $keyword not in \$keywords set\n";
52 exit(1);
53 }
54
55 my $keyword_len = 0;
56
57 if($keyword ne $last_keyword)
58 {
59 print("$keyword"); print($delim);
60 $keyword_len = length($keyword) + length($delim);
61 }
62 if($max_keyword_len > $keyword_len)
63 {
64 my $num_spaces = $max_keyword_len - $keyword_len;
65 print(' ' x $num_spaces);
66 }
67 print("$val");
68 if(0)
69 {
70 $last_keyword = $keyword;
71 }
72 }
73
74 my $root = '.';
75 $root = &realpath($root);
76 print_line("root", "$root\n");
77
78 find($find_opts, $root);
79
80 sub find_callback
81 {
82 if(exists($$makefiles{$_}))
83 {
84 my $makefile = $_;
85 my $reldir = $File::Find::dir;
86 $reldir =~ s|^$root/||;
87
88 &print_line("cwd", "\$root/$reldir\n");
89 my $cmd = [ "make" ];
90
91 push @$cmd, "-f";
92 push @$cmd, $makefile;
93 my $arg; foreach $arg (@ARGV) { push @$cmd, $arg; } # better way to do this?
94 &print_line("cmd", "@$cmd\n");
95
96 open(SAVEOUT, ">&STDOUT") || die("$!");
97 open(SAVEERR, ">&STDERR") || die("$!");
98 open(STDOUT, ">/tmp/unit-tests-stdout") || die("$!");
99 open(STDERR, ">/tmp/unit-tests-stderr") || die("$!");
100
101 $ENV{UNIT_TEST_NAME} = $reldir;
102 my $exit = system(@$cmd);
103
104 close(STDOUT) || die("$!");
105 close(STDERR) || die("$!");
106 open(STDOUT, ">&SAVEOUT") || die("$!");
107 open(STDERR, ">&SAVEERR") || die("$!");
108
109 &print_line("exit", "$exit\n");
110
111 open(OUT, "</tmp/unit-tests-stdout") || die("$!");
112 while(<OUT>)
113 {
114 &print_line("stdout", "$_");
115 }
116 close(OUT) || die("$!");
117 unlink("/tmp/unit-tests-stdout");
118
119 open(ERR, "</tmp/unit-tests-stderr") || die("$!");
120 while(<ERR>)
121 {
122 &print_line("stderr", "$_");
123 }
124 close(ERR) || die("$!");
125 }
126 unlink("/tmp/unit-tests-stderr");
127 }