BaseTools: Singleton the object to handle build conf file

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

The build config files are target.txt, build rule, tooldef
During a build, the config is not changed, so the object to
handle them need to be singleton.

Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Bob Feng <bob.c.feng@intel.com>
Acked-by: Laszlo Ersek <lersek@redhat.com>
Tested-by: Laszlo Ersek <lersek@redhat.com>
Acked-by: Liming Gao <liming.gao@intel.com>
This commit is contained in:
Feng, Bob C 2019-04-13 16:02:02 +08:00
parent 4b1b7c1913
commit db01c8e3d8
8 changed files with 62 additions and 96 deletions

View File

@ -24,7 +24,8 @@ from . import GenDepex
from io import BytesIO
from .StrGather import *
from .BuildEngine import BuildRule
from .BuildEngine import BuildRuleObj as BuildRule
from .BuildEngine import gDefaultBuildRuleFile,AutoGenReqBuildRuleVerNum
import shutil
from Common.LongFilePathSupport import CopyLongFilePath
from Common.BuildToolError import *
@ -78,12 +79,6 @@ gEfiVarStoreGuidPattern = re.compile("\s*guid\s*=\s*({.*?{.*?}\s*})")
gMakeTypeMap = {TAB_COMPILER_MSFT:"nmake", "GCC":"gmake"}
## Build rule configuration file
gDefaultBuildRuleFile = 'build_rule.txt'
## Build rule default version
AutoGenReqBuildRuleVerNum = "0.1"
## default file name for AutoGen
gAutoGenCodeFileName = "AutoGen.c"
gAutoGenHeaderFileName = "AutoGen.h"
@ -1972,28 +1967,6 @@ class PlatformAutoGen(AutoGen):
def EdkIIBuildOption(self):
return self._ExpandBuildOption(self.Platform.BuildOptions, EDKII_NAME)
## Parse build_rule.txt in Conf Directory.
#
# @retval BuildRule object
#
@cached_property
def BuildRule(self):
BuildRuleFile = None
if TAB_TAT_DEFINES_BUILD_RULE_CONF in self.Workspace.TargetTxt.TargetTxtDictionary:
BuildRuleFile = self.Workspace.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_BUILD_RULE_CONF]
if not BuildRuleFile:
BuildRuleFile = gDefaultBuildRuleFile
RetVal = BuildRule(BuildRuleFile)
if RetVal._FileVersion == "":
RetVal._FileVersion = AutoGenReqBuildRuleVerNum
else:
if RetVal._FileVersion < AutoGenReqBuildRuleVerNum :
# If Build Rule's version is less than the version number required by the tools, halting the build.
EdkLogger.error("build", AUTOGEN_ERROR,
ExtraData="The version number [%s] of build_rule.txt is less than the version number required by the AutoGen.(the minimum required version number is [%s])"\
% (RetVal._FileVersion, AutoGenReqBuildRuleVerNum))
return RetVal
## Summarize the packages used by modules in this platform
@cached_property
def PackageList(self):
@ -3151,7 +3124,7 @@ class ModuleAutoGen(AutoGen):
@cached_property
def BuildRules(self):
RetVal = {}
BuildRuleDatabase = self.PlatformInfo.BuildRule
BuildRuleDatabase = BuildRule
for Type in BuildRuleDatabase.FileTypeList:
#first try getting build rule by BuildRuleFamily
RuleObject = BuildRuleDatabase[Type, self.BuildType, self.Arch, self.BuildRuleFamily]

View File

@ -20,6 +20,9 @@ from Common.BuildToolError import *
from Common.Misc import tdict, PathClass
from Common.StringUtils import NormPath
from Common.DataType import *
from Common.TargetTxtClassObject import TargetTxt
gDefaultBuildRuleFile = 'build_rule.txt'
AutoGenReqBuildRuleVerNum = '0.1'
import Common.EdkLogger as EdkLogger
@ -583,6 +586,25 @@ class BuildRule:
_UnknownSection : SkipSection,
}
def GetBuildRule():
BuildRuleFile = None
if TAB_TAT_DEFINES_BUILD_RULE_CONF in TargetTxt.TargetTxtDictionary:
BuildRuleFile = TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_BUILD_RULE_CONF]
if not BuildRuleFile:
BuildRuleFile = gDefaultBuildRuleFile
RetVal = BuildRule(BuildRuleFile)
if RetVal._FileVersion == "":
RetVal._FileVersion = AutoGenReqBuildRuleVerNum
else:
if RetVal._FileVersion < AutoGenReqBuildRuleVerNum :
# If Build Rule's version is less than the version number required by the tools, halting the build.
EdkLogger.error("build", AUTOGEN_ERROR,
ExtraData="The version number [%s] of build_rule.txt is less than the version number required by the AutoGen.(the minimum required version number is [%s])"\
% (RetVal._FileVersion, AutoGenReqBuildRuleVerNum))
return RetVal
BuildRuleObj = GetBuildRule()
# This acts like the main() function for the script, unless it is 'import'ed into another
# script.
if __name__ == '__main__':

