git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@378 7335b...
authorhche10x <hche10x@7335b38e-4728-0410-8992-fb3ffe349368>
Tue, 24 Jul 2007 03:13:06 +0000 (03:13 +0000)
committerhche10x <hche10x@7335b38e-4728-0410-8992-fb3ffe349368>
Tue, 24 Jul 2007 03:13:06 +0000 (03:13 +0000)
Source/Python/Common/DecClassObject.py

index df48d00..df7fa38 100644 (file)
@@ -16,6 +16,8 @@ from String import *
 from DataType import *\r
 from Identification import *\r
 from Dictionary import *\r
+from CommonDataClass.PackageClass import *\r
+from BuildToolError import *\r
 \r
 class DecObject(object):\r
     def __init__(self):\r
@@ -45,9 +47,11 @@ class DecContents(DecObject):
         self.PcdsDynamicEx = []\r
 \r
 class Dec(DecObject):\r
-    def __init__(self, filename = None, isMergeAllArches = False):\r
-        self.identification = Identification()\r
+    def __init__(self, filename = None, isMergeAllArches = False, isToPackage = False):\r
+        self.Identification = Identification()\r
         self.Defines = DecDefines()\r
+        self.UserExtensions = ''\r
+        self.Package = PackageClass()\r
         \r
         self.Contents = {}\r
         for key in DataType.ARCH_LIST_FULL:\r
@@ -63,7 +67,10 @@ class Dec(DecObject):
             self.LoadDecFile(filename)\r
             \r
         if isMergeAllArches:\r
-            self.MergeAllArches()            \r
+            self.MergeAllArches()\r
+        \r
+        if isToPackage:\r
+            self.DecToPackage()\r
     \r
     def ParseDec(self, Lines, Key, KeyField):\r
         GetMultipleValuesOfKeyFromLines(Lines, Key, KeyField, TAB_COMMENT_SPLIT)\r
@@ -74,8 +81,13 @@ class Dec(DecObject):
                 Command = "self.Contents[arch]." + key + ".extend(" + "self.Contents['" + DataType.TAB_ARCH_COMMON + "']." + key + ")"\r
                 eval(Command)\r
 \r
-    def LoadDecFile(self, filename):\r
-        f = open(filename, 'r').read()\r
+    def LoadDecFile(self, Filename):\r
+        (Filepath, Name) = os.path.split(Filename)\r
+        self.Identification.FileName = Name\r
+        self.Identification.FileFullPath = Filename\r
+        self.Identification.FileRelativePath = Filepath\r
+        \r
+        f = open(Filename, 'r').read()\r
         sects = f.split('[')\r
         for sect in sects:\r
             tab = (sect.split(TAB_SECTION_END, 1)[0]).upper()\r
@@ -99,7 +111,141 @@ class Dec(DecObject):
                             continue\r
         #EndFor\r
 \r
