git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@184 7335b...
authorhche10x <hche10x@7335b38e-4728-0410-8992-fb3ffe349368>
Mon, 25 Jun 2007 02:33:27 +0000 (02:33 +0000)
committerhche10x <hche10x@7335b38e-4728-0410-8992-fb3ffe349368>
Mon, 25 Jun 2007 02:33:27 +0000 (02:33 +0000)
Source/Python/EdkIIWorkspaceBuild.py
Source/Python/StrGather.py
Source/Python/UniClassObject.py

index 0a372e1..53e0e33 100644 (file)
@@ -26,11 +26,22 @@ from DscClassObject import *
 from String import *\r
 \r
 class ModuleSourceFilesClassObject(object):\r
-    def __init__(self, Item):\r
-        self.SourceFile         = Item\r
-        self.TagName            = ''\r
-        self.ToolCode           = ''\r
-        self.ToolChainFamily    = ''\r
+    def __init__(self, SourceFile = '', PcdFeatureFlag = '', TagName = '', ToolCode = '', ToolChainFamily = '', String = ''):\r
+        self.SourceFile         = SourceFile\r
+        self.TagName            = TagName\r
+        self.ToolCode           = ToolCode\r
+        self.ToolChainFamily    = ToolChainFamily\r
+        self.String             = String\r
+        self.PcdFeatureFlag     = PcdFeatureFlag\r
+    \r
+    def __str__(self):\r
+        rtn = self.SourceFile + DataType.TAB_VALUE_SPLIT + \\r
+              self.PcdFeatureFlag + DataType.TAB_VALUE_SPLIT + \\r
+              self.ToolChainFamily +  DataType.TAB_VALUE_SPLIT + \\r
+              self.TagName + DataType.TAB_VALUE_SPLIT + \\r
+              self.ToolCode + DataType.TAB_VALUE_SPLIT + \\r
+              self.String\r
+        return rtn\r
         \r
 class PcdClassObject(object):\r
     def __init__(self, Name = None, Guid = None, Type = None, DatumType = None, Value = None, Token = None, MaxDatumSize = None):\r
@@ -143,7 +154,7 @@ class WorkspaceBuild(object):
         self.ToolDef                 = ToolDefClassObject()\r
         self.SupArchList             = []        #[ 'IA32', 'X64', ...]\r
         self.BuildTarget             = []        #[ 'RELEASE', 'DEBUG']\r
-        self.InfDatabase             = {}        #{ [InfFileName] : InfClassObject}        \r
+        self.InfDatabase             = {}        #{ [InfFileName] : InfClassObject}\r
         self.DecDatabase             = {}        #{ [DecFileName] : DecClassObject}\r
         self.DscDatabase             = {}        #{ [DscFileName] : DscClassObject}\r
         \r
@@ -338,7 +349,19 @@ class WorkspaceBuild(object):
 \r
                 #Sources\r
                 for index in range(len(infObj.Contents[key].Sources)):\r
-                    pb.Sources.append(ModuleSourceFilesClassObject(NormPath(infObj.Contents[key].Sources[index])))\r
+                    SourceFile = infObj.Contents[key].Sources[index].split(DataType.TAB_VALUE_SPLIT)\r
+                    if len(SourceFile) == 6:\r
+                        FileName = NormPath(SourceFile[0])\r
+                        PcdFeatureFlag = SourceFile[1]\r
+                        TagName = SourceFile[3]\r
+                        ToolCode = SourceFile[4]\r
+                        ToolChainFamily = SourceFile[2]\r
+                        String = SourceFile[5]\r
+                        pb.Sources.append(ModuleSourceFilesClassObject(FileName, PcdFeatureFlag, TagName, ToolCode, ToolChainFamily, String))\r
+                    elif len(SourceFile) == 1:\r
+                        pb.Sources.append(ModuleSourceFilesClassObject(NormPath(infObj.Contents[key].Sources[index])))\r
+                    else:\r
+                        EdkLogger.error("Inconsistent '|' value defined in SourceFiles." + key + " section in file " + inf)\r
 \r
                 #Protocols\r
                 for index in range(len(infObj.Contents[key].Protocols)):\r
@@ -565,7 +588,9 @@ if __name__ == '__main__':
             print 'ConstructorList = ', p.ConstructorList            \r
             print 'DestructorList = ', p.DestructorList             \r
                                                                      \r
-            print 'Sources = ', p.Sources                            \r
+            print 'Sources = '\r
+            for item in p.Sources:\r
+                print str(item)\r
             print 'LibraryClasses = ', p.LibraryClasses             \r
             print 'Protocols = ', p.Protocols                        \r
             print 'Ppis = ', p.Ppis                                 \r
