git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@179 7335b...
authorhche10x <hche10x@7335b38e-4728-0410-8992-fb3ffe349368>
Fri, 22 Jun 2007 09:31:50 +0000 (09:31 +0000)
committerhche10x <hche10x@7335b38e-4728-0410-8992-fb3ffe349368>
Fri, 22 Jun 2007 09:31:50 +0000 (09:31 +0000)
Source/Python/EdkIIWorkspaceBuild.py
Source/Python/StrGather.py
Source/Python/String.py
Source/Python/UniClassObject.py

index 8206e74..0a372e1 100644 (file)
@@ -141,6 +141,8 @@ class WorkspaceBuild(object):
         self.PlatformBuild           = True\r
         self.TargetTxt               = TargetTxtClassObject()\r
         self.ToolDef                 = ToolDefClassObject()\r
+        self.SupArchList             = []        #[ 'IA32', 'X64', ...]\r
+        self.BuildTarget             = []        #[ 'RELEASE', 'DEBUG']\r
         self.InfDatabase             = {}        #{ [InfFileName] : InfClassObject}        \r
         self.DecDatabase             = {}        #{ [DecFileName] : DecClassObject}\r
         self.DscDatabase             = {}        #{ [DscFileName] : DscClassObject}\r
@@ -164,6 +166,8 @@ class WorkspaceBuild(object):
         #parse platform to get module\r
         for dsc in self.DscDatabase.keys():\r
             dscObj = self.DscDatabase[dsc]\r
+            self.SupArchList = dscObj.Defines.DefinesDictionary[TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES]\r
+            self.BuildTarget = dscObj.Defines.DefinesDictionary[TAB_DSC_DEFINES_BUILD_TARGETS]\r
             #Get all inf\r
             for key in DataType.ARCH_LIST:\r
                 for index in range(len(dscObj.Contents[key].LibraryClasses)):\r
@@ -507,6 +511,8 @@ if __name__ == '__main__':
 #    print ewb.DscDatabase\r
 #    print ewb.InfDatabase\r
 #    print ewb.DecDatabase\r
+    print 'SupArchList', ewb.SupArchList\r
+    print 'BuildTarget', ewb.BuildTarget\r
     \r
     #\r
     for arch in DataType.ARCH_LIST:\r
index 6a6f665..789a632 100644 (file)
 import EdkLogger\r
 from UniClassObject import *\r
 \r
+DEFINE_STR = '#define'\r
+COMMENT_DEFINE_STR = '// #define'\r
+COMMENT_NOT_REFERENCED = ' // not referenced'\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
+LANGUAGE_NAME_STRING_NAME = '$LANGUAGE_NAME'\r
+PRINTABLE_LANGUAGE_NAME_STRING_NAME = '$PRINTABLE_LANGUAGE_NAME'\r
+\r
+def DecToHexStr(Dec):\r
+    HexHeader = '0x'\r
+    if Dec < 16:\r
+        return HexHeader + '000' + hex(Dec)[2:].upper()\r
+    elif Dec < 256:\r
+        return HexHeader + '00' + hex(Dec)[2:].upper()\r
+    elif Dec < 4096:\r
+        return HexHeader + '0' + hex(Dec)[2:].upper()\r
+    else:\r
+        return HexHeader + hex(Dec)\r
 \r
 def CreateBaseNameDefinition(BaseName):\r
-    Str = WriteLine('', '#ifndef _' + BaseName.upper() + '_STRINGS_DEFINE_H_')\r
-    Str = Write(Str, '#define _' + BaseName.upper() + '_STRINGS_DEFINE_H_')\r
+    Str = ''\r
+    for Item in H_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 CreateHFile(BaseName):\r
-    HFile = ''\r
-    for Item in H_FILE_HEADER:\r
-        HFile = WriteLine(HFile, Item)\r
-    HFile = WriteLine(HFile, CreateBaseNameDefinition(BaseName))\r
+def CreateStringDefinition(UniObjectClass):\r
+    Str = ''\r
+    ValueStartPtr = 60\r
+    for Index in range(len(UniObjectClass.StringList)):\r
+        Name = UniObjectClass.FindStringObjectNameByToken(Index)\r
+        if Name != None:\r
+            StringItem = UniObjectClass.StringList[Name]\r
+            Line = ''\r
+            if StringItem.Referenced == True:\r
+                Line = DEFINE_STR + Name + ' ' * (ValueStartPtr - len(DEFINE_STR + Name)) + DecToHexStr(StringItem.Token)\r
+            else:\r
+                Line = COMMENT_DEFINE_STR + Name + ' ' * (ValueStartPtr - len(DEFINE_STR + Name)) + DecToHexStr(StringItem.Token) + COMMENT_NOT_REFERENCED\r
+            Str = WriteLine(Str, Line)\r
+    return Str\r
+\r
+def CreateHFile(BaseName, UniObjectClass):\r
+    HFile = WriteLine('', CreateBaseNameDefinition(BaseName))\r
+    HFile = WriteLine(HFile, CreateStringDefinition(UniObjectClass))\r
+    HFile = WriteLine(HFile, '#endif')\r
     return HFile\r
 \r
 def CreateCFile(BaseName):\r
