phase1: add JSON merge step
[buildbot.git] / scripts / dumpinfo.pl
1 #!/usr/bin/env perl
2
3 use strict;
4 use warnings;
5 use Cwd;
6
7 my (%targets, %architectures);
8
9 $ENV{'TOPDIR'} = Cwd::getcwd();
10
11
12 sub parse_targetinfo {
13 my ($target_dir, $subtarget) = @_;
14
15 if (open M, "make -C '$target_dir' --no-print-directory DUMP=1 TARGET_BUILD=1 SUBTARGET='$subtarget' |") {
16 my ($target_name, $target_arch, @target_features);
17 while (defined(my $line = readline M)) {
18 chomp $line;
19
20 if ($line =~ /^Target: (.+)$/) {
21 $target_name = $1;
22 }
23 elsif ($line =~ /^Target-Arch-Packages: (.+)$/) {
24 $target_arch = $1;
25 }
26 elsif ($line =~ /^Target-Features: (.+)$/) {
27 @target_features = split /\s+/, $1;
28 }
29 elsif ($line =~ /^@\@$/) {
30 if ($target_name && $target_arch &&
31 !grep { $_ eq 'broken' or $_ eq 'source-only' } @target_features) {
32 $targets{$target_name} = $target_arch;
33 $architectures{$target_arch} ||= [];
34 push @{$architectures{$target_arch}}, $target_name;
35 }
36
37 undef $target_name;
38 undef $target_arch;
39 @target_features = ();
40 }
41 }
42 close M;
43 }
44 }
45
46 sub get_targetinfo {
47 foreach my $target_makefile (glob "target/linux/*/Makefile") {
48 my ($target_dir) = $target_makefile =~ m!^(.+)/Makefile$!;
49 my @subtargets;
50
51 if (open M, "make -C '$target_dir' --no-print-directory DUMP=1 TARGET_BUILD=1 val.FEATURES V=s 2>/dev/null |") {
52 if (defined(my $line = readline M)) {
53 chomp $line;
54 if (grep { $_ eq 'broken' or $_ eq 'source-only' } split /\s+/, $line) {
55 next;
56 }
57 }
58 }
59
60 if (open M, "make -C '$target_dir' --no-print-directory DUMP=1 TARGET_BUILD=1 val.SUBTARGETS V=s 2>/dev/null |") {
61 if (defined(my $line = readline M)) {
62 chomp $line;
63 @subtargets = split /\s+/, $line;
64 }
65 close M;
66 }
67
68 push @subtargets, 'generic' if @subtargets == 0;
69
70 foreach my $subtarget (@subtargets) {
71 parse_targetinfo($target_dir, $subtarget);
72 }
73 }
74 }
75
76 if (@ARGV == 1 && $ARGV[0] eq 'targets') {
77 get_targetinfo();
78 foreach my $target_name (sort keys %targets) {
79 printf "%s %s\n", $target_name, $targets{$target_name};
80 }
81 }
82 elsif (@ARGV == 1 && $ARGV[0] eq 'architectures') {
83 get_targetinfo();
84 foreach my $target_arch (sort keys %architectures) {
85 printf "%s %s\n", $target_arch, join ' ', @{$architectures{$target_arch}};
86 }
87 }
88 else {
89 print "Usage: $0 targets\n";
90 print "Usage: $0 architectures\n";
91 }