index 789a632..1238c10 100644 (file)
 import EdkLogger\r
 from UniClassObject import *\r
 \r
+COMMENT = '// '\r
 DEFINE_STR = '#define'\r
-COMMENT_DEFINE_STR = '// #define'\r
-COMMENT_NOT_REFERENCED = ' // not referenced'\r
+COMMENT_DEFINE_STR = COMMENT + DEFINE_STR\r
+NOT_REFERENCED = 'not referenced'\r
+COMMENT_NOT_REFERENCED = ' ' + COMMENT + NOT_REFERENCED\r
+CHAR_ARRAY_DEFIN = 'unsigned char'\r
+COMMON_FILE_NAME = 'Strings'\r
+OFFSET = 'offset'\r
+STRING = 'string'\r
+TO = 'to'\r
 STRING_TOKEN = 'STRING_TOKEN'\r
-H_FILE_HEADER = ['//', '//  DO NOT EDIT -- auto-generated file', '//', \\r
-                 '//  This file is generated by the string gather utility', '//']\r
+\r
+H_C_FILE_HEADER = ['//', \\r
+                   '//  DO NOT EDIT -- auto-generated file', \\r
+                   '//', \\r
+                   '//  This file is generated by the string gather utility', \\r
+                   '//']\r
 LANGUAGE_NAME_STRING_NAME = '$LANGUAGE_NAME'\r
 PRINTABLE_LANGUAGE_NAME_STRING_NAME = '$PRINTABLE_LANGUAGE_NAME'\r
 \r
@@ -34,15 +45,15 @@ def DecToHexStr(Dec):
     else:\r
         return HexHeader + hex(Dec)\r
 \r
-def CreateBaseNameDefinition(BaseName):\r
+def CreateHFileHeader(BaseName):\r
     Str = ''\r
-    for Item in H_FILE_HEADER:\r
+    for Item in H_C_FILE_HEADER:\r
         Str = WriteLine(Str, Item)\r
     Str = WriteLine(Str, '#ifndef _' + BaseName.upper() + '_STRINGS_DEFINE_H_')\r
     Str = WriteLine(Str, '#define _' + BaseName.upper() + '_STRINGS_DEFINE_H_')\r
     return Str\r
 \r
-def CreateStringDefinition(UniObjectClass):\r
+def CreateHFileContent(UniObjectClass):\r
     Str = ''\r
     ValueStartPtr = 60\r
     for Index in range(len(UniObjectClass.StringList)):\r
@@ -58,13 +69,68 @@ def CreateStringDefinition(UniObjectClass):
     return Str\r
 \r
 def CreateHFile(BaseName, UniObjectClass):\r
-    HFile = WriteLine('', CreateBaseNameDefinition(BaseName))\r
-    HFile = WriteLine(HFile, CreateStringDefinition(UniObjectClass))\r
+    HFile = WriteLine('', CreateHFileHeader(BaseName))\r
+    HFile = WriteLine(HFile, CreateHFileContent(UniObjectClass))\r
     HFile = WriteLine(HFile, '#endif')\r
     return HFile\r
 \r