@@ -43,30 +77,67 @@ def GetFileList(IncludeList, SkipList):
         \r
     for Dir in IncludeList:\r
         for File in os.listdir(Dir):\r
+            File = os.path.join(Dir, os.path.normcase(File))\r
+            #\r
+            # Ignore Dir\r
+            #\r
+            if os.path.isfile(File) != True:\r
+                continue\r
             #\r
             # Ignore file listed in skip list\r
             #\r
+            IsSkip = False\r
             for Skip in SkipList:\r
-                if os.path.splitext(os.path.normcase(File))[1] == Skip:\r
+                if os.path.splitext(File)[1].upper() == Skip.upper():\r
+                    IsSkip = True\r
                     break\r
             \r
-            FileList.append(os.path.join(Dir, os.path.normcase(File)))\r
+            if not IsSkip:\r
+                FileList.append(File)\r
     \r
     return FileList\r
 \r
+def SearchString(UniObjectClass, FileList):\r
+    if FileList == []:\r
+        return UniObjectClass\r
+    \r
+    for File in FileList:\r
+        if os.path.isfile(File):\r
+            Lines = open(File, 'r')\r
+            for Line in Lines:\r
+                if Line.find(STRING_TOKEN) >= 0:\r
+                    StrName = Line[Line.find('(', Line.find(STRING_TOKEN)) + len('(') : Line.find(')', Line.find(STRING_TOKEN))].strip()\r
+                    UniObjectClass.SetStringReferenced(StrName)\r
+     \r
+    UniObjectClass.ReToken()\r
+#    for index in range(len(UniObjectClass.StringList)):\r
+#        name = UniObjectClass.FindStringObjectNameByToken(index)\r
+#        if name != None:\r
+#            #print index, str(UniObjectClass.StringList[name])\r
+#            pass\r
+    return UniObjectClass\r
+\r
 def GetStringFiles(UniFilList, IncludeList, SkipList, BaseName):\r
+    Status = True\r
+    ErrorMessage = ''\r
+    \r
     if len(UniFilList) > 0:\r
         Uni = UniFileClassObject(UniFilList)\r
+    else:\r
+        Status = False\r
+        ErrorMessage = 'No Unicode Files Found'\r
+    \r
+    FileList = GetFileList(IncludeList, SkipList)\r
     \r
-    GetFileList(IncludeList, SkipList)\r
+    Uni = SearchString(Uni, FileList)\r
     \r
     if len(Uni.StringList) > 0:\r
         pass\r
     \r
-    HFile = CreateHFile(BaseName)\r
+    HFile = CreateHFile(BaseName, Uni)\r
     CFile = CreateCFile(BaseName)\r
 \r
-    return HFile, CFile\r
+    return Status, ErrorMessage, HFile, CFile\r
 \r
 def Write(Target, Item):\r
     return Target + Item\r
@@ -77,6 +148,10 @@ def WriteLine(Target, Item):
 # This acts like the main() function for the script, unless it is 'import'ed into another\r
 # script.\r
 if __name__ == '__main__':\r
-    (h, c) = GetStringFiles(['C:\\Documents and Settings\\hchen30\\Desktop\\inventorystrings.uni'], None, None, 'VVV' )\r
+    UniFileList = ['C:\\Tiano\\Edk\\Sample\\Universal\\UserInterface\\SetupBrowser\\Dxe\\DriverSample\\inventorystrings.uni', 'C:\\Tiano\\Edk\\Sample\\Universal\\UserInterface\\SetupBrowser\\Dxe\\DriverSample\\VfrStrings.uni']\r
+    IncludeList = ['C:\\Tiano\\Edk\\Sample\\Universal\\UserInterface\\SetupBrowser\\Dxe\\DriverSample']\r
+    SkipList = ['.inf', '.uni']\r
+    BaseName = 'DriverSample'\r
+    (s, e, h, c) = GetStringFiles(UniFileList, IncludeList, SkipList, BaseName)\r
     print h\r
     print c\r
