Added Build environment check feature
authorThomasE
Tue, 18 Aug 2009 09:22:36 +0100
changeset 359 61571c10c5d0
parent 358 881cbdd44910
child 360 16775fa40f8c
Added Build environment check feature
common/build.xml
common/tools/BuildEnv.xml
common/tools/BuildEnvXML.pm
common/tools/CheckBuildEnv.pl
--- a/common/build.xml	Mon Aug 17 14:26:30 2009 +0100
+++ b/common/build.xml	Tue Aug 18 09:22:36 2009 +0100
@@ -59,6 +59,15 @@
     <target name="sf-prep" depends="prep-drive,init-build-area,sf-generate-source-spec,check-tool-dependencies,create-bom,log-build-env">
         <echo>[SF-PREP]</echo>
         <tempfile property="prep.dynamic.config" suffix="ant.xml" destdir="${temp.build.dir}"/>
+		<echo message="Checking build Environment"/>
+          <exec executable="perl" dir="${sf.common.config.dir}/tools" failonerror="true">
+            <arg value="CheckBuildEnv.pl"/>
+            <arg value="--xml=BuildEnv.xml"/>
+            <arg value="--dbg=${build.log.dir}/BuildEnvironmentCheck.log"/>
+			<arg value="--sbs='${sf.spec.sbs.config}'"/>
+			<arg value="--tools='${sf.spec.sbs.tools.config}'"/>
+			<arg value="Common"/>
+          </exec>
     </target>
         
     <target name="sf-build-all" depends="sf-prebuild,sf-build-noprep,sf-postbuild">
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/common/tools/BuildEnv.xml	Tue Aug 18 09:22:36 2009 +0100
@@ -0,0 +1,160 @@
+<?xml version="1.0"?>
+<!DOCTYPE BuildEnv [
+
+        
+<!ELEMENT BuildEnv (context*)>
+    <!ATTLIST BuildEnv name CDATA #REQUIRED
+			revision CDATA #REQUIRED>
+
+<!ELEMENT context (context*, tool+)>
+    <!ATTLIST context id (system|p4|cbr) "system">
+
+<!ELEMENT tool (location?, verify*)>
+	<!ATTLIST tool name CDATA #REQUIRED>
+	<!ELEMENT location EMPTY>
+	<!ATTLIST location strict (true|false) "true" value CDATA #REQUIRED>
+	<!ELEMENT verify (check+)>
+	<!ATTLIST verify version CDATA #REQUIRED showstopper (true|false) "false">
+	<!ELEMENT check EMPTY>
+	<!ATTLIST check exclusive (false|true) "false"
+			 values  CDATA #REQUIRED
+			 locator CDATA #IMPLIED
+			 var     CDATA #IMPLIED
+			 execute CDATA #IMPLIED
+			 name    CDATA #IMPLIED
+			 silent	 (false|true) "false"
+			 log	 (false|true) "false">
+
+	]>
+
+
+<BuildEnv name="BuildEnv" revision="1">
+
+<!-- OS-dependant contexts -->
+<context id="Common">
+	<tool name="Perl">
+		<location strict="false" value="C:\apps\perl\bin\perl.exe"/>
+		<verify version="5.6.1" showstopper="true" >
+			<check name="version" execute="%location% -v" values="v5\.6\.1" locator="This is perl, (.*) built"/>
+			<check name="build" execute="%location% -v" values="build 633|build 635|build 638" locator="Binary (.*) provided by ActiveState" log="true"/>
+			<check name="module SAX version" execute="ppm query sax" values="0\.15" locator="XML-SAX \[(.*)\] Simple API" />
+        </verify>
+    </tool>
+    <tool name="Mercurial">
+		<location strict="false" value="C:\Apps\mercurial\hg.exe"/>
+		<verify version="1.2" showstopper="false">
+			<check name="version" execute="%location% version" values="1\.2\.[1-9]" locator="Mercurial Distributed SCM \(version ([0-9\.]*)\)"/>
+        </verify>
+    </tool>
+    <tool name="Python">
+		<location strict="false" value="c:\apps\python25\python.exe"/>
+		<verify version="2.5" showstopper="false">
+			<check name="version" execute="%location% -V" values="2\.5\.[0-9]" locator="Python (.*)"/>
+        </verify>
+    </tool>
+    <tool name="Java Compiler">
+		<location strict="false" value="C:\apps\jdk1.6.0_14\bin\javac"/>
+		<verify version="1.6" showstopper="true">
+			<check var="JAVA_6_HOME" values="jdk1\.6"/>
+			<check name="version" execute="%JAVA_6_HOME%\bin\javac -version" values="1\.6\.[0-9]_[0-9]+" locator="javac (.*)"/>
+		</verify>
+		<verify version="default" showstopper="false">
+			<check var="JAVA_HOME" values="jdk1\.6"/>
+		</verify>
+    </tool>
+	<tool name="7-Zip">
+		<location strict="false" value="C:\apps\7-zip\7z.exe"/>
+		<verify version="4.65" showstopper="false">
+			<check name="version" execute="%location% -h" values="4\.65" locator="7-Zip (.*)  Copyright"/>
+		</verify>
+    </tool>
+	<tool name="PDT Home">
+		<location strict="false" value="C:\Symbian\Tools\PDT_1.0\helium\hlm.bat"/>
+		<verify version="1.0 [beta]" showstopper="false">
+			<check var="PDT_HOME" values="\\Tools\\PDT_\d"/>
+		</verify>
+    </tool>
+	<tool name="EPOC">
+		<verify version="Environment Vars" showstopper="true">
+			<check var="EPOCROOT" values="^\\$"/>
+			<check var="PATH" values=";\\epoc32\\tools;" silent="true"/>
+		</verify>
+    </tool>
+	<tool name="Helium">
+		<location strict="false" value="C:\Symbian\Tools\PDT_1.0\helium\hlm.bat"/>
+		<verify version="4.0 [patched]" showstopper="true">
+			<check var="HELIUM_HOME" values="[CD]:\\Symbian\\Tools\\PDT_1.0\\helium"/>
+			<check name="version" execute="%HELIUM_HOME%\hlm.bat -f %HELIUM_HOME%\build.xml version" values="4\.0" locator="Helium version: ([\d\.]+)"/>
+		</verify>
+    </tool>
+	<tool name="Raptor">
+		<location strict="false" value="C:\apps\raptor2.7.2\bin\sbs.bat"/>
+		<verify version="2.7.2 [patched]" showstopper="true">
+			<check var="SBS_HOME" values="apps\\raptor"/>
+			<check name="version" execute="%SBS_HOME%\bin\sbs.bat -version" values="2\.7\.2" locator="sbs version (.*) \["/>
+			<check name="patch" execute="%SBS_HOME%\win32\python252\python.exe -V" values="2\.5\.4"/>
+		</verify>
+    </tool>
+</context>
+
+<context id="ARMv5">
+    <tool name="RVCT ARM Compiler">
+		<location strict="false" value="C:\apps\arm\RVCT2.2[616]\RVCT\Programs\2.2\349\win_32-pentium\armcc.exe"/>
+		<verify version="2.2" showstopper="true">
+			<check name="version" execute="%location% --help" values="RVCT2\.2\ \[Build 616\]" log="false" locator="ARM\/Thumb C\/C\+\+ Compiler, (.*)Usage"/>
+			<!-- <check execute="%RVCT22BIN%\armcc.exe" values="616" log="false"/> -->
+			<check var="RVCT22BIN" values="RVCT\\Programs\\2\.2\\349\\win_32-pentium" silent="true"/>
+			<check var="RVCT22INC" values="RVCT\\Data\\2\.2\\349\\include\\windows" silent="true"/>
+			<check var="RVCT22LIB" values="RVCT\\Data\\2\.2\\349\\lib" silent="true"/>
+			<check var="ARMLMD_LICENSE_FILE" values="8224@LON-ENGBUILD8[79]|8224@C10072[56]"/>
+		</verify>
+		<verify version="2.2 [options]" showstopper="false">
+			<check var="RVCT22_ASMOPT" values="--licretry" silent="true"/>
+			<check var="RVCT22_CCOPT" values="--licretry" silent="true"/>
+			<check var="RVCT22_LINKOPT" values="--licretry" silent="true"/>
+		</verify>
+    </tool>
+</context>
+
+<context id="Test">
+	<tool name="cURL">
+		<location strict="false" value="C:\apps\curl_7.18.2\curl.exe"/>
+		<verify version="7.18.2" showstopper="false">
+			<check name="version" execute="%location% -V" values="7\.18\.2" locator="curl (.*) \(i386-pc-win32\)"/>
+		</verify>
+    </tool>
+	<tool name="Junction">
+		<location strict="true" value="C:\Bin\junction.exe"/>
+		<verify version="1.0.5" showstopper="true">
+			<check name="version - local" execute="%location%" values="v1\.05" locator="Junction (.*) - Windows junction creator"/>
+			<check execute="junction - system" values="v1\.05" locator="Junction (.*) - Windows junction creator"/>
+		</verify>
+    </tool>
+	<tool name="ATS3 Worker">
+		<location strict="true" value="C:\apps\ats3\bin\STAFEnv.bat"/>
+		<verify version="7.18.2" showstopper="false">
+			<check execute="%location%" values=".*"/>
+			<check var="ATS3_HOME" values="\w:\\\w+"/>
+		</verify>
+    </tool>
+</context>
+
+<context id="Tools">
+    <tool name="Microsoft Visual C++ compiler">
+		<location strict="false" value="C:\apps\MSVC6\VC98\bin\vcvars32.bat"/>
+		<verify version="6.00" showstopper="false">
+			<check var="PATH" values="MSVC6\\Common\\MSDev98\\bin" silent="true"/>
+			<check var="PATH" values="MSVC6\\Common\\Tools\\WinNT" silent="true"/>
+			<check var="PATH" values="MSVC6\\Common\\Tools" silent="true"/>
+			<check var="PATH" values="MSVC6\\VC98\\bin" silent="true"/>
+			<check var="INCLUDE" values="MSVC6\\VC98\\atl\\include" silent="true"/>
+			<check var="INCLUDE" values="MSVC6\\VC98\\mfc\\include" silent="true"/>
+			<check var="INCLUDE" values="MSVC6\\VC98\\include" silent="true"/>
+			<check var="LIB" values="MSVC6\\VC98\\mfc\\lib" silent="true"/>
+			<check var="LIB" values="MSVC6\\VC98\\lib" silent="true"/>
+			<check var="MSDEVDIR" values="msvc6\\Common\\MSDev98" silent="true"/>
+		</verify>
+    </tool>
+</context>
+
+</BuildEnv>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/common/tools/BuildEnvXML.pm	Tue Aug 18 09:22:36 2009 +0100
@@ -0,0 +1,386 @@
+## @file BuildEnvXML.pm
+# @ingroup userscripts clientscripts
+#
+# Uses information which is defined in the BuildEnvXML.xml to set up a machine
+# specific environment, such as path for compilers. 
+#
+# @todo Document this script.
+#
+# Copyright (c) 2009 Symbian Foundation  Ltd. All rights reserved.
+#
+
+package BuildEnvXML;
+use strict;
+use XML::DOM;
+use Cwd;
+use Exporter;
+our @ISA = qw(Exporter);
+our @EXPORT_OK = qw(&getToolEnvironment &getLastErrorMsg &setDbgFile);
+
+my $sToolEnv  = "";
+my $sLocalDir = cwd();
+my $hParser      = XML::DOM::Parser->new();
+my $sErrorMsg = "";
+my $toolSummary = "";
+my $execLog = "";
+my $dbgfile = "";
+
+sub getToolEnvironment
+{
+ my $sBuildEnvXML = shift;
+ my (@aCat) = @_;
+
+ my $hXMLfile     = $hParser->parsefile ($sBuildEnvXML);
+ my $hNodes = $hXMLfile->getElementsByTagName ("context");
+ my $hSystemTools, my $hP4Tools, my $hCBRTools, my $sCat, my $nNumNodes;
+ 
+ if ($dbgfile ne "")
+ {
+	print "Logging output to file $dbgfile\n";
+	open DBGFILE, ">>$dbgfile" or die; 
+ }
+
+ $sErrorMsg = "";
+ $sToolEnv  = "";
+ my $nCatDepth = scalar(@aCat);
+ subTrace("Context Depth: $nCatDepth\n");
+ my $nLevel = ($nCatDepth-1);
+ $sCat = $aCat[$nLevel];
+ $nNumNodes = $hNodes->getLength;
+
+ my $hParentNode, my $sParentId;
+ for (my $nI = 0; $nI < $nNumNodes ; $nI++)
+ {
+     my $hNode = $hNodes->item ($nI);
+     my $hId = $hNode->getAttributeNode ("id");
+     # Discriminating Stages
+     subTrace("Context found: \"".$hId->getValue()."\"");
+     if (uc($hId->getValue()) eq uc($sCat))
+     {
+     	subTrace("---> requested! analyzing...");
+     	$hParentNode = $hNode->getParentNode;
+	     for (;$nLevel>0;$nLevel--)
+	     {
+		    $sParentId = $hParentNode->getAttributeNode("id")->getValue;
+	    	subTrace("...from Parent context= ".$sParentId);
+		    if ($sParentId ne $aCat[$nLevel-1]){ $nLevel =-1;}
+		    $hParentNode = $hParentNode->getParentNode;
+	     };
+	     if (($nLevel>-1)&&($hParentNode->getNodeName ne "context"))
+	     {
+		     $hSystemTools = $hNode->getElementsByTagName ("tool", 0);
+		     $nI = $nNumNodes;
+	     }
+     }
+ }
+ if (!defined $hSystemTools)
+ {
+	 subTrace("No Stage found for category $sCat !");
+	 subTrace("Program Terminated.");
+	 exit(0);
+ }
+ subTrace(""); 
+ subTrace("----------------------");
+ subTrace("Number of $sCat tools: ".$hSystemTools->getLength);
+ for (my $nI = 0; $nI < $hSystemTools->getLength; $nI++)
+ {
+     my $hTool     = $hSystemTools->item ($nI);
+     my $hToolName = $hTool->getAttributeNode ("name");
+     subTrace("");
+     subTrace("----------------------");
+     subTrace("Verifying tool: ".$hToolName->getValue());
+	 my $isToolNotFound = "true";
+
+     # Location element
+     my $hToolLocation = $hTool->getElementsByTagName("location")->item(0);
+     my $hToolLocationPath, my $hToolLocationStrict;
+     if (defined $hToolLocation)
+     {
+             $hToolLocationPath   = $hToolLocation->getAttributeNode("value");
+             $hToolLocationStrict = $hToolLocation->getAttributeNode("strict");
+	     subTrace("Expected Location: ".$hToolLocationPath->getValue());    
+     }
+
+     # Verify element
+	 my $hToolVerifys           = $hTool->getElementsByTagName("verify");
+	 my $nNumOfVerifys			= $hToolVerifys->getLength;
+	 for (my $nZ = 0; $nZ < $nNumOfVerifys; $nZ++)
+	 {
+		 my $hToolVerify            = $hTool->getElementsByTagName("verify")->item($nZ);
+		 my $hToolVerifyVersion     = $hToolVerify->getAttributeNode("version");
+		 my $hToolVerifyShowStopper = $hToolVerify->getAttributeNode("showstopper");
+		 subTrace("Expected Version: ".$hToolVerifyVersion->getValue());    
+		 subPrint("\nVerifying tool: ".$hToolName->getValue()." (version ".$hToolVerifyVersion->getValue().")\n");
+		 
+		 # Tool checks
+		 my $hToolChecks = $hToolVerify->getElementsByTagName("check");
+		 my $nNumOfChecks= $hToolChecks->getLength;
+		 my $nCheckNum;
+		 for (my $nJ = 0; $nJ < $nNumOfChecks; $nJ++)
+		 {
+			 $nCheckNum = $nJ+1;
+			 subTrace("");
+			 subTrace("Check #$nCheckNum:");
+			 subPrint("Check #$nCheckNum");
+			 my $hCheck = $hToolChecks->item($nJ);
+			 my $hCheckCmd    = $hCheck->getAttributeNode ("execute");
+			 my $hCheckVar    = $hCheck->getAttributeNode ("var");
+			 my $hCheckValues = $hCheck->getAttributeNode ("values");
+			 my $hCheckLog    = $hCheck->getAttributeNode ("log");
+			 my $hCheckExclu  = $hCheck->getAttributeNode ("exclusive");
+			 my $hCheckName   = $hCheck->getAttributeNode ("name");
+			 my $hCheckLocator= $hCheck->getAttributeNode ("locator");
+			 my $hCheckSilent = $hCheck->getAttributeNode ("silent");
+			 my $sCommand, my $sPattern, my $sToolCmd, my $sOut, my $sOutLocal, my $sCheckName;
+			 my $versionFound = "";
+			 my $sMsg = "";
+			 # If Check is exclusive, we will only test this one:
+			 if ($hCheckExclu->getValue() eq "true")
+			 {
+				 $nJ = $nNumOfChecks;
+				 subTrace("This check is exclusive: the remaining checks will not be tested");
+			 }
+			 # Preparing system command to execute
+			 if (defined $hCheckCmd) 
+			 {
+				 $sCommand = $hCheckCmd->getValue();
+				 if (defined $hToolLocation)
+				 {
+					 $sToolCmd= $hToolLocationPath->getValue();
+					 $sCommand =~ s/\%location\%/$sToolCmd/g;
+				 }
+				 
+				 # Execute the command
+				 subTrace("Check cmd: ".$sCommand."");
+				 $sOut = `$sCommand 2>&1`;
+				 $sOutLocal = $sOut;
+				 
+				 # Check if tool cannot be found at expected location
+				 if ($sOut =~/(not\srecognized)|(system\scannot\sfind)/)
+				 {
+					 $sOutLocal = "";
+					 subTrace("Tool cannot be found at location: ".$hToolLocationPath->getValue());
+					 subLogErrorMsg($hToolLocationStrict->getValue(), $hToolName->getValue()." CANNOT BE FOUND IN THE EXPECTED LOCATION: "
+								 .$hToolLocationPath->getValue());
+					 if ($hToolLocationStrict->getValue() eq "true")
+					 {
+						 subTrace("LOCATION STRICT activated, program terminated");
+						 $sMsg .= "[ERROR] wrong location\n";
+						 #return "";
+					 }
+					 else
+					 {
+						 $sMsg .= "[WARNING] wrong location\n";
+					 }	 
+				 }
+				 else
+				 {
+					 if ((defined $hToolLocation)&&(defined $hCheckCmd))
+					 {
+						$sCommand =~ /(.*)(\\).*$/i;
+						my $sTmp  = $1;
+						$sTmp =~ s/^\s+//;
+						$sTmp =~ s/\s+$//;
+						$sToolEnv = $sTmp.";".$sToolEnv;
+						subTrace("Tool path OK.");
+						subTrace("New appender: \"".$sToolEnv."\"");
+					 }
+					 $isToolNotFound = "false";
+				 }
+				 
+				 # Check if tool can be found with the Environment PATH
+				 $sCommand =~ s/.*(\\)(.*)$/\2/i;
+				 subTrace("Try command from ENV PATH: ".$sCommand);
+				 if (!defined $hCheckName) 
+				 {
+					$sCheckName = $sCommand;
+				 }
+				 else
+				 {
+					$sCheckName = $hCheckName->getValue();
+				 }
+				 subPrint(" [$sCheckName]: ");
+				 $sOut = `$sCommand 2>&1`;
+				 if ($sOut =~/(not\srecognized)|(system\scannot\sfind)/)
+				 {
+					 $sOut = "";
+					 my $type = "ERROR";
+					 if ($isToolNotFound eq "false") {$type = "WARNING";}
+					 subTrace("$type: ".$hToolName->getValue()." CANNOT BE FOUND IN THE SYSTEM PATH");
+					 subLogErrorMsg($isToolNotFound, $hToolName->getValue()." CANNOT BE FOUND IN THE SYSTEM PATH");
+					 $sMsg .= "[$type] NOT FOUND IN SYSTEM PATH\n";
+					 if ($isToolNotFound eq "true") {next;}
+					 #return "";
+				 }
+			 }
+			 else
+			 {	 # Check by verifying an env variable
+				 subPrint(" [".$hCheckVar->getValue()."]: ");
+				 $sCommand = "ECHO %".$hCheckVar->getValue()."%";
+				 subTrace("Check var: ".$hCheckVar->getValue());		     
+				 $sOut = `$sCommand 2>&1`;
+				 $sOut =~ s/^\s*//;
+				 $sOut =~ s/\s*$//;
+			 }
+			 
+			 # Log the output if necessary 
+			 if ($hCheckLog->getValue() eq "true")
+			 {
+					 subTrace("command: $sCommand");
+					 subTrace("logged output: ");
+					 subLog("Verifying \"".$hToolName->getValue()." [version ".$hToolVerifyVersion->getValue().
+					 "]\" -- check #$nCheckNum:");
+					 subLog("Executing: $sCommand");
+					 subLog($sOut);
+			 }
+			 
+			 # Perform the check against given values
+			 if (defined $hCheckValues)
+			 {
+				 my $sOutCopy = $sOut;
+				 my $bResultOk = "false";
+				 $sPattern = $hCheckValues->getValue();
+				 if (defined $hCheckLocator)
+				 {
+					 my $sLocator = $hCheckLocator->getValue();
+					 $sOut =~ s/.*$sLocator.*/\1/msi;
+					 subTrace("Searching in locator: ".$sOut);
+					 $sOutLocal =~ s/.*$sLocator.*/\1/msi;
+				 }
+				 else
+				 {
+					$sOut =~ s/.*($sPattern).*/\1/smi;
+					$sOutLocal =~ s/.*($sPattern).*/\1/smi;
+				 }
+				 
+				# Log the current version found
+				$versionFound = $sOut.$sOutLocal;
+				if ($sOut eq $sOutLocal)
+				{
+					$versionFound = $sOut;
+				}
+				elsif (($sOut.$sOutLocal ne $sOut) and ($sOut.$sOutLocal ne $sOutLocal) and ($sOut ne $sOutLocal))
+				{
+					$versionFound = "$sOut or $sOutLocal [Value Mismatch]";
+				}
+				if ($versionFound eq "") {$versionFound = "not found";}
+				 
+				 #$sPattern =~ s/(\\|\/|\.|\*|\[|\]|\(|\)|\$|\{|\})/\\\1/g;
+				 #$sPattern = "($sPattern)";
+				 subTrace("Check against pattern: ".$sPattern);
+				 # Check the Environment Variable
+				 if (defined $hCheckVar)
+				 {
+				    $sOut = $sOutCopy;
+					my $valueTested = $hCheckVar->getValue();
+					if ($sOut =~ /%$valueTested%/) {$sOut = "not defined!";}
+					elsif ( $sOut =~ m/$sPattern/smi )
+					{
+						$bResultOk = "true";
+						if ($hCheckSilent->getValue() eq "true") { $sOut = "ok. ";}
+					}
+					$versionFound = "$sOut";
+				 } # Or Check the command executed (for version checking...)
+				 elsif ( ( ( $sOut =~ s/.*($sPattern).*/\1/smi ) and (( $sOutLocal =~ s/.*($sPattern).*/\1/smi ) or ($sOutLocal eq "")) ) || 
+				      ( ( $sOutLocal =~ s/.*($sPattern).*/\1/smi ) and ($sOut eq "") ) )
+				 {
+					$bResultOk = "true";
+					subTrace("Value OK");
+					if ($versionFound eq "" || $hCheckSilent->getValue() eq "true") { $versionFound = "ok. ";}
+					
+				 }
+				 elsif (!defined $hCheckLocator)
+				 {
+					$versionFound = "";
+				 }
+
+				 # Log the warnings/errors regarding version checking
+				 if ($bResultOk eq "false")
+				 {
+					 if ($versionFound eq "") { $versionFound = "wrong value. ";}
+					 subTrace("ERROR: VALUE CHECK FAILED");
+					 subLogErrorMsg($hToolVerifyShowStopper->getValue(), $hToolName->getValue()." VALUE INCORRECT");
+					 if ($hToolVerifyShowStopper->getValue() eq "true")
+					 {
+						 $sMsg .= "[ERROR] WRONG VALUE\n";
+						 subTrace("SHOWSTOPPER RAISED: program should be terminated");
+					 }
+					 else
+					 {
+						 subTrace("No Showstopper, continuing analysis...");
+						 $sMsg .= "[WARNING] Wrong Value\n";
+					 }
+					 
+				 }
+			 }
+			 chomp($versionFound);
+			 &subPrint ("$versionFound\n$sMsg");
+			 &printToolSummary;
+			 &printLog;
+		 }		
+	 }
+
+     
+ }
+ close DBGFILE;
+ return $sToolEnv;
+}
+
+sub subTrace
+{
+  my $sString = $_[0];
+  if ($dbgfile ne "")
+  {
+	print DBGFILE "$sString\n";
+  }
+}
+
+sub subPrint
+{
+  my $sString = $_[0];
+  $toolSummary .= "$sString";
+}
+
+sub printToolSummary
+{
+  print $toolSummary."\n";
+  $toolSummary="";
+}
+
+sub subLog
+{
+  my $sString = $_[0];
+  $execLog .= "[LOG] $sString\n";
+  
+  if ($dbgfile ne "")
+  {
+	print DBGFILE "[LOG] $sString\n";
+  }
+}
+
+sub printLog
+{
+  #print $execLog;
+  $execLog="";
+}
+
+sub subLogErrorMsg
+{
+  my $isError = shift;
+  my $msg = shift;
+  my $type = "WARNING";
+  if ($isError eq "true") {$type = "ERROR";} 
+  $sErrorMsg = $sErrorMsg."\n[$type] ".$msg;
+}
+
+sub getLastErrorMsg
+{
+  return $sErrorMsg;
+}
+
+sub setDbgFile
+{
+  $dbgfile = shift;
+}
+
+1;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/common/tools/CheckBuildEnv.pl	Tue Aug 18 09:22:36 2009 +0100
@@ -0,0 +1,73 @@
+## @file BuildEnvXML.pl
+# @ingroup userscripts clientscripts
+#
+# Uses information which is defined in the BuildEnvXML.xml to set up a machine
+# specific environment, such as path for compilers. 
+#
+# @todo Document this script.
+#
+# Copyright (c) 2009 Symbian Foundation  Ltd. All rights reserved.
+#
+
+package BuildEnvXML;
+
+use Getopt::Long;
+use BuildEnvXML qw(&getToolEnvironment &getLastErrorMsg);
+
+my $toolenvxml = "";
+my $dbgfile = "";
+my $sbsconfig = "";
+my $toolsconfig = "";
+
+GetOptions ("xml=s" => \$toolenvxml, "dbg:s" => \$dbgfile, "sbs:s" => \$sbsconfig, "tools:s" => \$sbsconfig); 
+
+my @contexts = @ARGV;
+
+if ($toolenvxml eq "")
+{
+	print ("ERROR: XML file cannot be found!\n");
+}
+
+# Checking the SBS config to test only what's necessary for that build
+if ($sbsconfig =~ /armv5/i)
+{
+	push @contexts, "ARMv5";
+}
+
+# Checking the tools config to test only what's necessary for that build
+if ($sbsconfig =~ /tools[^2]?(,|$|_)/i)
+{
+	push @contexts, "tools";
+}
+
+my $sErrMsg;
+my $result = 0;
+
+if (-e $dbgfile)
+{
+	unlink($dbgfile);
+}
+
+&setDbgFile($dbgfile);
+
+foreach my $context (@contexts){
+	print "\n\n### Checking $context Tools ###\n";
+	my $sSystemPath = &getToolEnvironment($toolenvxml, $context);
+
+	$sErrMsg = &getLastErrorMsg;
+	if ($sErrMsg eq "") { $sErrMsg = "\nAll OK.\n";}
+	if($sErrMsg =~ /ERROR/)
+	{
+		print "\n$context Tools VERIFICATION FAILED:";
+		print $sErrMsg."\n\n";
+		$result = -1;
+	}else{
+		print "\n$context tools VERIFICATION PASSED:";
+		print $sErrMsg."\n\n";
+	}
+}
+if ($result ne 0)
+{
+	print "\n ==> PROGRAM STOPPED!!\n";
+}
+exit($result);