common/tools/envinfo.pl
changeset 884 18fc0e69c5b8
child 888 5cd45cbf7622
equal deleted inserted replaced
883:1281d0f13d9b 884:18fc0e69c5b8
       
     1 # Copyright (c) 2009 Symbian Foundation Ltd
       
     2 # This component and the accompanying materials are made available
       
     3 # under the terms of the License "Eclipse Public License v1.0"
       
     4 # which accompanies this distribution, and is available
       
     5 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     6 #
       
     7 # Initial Contributors:
       
     8 # Symbian Foundation Ltd - initial contribution.
       
     9 #
       
    10 # Contributors:
       
    11 #
       
    12 # Description:
       
    13 # Dumps environment info such as tools version to cmdline then to a Diamonds file
       
    14 
       
    15 use strict;
       
    16 
       
    17 use Getopt::Long;
       
    18 
       
    19 my $output = "\\output\\logs\\diamonds_envinfo.xml";
       
    20 my $help = 0;
       
    21 GetOptions((
       
    22 	'out=s' => \$output,
       
    23 	'help!' => \$help
       
    24 ));
       
    25 
       
    26 if ($help)
       
    27 {
       
    28 	print "Dumps environment info such as tools version to cmdline then to a Diamonds file\n";
       
    29 	print "Usage: perl envinfo.pl --out=XMLFILE\n";
       
    30 	print "\n";
       
    31 	print "XMLFILE is optional, its default is \\output\\logs\\diamonds_envinfo.xml\n";
       
    32 	exit(0);
       
    33 }
       
    34 
       
    35 my @environment_info = ();
       
    36 
       
    37 # Machine name
       
    38 push @environment_info, {name=>'Machine', version=>$ENV{'COMPUTERNAME'}};
       
    39 
       
    40 # OS Name and Version
       
    41 my $os_name = 'N.A.';
       
    42 my $os_ver = 'N.A.';
       
    43 my $os_out = `systeminfo`;
       
    44 $os_name = $1 if ($os_out =~ /^OS Name:\s+(.*)/m);
       
    45 $os_ver = $1 if ($os_out =~ /^OS Version:\s+(.*)/m);
       
    46 push @environment_info, {name=>'OS Name', version=>$os_name};
       
    47 push @environment_info, {name=>'OS Version', version=>$os_ver};
       
    48 
       
    49 # Perl
       
    50 my $perl_ver = 'N.A.';
       
    51 my $perl_out = `perl -v`;
       
    52 $perl_ver = $1 if ($perl_out =~ /This is perl, v(\S+)/m);
       
    53 push @environment_info, {name=>'Perl', version=>$perl_ver};
       
    54 
       
    55 # Python
       
    56 my $python_ver = 'N.A.';
       
    57 my $python_out = `python -V 2>&1`;
       
    58 $python_ver = $1 if ($python_out =~ /^Python\s+(\S+)/m);
       
    59 push @environment_info, {name=>'Python', version=>$python_ver};
       
    60 
       
    61 # Mercurial
       
    62 my $hg_ver = 'N.A.';
       
    63 my $hg_out = `hg --version`;
       
    64 $hg_ver = $1 if ($hg_out =~ /^Mercurial Distributed SCM \(version ([^)]+)\)/m);
       
    65 push @environment_info, {name=>'Mercurial', version=>$hg_ver};
       
    66 
       
    67 # 7-Zip
       
    68 my $zip_ver = 'N.A.';
       
    69 my $zip_out = `7z`;
       
    70 $zip_ver = $1 if ($zip_out =~ /^7-Zip\s+(\S+)\s+Copyright/m);
       
    71 push @environment_info, {name=>'7-Zip', version=>$zip_ver};
       
    72 
       
    73 # Raptor
       
    74 my $sbs_ver = 'N.A.';
       
    75 my $sbs_out = `sbs -v`;
       
    76 $sbs_ver = $1 if ($sbs_out =~ /^sbs version (.*)/m);
       
    77 push @environment_info, {name=>'sbs', version=>$sbs_ver};
       
    78 
       
    79 # Metrowerk Compiler
       
    80 my $mwcc_ver = 'N.A.';
       
    81 my $mwcc_out = `mwccsym2 -version`;
       
    82 $mwcc_ver = $1 if ($mwcc_out =~ /^Version (.*) \(Build/m);
       
    83 push @environment_info, {name=>'mwccsym2', version=>$mwcc_ver};
       
    84 
       
    85 # RVCT 2.2
       
    86 my $rvct22_ver = 'N.A.';
       
    87 my $rvct22_path = '';
       
    88 if (defined $ENV{'SBS_RVCT22BIN'})
       
    89 {
       
    90 	$rvct22_path = $ENV{'SBS_RVCT22BIN'};
       
    91 }
       
    92 elsif (defined $ENV{'RVCT22BIN'})
       
    93 {
       
    94 	$rvct22_path = $ENV{'RVCT22BIN'};
       
    95 }
       
    96 my $rvct22_cmd = 'armcc 2>&1';
       
    97 $rvct22_cmd = "$rvct22_path\\$rvct22_cmd" if ($rvct22_path);
       
    98 my $rvct22_out = `$rvct22_cmd`;
       
    99 $rvct22_ver = $1 if ($rvct22_out =~ m#ARM/Thumb C/C\+\+ Compiler, RVCT2.2 (.*)#m);
       
   100 push @environment_info, {name=>'RVCT2.2', version=>$rvct22_ver};
       
   101 
       
   102 # RVCT 4.0
       
   103 my $rvct40_ver = 'N.A.';
       
   104 my $rvct40_path = '';
       
   105 if (defined $ENV{'SBS_RVCT40BIN'})
       
   106 {
       
   107 	$rvct40_path = $ENV{'SBS_RVCT40BIN'};
       
   108 }
       
   109 elsif (defined $ENV{'RVCT40BIN'})
       
   110 {
       
   111 	$rvct40_path = $ENV{'RVCT40BIN'};
       
   112 }
       
   113 my $rvct40_cmd = 'armcc 2>&1';
       
   114 $rvct40_cmd = "$rvct40_path\\$rvct40_cmd" if ($rvct40_path);
       
   115 my $rvct40_out = `$rvct40_cmd`;
       
   116 $rvct40_ver = $1 if ($rvct40_out =~ m#ARM C/C\+\+ Compiler, RVCT4.0 (.*)#m);
       
   117 push @environment_info, {name=>'RVCT4.0', version=>$rvct40_ver};
       
   118 
       
   119 # GCCE 4.4.1
       
   120 my $gcc441_ver = 'N.A.';
       
   121 my $gcc441_path = '';
       
   122 if (defined $ENV{'SBS_GCCE441BIN'})
       
   123 {
       
   124 	$gcc441_path = $ENV{'SBS_GCCE441BIN'};
       
   125 }
       
   126 elsif (defined $ENV{'GCCE441BIN'})
       
   127 {
       
   128 	$gcc441_path = $ENV{'GCCE441BIN'};
       
   129 }
       
   130 if ($gcc441_path)
       
   131 {
       
   132 	my $gcc441_cmd = "$gcc441_path\\arm-none-symbianelf-g++ -dumpversion";
       
   133 	my $gcc441_out = `$gcc441_cmd`;
       
   134 	$gcc441_ver = "4.4.1" if ($gcc441_out =~ /4.4.1/);
       
   135 }
       
   136 push @environment_info, {name=>'GCC4.4.1', version=>$gcc441_ver};
       
   137 
       
   138 
       
   139 for my $tool_info (@environment_info)
       
   140 {
       
   141 	print $tool_info->{name} . ": " . $tool_info->{version} . "\n";
       
   142 }
       
   143 
       
   144 
       
   145 # write diamonds file
       
   146 
       
   147 @environment_info = reverse(@environment_info);
       
   148 
       
   149 my $xml_content = <<_EOX;
       
   150 
       
   151 <?xml version=\"1.0\" encoding=\"UTF-8\"?>
       
   152 <diamonds-build>
       
   153  <schema>10</schema>
       
   154   <tools>        
       
   155 _HERE_TOOLS_LINES_
       
   156   </tools>
       
   157 </diamonds-build>
       
   158 _EOX
       
   159 
       
   160 my $tools_lines = '';
       
   161 for my $tool_info (@environment_info)
       
   162 {
       
   163 	$tools_lines .= "   <tool><name>$tool_info->{name}</name><version>$tool_info->{version}</version></tool>\n";
       
   164 }
       
   165 
       
   166 $xml_content =~ s/_HERE_TOOLS_LINES_/$tools_lines/;
       
   167 
       
   168 if (open(ENVINFO, ">$output"))
       
   169 {
       
   170 	print ENVINFO $xml_content;
       
   171 	close(ENVINFO);
       
   172 	print "Wrote Diamonds file: $output\n";
       
   173 }
       
   174 else
       
   175 {
       
   176 	warn "Could not write to file: $output\n";
       
   177 }