index b82ce4c..a102eb8 100644 (file)
@@ -208,17 +208,15 @@ def GetSingleValueOfKeyFromLines(Lines, Dictionary, CommentCharacter, KeySplitCh
                 #Remove comments and white spaces\r
                 LineList[1] = CleanString(LineList[1], CommentCharacter)\r
                 if ValueSplitFlag:\r
-                    ValueList = LineList[1].replace('\\','/').split(ValueSplitCharacter)\r
-                    if len(ValueList) == 1:\r
-                        Value = ValueList[0]\r
+                    Value = LineList[1].replace('\\','/').split(ValueSplitCharacter)\r
                 else:\r
-                    Value = CleanString(LineList[1], CommentCharacter)\r
+                    Value = CleanString(LineList[1], CommentCharacter).splitlines()\r
                 \r
                 if Key[0] not in Keys:\r
-                    Dictionary[Key[0]] = Value.splitlines()\r
+                    Dictionary[Key[0]] = Value\r
                     Keys.append(Key[0])\r
                 else:\r
-                    Dictionary[Key[0]].extend(Value.splitlines())                \r
+                    Dictionary[Key[0]].extend(Value)                \r
     return True\r
 \r
 \r
index 7be579d..3c17bcb 100644 (file)
@@ -48,7 +48,7 @@ def UniToHexList(Uni):
     return List\r
 \r
 class StringDefinitionClassObject(object):\r
-    def __init__(self, Name = None, Language = None, Value = None):\r
+    def __init__(self, Name = None, Language = None, Value = None, Token = None):\r
         self.StringName = ''\r
         self.StringNameByteList = []\r
         self.StringValue = {}                        #{ u'Language' : u'Value' }\r
@@ -61,6 +61,8 @@ class StringDefinitionClassObject(object):
             self.StringNameByteList = UniToHexList(Name)\r
         if Value != None and Language != None:\r
             self.StringValue[Language] = UniToHexList(Value)\r
+        if Token != None:\r
+            self.Token = Token\r
         \r
     def Update(self, Name = None, Language = None, Value = None):\r
         if Name != None:\r
@@ -71,17 +73,28 @@ class StringDefinitionClassObject(object):
             self.StringValue[Language] = UniToHexList(Value)\r
         \r
     def __str__(self):\r
-        return repr(self.StringName) + ' ' + repr(self.StringValue)\r
+        return repr(self.StringName) + ' ' + \\r
+               repr(self.Token) + ' ' + \\r
+               repr(self.Referenced) + ' ' + \\r
+               repr(self.StringValue)\r
 \r
 class UniFileClassObject(object):\r
     def __init__(self, FileList = []):\r
         self.FileList = FileList\r
+        self.Token = 2\r
         self.LanguageDef = {}                   #{ 'LanguageIdentifier' : [PrintableName] }\r
         self.StringList = {}                    #{ 'StringName' : StringDefinitionClassObject }\r
         \r
         if len(self.FileList) > 0:\r
             self.LoadUniFiles(FileList)\r
-    \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
         LangPrintName = Line[Line.find(u'\"') + len(u'\"') : Line.rfind(u'\"')]\r
@@ -204,12 +217,46 @@ class UniFileClassObject(object):
             for File in FileList:\r
                 self.LoadUniFile(File)\r
                 \r
-    def AddStringToList(self, Name, Language, Value):\r
+    def AddStringToList(self, Name, Language, Value, Token = None):\r
         if Name in self.StringList.keys():\r
             self.StringList[UniToStr(Name)].Update(Name, Language, Value)\r
         else:\r
-            self.StringList[UniToStr(Name)] = StringDefinitionClassObject(Name, Language, Value)\r
-\r
+            if Token != None:\r
+                self.StringList[UniToStr(Name)] = StringDefinitionClassObject(Name, Language, Value, Token)\r
+            else:\r
+                self.StringList[UniToStr(Name)] = StringDefinitionClassObject(Name, Language, Value, self.Token)\r
+                self.Token = self.Token + 1\r
+            \r
+    def FindStringObjectNameByToken(self, Token):\r
+        for Item in self.StringList:\r
+            if self.StringList[Item].Token == Token:\r
+                return Item\r
+        return None\r
+    \r
+    def SetStringReferenced(self, Name):\r
+        if Name in self.StringList.keys():\r
+            self.StringList[Name].Referenced = True\r
+            \r
+    def ReToken(self):\r
+        Token = 2\r
+        FalseCount = 1\r
+        Length = len(self.StringList)\r
+        for Index in range(2, Length):\r
+            Name = self.FindStringObjectNameByToken(Index)\r
+            if Name != None:\r
+                if self.StringList[Name].Referenced == True:\r
+                    self.StringList[Name].Token = Token\r
+                    Token = Token + 1\r
+                else:\r
+                    self.StringList[Name].Token = Length + FalseCount\r
+                    FalseCount = FalseCount + 1\r
+                \r
+        for Index in range(2, Length + FalseCount):\r
+            Name = self.FindStringObjectNameByToken(Index)\r
+            if Name != None and self.StringList[Name].Referenced == False:\r
+                self.StringList[Name].Token = Token\r
+                Token = Token + 1\r
+            \r
 # This acts like the main() function for the script, unless it is 'import'ed into another\r
 # script.\r
 if __name__ == '__main__':\r