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