1. Add -m and -s to support only scanning meta-data files or source code files
[people/mcb30/basetools.git] / Source / Python / Common / DecClassObject.py
index 78280ba..b95ff62 100644 (file)
@@ -23,7 +23,7 @@ from CommonDataClass.PackageClass import *
 from CommonDataClass.CommonClass import PcdClass\r
 from BuildToolError import *\r
 from Table.TableDec import TableDec\r
-import Database as Database\r
+import Database\r
 from Parsing import *\r
 import GlobalData\r
 \r
@@ -92,7 +92,8 @@ class Dec(DecObject):
         \r
         self.Cur = Database.Cur\r
         self.TblFile = Database.TblFile\r
-        self.TblDec = TableDec(Database.Cur)\r
+        self.TblDec = Database.TblDec\r
+        self.FileID = -1\r
 \r
         self.KeyList = [\r
             TAB_INCLUDES, TAB_GUIDS, TAB_PROTOCOLS, TAB_PPIS, TAB_LIBRARY_CLASSES, \\r
@@ -136,13 +137,13 @@ class Dec(DecObject):
         Filename = NormPath(Filename)\r
         self.Identification.FileFullPath = Filename\r
         (self.Identification.FileRelativePath, self.Identification.FileName) = os.path.split(Filename)\r
-        FileID = self.TblFile.InsertFile(Filename, MODEL_FILE_DSC)\r
+        self.FileID = self.TblFile.InsertFile(Filename, MODEL_FILE_DEC)\r
         \r
         #\r
         # Init DecTable\r
         #\r
-        self.TblDec.Table = "Dec%s" % FileID\r
-        self.TblDec.Create()\r
+        #self.TblDec.Table = "Dec%s" % self.FileID\r
+        #self.TblDec.Create()\r
         \r
         #\r
         # Init common datas\r
@@ -188,7 +189,7 @@ class Dec(DecObject):
                 # Insert items data of previous section\r
                 #\r
                 Model = Section[CurrentSection.upper()]\r
-                InsertSectionItemsIntoDatabase(self.TblDec, FileID, Filename, Model, CurrentSection, SectionItemList, ArchList, ThirdList, IfDefList, self.RecordSet)\r
+                InsertSectionItemsIntoDatabase(self.TblDec, self.FileID, Filename, Model, CurrentSection, SectionItemList, ArchList, ThirdList, IfDefList, self.RecordSet)\r
 \r
                 #\r
                 # Parse the new section\r
@@ -205,7 +206,7 @@ class Dec(DecObject):
                         CurrentSection = ItemList[0]\r
                     else:\r
                         if CurrentSection != ItemList[0]:\r
-                            EdkLogger.error("Parser", PARSER_ERROR, "Different section names '%s' and '%s' are found in one section definition, this is not allowed." % (CurrentSection, ItemList[0]), File=Filename, Line=LineNo)\r
+                            EdkLogger.error("Parser", PARSER_ERROR, "Different section names '%s' and '%s' are found in one section definition, this is not allowed." % (CurrentSection, ItemList[0]), File=Filename, Line=LineNo, RaiseError = EdkLogger.IsRaiseError)\r
                     if CurrentSection.upper() not in self.KeyList:\r
                         RaiseParserError(Line, CurrentSection, Filename, '', LineNo)\r
                     ItemList.append('')\r
@@ -214,7 +215,7 @@ class Dec(DecObject):
                         RaiseParserError(Line, CurrentSection, Filename, '', LineNo)\r
                     else:\r
                         if ItemList[1] != '' and ItemList[1].upper() not in ARCH_LIST_FULL:\r
-                            EdkLogger.error("Parser", PARSER_ERROR, "Invalid Arch definition '%s' found" % ItemList[1], File=Filename, Line=LineNo)\r
+                            EdkLogger.error("Parser", PARSER_ERROR, "Invalid Arch definition '%s' found" % ItemList[1], File=Filename, Line=LineNo, RaiseError = EdkLogger.IsRaiseError)\r
                         ArchList.append(ItemList[1].upper())\r
                         ThirdList.append(ItemList[2])\r
 \r
@@ -225,7 +226,7 @@ class Dec(DecObject):
             #\r
             if CurrentSection == TAB_UNKNOWN:\r
                 ErrorMsg = "%s is not in any defined section" % Line\r
-                EdkLogger.error("Parser", PARSER_ERROR, ErrorMsg, File=Filename, Line=LineNo)\r
+                EdkLogger.error("Parser", PARSER_ERROR, ErrorMsg, File=Filename, Line=LineNo, RaiseError = EdkLogger.IsRaiseError)\r
 \r
             #\r
             # Add a section item\r
@@ -238,7 +239,7 @@ class Dec(DecObject):
         # Insert items data of last section\r
         #\r
         Model = Section[CurrentSection.upper()]\r
-        InsertSectionItemsIntoDatabase(self.TblDec, FileID, Filename, Model, CurrentSection, SectionItemList, ArchList, ThirdList, IfDefList, self.RecordSet)\r
+        InsertSectionItemsIntoDatabase(self.TblDec, self.FileID, Filename, Model, CurrentSection, SectionItemList, ArchList, ThirdList, IfDefList, self.RecordSet)\r
         \r
         #\r
         # Replace all DEFINE macros with its actual values\r
@@ -317,12 +318,12 @@ class Dec(DecObject):
         for Arch in self.SupArchList:\r
             PackageHeader = PackageHeaderClass()\r
             \r
-            PackageHeader.Name = QueryDefinesItem(self.TblDec, TAB_DEC_DEFINES_PACKAGE_NAME, Arch)[0]\r
-            PackageHeader.Guid = QueryDefinesItem(self.TblDec, TAB_DEC_DEFINES_PACKAGE_GUID, Arch)[0]\r
-            PackageHeader.Version = QueryDefinesItem(self.TblDec, TAB_DEC_DEFINES_PACKAGE_VERSION, Arch)[0]\r
+            PackageHeader.Name = QueryDefinesItem(self.TblDec, TAB_DEC_DEFINES_PACKAGE_NAME, Arch, self.FileID)[0]\r
+            PackageHeader.Guid = QueryDefinesItem(self.TblDec, TAB_DEC_DEFINES_PACKAGE_GUID, Arch, self.FileID)[0]\r
+            PackageHeader.Version = QueryDefinesItem(self.TblDec, TAB_DEC_DEFINES_PACKAGE_VERSION, Arch, self.FileID)[0]\r
             PackageHeader.FileName = self.Identification.FileName\r
             PackageHeader.FullPath = self.Identification.FileFullPath\r
-            PackageHeader.DecSpecification = QueryDefinesItem(self.TblDec, TAB_DEC_DEFINES_DEC_SPECIFICATION, Arch)[0]\r
+            PackageHeader.DecSpecification = QueryDefinesItem(self.TblDec, TAB_DEC_DEFINES_DEC_SPECIFICATION, Arch, self.FileID)[0]\r
             \r
             self.Package.Header[Arch] = PackageHeader\r
     \r
@@ -450,6 +451,7 @@ class Dec(DecObject):
     def GenPcds(self, ContainerFile):\r
         EdkLogger.debug(2, "Generate %s ..." % TAB_PCDS)\r
         Pcds = {}\r
+        PcdToken = {}\r
         #\r
         # Get all Guids\r
         #\r
@@ -465,19 +467,36 @@ class Dec(DecObject):
         for Arch in self.SupArchList:\r
             for Record in RecordSet1:\r
                 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
-                    MergeArches(Pcds, GetPcdOfDec(Record[0], TAB_PCDS_FIXED_AT_BUILD, ContainerFile, Record[2]), Arch)\r
+                    (TokenGuidCName, TokenName, Value, DatumType, Token, Type) = GetPcdOfDec(Record[0], TAB_PCDS_FIXED_AT_BUILD, ContainerFile, Record[2])\r
+                    MergeArches(Pcds, (TokenGuidCName, TokenName, Value, DatumType, Token, Type), Arch)\r
+                    PcdToken[Record[3]] = (TokenGuidCName, TokenName)\r
             for Record in RecordSet2:\r
                 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
-                    MergeArches(Pcds, GetPcdOfDec(Record[0], TAB_PCDS_PATCHABLE_IN_MODULE, ContainerFile, Record[2]), Arch)\r
+                    (TokenGuidCName, TokenName, Value, DatumType, Token, Type) = GetPcdOfDec(Record[0], TAB_PCDS_PATCHABLE_IN_MODULE, ContainerFile, Record[2])\r
+                    MergeArches(Pcds, (TokenGuidCName, TokenName, Value, DatumType, Token, Type), Arch)\r
+                    PcdToken[Record[3]] = (TokenGuidCName, TokenName)\r
             for Record in RecordSet3:\r
                 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
-                    MergeArches(Pcds, GetPcdOfDec(Record[0], TAB_PCDS_FEATURE_FLAG, ContainerFile, Record[2]), Arch)\r
+                    (TokenGuidCName, TokenName, Value, DatumType, Token, Type) = GetPcdOfDec(Record[0], TAB_PCDS_FEATURE_FLAG, ContainerFile, Record[2])\r
+                    MergeArches(Pcds, (TokenGuidCName, TokenName, Value, DatumType, Token, Type), Arch)\r
+                    PcdToken[Record[3]] = (TokenGuidCName, TokenName)\r
             for Record in RecordSet4:\r
                 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
-                    MergeArches(Pcds, GetPcdOfDec(Record[0], TAB_PCDS_DYNAMIC_EX, ContainerFile, Record[2]), Arch)\r
+                    (TokenGuidCName, TokenName, Value, DatumType, Token, Type) = GetPcdOfDec(Record[0], TAB_PCDS_DYNAMIC_EX, ContainerFile, Record[2])\r
+                    MergeArches(Pcds, (TokenGuidCName, TokenName, Value, DatumType, Token, Type), Arch)\r
+                    PcdToken[Record[3]] = (TokenGuidCName, TokenName)\r
             for Record in RecordSet5:\r
                 if Record[1] == Arch or Record[1] == TAB_ARCH_COMMON:\r
-                    MergeArches(Pcds, GetPcdOfDec(Record[0], TAB_PCDS_DYNAMIC, ContainerFile, Record[2]), Arch)                    \r
+                    (TokenGuidCName, TokenName, Value, DatumType, Token, Type) = GetPcdOfDec(Record[0], TAB_PCDS_DYNAMIC, ContainerFile, Record[2])\r
+                    MergeArches(Pcds, (TokenGuidCName, TokenName, Value, DatumType, Token, Type), Arch)\r
+                    PcdToken[Record[3]] = (TokenGuidCName, TokenName)\r
+        #\r
+        # Update to database\r
+        #\r
+        if self.IsToDatabase:\r
+            for Key in PcdToken.keys():\r
+                SqlCommand = """update %s set Value2 = '%s' where ID = %s""" % (self.TblDec.Table, ".".join((PcdToken[Key][0], PcdToken[Key][1])), Key)\r
+                self.TblDec.Exec(SqlCommand)\r
 \r
         for Key in Pcds.keys():\r
             Pcd = PcdClass()\r