|
1 # Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 # All rights reserved. |
|
3 # This component and the accompanying materials are made available |
|
4 # under the terms of "Eclipse Public License v1.0" |
|
5 # which accompanies this distribution, and is available |
|
6 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 # |
|
8 # Initial Contributors: |
|
9 # Nokia Corporation - initial contribution. |
|
10 # |
|
11 # Contributors: |
|
12 # |
|
13 # Description: |
|
14 # This module provides a mapping from build platforms (e.g. ARMV5) to the |
|
15 # corresponding RVCT environment settings. The information is obtained from an INI |
|
16 # file pointed to by the environment variable ABLD_PLAT_INI. The file can have two |
|
17 # different formats. The first format (Format 1) is: |
|
18 # [Symbian_OS_v9.5] |
|
19 # ARMV5 = RVCT 2.2.616 |
|
20 # ARMV6 = RVCT 2.2.616 |
|
21 # ARMV7 = RVCT 3.1.700 |
|
22 # [Symbian_OS_v9.6] |
|
23 # ARMV5 = RVCT 3.1.862 |
|
24 # ARMV7 = RVCT 4.0.100 |
|
25 # [Symbian_OS_vFuture] |
|
26 # ARMV5 = RVCT 4.1.812 |
|
27 # ARMV7 = RVCT 4.0.100 |
|
28 # This format matches the tuple <OS version, build platform> onto a RVCT version. |
|
29 # The build system will look up the OS version in "\epoc32\data\buildinfo.txt". |
|
30 # The second format (Format 2) is: |
|
31 # ARMV5 = RVCT 2.2.616 |
|
32 # ARMV6 = RVCT 2.2.616 |
|
33 # ARMV7 = RVCT 3.1.700 |
|
34 # This format doesn't take the OS version into account and is mostly intended for |
|
35 # the Integration team. |
|
36 # If ABLD_PLAT_INI is not set, or if the INI file doesn't contain any data for the |
|
37 # given platform, whatever RVCT version is found in the path will be used. |
|
38 # |
|
39 # |
|
40 |
|
41 package RVCT_plat2set; |
|
42 use strict; |
|
43 |
|
44 use RVCT_ver2set; |
|
45 |
|
46 # |
|
47 # PUBLIC FUNCTIONS |
|
48 # |
|
49 |
|
50 # Returns the RVCT version corresponding to the given build platform. The first |
|
51 # function returns the data as a string (e.g. "2.2.616"); the second function |
|
52 # returns the data as a list (e.g. [2,2,616]). |
|
53 sub get_version_string($); |
|
54 sub get_version_list($); |
|
55 |
|
56 # Returns true if an RVCT version corresponding to the given platform exists. |
|
57 sub compiler_exists($); |
|
58 |
|
59 # Given a build platform, returns what the name and value of the RVCT??BIN variable |
|
60 # would be. |
|
61 sub get_bin_name($); |
|
62 sub get_bin_path($); |
|
63 |
|
64 # Given a build platform, returns what the name and value of the RVCT??INC variable |
|
65 # would be. |
|
66 sub get_inc_name($); |
|
67 sub get_inc_path($); |
|
68 |
|
69 # Given a build platform, returns what the name and value of the RVCT??LIB variable |
|
70 # variable would be. |
|
71 sub get_lib_name($); |
|
72 sub get_lib_path($); |
|
73 |
|
74 # Given a build platform and the name of an RVCT library, returns the full path to |
|
75 # that library. |
|
76 sub find_lib($$); |
|
77 |
|
78 # |
|
79 # PRIVATE HELPER FUNCTIONS |
|
80 # |
|
81 |
|
82 sub _get_something(@); |
|
83 sub _err_and_die(@); |
|
84 sub _get_os_version(); |
|
85 sub _parse_section_data($@); |
|
86 |
|
87 |
|
88 # |
|
89 # GLOBAL DATA |
|
90 # |
|
91 |
|
92 my %g_data; |
|
93 |
|
94 |
|
95 sub get_version_string($) |
|
96 { |
|
97 return _get_something(@_, 'version'); |
|
98 } |
|
99 |
|
100 sub get_version_list($) |
|
101 { |
|
102 my $tmp = _get_something(@_, 'version'); |
|
103 |
|
104 return split(/\./, $tmp); |
|
105 } |
|
106 |
|
107 sub compiler_exists($) |
|
108 { |
|
109 my $plat = shift; |
|
110 |
|
111 if ( $g_data{$plat}->{version} || $g_data{0}->{version} ) |
|
112 { |
|
113 return 1; |
|
114 } |
|
115 else |
|
116 { |
|
117 return 0; |
|
118 } |
|
119 } |
|
120 |
|
121 sub get_bin_name($) |
|
122 { |
|
123 return _get_something(@_, 'bin_name'); |
|
124 } |
|
125 |
|
126 sub get_bin_path($) |
|
127 { |
|
128 return _get_something(@_, 'bin_path'); |
|
129 } |
|
130 |
|
131 sub get_inc_name($) |
|
132 { |
|
133 return _get_something(@_, 'inc_name'); |
|
134 } |
|
135 |
|
136 sub get_inc_path($) |
|
137 { |
|
138 return _get_something(@_, 'inc_path'); |
|
139 } |
|
140 |
|
141 sub get_lib_name($) |
|
142 { |
|
143 return _get_something(@_, 'lib_name'); |
|
144 } |
|
145 |
|
146 sub get_lib_path($) |
|
147 { |
|
148 return _get_something(@_, 'lib_path'); |
|
149 } |
|
150 |
|
151 sub find_lib($$) |
|
152 { |
|
153 my $plat = shift; |
|
154 my $lib = shift; |
|
155 |
|
156 my $p = get_lib_path($plat); |
|
157 |
|
158 my $f1 = "$p\\armlib\\$lib"; |
|
159 my $f2 = "$p\\cpplib\\$lib"; |
|
160 |
|
161 return "$p\\armlib\\$lib" if -f $f1; |
|
162 return "$p\\cpplib\\$lib" if -f $f2; |
|
163 |
|
164 _err_and_die("could not find $lib for platform $plat."); |
|
165 } |
|
166 |
|
167 sub _get_something(@) |
|
168 { |
|
169 my $plat = shift; |
|
170 my $what = shift; |
|
171 |
|
172 my $data = $g_data{$plat}->{$what}; |
|
173 |
|
174 if (!$data) |
|
175 { |
|
176 $data = $g_data{0}->{$what}; |
|
177 } |
|
178 |
|
179 return $data; |
|
180 } |
|
181 |
|
182 sub _err_and_die(@) |
|
183 { |
|
184 if ( defined(&main::FatalError) ) |
|
185 { |
|
186 main::FatalError(@_); |
|
187 } |
|
188 else |
|
189 { |
|
190 print STDERR "error: @_\n"; |
|
191 } |
|
192 |
|
193 exit 1; |
|
194 } |
|
195 |
|
196 sub _get_os_version() |
|
197 { |
|
198 my $fname = "/epoc32/data/buildinfo.txt"; |
|
199 |
|
200 my $os_ver = ""; |
|
201 |
|
202 open (my $in, "<", $fname) or _err_and_die("couldn't open $fname."); |
|
203 |
|
204 while (<$in>) |
|
205 { |
|
206 chomp; |
|
207 |
|
208 if ( $_ =~ /^\s*ManufacturerSoftwareBuild\s+M\d\d\d\d\d_(\S+)\s*$/i ) |
|
209 { |
|
210 $os_ver = $1; |
|
211 last |
|
212 } |
|
213 } |
|
214 |
|
215 close $in or _err_and_die("couldn't close $fname."); |
|
216 |
|
217 _err_and_die("couldn't read OS version in $fname") unless $os_ver; |
|
218 |
|
219 return $os_ver; |
|
220 } |
|
221 |
|
222 sub _parse_section_data($@) |
|
223 { |
|
224 my ($fname, @lines) = @_; |
|
225 |
|
226 for (@lines) |
|
227 { |
|
228 if ( $_ =~ /^\s*(\w+)\s*=\s*RVCT\s+(\d+\.\d+\.\d+)\s*$/i ) |
|
229 { |
|
230 my $plat = uc($1); |
|
231 my $vers = $2; |
|
232 |
|
233 _err_and_die("$fname: platform $plat already defined.") if $g_data{$plat}; |
|
234 _err_and_die("$fname: RVCT $vers doesn't exist.") unless RVCT_ver2set::compiler_exists($vers); |
|
235 |
|
236 $g_data{$plat}->{version} = $vers; |
|
237 |
|
238 $g_data{$plat}->{bin_name} = RVCT_ver2set::get_bin_name($vers); |
|
239 $g_data{$plat}->{bin_path} = RVCT_ver2set::get_bin_path($vers); |
|
240 |
|
241 $g_data{$plat}->{inc_name} = RVCT_ver2set::get_inc_name($vers); |
|
242 $g_data{$plat}->{inc_path} = RVCT_ver2set::get_inc_path($vers); |
|
243 |
|
244 $g_data{$plat}->{lib_name} = RVCT_ver2set::get_lib_name($vers); |
|
245 $g_data{$plat}->{lib_path} = RVCT_ver2set::get_lib_path($vers); |
|
246 } |
|
247 else |
|
248 { |
|
249 _err_and_die("$fname: invalid field: $_."); |
|
250 } |
|
251 } |
|
252 } |
|
253 |
|
254 |
|
255 # initialize module |
|
256 { |
|
257 # Initialise platform "0", wich represents the RVCT version found in the path. |
|
258 my $vsnworked = 0; # Flag to check if --vsn command worked |
|
259 # clear --licretry from RVCT22_CCOPT |
|
260 my $key; |
|
261 my %RVCT_CCOPT; |
|
262 foreach $key (keys %ENV) { |
|
263 if($key =~ /RVCT\d+_CCOPT/i ) { |
|
264 $RVCT_CCOPT{$key} = $ENV{$key}; |
|
265 $ENV{$key} =~ s/--licretry//i; |
|
266 } |
|
267 } |
|
268 my @lines = qx/armcc --vsn 2>&1/; |
|
269 |
|
270 foreach (@lines) |
|
271 { |
|
272 if ($_ =~ /\bRVCT(\d)\.(\d)\s+\[Build (\d+)\]/ ) |
|
273 { |
|
274 $vsnworked = 1; |
|
275 my ($bin, $inc, $lib) = ("RVCT$1$2BIN", "RVCT$1$2INC", "RVCT$1$2LIB"); |
|
276 |
|
277 $g_data{0}->{version} = "$1.$2.$3"; |
|
278 |
|
279 $g_data{0}->{bin_name} = $bin; |
|
280 $g_data{0}->{bin_path} = $ENV{$bin}; |
|
281 |
|
282 $g_data{0}->{inc_name} = $inc; |
|
283 $g_data{0}->{inc_path} = $ENV{$inc}; |
|
284 |
|
285 $g_data{0}->{lib_name} = $lib; |
|
286 $g_data{0}->{lib_path} = $ENV{$lib}; |
|
287 |
|
288 last; |
|
289 } |
|
290 } |
|
291 # In case --vsn doesn't work, call --version_number and setup environment variables |
|
292 if ($vsnworked == 0) |
|
293 { |
|
294 my @lines = qx/armcc --version_number 2>&1/; |
|
295 foreach (@lines) |
|
296 { |
|
297 if ($_ =~ /^(\d{1})(\d{1})\d{1}(\d{3})$/) |
|
298 { |
|
299 my ($bin, $inc, $lib) = ("RVCT$1$2BIN", "RVCT$1$2INC", "RVCT$1$2LIB"); |
|
300 $g_data{0}->{version} = "$1.$2.$3"; |
|
301 |
|
302 $g_data{0}->{bin_name} = $bin; |
|
303 $g_data{0}->{bin_path} = $ENV{$bin}; |
|
304 |
|
305 $g_data{0}->{inc_name} = $inc; |
|
306 $g_data{0}->{inc_path} = $ENV{$inc}; |
|
307 |
|
308 $g_data{0}->{lib_name} = $lib; |
|
309 $g_data{0}->{lib_path} = $ENV{$lib}; |
|
310 |
|
311 last; |
|
312 } |
|
313 } |
|
314 } |
|
315 |
|
316 # restore RVCT22_CCOPT |
|
317 foreach $key (keys %RVCT_CCOPT) { |
|
318 $ENV{$key} = $RVCT_CCOPT{$key}; |
|
319 } |
|
320 # Initialise all platforms defined in the INI file, if that file exists. |
|
321 |
|
322 my $fname = $ENV{ABLD_PLAT_INI}; |
|
323 |
|
324 if ($fname) # The environment variable is set. |
|
325 { |
|
326 _err_and_die("ABLD_PLAT_INI doesn't point to a file.") unless -f $fname; |
|
327 |
|
328 open (my $in, "<", $fname) or _err_and_die("couldn't open ABLD_PLAT_INI = $fname."); |
|
329 |
|
330 my @lines = (); |
|
331 my $format1 = 0; |
|
332 |
|
333 while (<$in>) |
|
334 { |
|
335 chomp; |
|
336 |
|
337 next if /^\s*;/ ; |
|
338 next if /^\s*#/ ; |
|
339 next if /^\s*$/ ; |
|
340 |
|
341 if ($_ =~ /^\s*\[/i) |
|
342 { |
|
343 # This must be the start of an INI section so We treat the file as |
|
344 # format 1. |
|
345 $format1 = 1; |
|
346 } |
|
347 |
|
348 push @lines, $_; |
|
349 } |
|
350 |
|
351 |
|
352 close $in or _err_and_die("couldn't close ABLD_PLAT_INI = $fname."); |
|
353 _err_and_die("$fname contains no data") unless @lines; |
|
354 |
|
355 if ($format1) |
|
356 { |
|
357 my $os_ver = _get_os_version(); |
|
358 my @lines2 = (); |
|
359 |
|
360 while (@lines) |
|
361 { |
|
362 my $line = shift @lines; |
|
363 |
|
364 if ( $line =~ /^\s*\[$os_ver\]/i) |
|
365 { |
|
366 last; |
|
367 } |
|
368 } |
|
369 |
|
370 while (@lines) |
|
371 { |
|
372 my $line = shift @lines; |
|
373 |
|
374 if ( $line =~ /^\s*\[/i) |
|
375 { |
|
376 last; |
|
377 } |
|
378 |
|
379 push @lines2, $line; |
|
380 } |
|
381 |
|
382 _parse_section_data($fname, @lines2); |
|
383 } |
|
384 else # Format 2. |
|
385 { |
|
386 # The file is one big section without header. |
|
387 _parse_section_data($fname, @lines); |
|
388 } |
|
389 |
|
390 } # if ($fname) |
|
391 } |
|
392 |
|
393 |
|
394 1; |
|
395 |
|
396 |