public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Gary Lin <glin@suse.com>
To: edk2-devel@lists.01.org
Cc: Yonghong Zhu <yonghong.zhu@intel.com>, Liming Gao <liming.gao@intel.com>
Subject: [PATCH v2 19/20] BaseTools: Move FindExtendTool to GenFdsGlobalVariable.py
Date: Thu,  1 Feb 2018 16:36:07 +0800	[thread overview]
Message-ID: <20180201083608.16036-20-glin@suse.com> (raw)
In-Reply-To: <20180201083608.16036-1-glin@suse.com>

Importing "FindExtendTool" from GenFds.GenFds could create the following
circular imports:

* GenFds.FdfParser => GenFds.Capsule => GenFds.GenFds => GenFds.FdfParser
* GenFds.FdfParser => GenFds.Fd => GenFds.Fv => GenFds.AprioriSection =>
  GenFds.FfsFileStatement => GenFds.GuidSection => GenFds.GenFds =>
  GenFds.FdfParser

This commit moves "FindExtendTool" to GenFdsGlobalVariable.py to break
the circles.

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>
---
 BaseTools/Source/Python/GenFds/Capsule.py              |  2 +-
 BaseTools/Source/Python/GenFds/GenFds.py               | 93 -------------------
 BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py | 95 +++++++++++++++++++-
 BaseTools/Source/Python/GenFds/GuidSection.py          |  2 +-
 4 files changed, 96 insertions(+), 96 deletions(-)

diff --git a/BaseTools/Source/Python/GenFds/Capsule.py b/BaseTools/Source/Python/GenFds/Capsule.py
index fb929065634e..55e9e1dade2f 100644
--- a/BaseTools/Source/Python/GenFds/Capsule.py
+++ b/BaseTools/Source/Python/GenFds/Capsule.py
@@ -17,6 +17,7 @@
 #
 from __future__ import absolute_import
 from .GenFdsGlobalVariable import GenFdsGlobalVariable
+from .GenFdsGlobalVariable import FindExtendTool
 from CommonDataClass.FdfClass import CapsuleClassObject
 import Common.LongFilePathOs as os
 import subprocess
@@ -56,7 +57,6 @@ class Capsule (CapsuleClassObject) :
     #   @retval string      Generated Capsule file path
     #
     def GenFmpCapsule(self):
-        from .GenFds import FindExtendTool
         #
         # Generate capsule header
         # typedef struct {
diff --git a/BaseTools/Source/Python/GenFds/GenFds.py b/BaseTools/Source/Python/GenFds/GenFds.py
index 7c1df37778fb..953069fc52f7 100644
--- a/BaseTools/Source/Python/GenFds/GenFds.py
+++ b/BaseTools/Source/Python/GenFds/GenFds.py
@@ -415,99 +415,6 @@ def CheckBuildOptionPcd():
 
             GlobalData.BuildOptionPcd[i] = (TokenSpaceGuidCName, TokenCName, NewValue)
 