-    def showDec(self):\r
+    def DecToPackage(self):\r
+        #\r
+        # Get value for Header\r
+        #\r
+        self.Package.Header.Name = self.Defines.DefinesDictionary[TAB_DEC_DEFINES_PACKAGE_NAME][0]\r
+        self.Package.Header.Guid = self.Defines.DefinesDictionary[TAB_DEC_DEFINES_PACKAGE_GUID][0]\r
+        self.Package.Header.Version = self.Defines.DefinesDictionary[TAB_DEC_DEFINES_PACKAGE_VERSION][0]\r
+        self.Package.Header.FileName = self.Identification.FileName\r
+        self.Package.Header.FullPath = self.Identification.FileFullPath\r
+        self.Package.Header.DecSpecification = self.Defines.DefinesDictionary[TAB_DEC_DEFINES_DEC_SPECIFICATION][0]\r
+        \r
+        #Includes\r
+        Includes = {}\r
+        for Arch in DataType.ARCH_LIST:\r
+            for Item in self.Contents[Arch].Includes:\r
+                MergeArches(Includes, Item, Arch)\r
+        for Key in Includes.keys():\r
+            Include = IncludeClass()\r
+            Include.FilePath = Key\r
+            Include.SupArchList = Includes[Key]\r
+            self.Package.Includes.append(Include)\r
+            \r
+        #Guids\r
+        Guids = {}\r
+        for Arch in DataType.ARCH_LIST:\r
+            for Item in self.Contents[Arch].Guids:\r
+                List = GetSplitValueList(Item, DataType.TAB_EQUAL_SPLIT)\r
+                if len(List) != 2:\r
+                    ErrorMsg = "Wrong statement '%s' found in section Guids in file '%s', correct format is '<CName>=<GuidValue>'" % (Item, self.Package.Header.FullPath) \r
+                    raise ParserError(PARSER_ERROR, msg = ErrorMsg)\r
+                else:\r
+                    MergeArches(Guids, (List[0], List[1]), Arch)\r
+        for Key in Guids.keys():\r
+            Guid = GuidClass()\r
+            Guid.CName = Key[0]\r
+            Guid.Guid = Key[1]\r
+            Guid.SupArchList = Guids[Key]\r
+            self.Package.GuidDeclarations.append(Guid)\r
+\r
+        #Protocols\r
+        Protocols = {}\r
+        for Arch in DataType.ARCH_LIST:\r
+            for Item in self.Contents[Arch].Protocols:\r
+                List = GetSplitValueList(Item, DataType.TAB_EQUAL_SPLIT)\r
+                if len(List) != 2:\r
+                    ErrorMsg = "Wrong statement '%s' found in section Protocols in file '%s', correct format is '<CName>=<GuidValue>'" % (Item, self.Package.Header.FullPath) \r
+                    raise ParserError(PARSER_ERROR, msg = ErrorMsg)\r
+                else:\r
+                    MergeArches(Protocols, (List[0], List[1]), Arch)\r
+        for Key in Protocols.keys():\r
+            Protocol = ProtocolClass()\r
+            Protocol.CName = Key[0]\r
+            Protocol.Guid = Key[1]\r
+            Protocol.SupArchList = Protocols[Key]\r
+            self.Package.ProtocolDeclarations.append(Protocol)\r
+        \r
+        #Ppis\r
+        Ppis = {}\r
+        for Arch in DataType.ARCH_LIST:\r
+            for Item in self.Contents[Arch].Ppis:\r
+                List = GetSplitValueList(Item, DataType.TAB_EQUAL_SPLIT)\r
+                if len(List) != 2:\r
+                    ErrorMsg = "Wrong statement '%s' found in section Ppis in file '%s', correct format is '<CName>=<GuidValue>'" % (Item, self.Package.Header.FullPath) \r
+                    raise ParserError(PARSER_ERROR, msg = ErrorMsg)\r
+                else:\r
+                    MergeArches(Ppis, (List[0], List[1]), Arch)\r
+        for Key in Ppis.keys():\r
+            Ppi = PpiClass()\r
+            Ppi.CName = Key[0]\r
+            Ppi.Guid = Key[1]\r
+            Ppi.SupArchList = Ppis[Key]\r
+            self.Package.PpiDeclarations.append(Ppi)\r
+            \r
+        #LibraryClasses\r
+        LibraryClasses = {}\r
+        for Arch in DataType.ARCH_LIST:\r
+            for Item in self.Contents[Arch].LibraryClasses:\r
+                List = GetSplitValueList(Item, DataType.TAB_VALUE_SPLIT)\r
+                if len(List) != 2:\r
+                    ErrorMsg = "Wrong statement '%s' found in section LibraryClasses in file '%s', correct format is '<CName>=<GuidValue>'" % (Item, self.Package.Header.FullPath) \r
+                    raise ParserError(PARSER_ERROR, msg = ErrorMsg)\r
+                else:\r
+                    MergeArches(LibraryClasses, (List[0], List[1]), Arch)\r
+        for Key in LibraryClasses.keys():\r
+            LibraryClass = LibraryClassClass()\r
+            LibraryClass.LibraryClass = Key[0]\r
+            LibraryClass.RecommendedInstance = Key[1]\r
+            LibraryClass.SupArchList = LibraryClasses[Key]\r
+            self.Package.LibraryClassDeclarations.append(LibraryClass)\r
+        \r
+        #Pcds\r
+        Pcds = {}\r
+        for Arch in DataType.ARCH_LIST:\r
+            for Item in self.Contents[Arch].PcdsFixedAtBuild:\r
+                List = GetSplitValueList(Item)\r
+                if len(List) != 5:\r
+                    ErrorMsg = "Wrong statement '%s' found in section PcdsFixedAtBuild in file '%s', correct format is '<TokenCName>|<Token>|<CName>|<DatumType>|<Default>'" % (Item, self.Package.Header.FullPath) \r
+                    raise ParserError(PARSER_ERROR, msg = ErrorMsg)\r
+                MergeArches(Pcds, (List[0], List[1], List[2], List[3], List[4],TAB_PCDS_FIXED_AT_BUILD), Arch)\r
+            for Item in self.Contents[Arch].PcdsPatchableInModule:\r
+                List = GetSplitValueList(Item)\r
+                if len(List) != 5:\r
+                    ErrorMsg = "Wrong statement '%s' found in section PcdsPatchableInModule in file '%s', correct format is '<TokenCName>|<Token>|<CName>|<DatumType>|<Default>'" % (Item, self.Package.Header.FullPath) \r
+                    raise ParserError(PARSER_ERROR, msg = ErrorMsg)\r
+                MergeArches(Pcds, (List[0], List[1], List[2], List[3], List[4], TAB_PCDS_PATCHABLE_IN_MODULE), Arch)\r
+            for Item in self.Contents[Arch].PcdsFeatureFlag:\r
+                List = GetSplitValueList(Item)\r
+                if len(List) != 5:\r
+                    ErrorMsg = "Wrong statement '%s' found in section PcdsFeatureFlag in file '%s', correct format is '<TokenCName>|<Token>|<CName>|<DatumType>|<Default>'" % (Item, self.Package.Header.FullPath) \r
+                    raise ParserError(PARSER_ERROR, msg = ErrorMsg)\r
+                MergeArches(Pcds, (List[0], List[1], List[2], List[3], List[4], TAB_PCDS_FEATURE_FLAG), Arch)\r
+            for Item in self.Contents[Arch].PcdsDynamicEx:\r
+                List = GetSplitValueList(Item)\r
+                if len(List) != 5:\r
+                    ErrorMsg = "Wrong statement '%s' found in section PcdsDynamicEx in file '%s', correct format is '<TokenCName>|<Token>|<CName>|<DatumType>|<Default>'" % (Item, self.Package.Header.FullPath) \r
+                    raise ParserError(PARSER_ERROR, msg = ErrorMsg)\r
+                MergeArches(Pcds, (List[0], List[1], List[2], List[3], List[4], TAB_PCDS_DYNAMIC_EX), Arch)\r
+            for Item in self.Contents[Arch].PcdsDynamic:\r
+                List = GetSplitValueList(Item)\r
+                if len(List) != 5:\r
+                    ErrorMsg = "Wrong statement '%s' found in section PcdsDynamic in file '%s', correct format is '<TokenCName>|<Token>|<CName>|<DatumType>|<Default>'" % (Item, self.Package.Header.FullPath) \r
+                    raise ParserError(PARSER_ERROR, msg = ErrorMsg)\r
+                MergeArches(Pcds, (List[0], List[1], List[2], List[3], List[4], TAB_PCDS_DYNAMIC), Arch)\r
+        for Key in Pcds.keys():\r
+            Pcd = PcdClass()\r
+            Pcd.CName = Key[0]\r
+            Pcd.Token = Key[1]\r
+            Pcd.TokenSpaceGuidCName = Key[2]\r
+            Pcd.DatumType = Key[3]\r
+            Pcd.DefaultValue = Key[4]\r
+            Pcd.ItemType = Key[5]\r
+            Pcd.SupArchList = Pcds[Key]\r
+            self.Package.PcdDeclarations.append(Pcd)\r
+    \r
+    def ShowDec(self):\r
         print TAB_SECTION_START + TAB_INF_DEFINES + TAB_SECTION_END\r
         printDict(self.Defines.DefinesDictionary)\r
 \r
@@ -109,6 +255,33 @@ class Dec(DecObject):
                                     key + DataType.TAB_SPLIT + arch + \\r
                                     "' + TAB_SECTION_END, self.Contents[arch]." + key + ')'\r
                 eval(Command)\r
+    \r
+    def ShowPackage(self):\r
+        m = self.Package\r
+        print 'Filename =', m.Header.FileName\r
+        print 'FullPath =', m.Header.FullPath\r
+        print 'BaseName =', m.Header.Name\r
+        print 'Guid =', m.Header.Guid\r
+        print 'Version =', m.Header.Version\r
+        print 'DecSpecification =', m.Header.DecSpecification\r
+        print '\nIncludes =', m.Includes\r
+        for Item in m.Includes:\r
+            print Item.FilePath, Item.SupArchList\r
+        print '\nGuids =', m.GuidDeclarations\r
+        for Item in m.GuidDeclarations:\r
+            print Item.CName, Item.Guid, Item.SupArchList\r
+        print '\nProtocols =', m.ProtocolDeclarations\r
+        for Item in m.ProtocolDeclarations:\r
+            print Item.CName, Item.Guid, Item.SupArchList\r
+        print '\nPpis =', m.PpiDeclarations\r
+        for Item in m.PpiDeclarations:\r
+            print Item.CName, Item.Guid, Item.SupArchList\r
+        print '\nLibraryClasses =', m.LibraryClassDeclarations\r
+        for Item in m.LibraryClassDeclarations:\r
+            print Item.LibraryClass, Item.RecommendedInstance, Item.SupArchList\r
+        print '\nPcds =', m.PcdDeclarations\r
+        for Item in m.PcdDeclarations:\r
+            print Item.CName, Item.TokenSpaceGuidCName, Item.DefaultValue, Item.ItemType, Item.Token, Item.DatumType, Item.SupArchList\r
 \r
 if __name__ == '__main__':\r
     p = Dec()\r
@@ -118,7 +291,7 @@ if __name__ == '__main__':
         if os.path.splitext(os.path.normcase(f))[1] == '.dec':\r
             fileList.append(os.path.join(directory, os.path.normcase(f)))\r
             \r
-            \r
     for f in fileList:\r
-        p.LoadDecFile(f)\r
-        p.showDec()\r
+        p = Dec(f, True, True)\r
+        #p.ShowDec()\r
+        p.ShowPackage()\r