BaseTools: Fix two drivers include the same file issue
authorYunhua Feng <yunhuax.feng@intel.com>
Thu, 21 Jun 2018 07:17:24 +0000 (15:17 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Fri, 29 Jun 2018 07:21:45 +0000 (15:21 +0800)
Two drivers include the same PCD file, the PCD value in the first
driver is correct, but it in the second driver is incorrect.

DSC:
[Components]
  Testpkg/Testdriver1.inf {
  <PcdsFixedAtBuild>
  !include Test.txt
  }
  Testpkg/Testdriver2.inf {
  <PcdsFixedAtBuild>
  !include Test.txt
  }

Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
BaseTools/Source/Python/Workspace/MetaDataTable.py
BaseTools/Source/Python/Workspace/MetaFileParser.py
BaseTools/Source/Python/Workspace/MetaFileTable.py

index e37a10c..bd751ea 100644 (file)
@@ -168,7 +168,8 @@ class TableFile(Table):
         Path VARCHAR,\r
         FullPath VARCHAR NOT NULL,\r
         Model INTEGER DEFAULT 0,\r
-        TimeStamp SINGLE NOT NULL\r
+        TimeStamp SINGLE NOT NULL,\r
+        FromItem REAL NOT NULL\r
         '''\r
     def __init__(self, Cursor):\r
         Table.__init__(self, Cursor, 'File')\r
@@ -184,7 +185,7 @@ class TableFile(Table):
     # @param Model:     Model of a File\r
     # @param TimeStamp: TimeStamp of a File\r
     #\r
-    def Insert(self, Name, ExtName, Path, FullPath, Model, TimeStamp):\r
+    def Insert(self, Name, ExtName, Path, FullPath, Model, TimeStamp, FromItem=0):\r
         (Name, ExtName, Path, FullPath) = ConvertToSqlString((Name, ExtName, Path, FullPath))\r
         return Table.Insert(\r
             self,\r
@@ -193,7 +194,8 @@ class TableFile(Table):
             Path,\r
             FullPath,\r
             Model,\r
-            TimeStamp\r
+            TimeStamp,\r
+            FromItem\r
             )\r
 \r
     ## InsertFile\r
@@ -205,7 +207,17 @@ class TableFile(Table):
     #\r
     # @retval FileID:       The ID after record is inserted\r
     #\r
-    def InsertFile(self, File, Model):\r
+    def InsertFile(self, File, Model, FromItem=''):\r
+        if FromItem:\r
+            return self.Insert(\r
+                        File.Name,\r
+                        File.Ext,\r
+                        File.Dir,\r
+                        File.Path,\r
+                        Model,\r
+                        File.TimeStamp,\r
+                        FromItem\r
+                        )\r
         return self.Insert(\r
                         File.Name,\r
                         File.Ext,\r
@@ -221,8 +233,11 @@ class TableFile(Table):
     #\r
     #   @retval ID          ID value of given file in the table\r
     #\r
-    def GetFileId(self, File):\r
-        QueryScript = "select ID from %s where FullPath = '%s'" % (self.Table, str(File))\r
+    def GetFileId(self, File, FromItem=None):\r
+        if FromItem:\r
+            QueryScript = "select ID from %s where FullPath = '%s' and FromItem = %s" % (self.Table, str(File), str(FromItem))\r
+        else:\r
+            QueryScript = "select ID from %s where FullPath = '%s'" % (self.Table, str(File))\r
         RecordList = self.Exec(QueryScript)\r
         if len(RecordList) == 0:\r
             return None\r
index f089758..f35778d 100644 (file)
@@ -886,7 +886,7 @@ class DscParser(MetaFileParser):
     #\r
     def __init__(self, FilePath, FileType, Arch, Table, Owner= -1, From= -1):\r
         # prevent re-initialization\r
-        if hasattr(self, "_Table"):\r
+        if hasattr(self, "_Table") and self._Table is Table:\r
             return\r
         MetaFileParser.__init__(self, FilePath, FileType, Arch, Table, Owner, From)\r
         self._Version = 0x00010005  # Only EDK2 dsc file is supported\r
@@ -1557,12 +1557,12 @@ class DscParser(MetaFileParser):
 \r
             self._FileWithError = IncludedFile1\r
 \r
-            IncludedFileTable = MetaFileStorage(self._Table.Cur, IncludedFile1, MODEL_FILE_DSC, False)\r
             FromItem = self._Content[self._ContentIndex - 1][0]\r
             if self._InSubsection:\r
                 Owner = self._Content[self._ContentIndex - 1][8]\r
             else:\r
                 Owner = self._Content[self._ContentIndex - 1][0]\r
+            IncludedFileTable = MetaFileStorage(self._Table.Cur, IncludedFile1, MODEL_FILE_DSC, False, FromItem=FromItem)\r
             Parser = DscParser(IncludedFile1, self._FileType, self._Arch, IncludedFileTable,\r
                                Owner=Owner, From=FromItem)\r
 \r
index 69b2c40..f528c1e 100644 (file)
@@ -31,15 +31,15 @@ class MetaFileTable(Table):
     _ID_MAX_ = 0.99999999\r
 \r
     ## Constructor\r
-    def __init__(self, Cursor, MetaFile, FileType, Temporary):\r
+    def __init__(self, Cursor, MetaFile, FileType, Temporary, FromItem=None):\r
         self.MetaFile = MetaFile\r
 \r
         self._FileIndexTable = TableFile(Cursor)\r
         self._FileIndexTable.Create(False)\r
 \r
-        FileId = self._FileIndexTable.GetFileId(MetaFile)\r
+        FileId = self._FileIndexTable.GetFileId(MetaFile, FromItem)\r
         if not FileId:\r
-            FileId = self._FileIndexTable.InsertFile(MetaFile, FileType)\r
+            FileId = self._FileIndexTable.InsertFile(MetaFile, FileType, FromItem)\r
 \r
         if Temporary:\r
             TableName = "_%s_%s_%s" % (FileType, FileId, uuid.uuid4().hex)\r
@@ -285,8 +285,8 @@ class PlatformTable(MetaFileTable):
     _DUMMY_ = "-1, -1, '====', '====', '====', '====', '====','====', -1, -1, -1, -1, -1, -1, -1"\r
 \r
     ## Constructor\r
-    def __init__(self, Cursor, MetaFile, Temporary):\r
-        MetaFileTable.__init__(self, Cursor, MetaFile, MODEL_FILE_DSC, Temporary)\r
+    def __init__(self, Cursor, MetaFile, Temporary, FromItem=0):\r
+        MetaFileTable.__init__(self, Cursor, MetaFile, MODEL_FILE_DSC, Temporary, FromItem)\r
 \r
     ## Insert table\r
     #\r
@@ -379,7 +379,7 @@ class MetaFileStorage(object):
     }\r
 \r
     ## Constructor\r
-    def __new__(Class, Cursor, MetaFile, FileType=None, Temporary=False):\r
+    def __new__(Class, Cursor, MetaFile, FileType=None, Temporary=False, FromItem=None):\r
         # no type given, try to find one\r
         if not FileType:\r
             if MetaFile.Type in self._FILE_TYPE_:\r
@@ -392,6 +392,8 @@ class MetaFileStorage(object):
             Args = (Cursor, MetaFile, FileType, Temporary)\r
         else:\r
             Args = (Cursor, MetaFile, Temporary)\r
+        if FromItem:\r
+            Args = Args + (FromItem,)\r
 \r
         # create the storage object and return it to caller\r
         return Class._FILE_TABLE_[FileType](*Args)\r