-
-## FindExtendTool()
-#
-#  Find location of tools to process data
-#
-#  @param  KeyStringList    Filter for inputs of section generation
-#  @param  CurrentArchList  Arch list
-#  @param  NameGuid         The Guid name
-#
-def FindExtendTool(KeyStringList, CurrentArchList, NameGuid):
-    ToolDb = ToolDefClassObject.ToolDefDict(GenFdsGlobalVariable.ConfDir).ToolsDefTxtDatabase
-    # if user not specify filter, try to deduce it from global data.
-    if KeyStringList == None or KeyStringList == []:
-        Target = GenFdsGlobalVariable.TargetName
-        ToolChain = GenFdsGlobalVariable.ToolChainTag
-        if ToolChain not in ToolDb['TOOL_CHAIN_TAG']:
-            EdkLogger.error("GenFds", GENFDS_ERROR, "Can not find external tool because tool tag %s is not defined in tools_def.txt!" % ToolChain)
-        KeyStringList = [Target + '_' + ToolChain + '_' + CurrentArchList[0]]
-        for Arch in CurrentArchList:
-            if Target + '_' + ToolChain + '_' + Arch not in KeyStringList:
-                KeyStringList.append(Target + '_' + ToolChain + '_' + Arch)
-
-    if GenFdsGlobalVariable.GuidToolDefinition:
-        if NameGuid in GenFdsGlobalVariable.GuidToolDefinition.keys():
-            return GenFdsGlobalVariable.GuidToolDefinition[NameGuid]
-
-    ToolDefinition = ToolDefClassObject.ToolDefDict(GenFdsGlobalVariable.ConfDir).ToolsDefTxtDictionary
-    ToolPathTmp = None
-    ToolOption = None
-    ToolPathKey = None
-    ToolOptionKey = None
-    KeyList = None
-    for ToolDef in ToolDefinition.items():
-        if NameGuid == ToolDef[1]:
-            KeyList = ToolDef[0].split('_')
-            Key = KeyList[0] + \
-                  '_' + \
-                  KeyList[1] + \
-                  '_' + \
-                  KeyList[2]
-            if Key in KeyStringList and KeyList[4] == 'GUID':
-                ToolPathKey   = Key + '_' + KeyList[3] + '_PATH'
-                ToolOptionKey = Key + '_' + KeyList[3] + '_FLAGS'
-                ToolPath = ToolDefinition.get(ToolPathKey)
-                ToolOption = ToolDefinition.get(ToolOptionKey)
-                if ToolPathTmp == None:
-                    ToolPathTmp = ToolPath
-                else:
-                    if ToolPathTmp != ToolPath:
-                        EdkLogger.error("GenFds", GENFDS_ERROR, "Don't know which tool to use, %s or %s ?" % (ToolPathTmp, ToolPath))
-
-    BuildOption = {}
-    for Arch in CurrentArchList:
-        Platform = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]
-        # key is (ToolChainFamily, ToolChain, CodeBase)
-        for item in Platform.BuildOptions:
-            if '_PATH' in item[1] or '_FLAGS' in item[1] or '_GUID' in item[1]:
-                if not item[0] or (item[0] and GenFdsGlobalVariable.ToolChainFamily== item[0]):
-                    if item[1] not in BuildOption:
-                        BuildOption[item[1]] = Platform.BuildOptions[item]
-        if BuildOption:
-            ToolList = [TAB_TOD_DEFINES_TARGET, TAB_TOD_DEFINES_TOOL_CHAIN_TAG, TAB_TOD_DEFINES_TARGET_ARCH]
-            for Index in range(2, -1, -1):
-                for Key in dict(BuildOption):
-                    List = Key.split('_')
-                    if List[Index] == '*':
-                        for String in ToolDb[ToolList[Index]]:
-                            if String in [Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]:
-                                List[Index] = String
-                                NewKey = '%s_%s_%s_%s_%s' % tuple(List)
-                                if NewKey not in BuildOption:
-                                    BuildOption[NewKey] = BuildOption[Key]
-                                    continue
-                                del BuildOption[Key]
-                    elif List[Index] not in ToolDb[ToolList[Index]]:
-                        del BuildOption[Key]
-    if BuildOption:
-        if not KeyList:
-            for Op in BuildOption:
-                if NameGuid == BuildOption[Op]:
-                    KeyList = Op.split('_')
-                    Key = KeyList[0] + '_' + KeyList[1] +'_' + KeyList[2]
-                    if Key in KeyStringList and KeyList[4] == 'GUID':
-                        ToolPathKey   = Key + '_' + KeyList[3] + '_PATH'
-                        ToolOptionKey = Key + '_' + KeyList[3] + '_FLAGS'
-        if ToolPathKey in BuildOption.keys():
-            ToolPathTmp = BuildOption.get(ToolPathKey)
-        if ToolOptionKey in BuildOption.keys():
-            ToolOption = BuildOption.get(ToolOptionKey)
-
-    GenFdsGlobalVariable.GuidToolDefinition[NameGuid] = (ToolPathTmp, ToolOption)
-    return ToolPathTmp, ToolOption
-
 ## Parse command line options
 #
 # Using standard Python module optparse to parse command line option of this tool.
diff --git a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
index d7fd58c7482f..a534fcb9371a 100644
--- a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
+++ b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
@@ -27,8 +27,9 @@ from Common.BuildToolError import *
 from Common import EdkLogger
 from Common.Misc import SaveFileOnChange
 
+from Common.DataType import TAB_TOD_DEFINES_TARGET, TAB_TOD_DEFINES_TOOL_CHAIN_TAG, TAB_TOD_DEFINES_TARGET_ARCH
 from Common.TargetTxtClassObject import TargetTxtClassObject
-from Common.ToolDefClassObject import ToolDefClassObject
+from Common.ToolDefClassObject import ToolDefClassObject, ToolDefDict
 from AutoGen.BuildEngine import BuildRule
 import Common.DataType as DataType
 from Common.Misc import PathClass
@@ -845,3 +846,95 @@ class GenFdsGlobalVariable:
     DebugLogger = staticmethod(DebugLogger)
     MacroExtend = staticmethod (MacroExtend)
     GetPcdValue = staticmethod(GetPcdValue)