View File

@ -146,6 +146,8 @@ def TargetTxtDict(ConfDir):
Target.LoadTargetTxtFile(os.path.normpath(os.path.join(ConfDir, gDefaultTargetTxtFile)))
return Target
TargetTxt = TargetTxtDict(os.path.join(os.getenv("WORKSPACE"),"Conf"))
##
#
# This acts like the main() function for the script, unless it is 'import'ed into another

View File

@ -14,7 +14,7 @@ import re
from . import EdkLogger
from .BuildToolError import *
from Common.TargetTxtClassObject import TargetTxtDict
from Common.TargetTxtClassObject import TargetTxt
from Common.LongFilePathSupport import OpenLongFilePath as open
from Common.Misc import PathClass
from Common.StringUtils import NormPath
@ -263,7 +263,7 @@ class ToolDefClassObject(object):
# @retval ToolDef An instance of ToolDefClassObject() with loaded tools_def.txt
#
def ToolDefDict(ConfDir):
Target = TargetTxtDict(ConfDir)
Target = TargetTxt
ToolDef = ToolDefClassObject()
if TAB_TAT_DEFINES_TOOL_CHAIN_CONF in Target.TargetTxtDictionary:
ToolsDefFile = Target.TargetTxtDictionary[TAB_TAT_DEFINES_TOOL_CHAIN_CONF]
@ -275,6 +275,8 @@ def ToolDefDict(ConfDir):
ToolDef.LoadToolDefFile(os.path.normpath(os.path.join(ConfDir, gDefaultToolsDefFile)))
return ToolDef
ToolDef = ToolDefDict((os.path.join(os.getenv("WORKSPACE"),"Conf")))
##
#
# This acts like the main() function for the script, unless it is 'import'ed into another

View File

@ -20,7 +20,7 @@ from linecache import getlines
from io import BytesIO
import Common.LongFilePathOs as os
from Common.TargetTxtClassObject import TargetTxtClassObject
from Common.TargetTxtClassObject import TargetTxt
from Common.DataType import *
import Common.GlobalData as GlobalData
from Common import EdkLogger
@ -207,8 +207,6 @@ def GenFdsApi(FdsCommandDict, WorkSpaceDataBase=None):
GlobalData.gConfDirectory = GenFdsGlobalVariable.ConfDir
BuildConfigurationFile = os.path.normpath(os.path.join(ConfDirectoryPath, "target.txt"))
if os.path.isfile(BuildConfigurationFile) == True:
TargetTxt = TargetTxtClassObject()
TargetTxt.LoadTargetTxtFile(BuildConfigurationFile)
# if no build target given in command line, get it from target.txt
if not GenFdsGlobalVariable.TargetName:
BuildTargetList = TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_TARGET]

View File

@ -22,9 +22,9 @@ from Common.BuildToolError import COMMAND_FAILURE,GENFDS_ERROR
from Common import EdkLogger
from Common.Misc import SaveFileOnChange
from Common.TargetTxtClassObject import TargetTxtClassObject
from Common.ToolDefClassObject import ToolDefClassObject, ToolDefDict
from AutoGen.BuildEngine import BuildRule
from Common.TargetTxtClassObject import TargetTxt
from Common.ToolDefClassObject import ToolDef
from AutoGen.BuildEngine import BuildRuleObj
import Common.DataType as DataType
from Common.Misc import PathClass
from Common.LongFilePathSupport import OpenLongFilePath as open
@ -95,31 +95,21 @@ class GenFdsGlobalVariable:
def _LoadBuildRule():
if GenFdsGlobalVariable.__BuildRuleDatabase:
return GenFdsGlobalVariable.__BuildRuleDatabase
BuildConfigurationFile = os.path.normpath(os.path.join(GenFdsGlobalVariable.ConfDir, "target.txt"))
TargetTxt = TargetTxtClassObject()
if os.path.isfile(BuildConfigurationFile) == True:
TargetTxt.LoadTargetTxtFile(BuildConfigurationFile)
if DataType.TAB_TAT_DEFINES_BUILD_RULE_CONF in TargetTxt.TargetTxtDictionary:
BuildRuleFile = TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_BUILD_RULE_CONF]
if not BuildRuleFile:
BuildRuleFile = 'Conf/build_rule.txt'
GenFdsGlobalVariable.__BuildRuleDatabase = BuildRule(BuildRuleFile)
ToolDefinitionFile = TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF]
if ToolDefinitionFile == '':
ToolDefinitionFile = "Conf/tools_def.txt"
if os.path.isfile(ToolDefinitionFile):
ToolDef = ToolDefClassObject()
ToolDef.LoadToolDefFile(ToolDefinitionFile)
ToolDefinition = ToolDef.ToolsDefTxtDatabase
if DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY in ToolDefinition \
and GenFdsGlobalVariable.ToolChainTag in ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY] \
and ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY][GenFdsGlobalVariable.ToolChainTag]:
GenFdsGlobalVariable.BuildRuleFamily = ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY][GenFdsGlobalVariable.ToolChainTag]
GenFdsGlobalVariable.__BuildRuleDatabase = BuildRuleObj
ToolDefinitionFile = TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF]
if ToolDefinitionFile == '':
ToolDefinitionFile = "Conf/tools_def.txt"
if os.path.isfile(ToolDefinitionFile):
ToolDefinition = ToolDef.ToolsDefTxtDatabase
if DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY in ToolDefinition \
and GenFdsGlobalVariable.ToolChainTag in ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY] \
and ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY][GenFdsGlobalVariable.ToolChainTag]:
GenFdsGlobalVariable.BuildRuleFamily = ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY][GenFdsGlobalVariable.ToolChainTag]
if DataType.TAB_TOD_DEFINES_FAMILY in ToolDefinition \
and GenFdsGlobalVariable.ToolChainTag in ToolDefinition[DataType.TAB_TOD_DEFINES_FAMILY] \
and ToolDefinition[DataType.TAB_TOD_DEFINES_FAMILY][GenFdsGlobalVariable.ToolChainTag]:
GenFdsGlobalVariable.ToolChainFamily = ToolDefinition[DataType.TAB_TOD_DEFINES_FAMILY][GenFdsGlobalVariable.ToolChainTag]
if DataType.TAB_TOD_DEFINES_FAMILY in ToolDefinition \
and GenFdsGlobalVariable.ToolChainTag in ToolDefinition[DataType.TAB_TOD_DEFINES_FAMILY] \
and ToolDefinition[DataType.TAB_TOD_DEFINES_FAMILY][GenFdsGlobalVariable.ToolChainTag]:
GenFdsGlobalVariable.ToolChainFamily = ToolDefinition[DataType.TAB_TOD_DEFINES_FAMILY][GenFdsGlobalVariable.ToolChainTag]
return GenFdsGlobalVariable.__BuildRuleDatabase
## GetBuildRules
@ -839,7 +829,7 @@ class GenFdsGlobalVariable:
# @param NameGuid The Guid name
#
def FindExtendTool(KeyStringList, CurrentArchList, NameGuid):
ToolDb = ToolDefDict(GenFdsGlobalVariable.ConfDir).ToolsDefTxtDatabase
ToolDb = ToolDef.ToolsDefTxtDatabase
# if user not specify filter, try to deduce it from global data.
if KeyStringList is None or KeyStringList == []:
Target = GenFdsGlobalVariable.TargetName
@ -855,15 +845,15 @@ def FindExtendTool(KeyStringList, CurrentArchList, NameGuid):
if NameGuid in GenFdsGlobalVariable.GuidToolDefinition:
return GenFdsGlobalVariable.GuidToolDefinition[NameGuid]
ToolDefinition = ToolDefDict(GenFdsGlobalVariable.ConfDir).ToolsDefTxtDictionary
ToolDefinition = ToolDef.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('_')
for tool_def in ToolDefinition.items():
if NameGuid.lower() == tool_def[1].lower():
KeyList = tool_def[0].split('_')
Key = KeyList[0] + \
'_' + \
KeyList[1] + \

View File

