BaseTools: Move ImageBinDict to GenFdsGlobalVariable.py
authorGary Lin <glin@suse.com>
Fri, 13 Jul 2018 10:18:36 +0000 (18:18 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Mon, 16 Jul 2018 03:22:14 +0000 (11:22 +0800)
Move "ImageBinDict" from GenFds.py to GenFdsGlobalVariable.py so that we
can remove the requirement to import GenFds.GenFds in Capsule.py, Fd.py and
Fv.py. This breaks the following circular imports:

* GenFds.FdfParser => GenFds.Capsule => GenFds.GenFds => GenFds.FdfParser
* GenFds.FdfParser => GenFds.Fd => GenFds.GenFds => GenFds.FdfParser
* GenFds.FdfParser => GenFds.Fd => GenFds.Fv => GenFds.GenFds =>
  GenFds.FdfParser

Contributed-under: TianoCore Contribution Agreement 1.1
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Gary Lin <glin@suse.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
BaseTools/Source/Python/GenFds/Capsule.py
BaseTools/Source/Python/GenFds/Fd.py
BaseTools/Source/Python/GenFds/Fv.py
BaseTools/Source/Python/GenFds/GenFds.py
BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py

index 8471cd5..baa6e1d 100644 (file)
@@ -201,9 +201,8 @@ class Capsule (CapsuleClassObject) :
     #   @retval string      Generated Capsule file path\r
     #\r
     def GenCapsule(self):\r
-        from .GenFds import GenFds\r
-        if self.UiCapsuleName.upper() + 'cap' in GenFds.ImageBinDict:\r
-            return GenFds.ImageBinDict[self.UiCapsuleName.upper() + 'cap']\r
+        if self.UiCapsuleName.upper() + 'cap' in GenFdsGlobalVariable.ImageBinDict:\r
+            return GenFdsGlobalVariable.ImageBinDict[self.UiCapsuleName.upper() + 'cap']\r
 \r
         GenFdsGlobalVariable.InfLogger( "\nGenerate %s Capsule" %self.UiCapsuleName)\r
         if ('CAPSULE_GUID' in self.TokensDict and\r
@@ -237,7 +236,7 @@ class Capsule (CapsuleClassObject) :
 \r
         GenFdsGlobalVariable.VerboseLogger( "\nGenerate %s Capsule Successfully" %self.UiCapsuleName)\r
         GenFdsGlobalVariable.SharpCounter = 0\r
-        GenFds.ImageBinDict[self.UiCapsuleName.upper() + 'cap'] = CapOutputFile\r
+        GenFdsGlobalVariable.ImageBinDict[self.UiCapsuleName.upper() + 'cap'] = CapOutputFile\r
         return CapOutputFile\r
 \r
     ## Generate inf file for capsule\r
index 53318c9..bfae121 100644 (file)
@@ -47,9 +47,8 @@ class FD(FDClassObject):
     #   @retval string      Generated FD file name\r
     #\r
     def GenFd (self, Flag = False):\r
-        from .GenFds import GenFds\r
-        if self.FdUiName.upper() + 'fd' in GenFds.ImageBinDict:\r
-            return GenFds.ImageBinDict[self.FdUiName.upper() + 'fd']\r
+        if self.FdUiName.upper() + 'fd' in GenFdsGlobalVariable.ImageBinDict:\r
+            return GenFdsGlobalVariable.ImageBinDict[self.FdUiName.upper() + 'fd']\r
 \r
         #\r
         # Print Information\r
@@ -94,7 +93,7 @@ class FD(FDClassObject):
                     PadRegion.Offset = PreviousRegionStart + PreviousRegionSize\r
                     PadRegion.Size = RegionObj.Offset - PadRegion.Offset\r
                     if not Flag:\r
-                        PadRegion.AddToBuffer(TempFdBuffer, self.BaseAddress, self.BlockSizeList, self.ErasePolarity, GenFds.ImageBinDict, self.vtfRawDict, self.DefineVarDict)\r
+                        PadRegion.AddToBuffer(TempFdBuffer, self.BaseAddress, self.BlockSizeList, self.ErasePolarity, GenFdsGlobalVariable.ImageBinDict, self.vtfRawDict, self.DefineVarDict)\r
                 PreviousRegionStart = RegionObj.Offset\r
                 PreviousRegionSize = RegionObj.Size\r
                 #\r
@@ -103,7 +102,7 @@ class FD(FDClassObject):
                 if PreviousRegionSize > self.Size:\r
                     pass\r
                 GenFdsGlobalVariable.VerboseLogger('Call each region\'s AddToBuffer function')\r
-                RegionObj.AddToBuffer (TempFdBuffer, self.BaseAddress, self.BlockSizeList, self.ErasePolarity, GenFds.ImageBinDict, self.vtfRawDict, self.DefineVarDict)\r
+                RegionObj.AddToBuffer (TempFdBuffer, self.BaseAddress, self.BlockSizeList, self.ErasePolarity, GenFdsGlobalVariable.ImageBinDict, self.vtfRawDict, self.DefineVarDict)\r
 \r
         FdBuffer = BytesIO('')\r
         PreviousRegionStart = -1\r
@@ -124,7 +123,7 @@ class FD(FDClassObject):
                 PadRegion.Offset = PreviousRegionStart + PreviousRegionSize\r
                 PadRegion.Size = RegionObj.Offset - PadRegion.Offset\r
                 if not Flag:\r
-                    PadRegion.AddToBuffer(FdBuffer, self.BaseAddress, self.BlockSizeList, self.ErasePolarity, GenFds.ImageBinDict, self.vtfRawDict, self.DefineVarDict)\r
+                    PadRegion.AddToBuffer(FdBuffer, self.BaseAddress, self.BlockSizeList, self.ErasePolarity, GenFdsGlobalVariable.ImageBinDict, self.vtfRawDict, self.DefineVarDict)\r
             PreviousRegionStart = RegionObj.Offset\r
             PreviousRegionSize = RegionObj.Size\r
             #\r
@@ -138,7 +137,7 @@ class FD(FDClassObject):
             # Call each region's AddToBuffer function\r
             #\r
             GenFdsGlobalVariable.VerboseLogger('Call each region\'s AddToBuffer function')\r
-            RegionObj.AddToBuffer (FdBuffer, self.BaseAddress, self.BlockSizeList, self.ErasePolarity, GenFds.ImageBinDict, self.vtfRawDict, self.DefineVarDict, Flag=Flag)\r
+            RegionObj.AddToBuffer (FdBuffer, self.BaseAddress, self.BlockSizeList, self.ErasePolarity, GenFdsGlobalVariable.ImageBinDict, self.vtfRawDict, self.DefineVarDict, Flag=Flag)\r
         #\r
         # Write the buffer contents to Fd file\r
         #\r
@@ -146,7 +145,7 @@ class FD(FDClassObject):
         if not Flag:\r
             SaveFileOnChange(FdFileName, FdBuffer.getvalue())\r
         FdBuffer.close()\r
-        GenFds.ImageBinDict[self.FdUiName.upper() + 'fd'] = FdFileName\r
+        GenFdsGlobalVariable.ImageBinDict[self.FdUiName.upper() + 'fd'] = FdFileName\r
         return FdFileName\r
 \r
     ## generate VTF\r
index 097f51f..0d005eb 100644 (file)
@@ -70,9 +70,8 @@ class FV (FvClassObject):
     #\r
     def AddToBuffer (self, Buffer, BaseAddress=None, BlockSize= None, BlockNum=None, ErasePloarity='1', VtfDict=None, MacroDict = {}, Flag=False) :\r
 \r
-        from .GenFds import GenFds\r
-        if BaseAddress is None and self.UiFvName.upper() + 'fv' in GenFds.ImageBinDict:\r
-            return GenFds.ImageBinDict[self.UiFvName.upper() + 'fv']\r
+        if BaseAddress is None and self.UiFvName.upper() + 'fv' in GenFdsGlobalVariable.ImageBinDict:\r
+            return GenFdsGlobalVariable.ImageBinDict[self.UiFvName.upper() + 'fv']\r
 \r
         #\r
         # Check whether FV in Capsule is in FD flash region.\r
@@ -85,7 +84,7 @@ class FV (FvClassObject):
                         for RegionData in RegionObj.RegionDataList:\r
                             if RegionData.endswith(".fv"):\r
                                 continue\r
-                            elif RegionData.upper() + 'fv' in GenFds.ImageBinDict:\r
+                            elif RegionData.upper() + 'fv' in GenFdsGlobalVariable.ImageBinDict:\r
                                 continue\r
                             elif self.UiFvName.upper() == RegionData.upper():\r
                                 GenFdsGlobalVariable.ErrorLogger("Capsule %s in FD region can't contain a FV %s in FD region." % (self.CapsuleName, self.UiFvName.upper()))\r
@@ -140,7 +139,7 @@ class FV (FvClassObject):
             FvOutputFile = self.CreateFileName\r
 \r
         if Flag:\r
-            GenFds.ImageBinDict[self.UiFvName.upper() + 'fv'] = FvOutputFile\r
+            GenFdsGlobalVariable.ImageBinDict[self.UiFvName.upper() + 'fv'] = FvOutputFile\r
             return FvOutputFile\r
 \r
         FvInfoFileName = os.path.join(GenFdsGlobalVariable.FfsDir, self.UiFvName + '.inf')\r
@@ -220,7 +219,7 @@ class FV (FvClassObject):
                     # FvAlignmentValue is less than 1K\r
                     self.FvAlignment = str (FvAlignmentValue)\r
                 FvFileObj.close()\r
-                GenFds.ImageBinDict[self.UiFvName.upper() + 'fv'] = FvOutputFile\r
+                GenFdsGlobalVariable.ImageBinDict[self.UiFvName.upper() + 'fv'] = FvOutputFile\r
                 GenFdsGlobalVariable.LargeFileInFvFlags.pop()\r
             else:\r
                 GenFdsGlobalVariable.ErrorLogger("Failed to generate %s FV file." %self.UiFvName)\r
index 865c509..a7c1e6c 100644 (file)
@@ -415,8 +415,6 @@ def myOptionParser():
 #\r
 class GenFds :\r
     FdfParsef = None\r
-    # FvName, FdName, CapName in FDF, Image file name\r
-    ImageBinDict = {}\r
     OnlyGenerateThisFd = None\r
     OnlyGenerateThisFv = None\r
     OnlyGenerateThisCap = None\r
index 52aa7a1..9936498 100644 (file)
@@ -91,6 +91,9 @@ class GenFdsGlobalVariable:
 \r
     SectionHeader = struct.Struct("3B 1B")\r
 \r
+    # FvName, FdName, CapName in FDF, Image file name\r
+    ImageBinDict = {}\r
+\r
     ## LoadBuildRule\r
     #\r
     @staticmethod\r