BaseTools:Fix GenFds issue for BuildOption replace GenFdsOption

BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=2455

BuildOption is used by TargetTxtClassObj.py
GenFdsOption is used by GenFds.py
When the GenFds tool is used alone (e.g. python3 -m GenFds.GenFds -h)
With the OptionParser function, the first detected function
prints the help message

import TargetTxtClassObj to GenFds,
The BuildOption will be executed and replace GenFdsOption

We removed all objects associated with this problem that
were created directly during the import process
(e.g. BuildOption, BuildTarget = MyOptionParser(),
 TargetTxt = TargetTxtDict())

The Patch is going to fix this issue

Signed-off-by: Zhiju.Fan <zhijux.fan@intel.com>

Cc: Liming Gao <liming.gao@intel.com>
Cc: Bob Feng <bob.c.feng@intel.com>
Reviewed-by: Bob Feng <bob.c.feng@intel.com>
This commit is contained in:
Fan, ZhijuX
2020-01-10 16:29:45 +08:00
committed by mergify[bot]
parent 072b9c2839
commit 4465cd124f
10 changed files with 259 additions and 167 deletions

View File

@ -14,7 +14,7 @@ import re
from . import EdkLogger
from .BuildToolError import *
from Common.TargetTxtClassObject import TargetTxt
from Common.TargetTxtClassObject import TargetTxtDict
from Common.LongFilePathSupport import OpenLongFilePath as open
from Common.Misc import PathClass
from Common.StringUtils import NormPath
@ -262,20 +262,40 @@ class ToolDefClassObject(object):
#
# @retval ToolDef An instance of ToolDefClassObject() with loaded tools_def.txt
#
def ToolDefDict(ConfDir):
Target = TargetTxt
ToolDef = ToolDefClassObject()
if TAB_TAT_DEFINES_TOOL_CHAIN_CONF in Target.TargetTxtDictionary:
ToolsDefFile = Target.TargetTxtDictionary[TAB_TAT_DEFINES_TOOL_CHAIN_CONF]
if ToolsDefFile:
ToolDef.LoadToolDefFile(os.path.normpath(ToolsDefFile))
else:
ToolDef.LoadToolDefFile(os.path.normpath(os.path.join(ConfDir, gDefaultToolsDefFile)))
else:
ToolDef.LoadToolDefFile(os.path.normpath(os.path.join(ConfDir, gDefaultToolsDefFile)))
return ToolDef
ToolDef = ToolDefDict((os.path.join(os.getenv("WORKSPACE"),"Conf")))
class ToolDefDict():
def __new__(cls, ConfDir, *args, **kw):
if not hasattr(cls, '_instance'):
orig = super(ToolDefDict, cls)
cls._instance = orig.__new__(cls, *args, **kw)
return cls._instance
def __init__(self, ConfDir):
self.ConfDir = ConfDir
if not hasattr(self, 'ToolDef'):
self._ToolDef = None
@property
def ToolDef(self):
if not self._ToolDef:
self._GetToolDef()
return self._ToolDef
def _GetToolDef(self):
TargetObj = TargetTxtDict()
Target = TargetObj.Target
ToolDef = ToolDefClassObject()
if TAB_TAT_DEFINES_TOOL_CHAIN_CONF in Target.TargetTxtDictionary:
ToolsDefFile = Target.TargetTxtDictionary[TAB_TAT_DEFINES_TOOL_CHAIN_CONF]
if ToolsDefFile:
ToolDef.LoadToolDefFile(os.path.normpath(ToolsDefFile))
else:
ToolDef.LoadToolDefFile(os.path.normpath(os.path.join(self.ConfDir, gDefaultToolsDefFile)))
else:
ToolDef.LoadToolDefFile(os.path.normpath(os.path.join(self.ConfDir, gDefaultToolsDefFile)))
self._ToolDef = ToolDef
##
#