@ -19,8 +19,8 @@ from Common.Misc import *
from types import *
from Common.Expression import *
from CommonDataClass.CommonClass import SkuInfoClass
from Common.TargetTxtClassObject import TargetTxtClassObject
from Common.ToolDefClassObject import ToolDefClassObject
from Common.TargetTxtClassObject import TargetTxt
from Common.ToolDefClassObject import ToolDef
from .MetaDataTable import *
from .MetaFileTable import *
from .MetaFileParser import *
@ -3262,15 +3262,11 @@ class DscBuildData(PlatformBuildClassObject):
self._ToolChainFamily = TAB_COMPILER_MSFT
BuildConfigurationFile = os.path.normpath(os.path.join(GlobalData.gConfDirectory, "target.txt"))
if os.path.isfile(BuildConfigurationFile) == True:
TargetTxt = TargetTxtClassObject()
TargetTxt.LoadTargetTxtFile(BuildConfigurationFile)
ToolDefinitionFile = TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF]
if ToolDefinitionFile == '':
ToolDefinitionFile = "tools_def.txt"
ToolDefinitionFile = os.path.normpath(mws.join(self.WorkspaceDir, 'Conf', ToolDefinitionFile))
if os.path.isfile(ToolDefinitionFile) == True:
ToolDef = ToolDefClassObject()
ToolDef.LoadToolDefFile(ToolDefinitionFile)
ToolDefinition = ToolDef.ToolsDefTxtDatabase
if TAB_TOD_DEFINES_FAMILY not in ToolDefinition \
or self._Toolchain not in ToolDefinition[TAB_TOD_DEFINES_FAMILY] \

View File

@ -30,8 +30,8 @@ from subprocess import *
from Common import Misc as Utils
from Common.LongFilePathSupport import OpenLongFilePath as open
from Common.TargetTxtClassObject import TargetTxtClassObject
from Common.ToolDefClassObject import ToolDefClassObject
from Common.TargetTxtClassObject import TargetTxt
from Common.ToolDefClassObject import ToolDef
from Common.DataType import *
from Common.BuildVersion import gBUILD_VERSION
from AutoGen.AutoGen import *
@ -716,8 +716,8 @@ class Build():
self.ConfDirectory = BuildOptions.ConfDirectory
self.SpawnMode = True
self.BuildReport = BuildReport(BuildOptions.ReportFile, BuildOptions.ReportType)
self.TargetTxt = TargetTxtClassObject()
self.ToolDef = ToolDefClassObject()
self.TargetTxt = TargetTxt
self.ToolDef = ToolDef
self.AutoGenTime = 0
self.MakeTime = 0
self.GenFdsTime = 0
@ -816,8 +816,8 @@ class Build():
EdkLogger.quiet("%-16s = %s" % ("POSTBUILD", self.Postbuild))
if self.Prebuild:
self.LaunchPrebuild()
self.TargetTxt = TargetTxtClassObject()
self.ToolDef = ToolDefClassObject()
self.TargetTxt = TargetTxt
self.ToolDef = ToolDef
if not (self.LaunchPrebuildFlag and os.path.exists(self.PlatformBuildPath)):
self.InitBuild()
@ -829,23 +829,6 @@ class Build():
# This method will parse target.txt and get the build configurations.
#
def LoadConfiguration(self):
#
# Check target.txt and tools_def.txt and Init them
#
BuildConfigurationFile = os.path.normpath(os.path.join(GlobalData.gConfDirectory, gBuildConfiguration))
if os.path.isfile(BuildConfigurationFile) == True:
StatusCode = self.TargetTxt.LoadTargetTxtFile(BuildConfigurationFile)
ToolDefinitionFile = self.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_TOOL_CHAIN_CONF]
if ToolDefinitionFile == '':
ToolDefinitionFile = gToolsDefinition
ToolDefinitionFile = os.path.normpath(mws.join(self.WorkspaceDir, 'Conf', ToolDefinitionFile))
if os.path.isfile(ToolDefinitionFile) == True:
StatusCode = self.ToolDef.LoadToolDefFile(ToolDefinitionFile)
else:
EdkLogger.error("build", FILE_NOT_FOUND, ExtraData=ToolDefinitionFile)
else:
EdkLogger.error("build", FILE_NOT_FOUND, ExtraData=BuildConfigurationFile)
# if no ARCH given in command line, get it from target.txt
if not self.ArchList: