From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=195.135.221.5; helo=smtp.nue.novell.com; envelope-from=glin@suse.com; receiver=edk2-devel@lists.01.org Received: from smtp.nue.novell.com (smtp.nue.novell.com [195.135.221.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id D4C9E2096DCE8 for ; Mon, 9 Jul 2018 20:31:31 -0700 (PDT) Received: from localhost.localdomain (unknown.telstraglobal.net [134.159.103.118]) by smtp.nue.novell.com with ESMTP (NOT encrypted); Tue, 10 Jul 2018 05:31:28 +0200 From: Gary Lin To: edk2-devel@lists.01.org Cc: Yonghong Zhu , Liming Gao Date: Tue, 10 Jul 2018 11:30:57 +0800 Message-Id: <20180710033107.32359-5-glin@suse.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180710033107.32359-1-glin@suse.com> References: <20180710033107.32359-1-glin@suse.com> Subject: [PATCH 04/14] BaseTools: Move FindExtendTool to GenFdsGlobalVariable.py X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 Jul 2018 03:31:32 -0000 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. Besides, FindExtendTool is tweaked slightly with the following changes: ToolDefClassObject.ToolDefDict => ToolDefDict TAB_GUID => DataType.TAB_GUID TAB_TOD_DEFINES_TARGET => DataType.TAB_TOD_DEFINES_TARGET TAB_TOD_DEFINES_TOOL_CHAIN_TAG => DataType.TAB_TOD_DEFINES_TOOL_CHAIN_TAG TAB_TOD_DEFINES_TARGET_ARCH => DataType.TAB_TOD_DEFINES_TARGET_ARCH Contributed-under: TianoCore Contribution Agreement 1.1 Cc: Yonghong Zhu Cc: Liming Gao Signed-off-by: Gary Lin --- BaseTools/Source/Python/GenFds/Capsule.py | 2 +- BaseTools/Source/Python/GenFds/GenFds.py | 92 ------------------- BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py | 94 +++++++++++++++++++- BaseTools/Source/Python/GenFds/GuidSection.py | 2 +- 4 files changed, 95 insertions(+), 95 deletions(-) diff --git a/BaseTools/Source/Python/GenFds/Capsule.py b/BaseTools/Source/Python/GenFds/Capsule.py index 27932ef0020c..8471cd5d0f7a 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 @@ -65,7 +66,6 @@ class Capsule (CapsuleClassObject) : # UINT32 CapsuleImageSize; # } EFI_CAPSULE_HEADER; # - from .GenFds import FindExtendTool Header = BytesIO() # # Use FMP capsule GUID: 6DCBD5ED-E82D-4C44-BDA1-7194199AD92A diff --git a/BaseTools/Source/Python/GenFds/GenFds.py b/BaseTools/Source/Python/GenFds/GenFds.py index c0b60b9b3c1f..865c5099d1eb 100644 --- a/BaseTools/Source/Python/GenFds/GenFds.py +++ b/BaseTools/Source/Python/GenFds/GenFds.py @@ -368,98 +368,6 @@ def SingleCheckCallback(option, opt_str, value, parser): else: parser.error("Option %s only allows one instance in command line!" % option) -## 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 is 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: - 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.lower() == ToolDef[1].lower() : - KeyList = ToolDef[0].split('_') - Key = KeyList[0] + \ - '_' + \ - KeyList[1] + \ - '_' + \ - KeyList[2] - if Key in KeyStringList and KeyList[4] == TAB_GUID: - ToolPathKey = Key + '_' + KeyList[3] + '_PATH' - ToolOptionKey = Key + '_' + KeyList[3] + '_FLAGS' - ToolPath = ToolDefinition.get(ToolPathKey) - ToolOption = ToolDefinition.get(ToolOptionKey) - if ToolPathTmp is 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 list(BuildOption.keys()): - 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] == TAB_GUID: - ToolPathKey = Key + '_' + KeyList[3] + '_PATH' - ToolOptionKey = Key + '_' + KeyList[3] + '_FLAGS' - if ToolPathKey in BuildOption: - ToolPathTmp = BuildOption[ToolPathKey] - if ToolOptionKey in BuildOption: - ToolOption = BuildOption[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 eeb3ec2197a8..52aa7a1538f7 100644 --- a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py +++ b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py @@ -27,7 +27,7 @@ from Common import EdkLogger from Common.Misc import SaveFileOnChange 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 @@ -843,3 +843,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 is 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: + 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.lower() == ToolDef[1].lower() : + KeyList = ToolDef[0].split('_') + Key = KeyList[0] + \ + '_' + \ + KeyList[1] + \ + '_' + \ + KeyList[2] + if Key in KeyStringList and KeyList[4] == DataType.TAB_GUID: + ToolPathKey = Key + '_' + KeyList[3] + '_PATH' + ToolOptionKey = Key + '_' + KeyList[3] + '_FLAGS' + ToolPath = ToolDefinition.get(ToolPathKey) + ToolOption = ToolDefinition.get(ToolOptionKey) + if ToolPathTmp is 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 = [DataType.TAB_TOD_DEFINES_TARGET, DataType.TAB_TOD_DEFINES_TOOL_CHAIN_TAG, DataType.TAB_TOD_DEFINES_TARGET_ARCH] + for Index in range(2, -1, -1): + for Key in list(BuildOption.keys()): + 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] == DataType.TAB_GUID: + ToolPathKey = Key + '_' + KeyList[3] + '_PATH' + ToolOptionKey = Key + '_' + KeyList[3] + '_FLAGS' + if ToolPathKey in BuildOption: + ToolPathTmp = BuildOption[ToolPathKey] + if ToolOptionKey in BuildOption: + ToolOption = BuildOption[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 e41c2fd31e6c..fd660737f421 100644 --- a/BaseTools/Source/Python/GenFds/GuidSection.py +++ b/BaseTools/Source/Python/GenFds/GuidSection.py @@ -22,6 +22,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 @@ -131,7 +132,6 @@ class GuidSection(GuidSectionClassObject) : ExternalTool = None ExternalOption = None if self.NameGuid is not None: - from .GenFds import FindExtendTool ExternalTool, ExternalOption = FindExtendTool(self.KeyStringList, self.CurrentArchList, self.NameGuid) # -- 2.18.0