+
+## FindExtendTool()
+#
+#  Find location of tools to process data
+#
+#  @param  KeyStringList    Filter for inputs of section generation
+#  @param  CurrentArchList  Arch list
+#  @param  NameGuid         The Guid name
+#
+def FindExtendTool(KeyStringList, CurrentArchList, NameGuid):
+    ToolDb = ToolDefDict(GenFdsGlobalVariable.ConfDir).ToolsDefTxtDatabase
+    # if user not specify filter, try to deduce it from global data.
+    if KeyStringList == None or KeyStringList == []:
+        Target = GenFdsGlobalVariable.TargetName
+        ToolChain = GenFdsGlobalVariable.ToolChainTag
+        if ToolChain not in ToolDb['TOOL_CHAIN_TAG']:
+            EdkLogger.error("GenFds", GENFDS_ERROR, "Can not find external tool because tool tag %s is not defined in tools_def.txt!" % ToolChain)
+        KeyStringList = [Target + '_' + ToolChain + '_' + CurrentArchList[0]]
+        for Arch in CurrentArchList:
+            if Target + '_' + ToolChain + '_' + Arch not in KeyStringList:
+                KeyStringList.append(Target + '_' + ToolChain + '_' + Arch)
+
+    if GenFdsGlobalVariable.GuidToolDefinition:
+        if NameGuid in GenFdsGlobalVariable.GuidToolDefinition.keys():
+            return GenFdsGlobalVariable.GuidToolDefinition[NameGuid]
+
+    ToolDefinition = ToolDefDict(GenFdsGlobalVariable.ConfDir).ToolsDefTxtDictionary
+    ToolPathTmp = None
+    ToolOption = None
+    ToolPathKey = None
+    ToolOptionKey = None
+    KeyList = None
+    for ToolDef in ToolDefinition.items():
+        if NameGuid == ToolDef[1]:
+            KeyList = ToolDef[0].split('_')
+            Key = KeyList[0] + \
+                  '_' + \
+                  KeyList[1] + \
+                  '_' + \
+                  KeyList[2]
+            if Key in KeyStringList and KeyList[4] == 'GUID':
+                ToolPathKey   = Key + '_' + KeyList[3] + '_PATH'
+                ToolOptionKey = Key + '_' + KeyList[3] + '_FLAGS'
+                ToolPath = ToolDefinition.get(ToolPathKey)
+                ToolOption = ToolDefinition.get(ToolOptionKey)
+                if ToolPathTmp == None:
+                    ToolPathTmp = ToolPath
+                else:
+                    if ToolPathTmp != ToolPath:
+                        EdkLogger.error("GenFds", GENFDS_ERROR, "Don't know which tool to use, %s or %s ?" % (ToolPathTmp, ToolPath))
+
+    BuildOption = {}
+    for Arch in CurrentArchList:
+        Platform = GenFdsGlobalVariable.WorkSpace.BuildObject[GenFdsGlobalVariable.ActivePlatform, Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]
+        # key is (ToolChainFamily, ToolChain, CodeBase)
+        for item in Platform.BuildOptions:
+            if '_PATH' in item[1] or '_FLAGS' in item[1] or '_GUID' in item[1]:
+                if not item[0] or (item[0] and GenFdsGlobalVariable.ToolChainFamily== item[0]):
+                    if item[1] not in BuildOption:
+                        BuildOption[item[1]] = Platform.BuildOptions[item]
+        if BuildOption:
+            ToolList = [TAB_TOD_DEFINES_TARGET, TAB_TOD_DEFINES_TOOL_CHAIN_TAG, TAB_TOD_DEFINES_TARGET_ARCH]
+            for Index in range(2, -1, -1):
+                for Key in dict(BuildOption):
+                    List = Key.split('_')
+                    if List[Index] == '*':
+                        for String in ToolDb[ToolList[Index]]:
+                            if String in [Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]:
+                                List[Index] = String
+                                NewKey = '%s_%s_%s_%s_%s' % tuple(List)
+                                if NewKey not in BuildOption:
+                                    BuildOption[NewKey] = BuildOption[Key]
+                                    continue
+                                del BuildOption[Key]
+                    elif List[Index] not in ToolDb[ToolList[Index]]:
+                        del BuildOption[Key]
+    if BuildOption:
+        if not KeyList:
+            for Op in BuildOption:
+                if NameGuid == BuildOption[Op]:
+                    KeyList = Op.split('_')
+                    Key = KeyList[0] + '_' + KeyList[1] +'_' + KeyList[2]
+                    if Key in KeyStringList and KeyList[4] == 'GUID':
+                        ToolPathKey   = Key + '_' + KeyList[3] + '_PATH'
+                        ToolOptionKey = Key + '_' + KeyList[3] + '_FLAGS'
+        if ToolPathKey in BuildOption.keys():
+            ToolPathTmp = BuildOption.get(ToolPathKey)
+        if ToolOptionKey in BuildOption.keys():
+            ToolOption = BuildOption.get(ToolOptionKey)
+
+    GenFdsGlobalVariable.GuidToolDefinition[NameGuid] = (ToolPathTmp, ToolOption)
+    return ToolPathTmp, ToolOption
diff --git a/BaseTools/Source/Python/GenFds/GuidSection.py b/BaseTools/Source/Python/GenFds/GuidSection.py
index 877dabc196e1..679934dc7794 100644
--- a/BaseTools/Source/Python/GenFds/GuidSection.py
+++ b/BaseTools/Source/Python/GenFds/GuidSection.py
@@ -21,6 +21,7 @@ import subprocess
 from .Ffs import Ffs
 import Common.LongFilePathOs as os
 from .GenFdsGlobalVariable import GenFdsGlobalVariable
+from .GenFdsGlobalVariable import FindExtendTool
 from CommonDataClass.FdfClass import GuidSectionClassObject
 from Common import ToolDefClassObject
 import sys
@@ -129,7 +130,6 @@ class GuidSection(GuidSectionClassObject) :
         ExternalTool = None
         ExternalOption = None
         if self.NameGuid != None:
-            from .GenFds import FindExtendTool
             ExternalTool, ExternalOption = FindExtendTool(self.KeyStringList, self.CurrentArchList, self.NameGuid)
 
         #
-- 
2.16.1



  parent reply	other threads:[~2018-02-01  8:31 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-01  8:35 [PATCH v2 00/20] BaseTools: One step toward python3 Gary Lin
2018-02-01  8:35 ` [PATCH v2 01/20] BaseTools: Refactor python except statements Gary Lin
2018-02-01  8:35 ` [PATCH v2 02/20] BaseTools: Refactor python print statements Gary Lin
2018-02-01  8:35 ` [PATCH v2 03/20] BaseTools: Remove the old python "not-equal" Gary Lin
2018-02-01  8:35 ` [PATCH v2 04/20] BaseTools: Use the python3-range functions Gary Lin
2018-02-01  8:35 ` [PATCH v2 05/20] BaseTools: Remove tuple parameter in python scripts Gary Lin
2018-02-01  8:35 ` [PATCH v2 06/20] BaseTools: Remove the deprecated hash_key() Gary Lin
2018-02-01  8:35 ` [PATCH v2 07/20] BaseTools: Import reduce() from functools Gary Lin
2018-02-01  8:35 ` [PATCH v2 08/20] BaseTools: Replace StandardError with Expression Gary Lin
2018-02-01  8:35 ` [PATCH v2 09/20] BaseTools: Remove types.TypeType Gary Lin
2018-02-01  8:35 ` [PATCH v2 10/20] BaseTools: Refactor python raise statement Gary Lin
2018-02-01  8:35 ` [PATCH v2 11/20] BaseTools: Adjust the spaces around commas and colons Gary Lin
2018-02-01  8:36 ` [PATCH v2 12/20] BaseTools: Migrate to the new octal literal Gary Lin
2018-02-01  8:36 ` [PATCH v2 13/20] BaseTools: Unify long int and int in python scripts Gary Lin
2018-02-01  8:36 ` [PATCH v2 14/20] BaseTools: Adjust old python2 idioms Gary Lin
2018-02-01  8:36 ` [PATCH v2 15/20] BaseTools: Replace StringIO.StringIO with io.BytesIO Gary Lin
2018-02-01  8:36 ` [PATCH v2 16/20] BaseTools: Treat GenFds.py and build.py as python modules Gary Lin
2018-02-01  8:36 ` [PATCH v2 17/20] BaseTools: Adopt absolute import for python scripts Gary Lin
2018-02-01  8:36 ` [PATCH v2 18/20] BaseTools: Move OverrideAttribs to OptRomInfStatement.py Gary Lin
2018-02-01  8:36 ` Gary Lin [this message]
2018-02-01  8:36 ` [PATCH v2 20/20] BaseTools: Move ImageBinDict to GenFdsGlobalVariable.py Gary Lin
2018-06-20  6:22 ` [PATCH v2 00/20] BaseTools: One step toward python3 Paolo Bonzini
2018-06-20  7:29   ` Zhu, Yonghong
2018-06-20  8:08     ` Gary Lin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180201083608.16036-20-glin@suse.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox