fix ou1cimx1#651819 rofsbiuld fails to generate correct log info when using multi-thread
authormarvin shi <marvin.shi@nokia.com>
Fri, 19 Nov 2010 13:37:08 +0800
changeset 698 e3ee96a3961c
parent 697 818fe0ed324b
child 700 c22eff170fac
fix ou1cimx1#651819 rofsbiuld fails to generate correct log info when using multi-thread
imgtools/romtools/group/release.txt
imgtools/romtools/rofsbuild/r_build.cpp
imgtools/romtools/rofsbuild/r_rofs.cpp
imgtools/romtools/rofsbuild/r_romnode.h
imgtools/romtools/rofsbuild/rofsbuild.cpp
imgtools/romtools/rombuild/rombuild.cpp
--- a/imgtools/romtools/group/release.txt	Thu Nov 18 16:02:32 2010 +0800
+++ b/imgtools/romtools/group/release.txt	Fri Nov 19 13:37:08 2010 +0800
@@ -1,4 +1,8 @@
-
+Version 2.17.1 (ROFSBUILD)
+===============
+Released by Marvin Shi, 19/11/2010
+	1) ou1cimx1#651819 rofsbiuld fails to generate correct log info when using multi-thread 
+
 Version 2.19.0 (ROMBUILD)
 ===============
 Released by Marvin Shi, 17/11/2010
--- a/imgtools/romtools/rofsbuild/r_build.cpp	Thu Nov 18 16:02:32 2010 +0800
+++ b/imgtools/romtools/rofsbuild/r_build.cpp	Fri Nov 19 13:37:08 2010 +0800
@@ -68,6 +68,9 @@
 extern TInt  gLogLevel;
 extern bool gCache;
 extern TBool gIsOBYUTF8;
+
+#define MAX_LINE  65535
+
 TBool gDriveImage=EFalse;	// for drive image support.
 
 
@@ -789,6 +792,18 @@
 		}
 	iNextNodeForSameFile = aPreviousNode;
 	}
+void TRomNode::FlushLogMessages()
+	{
+	if(iEntry)
+		{
+		for(int i = 0; i < (int)iEntry->iLogMessages.size(); i++)
+			{
+			TLogItem& aLogItem = iEntry->iLogMessages[i];
+			Print(aLogItem.iPrintType, aLogItem.iLogMessage.c_str());
+			}
+		iEntry->iLogMessages.clear();
+		}
+	}
 
 
 
@@ -862,13 +877,23 @@
 // Returns the number of bytes used, or -ve error code
 TInt TRomBuilderEntry::PlaceFile( TUint8* &aDest,TUint aMaxSize, CBytePair *aBPE ){
 
-
+	char tmpbuf[MAX_LINE];
+	TLogItem tmpLog;
 	TUint compression = 0;
 	TBool executable = iExecutable;
-	Print(ELog,"Reading file %s to image\n", iFileName );
+	sprintf(tmpbuf,"Reading file %s to image\n", iFileName );
+	tmpLog.iPrintType = ELog;
+	tmpLog.iLogMessage = tmpbuf;
+	iLogMessages.push_back(tmpLog);
+
 	TUint32 size = HFile::GetLength(iFileName);
 	if (size==0)
-		Print(EWarning, "File %s does not exist or is 0 bytes in length.\n",iFileName);
+	{
+		sprintf(tmpbuf, "File %s does not exist or is 0 bytes in length.\n",iFileName);
+		tmpLog.iPrintType = EWarning;
+		tmpLog.iLogMessage = tmpbuf;
+		iLogMessages.push_back(tmpLog);
+	}
 	if (aDest == NULL) {
 		aMaxSize = size << 1;
 		aMaxSize = (aMaxSize>0) ? aMaxSize : 2;
@@ -890,7 +915,10 @@
 		// is it really a valid E32ImageFile?
 		if (r != KErrNone)
 		{
-			Print(EWarning, "File '%s' is not a valid executable.  Placing file as data.\n", iFileName);
+			sprintf(tmpbuf, "File '%s' is not a valid executable.  Placing file as data.\n", iFileName);
+			tmpLog.iPrintType = EWarning;
+			tmpLog.iLogMessage = tmpbuf;
+			iLogMessages.push_back(tmpLog);
 			executable = EFalse;
 		}
 		else
@@ -912,7 +940,10 @@
 				while( aDllEntry ){
 					if(aDllEntry->iOrdinal != (TUint32)-1){
 						if(aDllEntry->iOrdinal < 1 || aDllEntry->iOrdinal > (TUint)f.iOrigHdr->iExportDirCount){
-							Print(EWarning, "Invalid ordinal %d specified for DLL %s\n", aDllEntry->iOrdinal, iRomNode->iName);
+							sprintf(tmpbuf, "Invalid ordinal %d specified for DLL %s\n", (unsigned int) aDllEntry->iOrdinal, iRomNode->iName);
+							tmpLog.iPrintType = EWarning;
+							tmpLog.iLogMessage = tmpbuf;
+							iLogMessages.push_back(tmpLog);
 							aDllEntry = aDllEntry->NextDllDataEntry();
 							continue;
 						}
@@ -931,7 +962,10 @@
 						}
 						else
 						{
-							Print(EWarning, "Patchdata failed as address pointed by ordinal %d of DLL %s doesn't lie within Code or Data section limits\n", aDllEntry->iOrdinal, iRomNode->iName);
+							sprintf(tmpbuf, "Patchdata failed as address pointed by ordinal %d of DLL %s doesn't lie within Code or Data section limits\n", (unsigned int) aDllEntry->iOrdinal, iRomNode->iName);
+							tmpLog.iPrintType = EWarning;
+							tmpLog.iLogMessage = tmpbuf;
+							iLogMessages.push_back(tmpLog);
 						}
 					}
 					else if(aDllEntry->iDataAddress != (TLinAddr)-1){
@@ -948,7 +982,10 @@
 						}
 						else
 						{
-							Print(EWarning, "Patchdata failed as address 0x%x of DLL %s doesn't lie within Code or Data section limits\n", aDllEntry->iOrdinal, iRomNode->iName);
+							sprintf(tmpbuf, "Patchdata failed as address 0x%x of DLL %s doesn't lie within Code or Data section limits\n", (unsigned int) aDllEntry->iOrdinal, iRomNode->iName);
+							tmpLog.iPrintType = EWarning;
+							tmpLog.iLogMessage = tmpbuf;
+							iLogMessages.push_back(tmpLog);
 						}
 					}
 					aDllEntry = aDllEntry->NextDllDataEntry();
@@ -956,7 +993,10 @@
 			}
 
 			compression = f.iHdr->CompressionType();
-			Print(ELog,"Original file:'%s' is compressed by method:%08x\n", iFileName, compression);
+			sprintf(tmpbuf,"Original file:'%s' is compressed by method:%08x\n", iFileName, compression);
+			tmpLog.iPrintType = ELog;
+			tmpLog.iLogMessage = tmpbuf;
+			iLogMessages.push_back(tmpLog);
 
 
 			TUint32 oldFileComp;
@@ -1070,12 +1110,18 @@
 
 				if( newFileComp == 0)
 				{
-					Print(ELog,"Decompressing executable '%s'\n", iFileName);
+					sprintf(tmpbuf,"Decompressing executable '%s'\n", iFileName);
 					f.iHdr->iCompressionType = 0;
+					tmpLog.iPrintType = ELog;
+					tmpLog.iLogMessage = tmpbuf;
+					iLogMessages.push_back(tmpLog);
 				}
 				else
 				{
-					Print(ELog,"Compressing executable '%s' with method:%08x\n", iFileName, newFileComp);
+					sprintf(tmpbuf,"Compressing executable '%s' with method:%08x\n", iFileName, (unsigned int) newFileComp);
+					tmpLog.iPrintType = ELog;
+					tmpLog.iLogMessage = tmpbuf;
+					iLogMessages.push_back(tmpLog);
 					f.iHdr->iCompressionType = newFileComp;
 				}
 				f.UpdateHeaderCrc();
@@ -1103,8 +1149,14 @@
 			}
 			if (overflow)
 			{
-				Print(EError, "Can't fit '%s' in image\n", iFileName);
-				Print(EError, "Overflowed by approximately 0x%x bytes.\n", size - aMaxSize);
+				sprintf(tmpbuf, "Can't fit '%s' in image\n", iFileName);
+				tmpLog.iPrintType = EError;
+				tmpLog.iLogMessage = tmpbuf;
+				iLogMessages.push_back(tmpLog);
+				sprintf(tmpbuf, "Overflowed by approximately 0x%x bytes.\n", (unsigned int) (size - aMaxSize));
+				tmpLog.iPrintType = EError;
+				tmpLog.iLogMessage = tmpbuf;
+				iLogMessages.push_back(tmpLog);
 				exit(667);
 			}
 
@@ -1124,11 +1176,27 @@
 					compression = atoi(entryref->GetCachedFileCompressionID());
 					memcpy(&iUids[0], aDest, sizeof(iUids));
 					if (compression)
-						Print(ELog,"Compressed executable File '%s' size: %08x, mode:%08x\n", iFileName, size, compression);
+					{
+						sprintf(tmpbuf,"Compressed executable File '%s' size: %08x, mode:%08x\n", iFileName, (unsigned int) size, (unsigned int) compression);
+
+						tmpLog.iPrintType = ELog;
+						tmpLog.iLogMessage = tmpbuf;
+						iLogMessages.push_back(tmpLog);
+					}
 					else if (iExecutable)
-						Print(ELog,"Executable File '%s' size: %08x\n", iFileName, size);
+					{
+						sprintf(tmpbuf,"Executable File '%s' size: %08x\n", iFileName, (unsigned int) size);
+						tmpLog.iPrintType = ELog;
+						tmpLog.iLogMessage = tmpbuf;
+						iLogMessages.push_back(tmpLog);
+					}
 					else
-						Print(ELog,"File '%s' size: %08x\n", iFileName, size);
+					{
+						sprintf(tmpbuf,"File '%s' size: %08x\n", iFileName, (unsigned int) size);
+						tmpLog.iPrintType = ELog;
+						tmpLog.iLogMessage = tmpbuf;
+						iLogMessages.push_back(tmpLog);
+					}
 					iRealFileSize = size;	// required later when directory is written
 
 					return size;
@@ -1183,7 +1251,10 @@
 					}
 					catch (CacheException ce)
 					{
-						Print(EWarning, "Cache brings up an exception (%s) when processes %s\r\n", ce.GetErrorMessage(), iFileName);
+						sprintf(tmpbuf, "Cache brings up an exception (%s) when processes %s\r\n", ce.GetErrorMessage(), iFileName);
+						tmpLog.iPrintType = EWarning;
+						tmpLog.iLogMessage = tmpbuf;
+						iLogMessages.push_back(tmpLog);
 					}
 				}
 			}
@@ -1196,8 +1267,14 @@
 	{
 		if ( size > aMaxSize )
 		{
-			Print(EError, "Can't fit '%s' in image\n", iFileName);
-			Print(EError, "Overflowed by approximately 0x%x bytes.\n", size - aMaxSize);
+			sprintf(tmpbuf, "Can't fit '%s' in image\n", iFileName);
+			tmpLog.iPrintType = EError;
+			tmpLog.iLogMessage = tmpbuf;
+			iLogMessages.push_back(tmpLog);
+			sprintf(tmpbuf, "Overflowed by approximately 0x%x bytes.\n", (unsigned int) (size - aMaxSize));
+			tmpLog.iPrintType = EError;
+			tmpLog.iLogMessage = tmpbuf;
+			iLogMessages.push_back(tmpLog);
 			exit(667);
 		}
 		size = HFile::Read(iFileName, (TAny *)aDest);
@@ -1206,11 +1283,26 @@
 	}
 
 	if (compression)
-		Print(ELog,"Compressed executable File '%s' size: %08x, mode:%08x\n", iFileName, size, compression);
+	{
+		sprintf(tmpbuf,"Compressed executable File '%s' size: %08x, mode:%08x\n", iFileName, (unsigned int) size, (unsigned int) compression);
+		tmpLog.iPrintType = ELog;
+		tmpLog.iLogMessage = tmpbuf;
+		iLogMessages.push_back(tmpLog);
+	}
 	else if (iExecutable)
-		Print(ELog,"Executable File '%s' size: %08x\n", iFileName, size);
+	{
+		sprintf(tmpbuf,"Executable File '%s' size: %08x\n", iFileName, (unsigned int) size);
+		tmpLog.iPrintType = ELog;
+		tmpLog.iLogMessage = tmpbuf;
+		iLogMessages.push_back(tmpLog);
+	}
 	else
-		Print(ELog,"File '%s' size: %08x\n", iFileName, size);
+	{
+		sprintf(tmpbuf,"File '%s' size: %08x\n", iFileName, (unsigned int) size);
+		tmpLog.iPrintType = ELog;
+		tmpLog.iLogMessage = tmpbuf;
+		iLogMessages.push_back(tmpLog);
+	}
 	iCompressEnabled = compression;
 	iRealFileSize = size;	// required later when directory is written
 
