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