-def CreateCFile(BaseName):\r
-    CFile = ''\r
+def CreateCFileHeader():\r
+    Str = ''\r
+    for Item in H_C_FILE_HEADER:\r
+        Str = WriteLine(Str, Item)\r
+    \r
+    return Str\r
+  \r
+def CreateArrayItem(Value):\r
+    MaxLength = 16\r
+    Index = 0\r
+    Line = '  '\r
+    ArrayItem = ''\r
+    \r
+    for Item in Value:\r
+        if Index < MaxLength:\r
+            Line = Line + Item + ', '\r
+            Index = Index + 1\r
+        else:\r
+            ArrayItem = WriteLine(ArrayItem, Line)\r
+            Line = '  ' + Item +  ', '\r
+            Index = 1\r
+    ArrayItem = Write(ArrayItem, Line)\r
+    \r
+    return ArrayItem\r
+\r
+def CreateCFileLanguageHeader(Name, PrintableName, Offset):\r
+    Str = WriteLine('  ', COMMENT + STRING + ' ' + LANGUAGE_NAME_STRING_NAME + ' ' + OFFSET + ' ' + Offset)\r
+    Str = WriteLine(Str, CreateArrayItem(UniToHexList(Name + u'\x00')))\r
+    Str = WriteLine(Str, '  ' + COMMENT + STRING + ' ' + PRINTABLE_LANGUAGE_NAME_STRING_NAME + ' ' + OFFSET + ' ' + Offset)\r
+    Str = WriteLine(Str, CreateArrayItem(PrintableName + UniToHexList(u'\x00')))\r
+    \r
+    return Str\r
+    \r
+def CreateCFileStringValue(Name, Language, Value, Offset):\r
+    Str = WriteLine('  ', COMMENT + STRING + ' ' + UniToStr(Name) + ' ' + OFFSET + ' ' + Offset)\r
+    Str = WriteLine(Str, CreateArrayItem(Value))\r
+    \r
+    return Str\r
+\r
+def CreateCFileContent(BaseName, UniObjectClass):\r
+    Str = ''\r
+    Str = WriteLine(Str, CHAR_ARRAY_DEFIN + BaseName + COMMON_FILE_NAME + '[] = {')\r
+    for Language in UniObjectClass.LanguageDef:        \r
+        Str = Write(Str, CreateCFileLanguageHeader(Language, UniObjectClass.LanguageDef[Language], '0x00001'))\r
+        for Index in range(2, len(UniObjectClass.StringList)):\r
+            Name = UniObjectClass.FindStringObjectNameByToken(Index)\r
+            if Name != None:\r
+                #print Language\r
+                #print Name\r
+                #print UniObjectClass.StringList[Name].StringValue\r
+                if Language in UniObjectClass.StringList[Name].StringValue.keys():\r
+                    Str = Write(Str, CreateCFileStringValue(Name, Language, UniObjectClass.StringList[Name].StringValue[Language], '0x000000'))\r
+    return Str\r
+\r
+def CreateCFile(BaseName, UniObjectClass):\r
+    CFile = WriteLine('', CreateCFileHeader())\r
+    CFile = WriteLine(CFile, CreateCFileContent(BaseName, UniObjectClass))\r
     return CFile\r
 \r
 def GetFileList(IncludeList, SkipList):\r
@@ -135,7 +201,7 @@ def GetStringFiles(UniFilList, IncludeList, SkipList, BaseName):
         pass\r
     \r
     HFile = CreateHFile(BaseName, Uni)\r
-    CFile = CreateCFile(BaseName)\r
+    CFile = CreateCFile(BaseName, Uni)\r
 \r
     return Status, ErrorMessage, HFile, CFile\r
 \r
index 3c17bcb..ef67d6f 100644 (file)
@@ -82,18 +82,12 @@ class UniFileClassObject(object):
     def __init__(self, FileList = []):\r
         self.FileList = FileList\r
         self.Token = 2\r
-        self.LanguageDef = {}                   #{ 'LanguageIdentifier' : [PrintableName] }\r
+        self.LanguageDef = {}                   #{ u'LanguageIdentifier' : [PrintableName] }\r
         self.StringList = {}                    #{ 'StringName' : StringDefinitionClassObject }\r
+        self.OrderedStringList = []               #[ StringDefinitionClassObject ] \r
         \r
         if len(self.FileList) > 0:\r
             self.LoadUniFiles(FileList)\r
-        \r
-        #\r
-        # Add default string\r
-        #\r
-        for Language in self.LanguageDef.keys():\r
-            self.AddStringToList(u'$LANGUAGE_NAME', Language, '', 0)\r
-            self.AddStringToList(u'$PRINTABLE_LANGUAGE_NAME', Language, '', 1)\r
                 \r
     def GetLangDef(self, Line):\r
         LangName = Line[Line.find(u'#langdef ') + len(u'#langdef ') : Line.find(u' ', len(u'#langdef '))]\r
@@ -211,6 +205,13 @@ class UniFileClassObject(object):
                             elif Lines[IndexJ].find(u'\"') >= 2:\r
                                 StringItem = StringItem[ : StringItem.rfind(u'\"')] + Lines[IndexJ][Lines[IndexJ].find(u'\"') + len(u'\"') : ]\r
                         self.GetStringObject(StringItem)\r
+                \r
+                #\r
+                # Add default string\r
+                #\r
+                for Language in self.LanguageDef.keys():\r
+                    self.AddStringToList(u'$LANGUAGE_NAME', Language, Language, 0)\r
+                    self.AddStringToList(u'$PRINTABLE_LANGUAGE_NAME', Language, self.LanguageDef[Language], 1)                \r
 \r
     def LoadUniFiles(self, FileList = []):\r
         if len(FileList) > 0:\r
@@ -237,6 +238,10 @@ class UniFileClassObject(object):
         if Name in self.StringList.keys():\r
             self.StringList[Name].Referenced = True\r
             \r
+    \r
+    def CreateOrderedStringList(self):\r
+        pass\r
+    \r
     def ReToken(self):\r
         Token = 2\r
         FalseCount = 1\r