--- a/imgtools/romtools/rofsbuild/r_rofs.cpp	Thu Nov 18 16:02:32 2010 +0800
+++ b/imgtools/romtools/rofsbuild/r_rofs.cpp	Fri Nov 19 13:37:08 2010 +0800
@@ -266,6 +266,7 @@
 }
 class Worker : public boost::thread {
     public:
+    static boost::mutex iMutexOut;
     static void thrd_func(E32Rofs* rofs){
         CBytePair bpe;
 
@@ -282,6 +283,9 @@
 		    rofs->iSymGen->AddEntry(tmpEntry);
 		    delete[] fullsystemname; 
 		}
+		iMutexOut.lock();
+		p->node->FlushLogMessages();
+		iMutexOut.unlock();
             }
             p = rofs->GetFileNode(deferred);
         }
@@ -296,6 +300,8 @@
     }
 };
 
+boost::mutex Worker::iMutexOut;
+
 TPlacingSection* E32Rofs::GetFileNode(bool &aDeferred) {
 	//get a node from the node list, the node list is protected by mutex iMuxTree.
 	//The iMuxTree also helps to make sure the order in iVPS is consistent with the node list.
--- a/imgtools/romtools/rofsbuild/r_romnode.h	Thu Nov 18 16:02:32 2010 +0800
+++ b/imgtools/romtools/rofsbuild/r_romnode.h	Fri Nov 19 13:37:08 2010 +0800
@@ -21,6 +21,8 @@
 
 #include <fstream>
 #include <e32std.h>
+#include <vector>
+#include <string>
 #include "rofs.h"
 #include "e32image.h"
 #include "h_utl.h"
@@ -123,7 +125,8 @@
 	TInt GetFullName(char* aBuf, TBool aIgnoreHiddenAttrib = EFalse) const;
 	static void InitializeCount();
 	// Accessor Function.
-    inline TRomNode* GetParent() const { return iParent; }
+    	inline TRomNode* GetParent() const { return iParent; }
+	void FlushLogMessages();
 
 private:
 	void Remove(TRomNode* aChild);
@@ -187,6 +190,12 @@
 
 
 class DllDataEntry;
+struct TLogItem
+	{
+		TPrintType iPrintType;
+		std::string iLogMessage;
+	};
+typedef vector<TLogItem> LogVector;
 class TRomBuilderEntry
 	{
 public:
@@ -218,6 +227,7 @@
 	TUint iCompressEnabled;
 	TUint8 iUids[sizeof(TCheckedUid)];
 	TBool iHidden;
+	LogVector iLogMessages;
   	DllDataEntry* GetFirstDllDataEntry() const;
 	void SetFirstDllDataEntry(DllDataEntry *aDllDataEntry);
 
--- a/imgtools/romtools/rofsbuild/rofsbuild.cpp	Thu Nov 18 16:02:32 2010 +0800
+++ b/imgtools/romtools/rofsbuild/rofsbuild.cpp	Fri Nov 19 13:37:08 2010 +0800
@@ -48,7 +48,7 @@
 
 static const TInt RofsbuildMajorVersion=2;
 static const TInt RofsbuildMinorVersion=17;
-static const TInt RofsbuildPatchVersion=0;
+static const TInt RofsbuildPatchVersion=1;
 static TBool SizeSummary=EFalse;
 static TPrintType SizeWhere=EAlways;
 
@@ -166,7 +166,7 @@
 					gSmrFileName.assign(&argv[i][5]);
 				}
 				else {
-					Print (EError, "SMR obey file is missing\n");
+					printf ("ERROR: SMR obey file is missing\n");
 				}
 			} else if (stricmp(argv[i], "-K") == 0) {
 				gKeepGoing = ETrue;
@@ -245,7 +245,7 @@
 				if((stricmp(&argv[i][13], "UTF8")==0) || (stricmp(&argv[i][13], "UTF-8")==0))
 					gIsOBYUTF8 = ETrue;
 				else
-					Print(EError, "Invalid encoding %s, default system internal encoding will be used.\n", &argv[i][13]);
+					printf("ERROR: Invalid encoding %s, default system internal encoding will be used.\n", &argv[i][13]);
 			}
 			else if (stricmp(argv[i], "-UNCOMPRESS") == 0) {
 				gCompress = ECompressionUncompress;
@@ -253,7 +253,7 @@
 			else if( stricmp(argv[i], "-COMPRESSIONMETHOD") == 0 ) {
 				// next argument should a be method
 				if( (i+1) >= argc || argv[i+1][0] == '-') {
-					Print (EError, "Missing compression method! Set it to default (no compression)!");
+					printf("ERROR: Missing compression method! Set it to default (no compression)!");
 					gCompressionMethod = 0;
 				}
 				else {
@@ -271,7 +271,7 @@
 						gCompressionMethod = KUidCompressionBytePair;	
 					}
 					else {
-						Print (EError, "Unknown compression method! Set it to default (no compression)!");
+						printf("ERROR: Unknown compression method! Set it to default (no compression)!");
 						gCompress = ECompressionUnknown;
 						gCompressionMethod = 0;		
 					}
@@ -283,7 +283,7 @@
 				gUseCoreImage = ETrue;
 				// next argument should be image filename
 				if ((i+1 >= argc) || argv[i+1][0] == '-')
-					Print (EError, "Missing image file name");
+					printf("ERROR: Missing image file name");
 				else {
 					i++;
 					gImageFilename.assign(argv[i]);
@@ -295,7 +295,7 @@
 					gDriveFilename.assign(&argv[i][11]);	
 				}
 				else {
-					Print (EError, "Drive obey file is missing\n"); 
+					printf("ERROR: Drive obey file is missing\n"); 
 				}
 			}
 			else if (argv[i][1] == '?') {
@@ -307,7 +307,7 @@
 			else if( stricmp(argv[i], "-LOGLEVEL") == 0) {
 				// next argument should a be loglevel
 				if( (i+1) >= argc || argv[i+1][0] == '-') {
-					Print (EError, "Missing loglevel!");
+					printf ("ERROR: Missing loglevel!");
 					gLogLevel = DEFAULT_LOG_LEVEL;
 				}
 				else {
@@ -319,7 +319,7 @@
 					else if (strcmp(argv[i], "0") == 0)
 						gLogLevel = DEFAULT_LOG_LEVEL;
 					else
-						Print(EError, "Only loglevel 0, 1 or 2 is allowed!");
+						printf("ERROR: Only loglevel 0, 1 or 2 is allowed!");
 				}
 			}
 			else if( stricmp(argv[i], "-LOGLEVEL2") == 0)
@@ -338,13 +338,13 @@
 			}
 			else {
 #ifdef WIN32
-				Print (EWarning, "Unrecognised option %s\n",argv[i]);
+				printf ("WARNING: Unrecognised option %s\n",argv[i]);
 #else
 				if(0 == access(argv[i],R_OK)){
 					filename.assign(argv[i]);
 				}
 				else {
-					Print (EWarning, "Unrecognised option %s\n",argv[i]);
+					printf("WARNING: Unrecognised option %s\n",argv[i]);
 				}
 #endif				
 
@@ -359,7 +359,7 @@
 		return;
 	if(gGenSymbols && gGenBsymbols)
 	{
-		Print(EWarning, "Options symbols and bsymbols cannot be used at the same time, the common symbols file will be created this time!\n");
+		printf("WARNING: Options symbols and bsymbols cannot be used at the same time, the common symbols file will be created this time!\n");
 		gGenBsymbols = EFalse;
 	}
 
@@ -371,7 +371,7 @@
 				Print (EAlways, ReallyHelpText);
 			}
 			else if (filename.empty()){
-				Print(EAlways, "Obey filename is missing\n");
+				printf("WARNING: Obey filename is missing\n");
 			}
 	}	
 }
--- a/imgtools/romtools/rombuild/rombuild.cpp	Thu Nov 18 16:02:32 2010 +0800
+++ b/imgtools/romtools/rombuild/rombuild.cpp	Fri Nov 19 13:37:08 2010 +0800
@@ -490,7 +490,7 @@
 		}
 		return 0;
 	}
-	if (romlogfile[romlogfile.size()-1] == '\\' || romlogfile[romlogfile.size()-1] == '/')
+	if (romlogfile.empty() || romlogfile[romlogfile.size()-1] == '\\' || romlogfile[romlogfile.size()-1] == '/')
 		romlogfile += "ROMBUILD.LOG";
  	H.SetLogFile(romlogfile.c_str());
 	ObeyFileReader *reader=new ObeyFileReader(filename.c_str());