|
1 #!perl |
|
2 # Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 # All rights reserved. |
|
4 # This component and the accompanying materials are made available |
|
5 # under the terms of the License "Eclipse Public License v1.0" |
|
6 # which accompanies this distribution, and is available |
|
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 # |
|
9 # Initial Contributors: |
|
10 # Nokia Corporation - initial contribution. |
|
11 # |
|
12 # Contributors: |
|
13 # |
|
14 # Description: |
|
15 # |
|
16 # |
|
17 |
|
18 use strict; |
|
19 use FindBin; |
|
20 use lib "$FindBin::Bin"; |
|
21 use Getopt::Long; |
|
22 use IniData; |
|
23 use EnvDb; |
|
24 use MrpData; |
|
25 use CommandController; |
|
26 use Cwd; |
|
27 |
|
28 |
|
29 # |
|
30 # Globals. |
|
31 # |
|
32 |
|
33 my $verbose = 0; |
|
34 my $comp; |
|
35 my $iniData = IniData->New(); |
|
36 my $commandController = CommandController->New($iniData, 'BuildRel'); |
|
37 my $envDb; |
|
38 my $buildall; |
|
39 my $noclean; |
|
40 my $dummyrun; |
|
41 |
|
42 |
|
43 # |
|
44 # Main. |
|
45 # |
|
46 |
|
47 ProcessCommandLine(); |
|
48 BuildRel(); |
|
49 |
|
50 |
|
51 # |
|
52 # Subs. |
|
53 # |
|
54 |
|
55 sub ProcessCommandLine { |
|
56 Getopt::Long::Configure ("bundling"); |
|
57 my $help; |
|
58 my $ignore; |
|
59 my $stdin; |
|
60 GetOptions("h" => \$help, "v+" => \$verbose, "a" => \$buildall, "q" => \$noclean, "d" => \$dummyrun, "f" => \$ignore); |
|
61 |
|
62 if ($help) { |
|
63 Usage(0); |
|
64 } |
|
65 |
|
66 $comp = shift @ARGV; |
|
67 |
|
68 if (@ARGV) { |
|
69 print "Error: too many arguments\n"; |
|
70 Usage(1); |
|
71 } elsif ($buildall && $comp) { |
|
72 print "Error: can't use -a with a component name\n"; |
|
73 Usage(1); |
|
74 } elsif (!$buildall && !$comp) { |
|
75 print "Error: Must specify -a or a component name\n"; |
|
76 Usage(1); |
|
77 } |
|
78 |
|
79 $envDb = EnvDb->Open($iniData, $verbose); |
|
80 } |
|
81 |
|
82 sub Usage { |
|
83 my $exitCode = shift; |
|
84 |
|
85 Utils::PrintDeathMessage($exitCode, "\nUsage: buildrel [options] -a | <component> |
|
86 |
|
87 options: |
|
88 |
|
89 -a build all pending release components |
|
90 -h help |
|
91 -f (deprecated) |
|
92 -v verbose output (-vv very verbose) |
|
93 -q quick (don't do \"abld reallyclean\") |
|
94 -d dummy run: just show what would happen\n"); |
|
95 } |
|
96 |
|
97 sub BuildRel { |
|
98 if ($buildall) { |
|
99 BuildEnvironment(); |
|
100 } else { |
|
101 BuildComp($comp); |
|
102 } |
|
103 } |
|
104 |
|
105 # Implementation |
|
106 |
|
107 sub BuildComp { |
|
108 my $comp = shift; # could accept a component name or an entry |
|
109 |
|
110 print "Building \"$comp\"\n" if ($verbose); |
|
111 |
|
112 print "Gathering data from MRP file...\n" if ($verbose>1); |
|
113 my $mrpData = $envDb->GetMrpData($comp); |
|
114 print "Working out build commands...\n" if ($verbose>1); |
|
115 my $cwd = cwd(); |
|
116 my $nul = ($verbose > 2)?"":" > NUL"; |
|
117 my %commands_by_path; |
|
118 |
|
119 foreach my $binset (@{$mrpData->BinSets()}) { |
|
120 my $path = Utils::PrependSourceRoot($binset->{path}); |
|
121 unless ($commands_by_path{$path}) { |
|
122 $commands_by_path{$path} = [ "bldmake bldfiles" ]; |
|
123 push @{$commands_by_path{$path}}, "abld reallyclean" unless $noclean; |
|
124 } |
|
125 push @{$commands_by_path{$path}}, "abld $binset->{test} build $binset->{plat} $binset->{var} $binset->{mmp}"; |
|
126 } |
|
127 |
|
128 print "Running build commands...\n" if ($verbose>1); |
|
129 foreach my $path (sort keys %commands_by_path) { |
|
130 chdir($path); |
|
131 my $cmds = $commands_by_path{$path}; |
|
132 foreach my $cmd (@$cmds) { |
|
133 print "Build command: $cmd\n" if ($dummyrun || $verbose > 1); |
|
134 next if $dummyrun; |
|
135 open(CMD, "$cmd|") or die "Couldn't start command \"$_\" because $!"; |
|
136 my $output = ""; |
|
137 my $failure = 0; |
|
138 while (<CMD>) { |
|
139 print $_ if $verbose > 2; |
|
140 $failure = 1 if m/fatal error/i; |
|
141 $output .= $_; |
|
142 } |
|
143 close CMD; |
|
144 die "Error: build failed. Command \"$cmd\" in directory \"$path\" failed with error code $? and output:\n$output\n\n" if ($? || $failure); |
|
145 # ABLD currently doesn't pass through error codes. I have requested |
|
146 # that it be modified to do so. |
|
147 } |
|
148 } |
|
149 chdir $cwd; |
|
150 } |
|
151 |
|
152 sub BuildEnvironment { |
|
153 foreach my $comp (keys %{$envDb->{db}}) { |
|
154 next unless $envDb->Status($comp) == EnvDb::STATUS_PENDING_RELEASE; |
|
155 BuildComp($comp); |
|
156 } |
|
157 } |
|
158 |
|
159 |
|
160 __END__ |
|
161 |
|
162 =head1 NAME |
|
163 |
|
164 BuildRel - Attempt to build a component. |
|
165 |
|
166 =head1 SYNOPSIS |
|
167 |
|
168 buildrel [options] -a | <component> |
|
169 |
|
170 options: |
|
171 |
|
172 -a build all components pending release |
|
173 -h help |
|
174 -v verbose output (-vv very verbose) |
|
175 -q quick (don't do abld reallyclean) |
|
176 -d dummy run: just show what would happen |
|
177 |
|
178 =head1 DESCRIPTION |
|
179 |
|
180 Attempts to build a component, using all the platforms listed in the |
|
181 MRP file. Using -a will build all the components that are pending |
|
182 release. |
|
183 |
|
184 The -d option doesn't do any building. However, in the process of |
|
185 reading the details from the MRP it may be forced to run commands |
|
186 such as C<bldmake bldfiles> and C<abld makefile>. |
|
187 |
|
188 The commands this script runs are: |
|
189 |
|
190 bldmake bldfiles |
|
191 abld reallyclean (unless you're using -q) |
|
192 abld build XXX XXX (or abld test build XXX XXX) |
|
193 |
|
194 =head1 STATUS |
|
195 |
|
196 Supported. If you find a problem, please report it to us. |
|
197 |
|
198 =head1 KNOWN BUGS |
|
199 |
|
200 None. |
|
201 |
|
202 =head1 COPYRIGHT |
|
203 |
|
204 Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
205 All rights reserved. |
|
206 This component and the accompanying materials are made available |
|
207 under the terms of the License "Eclipse Public License v1.0" |
|
208 which accompanies this distribution, and is available |
|
209 at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
210 |
|
211 Initial Contributors: |
|
212 Nokia Corporation - initial contribution. |
|
213 |
|
214 Contributors: |
|
215 |
|
216 Description: |
|
217 |
|
218 |
|
219 =cut |