public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [Patch 1/1] BaseTools: Singleton the object to handle build conf file
@ 2019-06-28  7:07 Bob Feng
  2019-07-11  9:11 ` Liming Gao
  0 siblings, 1 reply; 6+ messages in thread
From: Bob Feng @ 2019-06-28  7:07 UTC (permalink / raw)
  To: devel; +Cc: Liming Gao, Bob Feng

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>
---
 BaseTools/Source/Python/AutoGen/AutoGen.py    | 33 ++----------
 .../Source/Python/AutoGen/BuildEngine.py      | 22 ++++++++
 .../Python/Common/TargetTxtClassObject.py     |  2 +
 .../Python/Common/ToolDefClassObject.py       |  6 ++-
 BaseTools/Source/Python/GenFds/GenFds.py      |  4 +-
 .../Python/GenFds/GenFdsGlobalVariable.py     | 54 ++++++++-----------
 .../Source/Python/Workspace/DscBuildData.py   |  8 +--
 BaseTools/Source/Python/build/build.py        | 29 +++-------
 8 files changed, 62 insertions(+), 96 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py b/BaseTools/Source/Python/AutoGen/AutoGen.py
index e8e09dc8a366..a1f7f5641e09 100644
--- a/BaseTools/Source/Python/AutoGen/AutoGen.py
+++ b/BaseTools/Source/Python/AutoGen/AutoGen.py
@@ -22,11 +22,12 @@ from . import GenC
 from . import GenMake
 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 *
 from Common.DataType import *
 from Common.Misc import *
@@ -76,16 +77,10 @@ gEfiVarStoreGuidPattern = re.compile("\s*guid\s*=\s*({.*?{.*?}\s*})")
 
 ## Mapping Makefile type
 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"
 gAutoGenStringFileName = "%(module_name)sStrDefs.h"
 gAutoGenStringFormFileName = "%(module_name)sStrDefs.hpk"
@@ -1964,32 +1959,10 @@ class PlatformAutoGen(AutoGen):
     ## Return the build options specific for EDKII modules in this platform
     @cached_property
     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):
         RetVal = set()
         for La in self.LibraryAutoGenList:
@@ -3143,11 +3116,11 @@ class ModuleAutoGen(AutoGen):
         return RetVal
 
     @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]
             if not RuleObject:
                 # build type is always module type, but ...
diff --git a/BaseTools/Source/Python/AutoGen/BuildEngine.py b/BaseTools/Source/Python/AutoGen/BuildEngine.py
index 14e61140e7ba..bb9153447793 100644
--- a/BaseTools/Source/Python/AutoGen/BuildEngine.py
+++ b/BaseTools/Source/Python/AutoGen/BuildEngine.py
@@ -18,10 +18,13 @@ from Common.LongFilePathSupport import OpenLongFilePath as open
 from Common.GlobalData import *
 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
 
 ## Convert file type to file list macro name
 #
@@ -581,10 +584,29 @@ class BuildRule:
         _ExtraDependency   : ParseCommonSubSection,
         _Command           : ParseCommonSubSection,
         _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__':
     import sys
     EdkLogger.Initialize()
diff --git a/BaseTools/Source/Python/Common/TargetTxtClassObject.py b/BaseTools/Source/Python/Common/TargetTxtClassObject.py
index 9d7673b41bb5..79a5acc01074 100644
--- a/BaseTools/Source/Python/Common/TargetTxtClassObject.py
+++ b/BaseTools/Source/Python/Common/TargetTxtClassObject.py
@@ -144,10 +144,12 @@ class TargetTxtClassObject(object):
 def TargetTxtDict(ConfDir):
     Target = TargetTxtClassObject()
     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
 # script.
 #
diff --git a/BaseTools/Source/Python/Common/ToolDefClassObject.py b/BaseTools/Source/Python/Common/ToolDefClassObject.py
index 5d692ea13cfc..0bfa263270c3 100644
--- a/BaseTools/Source/Python/Common/ToolDefClassObject.py
+++ b/BaseTools/Source/Python/Common/ToolDefClassObject.py
@@ -12,11 +12,11 @@ from __future__ import absolute_import
 import Common.LongFilePathOs as os
 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
 import Common.GlobalData as GlobalData
 from Common import GlobalData
@@ -261,11 +261,11 @@ class ToolDefClassObject(object):
 # @param ConfDir:  Conf dir
 #
 # @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]
         if ToolsDefFile:
             ToolDef.LoadToolDefFile(os.path.normpath(ToolsDefFile))
@@ -273,10 +273,12 @@ def ToolDefDict(ConfDir):
             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")))
+
 ##
 #
 # This acts like the main() function for the script, unless it is 'import'ed into another
 # script.
 #
diff --git a/BaseTools/Source/Python/GenFds/GenFds.py b/BaseTools/Source/Python/GenFds/GenFds.py
index 5888997761bb..51943411ad1f 100644
--- a/BaseTools/Source/Python/GenFds/GenFds.py
+++ b/BaseTools/Source/Python/GenFds/GenFds.py
@@ -18,11 +18,11 @@ from glob import glob
 from struct import unpack
 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
 from Common.StringUtils import NormPath
 from Common.Misc import DirCache, PathClass, GuidStructureStringToGuidString
@@ -205,12 +205,10 @@ def GenFdsApi(FdsCommandDict, WorkSpaceDataBase=None):
         GenFdsGlobalVariable.ConfDir = ConfDirectoryPath
         if not GlobalData.gConfDirectory:
             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]
                 if len(BuildTargetList) != 1:
                     EdkLogger.error("GenFds", OPTION_VALUE_INVALID, ExtraData="Only allows one instance for Target.")
diff --git a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
index c9c476cf6154..f49af9371b8d 100644
--- a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
+++ b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
@@ -20,13 +20,13 @@ from array import array
 
 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
 from Common.MultipleWorkspace import MultipleWorkspace as mws
 import Common.GlobalData as GlobalData
@@ -93,35 +93,25 @@ class GenFdsGlobalVariable:
     #
     @staticmethod
     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
     #    @param Inf: object of InfBuildData
     #    @param Arch: current arch
@@ -834,11 +824,11 @@ class GenFdsGlobalVariable:
 #  @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
+    ToolDb = ToolDef.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']:
@@ -850,19 +840,19 @@ def FindExtendTool(KeyStringList, CurrentArchList, NameGuid):
 
     if GenFdsGlobalVariable.GuidToolDefinition:
         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] + \
                   '_' + \
                   KeyList[2]
diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py
index 9f65ad54257d..bfd203aee805 100644
--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
@@ -17,12 +17,12 @@ from Common.StringUtils import *
 from Common.DataType import *
 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 *
 
 from .WorkspaceCommon import GetDeclaredPcd
@@ -3259,19 +3259,15 @@ class DscBuildData(PlatformBuildClassObject):
     @property
     def ToolChainFamily(self):
         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] \
                    or not ToolDefinition[TAB_TOD_DEFINES_FAMILY][self._Toolchain]:
                     self._ToolChainFamily = TAB_COMPILER_MSFT
diff --git a/BaseTools/Source/Python/build/build.py b/BaseTools/Source/Python/build/build.py
index 8c3315619afa..5e13453a1254 100644
--- a/BaseTools/Source/Python/build/build.py
+++ b/BaseTools/Source/Python/build/build.py
@@ -28,12 +28,12 @@ import threading
 from optparse import OptionParser
 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 *
 from Common.BuildToolError import *
 from Workspace.WorkspaceDatabase import WorkspaceDatabase
@@ -714,12 +714,12 @@ class Build():
         if self.SkuId:
             GlobalData.gSKUID_CMD = self.SkuId
         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
         GlobalData.BuildOptionPcd     = BuildOptions.OptionPcd if BuildOptions.OptionPcd else []
         #Set global flag for build mode
@@ -813,12 +813,12 @@ class Build():
             EdkLogger.quiet("%-16s = %s" % ("PREBUILD", self.Prebuild))
         if self.Postbuild:
             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()
 
         EdkLogger.info("")
         os.chdir(self.WorkspaceDir)
@@ -826,27 +826,10 @@ class Build():
     ## Load configuration
     #
     #   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:
             self.ArchList = self.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_TARGET_ARCH]
         self.ArchList = tuple(self.ArchList)
-- 
2.20.1.windows.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [Patch 1/1] BaseTools: Singleton the object to handle build conf file
  2019-06-28  7:07 [Patch 1/1] BaseTools: Singleton the object to handle build conf file Bob Feng
@ 2019-07-11  9:11 ` Liming Gao
  2019-07-11  9:26   ` Bob Feng
       [not found]   ` <15B0502B4303BDC5.2265@groups.io>
  0 siblings, 2 replies; 6+ messages in thread
From: Liming Gao @ 2019-07-11  9:11 UTC (permalink / raw)
  To: Feng, Bob C, devel@edk2.groups.io

Bob:
  target.txt is from Conf directory. build_rule.txt and tools_def.txt are specified in target.txt. Please take care this case that they may have the different file name. 

  And, Conf directory is relative to WORKSPACE and PACKAGES_PATH. Does this patch support it?

Thanks
Liming
>-----Original Message-----
>From: Feng, Bob C
>Sent: Friday, June 28, 2019 3:07 PM
>To: devel@edk2.groups.io
>Cc: Gao, Liming <liming.gao@intel.com>; Feng, Bob C <bob.c.feng@intel.com>
>Subject: [Patch 1/1] 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>
>---
> BaseTools/Source/Python/AutoGen/AutoGen.py    | 33 ++----------
> .../Source/Python/AutoGen/BuildEngine.py      | 22 ++++++++
> .../Python/Common/TargetTxtClassObject.py     |  2 +
> .../Python/Common/ToolDefClassObject.py       |  6 ++-
> BaseTools/Source/Python/GenFds/GenFds.py      |  4 +-
> .../Python/GenFds/GenFdsGlobalVariable.py     | 54 ++++++++-----------
> .../Source/Python/Workspace/DscBuildData.py   |  8 +--
> BaseTools/Source/Python/build/build.py        | 29 +++-------
> 8 files changed, 62 insertions(+), 96 deletions(-)
>
>diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py
>b/BaseTools/Source/Python/AutoGen/AutoGen.py
>index e8e09dc8a366..a1f7f5641e09 100644
>--- a/BaseTools/Source/Python/AutoGen/AutoGen.py
>+++ b/BaseTools/Source/Python/AutoGen/AutoGen.py
>@@ -22,11 +22,12 @@ from . import GenC
> from . import GenMake
> 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 *
> from Common.DataType import *
> from Common.Misc import *
>@@ -76,16 +77,10 @@ gEfiVarStoreGuidPattern =
>re.compile("\s*guid\s*=\s*({.*?{.*?}\s*})")
>
> ## Mapping Makefile type
> 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"
> gAutoGenStringFileName = "%(module_name)sStrDefs.h"
> gAutoGenStringFormFileName = "%(module_name)sStrDefs.hpk"
>@@ -1964,32 +1959,10 @@ class PlatformAutoGen(AutoGen):
>     ## Return the build options specific for EDKII modules in this platform
>     @cached_property
>     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_RUL
>E_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):
>         RetVal = set()
>         for La in self.LibraryAutoGenList:
>@@ -3143,11 +3116,11 @@ class ModuleAutoGen(AutoGen):
>         return RetVal
>
>     @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]
>             if not RuleObject:
>                 # build type is always module type, but ...
>diff --git a/BaseTools/Source/Python/AutoGen/BuildEngine.py
>b/BaseTools/Source/Python/AutoGen/BuildEngine.py
>index 14e61140e7ba..bb9153447793 100644
>--- a/BaseTools/Source/Python/AutoGen/BuildEngine.py
>+++ b/BaseTools/Source/Python/AutoGen/BuildEngine.py
>@@ -18,10 +18,13 @@ from Common.LongFilePathSupport import
>OpenLongFilePath as open
> from Common.GlobalData import *
> 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
>
> ## Convert file type to file list macro name
> #
>@@ -581,10 +584,29 @@ class BuildRule:
>         _ExtraDependency   : ParseCommonSubSection,
>         _Command           : ParseCommonSubSection,
>         _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__':
>     import sys
>     EdkLogger.Initialize()
>diff --git a/BaseTools/Source/Python/Common/TargetTxtClassObject.py
>b/BaseTools/Source/Python/Common/TargetTxtClassObject.py
>index 9d7673b41bb5..79a5acc01074 100644
>--- a/BaseTools/Source/Python/Common/TargetTxtClassObject.py
>+++ b/BaseTools/Source/Python/Common/TargetTxtClassObject.py
>@@ -144,10 +144,12 @@ class TargetTxtClassObject(object):
> def TargetTxtDict(ConfDir):
>     Target = TargetTxtClassObject()
>     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
> # script.
> #
>diff --git a/BaseTools/Source/Python/Common/ToolDefClassObject.py
>b/BaseTools/Source/Python/Common/ToolDefClassObject.py
>index 5d692ea13cfc..0bfa263270c3 100644
>--- a/BaseTools/Source/Python/Common/ToolDefClassObject.py
>+++ b/BaseTools/Source/Python/Common/ToolDefClassObject.py
>@@ -12,11 +12,11 @@ from __future__ import absolute_import
> import Common.LongFilePathOs as os
> 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
> import Common.GlobalData as GlobalData
> from Common import GlobalData
>@@ -261,11 +261,11 @@ class ToolDefClassObject(object):
> # @param ConfDir:  Conf dir
> #
> # @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]
>         if ToolsDefFile:
>             ToolDef.LoadToolDefFile(os.path.normpath(ToolsDefFile))
>@@ -273,10 +273,12 @@ def ToolDefDict(ConfDir):
>             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")))
>+
> ##
> #
> # This acts like the main() function for the script, unless it is 'import'ed into
>another
> # script.
> #
>diff --git a/BaseTools/Source/Python/GenFds/GenFds.py
>b/BaseTools/Source/Python/GenFds/GenFds.py
>index 5888997761bb..51943411ad1f 100644
>--- a/BaseTools/Source/Python/GenFds/GenFds.py
>+++ b/BaseTools/Source/Python/GenFds/GenFds.py
>@@ -18,11 +18,11 @@ from glob import glob
> from struct import unpack
> 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
> from Common.StringUtils import NormPath
> from Common.Misc import DirCache, PathClass,
>GuidStructureStringToGuidString
>@@ -205,12 +205,10 @@ def GenFdsApi(FdsCommandDict,
>WorkSpaceDataBase=None):
>         GenFdsGlobalVariable.ConfDir = ConfDirectoryPath
>         if not GlobalData.gConfDirectory:
>             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]
>                 if len(BuildTargetList) != 1:
>                     EdkLogger.error("GenFds", OPTION_VALUE_INVALID,
>ExtraData="Only allows one instance for Target.")
>diff --git a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
>b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
>index c9c476cf6154..f49af9371b8d 100644
>--- a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
>+++ b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
>@@ -20,13 +20,13 @@ from array import array
>
> 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
> from Common.MultipleWorkspace import MultipleWorkspace as mws
> import Common.GlobalData as GlobalData
>@@ -93,35 +93,25 @@ class GenFdsGlobalVariable:
>     #
>     @staticmethod
>     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_CO
>NF]
>-            if not BuildRuleFile:
>-                BuildRuleFile = 'Conf/build_rule.txt'
>-            GenFdsGlobalVariable.__BuildRuleDatabase = BuildRule(BuildRuleFile)
>-            ToolDefinitionFile =
>TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_C
>ONF]
>-            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][GenFdsGlo
>balVariable.ToolChainTag]:
>-                    GenFdsGlobalVariable.BuildRuleFamily =
>ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY][GenFdsGlo
>balVariable.ToolChainTag]
>+        GenFdsGlobalVariable.__BuildRuleDatabase = BuildRuleObj
>+        ToolDefinitionFile =
>TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_C
>ONF]
>+        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][GenFdsGlo
>balVariable.ToolChainTag]:
>+                GenFdsGlobalVariable.BuildRuleFamily =
>ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY][GenFdsGlo
>balVariable.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
>     #    @param Inf: object of InfBuildData
>     #    @param Arch: current arch
>@@ -834,11 +824,11 @@ class GenFdsGlobalVariable:
> #  @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
>+    ToolDb = ToolDef.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']:
>@@ -850,19 +840,19 @@ def FindExtendTool(KeyStringList, CurrentArchList,
>NameGuid):
>
>     if GenFdsGlobalVariable.GuidToolDefinition:
>         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] + \
>                   '_' + \
>                   KeyList[2]
>diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py
>b/BaseTools/Source/Python/Workspace/DscBuildData.py
>index 9f65ad54257d..bfd203aee805 100644
>--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
>+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
>@@ -17,12 +17,12 @@ from Common.StringUtils import *
> from Common.DataType import *
> 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 *
>
> from .WorkspaceCommon import GetDeclaredPcd
>@@ -3259,19 +3259,15 @@ class DscBuildData(PlatformBuildClassObject):
>     @property
>     def ToolChainFamily(self):
>         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_C
>ONF]
>             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]
>\
>                    or not ToolDefinition[TAB_TOD_DEFINES_FAMILY][self._Toolchain]:
>                     self._ToolChainFamily = TAB_COMPILER_MSFT
>diff --git a/BaseTools/Source/Python/build/build.py
>b/BaseTools/Source/Python/build/build.py
>index 8c3315619afa..5e13453a1254 100644
>--- a/BaseTools/Source/Python/build/build.py
>+++ b/BaseTools/Source/Python/build/build.py
>@@ -28,12 +28,12 @@ import threading
> from optparse import OptionParser
> 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 *
> from Common.BuildToolError import *
> from Workspace.WorkspaceDatabase import WorkspaceDatabase
>@@ -714,12 +714,12 @@ class Build():
>         if self.SkuId:
>             GlobalData.gSKUID_CMD = self.SkuId
>         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
>         GlobalData.BuildOptionPcd     = BuildOptions.OptionPcd if
>BuildOptions.OptionPcd else []
>         #Set global flag for build mode
>@@ -813,12 +813,12 @@ class Build():
>             EdkLogger.quiet("%-16s = %s" % ("PREBUILD", self.Prebuild))
>         if self.Postbuild:
>             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()
>
>         EdkLogger.info("")
>         os.chdir(self.WorkspaceDir)
>@@ -826,27 +826,10 @@ class Build():
>     ## Load configuration
>     #
>     #   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:
>             self.ArchList =
>self.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_TARGET_ARCH]
>         self.ArchList = tuple(self.ArchList)
>--
>2.20.1.windows.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Patch 1/1] BaseTools: Singleton the object to handle build conf file
  2019-07-11  9:11 ` Liming Gao
@ 2019-07-11  9:26   ` Bob Feng
       [not found]   ` <15B0502B4303BDC5.2265@groups.io>
  1 sibling, 0 replies; 6+ messages in thread
From: Bob Feng @ 2019-07-11  9:26 UTC (permalink / raw)
  To: Gao, Liming, devel@edk2.groups.io

Liming,

Thanks for your comments. I'll  test the cases you mentioned.

Thanks,
Bob

-----Original Message-----
From: Gao, Liming 
Sent: Thursday, July 11, 2019 5:11 PM
To: Feng, Bob C <bob.c.feng@intel.com>; devel@edk2.groups.io
Subject: RE: [Patch 1/1] BaseTools: Singleton the object to handle build conf file

Bob:
  target.txt is from Conf directory. build_rule.txt and tools_def.txt are specified in target.txt. Please take care this case that they may have the different file name. 

  And, Conf directory is relative to WORKSPACE and PACKAGES_PATH. Does this patch support it?

Thanks
Liming
>-----Original Message-----
>From: Feng, Bob C
>Sent: Friday, June 28, 2019 3:07 PM
>To: devel@edk2.groups.io
>Cc: Gao, Liming <liming.gao@intel.com>; Feng, Bob C 
><bob.c.feng@intel.com>
>Subject: [Patch 1/1] 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>
>---
> BaseTools/Source/Python/AutoGen/AutoGen.py    | 33 ++----------
> .../Source/Python/AutoGen/BuildEngine.py      | 22 ++++++++
> .../Python/Common/TargetTxtClassObject.py     |  2 +
> .../Python/Common/ToolDefClassObject.py       |  6 ++-
> BaseTools/Source/Python/GenFds/GenFds.py      |  4 +-
> .../Python/GenFds/GenFdsGlobalVariable.py     | 54 ++++++++-----------
> .../Source/Python/Workspace/DscBuildData.py   |  8 +--
> BaseTools/Source/Python/build/build.py        | 29 +++-------
> 8 files changed, 62 insertions(+), 96 deletions(-)
>
>diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py
>b/BaseTools/Source/Python/AutoGen/AutoGen.py
>index e8e09dc8a366..a1f7f5641e09 100644
>--- a/BaseTools/Source/Python/AutoGen/AutoGen.py
>+++ b/BaseTools/Source/Python/AutoGen/AutoGen.py
>@@ -22,11 +22,12 @@ from . import GenC
> from . import GenMake
> 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 *  from Common.DataType import *  from 
>Common.Misc import * @@ -76,16 +77,10 @@ gEfiVarStoreGuidPattern =
>re.compile("\s*guid\s*=\s*({.*?{.*?}\s*})")
>
> ## Mapping Makefile type
> 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"
> gAutoGenStringFileName = "%(module_name)sStrDefs.h"
> gAutoGenStringFormFileName = "%(module_name)sStrDefs.hpk"
>@@ -1964,32 +1959,10 @@ class PlatformAutoGen(AutoGen):
>     ## Return the build options specific for EDKII modules in this platform
>     @cached_property
>     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_RUL
>E_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):
>         RetVal = set()
>         for La in self.LibraryAutoGenList:
>@@ -3143,11 +3116,11 @@ class ModuleAutoGen(AutoGen):
>         return RetVal
>
>     @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]
>             if not RuleObject:
>                 # build type is always module type, but ...
>diff --git a/BaseTools/Source/Python/AutoGen/BuildEngine.py
>b/BaseTools/Source/Python/AutoGen/BuildEngine.py
>index 14e61140e7ba..bb9153447793 100644
>--- a/BaseTools/Source/Python/AutoGen/BuildEngine.py
>+++ b/BaseTools/Source/Python/AutoGen/BuildEngine.py
>@@ -18,10 +18,13 @@ from Common.LongFilePathSupport import 
>OpenLongFilePath as open  from Common.GlobalData import *  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
>
> ## Convert file type to file list macro name  # @@ -581,10 +584,29 @@ 
>class BuildRule:
>         _ExtraDependency   : ParseCommonSubSection,
>         _Command           : ParseCommonSubSection,
>         _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__':
>     import sys
>     EdkLogger.Initialize()
>diff --git a/BaseTools/Source/Python/Common/TargetTxtClassObject.py
>b/BaseTools/Source/Python/Common/TargetTxtClassObject.py
>index 9d7673b41bb5..79a5acc01074 100644
>--- a/BaseTools/Source/Python/Common/TargetTxtClassObject.py
>+++ b/BaseTools/Source/Python/Common/TargetTxtClassObject.py
>@@ -144,10 +144,12 @@ class TargetTxtClassObject(object):
> def TargetTxtDict(ConfDir):
>     Target = TargetTxtClassObject()
>     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  # script.
> #
>diff --git a/BaseTools/Source/Python/Common/ToolDefClassObject.py
>b/BaseTools/Source/Python/Common/ToolDefClassObject.py
>index 5d692ea13cfc..0bfa263270c3 100644
>--- a/BaseTools/Source/Python/Common/ToolDefClassObject.py
>+++ b/BaseTools/Source/Python/Common/ToolDefClassObject.py
>@@ -12,11 +12,11 @@ from __future__ import absolute_import  import 
>Common.LongFilePathOs as os  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  
>import Common.GlobalData as GlobalData  from Common import GlobalData 
>@@ -261,11 +261,11 @@ class ToolDefClassObject(object):
> # @param ConfDir:  Conf dir
> #
> # @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]
>         if ToolsDefFile:
>             ToolDef.LoadToolDefFile(os.path.normpath(ToolsDefFile))
>@@ -273,10 +273,12 @@ def ToolDefDict(ConfDir):
>             
>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")))
>+
> ##
> #
> # This acts like the main() function for the script, unless it is 
>'import'ed into another  # script.
> #
>diff --git a/BaseTools/Source/Python/GenFds/GenFds.py
>b/BaseTools/Source/Python/GenFds/GenFds.py
>index 5888997761bb..51943411ad1f 100644
>--- a/BaseTools/Source/Python/GenFds/GenFds.py
>+++ b/BaseTools/Source/Python/GenFds/GenFds.py
>@@ -18,11 +18,11 @@ from glob import glob  from struct import unpack  
>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  
>from Common.StringUtils import NormPath  from Common.Misc import 
>DirCache, PathClass, GuidStructureStringToGuidString @@ -205,12 +205,10 
>@@ def GenFdsApi(FdsCommandDict,
>WorkSpaceDataBase=None):
>         GenFdsGlobalVariable.ConfDir = ConfDirectoryPath
>         if not GlobalData.gConfDirectory:
>             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]
>                 if len(BuildTargetList) != 1:
>                     EdkLogger.error("GenFds", OPTION_VALUE_INVALID, 
>ExtraData="Only allows one instance for Target.") diff --git 
>a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
>b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
>index c9c476cf6154..f49af9371b8d 100644
>--- a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
>+++ b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
>@@ -20,13 +20,13 @@ from array import array
>
> 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  from 
>Common.MultipleWorkspace import MultipleWorkspace as mws  import 
>Common.GlobalData as GlobalData @@ -93,35 +93,25 @@ class 
>GenFdsGlobalVariable:
>     #
>     @staticmethod
>     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_CO
>NF]
>-            if not BuildRuleFile:
>-                BuildRuleFile = 'Conf/build_rule.txt'
>-            GenFdsGlobalVariable.__BuildRuleDatabase = BuildRule(BuildRuleFile)
>-            ToolDefinitionFile =
>TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_C
>ONF]
>-            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][GenFdsGlo
>balVariable.ToolChainTag]:
>-                    GenFdsGlobalVariable.BuildRuleFamily =
>ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY][GenFdsGlo
>balVariable.ToolChainTag]
>+        GenFdsGlobalVariable.__BuildRuleDatabase = BuildRuleObj
>+        ToolDefinitionFile =
>TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_C
>ONF]
>+        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][GenFdsGlo
>balVariable.ToolChainTag]:
>+                GenFdsGlobalVariable.BuildRuleFamily =
>ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY][GenFdsGlo
>balVariable.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
>     #    @param Inf: object of InfBuildData
>     #    @param Arch: current arch
>@@ -834,11 +824,11 @@ class GenFdsGlobalVariable:
> #  @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
>+    ToolDb = ToolDef.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']:
>@@ -850,19 +840,19 @@ def FindExtendTool(KeyStringList, 
>CurrentArchList,
>NameGuid):
>
>     if GenFdsGlobalVariable.GuidToolDefinition:
>         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] + \
>                   '_' + \
>                   KeyList[2]
>diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py
>b/BaseTools/Source/Python/Workspace/DscBuildData.py
>index 9f65ad54257d..bfd203aee805 100644
>--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
>+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
>@@ -17,12 +17,12 @@ from Common.StringUtils import *  from 
>Common.DataType import *  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 *
>
> from .WorkspaceCommon import GetDeclaredPcd @@ -3259,19 +3259,15 @@ 
>class DscBuildData(PlatformBuildClassObject):
>     @property
>     def ToolChainFamily(self):
>         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_C
>ONF]
>             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]
>\
>                    or not ToolDefinition[TAB_TOD_DEFINES_FAMILY][self._Toolchain]:
>                     self._ToolChainFamily = TAB_COMPILER_MSFT diff 
>--git a/BaseTools/Source/Python/build/build.py
>b/BaseTools/Source/Python/build/build.py
>index 8c3315619afa..5e13453a1254 100644
>--- a/BaseTools/Source/Python/build/build.py
>+++ b/BaseTools/Source/Python/build/build.py
>@@ -28,12 +28,12 @@ import threading
> from optparse import OptionParser
> 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 *  from Common.BuildToolError import *  from 
>Workspace.WorkspaceDatabase import WorkspaceDatabase @@ -714,12 +714,12 
>@@ class Build():
>         if self.SkuId:
>             GlobalData.gSKUID_CMD = self.SkuId
>         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
>         GlobalData.BuildOptionPcd     = BuildOptions.OptionPcd if
>BuildOptions.OptionPcd else []
>         #Set global flag for build mode @@ -813,12 +813,12 @@ class 
>Build():
>             EdkLogger.quiet("%-16s = %s" % ("PREBUILD", self.Prebuild))
>         if self.Postbuild:
>             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()
>
>         EdkLogger.info("")
>         os.chdir(self.WorkspaceDir)
>@@ -826,27 +826,10 @@ class Build():
>     ## Load configuration
>     #
>     #   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:
>             self.ArchList =
>self.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_TARGET_ARCH]
>         self.ArchList = tuple(self.ArchList)
>--
>2.20.1.windows.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [edk2-devel] [Patch 1/1] BaseTools: Singleton the object to handle build conf file
       [not found]   ` <15B0502B4303BDC5.2265@groups.io>
@ 2019-07-11 12:12     ` Bob Feng
  2019-07-11 14:30       ` Liming Gao
  0 siblings, 1 reply; 6+ messages in thread
From: Bob Feng @ 2019-07-11 12:12 UTC (permalink / raw)
  To: devel@edk2.groups.io, Feng, Bob C, Gao, Liming

Liming,

I tested the cases:
1. move tool_def.txt and build_rule.txt from Conf to another folder and update target.txt to set BUILD_RULE_CONF and TOOL_CHAIN_CONF to point to the new folder.
2. Move Conf folder to a new place and Set WORKSPACE to point the parent folder of Conf. Append original WORKSPACE folder to PACKAGES_PATH

My patch works fine.

But there is a bug in original code for case 1#, I'll send out another patch to fix that.

Thanks,
Bob

-----Original Message-----
From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of Bob Feng
Sent: Thursday, July 11, 2019 5:27 PM
To: Gao, Liming <liming.gao@intel.com>; devel@edk2.groups.io
Subject: Re: [edk2-devel] [Patch 1/1] BaseTools: Singleton the object to handle build conf file

Liming,

Thanks for your comments. I'll  test the cases you mentioned.

Thanks,
Bob

-----Original Message-----
From: Gao, Liming
Sent: Thursday, July 11, 2019 5:11 PM
To: Feng, Bob C <bob.c.feng@intel.com>; devel@edk2.groups.io
Subject: RE: [Patch 1/1] BaseTools: Singleton the object to handle build conf file

Bob:
  target.txt is from Conf directory. build_rule.txt and tools_def.txt are specified in target.txt. Please take care this case that they may have the different file name. 

  And, Conf directory is relative to WORKSPACE and PACKAGES_PATH. Does this patch support it?

Thanks
Liming
>-----Original Message-----
>From: Feng, Bob C
>Sent: Friday, June 28, 2019 3:07 PM
>To: devel@edk2.groups.io
>Cc: Gao, Liming <liming.gao@intel.com>; Feng, Bob C 
><bob.c.feng@intel.com>
>Subject: [Patch 1/1] 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>
>---
> BaseTools/Source/Python/AutoGen/AutoGen.py    | 33 ++----------
> .../Source/Python/AutoGen/BuildEngine.py      | 22 ++++++++
> .../Python/Common/TargetTxtClassObject.py     |  2 +
> .../Python/Common/ToolDefClassObject.py       |  6 ++-
> BaseTools/Source/Python/GenFds/GenFds.py      |  4 +-
> .../Python/GenFds/GenFdsGlobalVariable.py     | 54 ++++++++-----------
> .../Source/Python/Workspace/DscBuildData.py   |  8 +--
> BaseTools/Source/Python/build/build.py        | 29 +++-------
> 8 files changed, 62 insertions(+), 96 deletions(-)
>
>diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py
>b/BaseTools/Source/Python/AutoGen/AutoGen.py
>index e8e09dc8a366..a1f7f5641e09 100644
>--- a/BaseTools/Source/Python/AutoGen/AutoGen.py
>+++ b/BaseTools/Source/Python/AutoGen/AutoGen.py
>@@ -22,11 +22,12 @@ from . import GenC
> from . import GenMake
> 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 *  from Common.DataType import *  from 
>Common.Misc import * @@ -76,16 +77,10 @@ gEfiVarStoreGuidPattern =
>re.compile("\s*guid\s*=\s*({.*?{.*?}\s*})")
>
> ## Mapping Makefile type
> 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"
> gAutoGenStringFileName = "%(module_name)sStrDefs.h"
> gAutoGenStringFormFileName = "%(module_name)sStrDefs.hpk"
>@@ -1964,32 +1959,10 @@ class PlatformAutoGen(AutoGen):
>     ## Return the build options specific for EDKII modules in this platform
>     @cached_property
>     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_RUL
>E_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):
>         RetVal = set()
>         for La in self.LibraryAutoGenList:
>@@ -3143,11 +3116,11 @@ class ModuleAutoGen(AutoGen):
>         return RetVal
>
>     @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]
>             if not RuleObject:
>                 # build type is always module type, but ...
>diff --git a/BaseTools/Source/Python/AutoGen/BuildEngine.py
>b/BaseTools/Source/Python/AutoGen/BuildEngine.py
>index 14e61140e7ba..bb9153447793 100644
>--- a/BaseTools/Source/Python/AutoGen/BuildEngine.py
>+++ b/BaseTools/Source/Python/AutoGen/BuildEngine.py
>@@ -18,10 +18,13 @@ from Common.LongFilePathSupport import 
>OpenLongFilePath as open  from Common.GlobalData import *  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
>
> ## Convert file type to file list macro name  # @@ -581,10 +584,29 @@ 
>class BuildRule:
>         _ExtraDependency   : ParseCommonSubSection,
>         _Command           : ParseCommonSubSection,
>         _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__':
>     import sys
>     EdkLogger.Initialize()
>diff --git a/BaseTools/Source/Python/Common/TargetTxtClassObject.py
>b/BaseTools/Source/Python/Common/TargetTxtClassObject.py
>index 9d7673b41bb5..79a5acc01074 100644
>--- a/BaseTools/Source/Python/Common/TargetTxtClassObject.py
>+++ b/BaseTools/Source/Python/Common/TargetTxtClassObject.py
>@@ -144,10 +144,12 @@ class TargetTxtClassObject(object):
> def TargetTxtDict(ConfDir):
>     Target = TargetTxtClassObject()
>     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  # script.
> #
>diff --git a/BaseTools/Source/Python/Common/ToolDefClassObject.py
>b/BaseTools/Source/Python/Common/ToolDefClassObject.py
>index 5d692ea13cfc..0bfa263270c3 100644
>--- a/BaseTools/Source/Python/Common/ToolDefClassObject.py
>+++ b/BaseTools/Source/Python/Common/ToolDefClassObject.py
>@@ -12,11 +12,11 @@ from __future__ import absolute_import  import 
>Common.LongFilePathOs as os  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 
>import Common.GlobalData as GlobalData  from Common import GlobalData 
>@@ -261,11 +261,11 @@ class ToolDefClassObject(object):
> # @param ConfDir:  Conf dir
> #
> # @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]
>         if ToolsDefFile:
>             ToolDef.LoadToolDefFile(os.path.normpath(ToolsDefFile))
>@@ -273,10 +273,12 @@ def ToolDefDict(ConfDir):
>             
>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")))
>+
> ##
> #
> # This acts like the main() function for the script, unless it is 
>'import'ed into another  # script.
> #
>diff --git a/BaseTools/Source/Python/GenFds/GenFds.py
>b/BaseTools/Source/Python/GenFds/GenFds.py
>index 5888997761bb..51943411ad1f 100644
>--- a/BaseTools/Source/Python/GenFds/GenFds.py
>+++ b/BaseTools/Source/Python/GenFds/GenFds.py
>@@ -18,11 +18,11 @@ from glob import glob  from struct import unpack 
>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 
>from Common.StringUtils import NormPath  from Common.Misc import 
>DirCache, PathClass, GuidStructureStringToGuidString @@ -205,12 +205,10 
>@@ def GenFdsApi(FdsCommandDict,
>WorkSpaceDataBase=None):
>         GenFdsGlobalVariable.ConfDir = ConfDirectoryPath
>         if not GlobalData.gConfDirectory:
>             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]
>                 if len(BuildTargetList) != 1:
>                     EdkLogger.error("GenFds", OPTION_VALUE_INVALID, 
>ExtraData="Only allows one instance for Target.") diff --git 
>a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
>b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
>index c9c476cf6154..f49af9371b8d 100644
>--- a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
>+++ b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
>@@ -20,13 +20,13 @@ from array import array
>
> 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  from 
>Common.MultipleWorkspace import MultipleWorkspace as mws  import 
>Common.GlobalData as GlobalData @@ -93,35 +93,25 @@ class
>GenFdsGlobalVariable:
>     #
>     @staticmethod
>     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_CO
>NF]
>-            if not BuildRuleFile:
>-                BuildRuleFile = 'Conf/build_rule.txt'
>-            GenFdsGlobalVariable.__BuildRuleDatabase = BuildRule(BuildRuleFile)
>-            ToolDefinitionFile =
>TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_C
>ONF]
>-            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][GenFdsGlo
>balVariable.ToolChainTag]:
>-                    GenFdsGlobalVariable.BuildRuleFamily =
>ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY][GenFdsGlo
>balVariable.ToolChainTag]
>+        GenFdsGlobalVariable.__BuildRuleDatabase = BuildRuleObj
>+        ToolDefinitionFile =
>TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_C
>ONF]
>+        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][GenFdsGlo
>balVariable.ToolChainTag]:
>+                GenFdsGlobalVariable.BuildRuleFamily =
>ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY][GenFdsGlo
>balVariable.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
>     #    @param Inf: object of InfBuildData
>     #    @param Arch: current arch
>@@ -834,11 +824,11 @@ class GenFdsGlobalVariable:
> #  @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
>+    ToolDb = ToolDef.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']:
>@@ -850,19 +840,19 @@ def FindExtendTool(KeyStringList, 
>CurrentArchList,
>NameGuid):
>
>     if GenFdsGlobalVariable.GuidToolDefinition:
>         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] + \
>                   '_' + \
>                   KeyList[2]
>diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py
>b/BaseTools/Source/Python/Workspace/DscBuildData.py
>index 9f65ad54257d..bfd203aee805 100644
>--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
>+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
>@@ -17,12 +17,12 @@ from Common.StringUtils import *  from 
>Common.DataType import *  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 *
>
> from .WorkspaceCommon import GetDeclaredPcd @@ -3259,19 +3259,15 @@ 
>class DscBuildData(PlatformBuildClassObject):
>     @property
>     def ToolChainFamily(self):
>         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_C
>ONF]
>             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]
>\
>                    or not ToolDefinition[TAB_TOD_DEFINES_FAMILY][self._Toolchain]:
>                     self._ToolChainFamily = TAB_COMPILER_MSFT diff 
>--git a/BaseTools/Source/Python/build/build.py
>b/BaseTools/Source/Python/build/build.py
>index 8c3315619afa..5e13453a1254 100644
>--- a/BaseTools/Source/Python/build/build.py
>+++ b/BaseTools/Source/Python/build/build.py
>@@ -28,12 +28,12 @@ import threading
> from optparse import OptionParser
> 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 *  from Common.BuildToolError import *  from 
>Workspace.WorkspaceDatabase import WorkspaceDatabase @@ -714,12 +714,12 
>@@ class Build():
>         if self.SkuId:
>             GlobalData.gSKUID_CMD = self.SkuId
>         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
>         GlobalData.BuildOptionPcd     = BuildOptions.OptionPcd if
>BuildOptions.OptionPcd else []
>         #Set global flag for build mode @@ -813,12 +813,12 @@ class
>Build():
>             EdkLogger.quiet("%-16s = %s" % ("PREBUILD", self.Prebuild))
>         if self.Postbuild:
>             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()
>
>         EdkLogger.info("")
>         os.chdir(self.WorkspaceDir)
>@@ -826,27 +826,10 @@ class Build():
>     ## Load configuration
>     #
>     #   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:
>             self.ArchList =
>self.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_TARGET_ARCH]
>         self.ArchList = tuple(self.ArchList)
>--
>2.20.1.windows.1





^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [edk2-devel] [Patch 1/1] BaseTools: Singleton the object to handle build conf file
  2019-07-11 12:12     ` [edk2-devel] " Bob Feng
@ 2019-07-11 14:30       ` Liming Gao
  2019-07-11 14:57         ` Bob Feng
  0 siblings, 1 reply; 6+ messages in thread
From: Liming Gao @ 2019-07-11 14:30 UTC (permalink / raw)
  To: Feng, Bob C, devel@edk2.groups.io

Bob:


> -----Original Message-----
> From: Feng, Bob C
> Sent: Thursday, July 11, 2019 8:13 PM
> To: devel@edk2.groups.io; Feng, Bob C <bob.c.feng@intel.com>; Gao, Liming <liming.gao@intel.com>
> Subject: RE: [edk2-devel] [Patch 1/1] BaseTools: Singleton the object to handle build conf file
> 
> Liming,
> 
> I tested the cases:
> 1. move tool_def.txt and build_rule.txt from Conf to another folder and update target.txt to set BUILD_RULE_CONF and
> TOOL_CHAIN_CONF to point to the new folder.

If their file name is also changed in target.txt, does it work in current BaseTools? I just want to make sure keep the same support scope with this change. 

Thanks
Liming
> 2. Move Conf folder to a new place and Set WORKSPACE to point the parent folder of Conf. Append original WORKSPACE folder to
> PACKAGES_PATH
> 
> My patch works fine.
> 
> But there is a bug in original code for case 1#, I'll send out another patch to fix that.
> 
> Thanks,
> Bob
> 
> -----Original Message-----
> From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of Bob Feng
> Sent: Thursday, July 11, 2019 5:27 PM
> To: Gao, Liming <liming.gao@intel.com>; devel@edk2.groups.io
> Subject: Re: [edk2-devel] [Patch 1/1] BaseTools: Singleton the object to handle build conf file
> 
> Liming,
> 
> Thanks for your comments. I'll  test the cases you mentioned.
> 
> Thanks,
> Bob
> 
> -----Original Message-----
> From: Gao, Liming
> Sent: Thursday, July 11, 2019 5:11 PM
> To: Feng, Bob C <bob.c.feng@intel.com>; devel@edk2.groups.io
> Subject: RE: [Patch 1/1] BaseTools: Singleton the object to handle build conf file
> 
> Bob:
>   target.txt is from Conf directory. build_rule.txt and tools_def.txt are specified in target.txt. Please take care this case that they may have
> the different file name.
> 
>   And, Conf directory is relative to WORKSPACE and PACKAGES_PATH. Does this patch support it?
> 
> Thanks
> Liming
> >-----Original Message-----
> >From: Feng, Bob C
> >Sent: Friday, June 28, 2019 3:07 PM
> >To: devel@edk2.groups.io
> >Cc: Gao, Liming <liming.gao@intel.com>; Feng, Bob C
> ><bob.c.feng@intel.com>
> >Subject: [Patch 1/1] 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>
> >---
> > BaseTools/Source/Python/AutoGen/AutoGen.py    | 33 ++----------
> > .../Source/Python/AutoGen/BuildEngine.py      | 22 ++++++++
> > .../Python/Common/TargetTxtClassObject.py     |  2 +
> > .../Python/Common/ToolDefClassObject.py       |  6 ++-
> > BaseTools/Source/Python/GenFds/GenFds.py      |  4 +-
> > .../Python/GenFds/GenFdsGlobalVariable.py     | 54 ++++++++-----------
> > .../Source/Python/Workspace/DscBuildData.py   |  8 +--
> > BaseTools/Source/Python/build/build.py        | 29 +++-------
> > 8 files changed, 62 insertions(+), 96 deletions(-)
> >
> >diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py
> >b/BaseTools/Source/Python/AutoGen/AutoGen.py
> >index e8e09dc8a366..a1f7f5641e09 100644
> >--- a/BaseTools/Source/Python/AutoGen/AutoGen.py
> >+++ b/BaseTools/Source/Python/AutoGen/AutoGen.py
> >@@ -22,11 +22,12 @@ from . import GenC
> > from . import GenMake
> > 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 *  from Common.DataType import *  from
> >Common.Misc import * @@ -76,16 +77,10 @@ gEfiVarStoreGuidPattern =
> >re.compile("\s*guid\s*=\s*({.*?{.*?}\s*})")
> >
> > ## Mapping Makefile type
> > 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"
> > gAutoGenStringFileName = "%(module_name)sStrDefs.h"
> > gAutoGenStringFormFileName = "%(module_name)sStrDefs.hpk"
> >@@ -1964,32 +1959,10 @@ class PlatformAutoGen(AutoGen):
> >     ## Return the build options specific for EDKII modules in this platform
> >     @cached_property
> >     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_RUL
> >E_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):
> >         RetVal = set()
> >         for La in self.LibraryAutoGenList:
> >@@ -3143,11 +3116,11 @@ class ModuleAutoGen(AutoGen):
> >         return RetVal
> >
> >     @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]
> >             if not RuleObject:
> >                 # build type is always module type, but ...
> >diff --git a/BaseTools/Source/Python/AutoGen/BuildEngine.py
> >b/BaseTools/Source/Python/AutoGen/BuildEngine.py
> >index 14e61140e7ba..bb9153447793 100644
> >--- a/BaseTools/Source/Python/AutoGen/BuildEngine.py
> >+++ b/BaseTools/Source/Python/AutoGen/BuildEngine.py
> >@@ -18,10 +18,13 @@ from Common.LongFilePathSupport import
> >OpenLongFilePath as open  from Common.GlobalData import *  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
> >
> > ## Convert file type to file list macro name  # @@ -581,10 +584,29 @@
> >class BuildRule:
> >         _ExtraDependency   : ParseCommonSubSection,
> >         _Command           : ParseCommonSubSection,
> >         _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__':
> >     import sys
> >     EdkLogger.Initialize()
> >diff --git a/BaseTools/Source/Python/Common/TargetTxtClassObject.py
> >b/BaseTools/Source/Python/Common/TargetTxtClassObject.py
> >index 9d7673b41bb5..79a5acc01074 100644
> >--- a/BaseTools/Source/Python/Common/TargetTxtClassObject.py
> >+++ b/BaseTools/Source/Python/Common/TargetTxtClassObject.py
> >@@ -144,10 +144,12 @@ class TargetTxtClassObject(object):
> > def TargetTxtDict(ConfDir):
> >     Target = TargetTxtClassObject()
> >     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  # script.
> > #
> >diff --git a/BaseTools/Source/Python/Common/ToolDefClassObject.py
> >b/BaseTools/Source/Python/Common/ToolDefClassObject.py
> >index 5d692ea13cfc..0bfa263270c3 100644
> >--- a/BaseTools/Source/Python/Common/ToolDefClassObject.py
> >+++ b/BaseTools/Source/Python/Common/ToolDefClassObject.py
> >@@ -12,11 +12,11 @@ from __future__ import absolute_import  import
> >Common.LongFilePathOs as os  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
> >import Common.GlobalData as GlobalData  from Common import GlobalData
> >@@ -261,11 +261,11 @@ class ToolDefClassObject(object):
> > # @param ConfDir:  Conf dir
> > #
> > # @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]
> >         if ToolsDefFile:
> >             ToolDef.LoadToolDefFile(os.path.normpath(ToolsDefFile))
> >@@ -273,10 +273,12 @@ def ToolDefDict(ConfDir):
> >
> >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")))
> >+
> > ##
> > #
> > # This acts like the main() function for the script, unless it is
> >'import'ed into another  # script.
> > #
> >diff --git a/BaseTools/Source/Python/GenFds/GenFds.py
> >b/BaseTools/Source/Python/GenFds/GenFds.py
> >index 5888997761bb..51943411ad1f 100644
> >--- a/BaseTools/Source/Python/GenFds/GenFds.py
> >+++ b/BaseTools/Source/Python/GenFds/GenFds.py
> >@@ -18,11 +18,11 @@ from glob import glob  from struct import unpack
> >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
> >from Common.StringUtils import NormPath  from Common.Misc import
> >DirCache, PathClass, GuidStructureStringToGuidString @@ -205,12 +205,10
> >@@ def GenFdsApi(FdsCommandDict,
> >WorkSpaceDataBase=None):
> >         GenFdsGlobalVariable.ConfDir = ConfDirectoryPath
> >         if not GlobalData.gConfDirectory:
> >             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]
> >                 if len(BuildTargetList) != 1:
> >                     EdkLogger.error("GenFds", OPTION_VALUE_INVALID,
> >ExtraData="Only allows one instance for Target.") diff --git
> >a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
> >b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
> >index c9c476cf6154..f49af9371b8d 100644
> >--- a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
> >+++ b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
> >@@ -20,13 +20,13 @@ from array import array
> >
> > 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  from
> >Common.MultipleWorkspace import MultipleWorkspace as mws  import
> >Common.GlobalData as GlobalData @@ -93,35 +93,25 @@ class
> >GenFdsGlobalVariable:
> >     #
> >     @staticmethod
> >     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_CO
> >NF]
> >-            if not BuildRuleFile:
> >-                BuildRuleFile = 'Conf/build_rule.txt'
> >-            GenFdsGlobalVariable.__BuildRuleDatabase = BuildRule(BuildRuleFile)
> >-            ToolDefinitionFile =
> >TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_C
> >ONF]
> >-            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][GenFdsGlo
> >balVariable.ToolChainTag]:
> >-                    GenFdsGlobalVariable.BuildRuleFamily =
> >ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY][GenFdsGlo
> >balVariable.ToolChainTag]
> >+        GenFdsGlobalVariable.__BuildRuleDatabase = BuildRuleObj
> >+        ToolDefinitionFile =
> >TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_C
> >ONF]
> >+        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][GenFdsGlo
> >balVariable.ToolChainTag]:
> >+                GenFdsGlobalVariable.BuildRuleFamily =
> >ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY][GenFdsGlo
> >balVariable.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
> >     #    @param Inf: object of InfBuildData
> >     #    @param Arch: current arch
> >@@ -834,11 +824,11 @@ class GenFdsGlobalVariable:
> > #  @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
> >+    ToolDb = ToolDef.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']:
> >@@ -850,19 +840,19 @@ def FindExtendTool(KeyStringList,
> >CurrentArchList,
> >NameGuid):
> >
> >     if GenFdsGlobalVariable.GuidToolDefinition:
> >         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] + \
> >                   '_' + \
> >                   KeyList[2]
> >diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py
> >b/BaseTools/Source/Python/Workspace/DscBuildData.py
> >index 9f65ad54257d..bfd203aee805 100644
> >--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
> >+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
> >@@ -17,12 +17,12 @@ from Common.StringUtils import *  from
> >Common.DataType import *  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 *
> >
> > from .WorkspaceCommon import GetDeclaredPcd @@ -3259,19 +3259,15 @@
> >class DscBuildData(PlatformBuildClassObject):
> >     @property
> >     def ToolChainFamily(self):
> >         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_C
> >ONF]
> >             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]
> >\
> >                    or not ToolDefinition[TAB_TOD_DEFINES_FAMILY][self._Toolchain]:
> >                     self._ToolChainFamily = TAB_COMPILER_MSFT diff
> >--git a/BaseTools/Source/Python/build/build.py
> >b/BaseTools/Source/Python/build/build.py
> >index 8c3315619afa..5e13453a1254 100644
> >--- a/BaseTools/Source/Python/build/build.py
> >+++ b/BaseTools/Source/Python/build/build.py
> >@@ -28,12 +28,12 @@ import threading
> > from optparse import OptionParser
> > 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 *  from Common.BuildToolError import *  from
> >Workspace.WorkspaceDatabase import WorkspaceDatabase @@ -714,12 +714,12
> >@@ class Build():
> >         if self.SkuId:
> >             GlobalData.gSKUID_CMD = self.SkuId
> >         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
> >         GlobalData.BuildOptionPcd     = BuildOptions.OptionPcd if
> >BuildOptions.OptionPcd else []
> >         #Set global flag for build mode @@ -813,12 +813,12 @@ class
> >Build():
> >             EdkLogger.quiet("%-16s = %s" % ("PREBUILD", self.Prebuild))
> >         if self.Postbuild:
> >             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()
> >
> >         EdkLogger.info("")
> >         os.chdir(self.WorkspaceDir)
> >@@ -826,27 +826,10 @@ class Build():
> >     ## Load configuration
> >     #
> >     #   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:
> >             self.ArchList =
> >self.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_TARGET_ARCH]
> >         self.ArchList = tuple(self.ArchList)
> >--
> >2.20.1.windows.1
> 
> 
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [edk2-devel] [Patch 1/1] BaseTools: Singleton the object to handle build conf file
  2019-07-11 14:30       ` Liming Gao
@ 2019-07-11 14:57         ` Bob Feng
  0 siblings, 0 replies; 6+ messages in thread
From: Bob Feng @ 2019-07-11 14:57 UTC (permalink / raw)
  To: Gao, Liming, devel@edk2.groups.io

Yes.  it will work after I fix this bug in WorkspaceAutoGen._GetMetaFiles()

Here, the code assumes the tools_def.txt and build_rule.txt are always in Conf directory.

       #
        # add build_rule.txt & tools_def.txt
        #
        AllWorkSpaceMetaFiles.add(os.path.join(GlobalData.gConfDirectory, gDefaultBuildRuleFile))
        AllWorkSpaceMetaFiles.add(os.path.join(GlobalData.gConfDirectory, gDefaultToolsDefFile))

Thanks,
Bob

-----Original Message-----
From: Gao, Liming 
Sent: Thursday, July 11, 2019 10:31 PM
To: Feng, Bob C <bob.c.feng@intel.com>; devel@edk2.groups.io
Subject: RE: [edk2-devel] [Patch 1/1] BaseTools: Singleton the object to handle build conf file

Bob:


> -----Original Message-----
> From: Feng, Bob C
> Sent: Thursday, July 11, 2019 8:13 PM
> To: devel@edk2.groups.io; Feng, Bob C <bob.c.feng@intel.com>; Gao, 
> Liming <liming.gao@intel.com>
> Subject: RE: [edk2-devel] [Patch 1/1] BaseTools: Singleton the object 
> to handle build conf file
> 
> Liming,
> 
> I tested the cases:
> 1. move tool_def.txt and build_rule.txt from Conf to another folder 
> and update target.txt to set BUILD_RULE_CONF and TOOL_CHAIN_CONF to point to the new folder.

If their file name is also changed in target.txt, does it work in current BaseTools? I just want to make sure keep the same support scope with this change. 

Thanks
Liming
> 2. Move Conf folder to a new place and Set WORKSPACE to point the 
> parent folder of Conf. Append original WORKSPACE folder to 
> PACKAGES_PATH
> 
> My patch works fine.
> 
> But there is a bug in original code for case 1#, I'll send out another patch to fix that.
> 
> Thanks,
> Bob
> 
> -----Original Message-----
> From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of 
> Bob Feng
> Sent: Thursday, July 11, 2019 5:27 PM
> To: Gao, Liming <liming.gao@intel.com>; devel@edk2.groups.io
> Subject: Re: [edk2-devel] [Patch 1/1] BaseTools: Singleton the object 
> to handle build conf file
> 
> Liming,
> 
> Thanks for your comments. I'll  test the cases you mentioned.
> 
> Thanks,
> Bob
> 
> -----Original Message-----
> From: Gao, Liming
> Sent: Thursday, July 11, 2019 5:11 PM
> To: Feng, Bob C <bob.c.feng@intel.com>; devel@edk2.groups.io
> Subject: RE: [Patch 1/1] BaseTools: Singleton the object to handle 
> build conf file
> 
> Bob:
>   target.txt is from Conf directory. build_rule.txt and tools_def.txt 
> are specified in target.txt. Please take care this case that they may have the different file name.
> 
>   And, Conf directory is relative to WORKSPACE and PACKAGES_PATH. Does this patch support it?
> 
> Thanks
> Liming
> >-----Original Message-----
> >From: Feng, Bob C
> >Sent: Friday, June 28, 2019 3:07 PM
> >To: devel@edk2.groups.io
> >Cc: Gao, Liming <liming.gao@intel.com>; Feng, Bob C 
> ><bob.c.feng@intel.com>
> >Subject: [Patch 1/1] 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>
> >---
> > BaseTools/Source/Python/AutoGen/AutoGen.py    | 33 ++----------
> > .../Source/Python/AutoGen/BuildEngine.py      | 22 ++++++++
> > .../Python/Common/TargetTxtClassObject.py     |  2 +
> > .../Python/Common/ToolDefClassObject.py       |  6 ++-
> > BaseTools/Source/Python/GenFds/GenFds.py      |  4 +-
> > .../Python/GenFds/GenFdsGlobalVariable.py     | 54 ++++++++-----------
> > .../Source/Python/Workspace/DscBuildData.py   |  8 +--
> > BaseTools/Source/Python/build/build.py        | 29 +++-------
> > 8 files changed, 62 insertions(+), 96 deletions(-)
> >
> >diff --git a/BaseTools/Source/Python/AutoGen/AutoGen.py
> >b/BaseTools/Source/Python/AutoGen/AutoGen.py
> >index e8e09dc8a366..a1f7f5641e09 100644
> >--- a/BaseTools/Source/Python/AutoGen/AutoGen.py
> >+++ b/BaseTools/Source/Python/AutoGen/AutoGen.py
> >@@ -22,11 +22,12 @@ from . import GenC  from . import GenMake  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 *  from Common.DataType import *  from 
> >Common.Misc import * @@ -76,16 +77,10 @@ gEfiVarStoreGuidPattern =
> >re.compile("\s*guid\s*=\s*({.*?{.*?}\s*})")
> >
> > ## Mapping Makefile type
> > 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"
> > gAutoGenStringFileName = "%(module_name)sStrDefs.h"
> > gAutoGenStringFormFileName = "%(module_name)sStrDefs.hpk"
> >@@ -1964,32 +1959,10 @@ class PlatformAutoGen(AutoGen):
> >     ## Return the build options specific for EDKII modules in this platform
> >     @cached_property
> >     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_RU
> >L
> >E_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):
> >         RetVal = set()
> >         for La in self.LibraryAutoGenList:
> >@@ -3143,11 +3116,11 @@ class ModuleAutoGen(AutoGen):
> >         return RetVal
> >
> >     @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]
> >             if not RuleObject:
> >                 # build type is always module type, but ...
> >diff --git a/BaseTools/Source/Python/AutoGen/BuildEngine.py
> >b/BaseTools/Source/Python/AutoGen/BuildEngine.py
> >index 14e61140e7ba..bb9153447793 100644
> >--- a/BaseTools/Source/Python/AutoGen/BuildEngine.py
> >+++ b/BaseTools/Source/Python/AutoGen/BuildEngine.py
> >@@ -18,10 +18,13 @@ from Common.LongFilePathSupport import 
> >OpenLongFilePath as open  from Common.GlobalData import *  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
> >
> > ## Convert file type to file list macro name  # @@ -581,10 +584,29 
> >@@ class BuildRule:
> >         _ExtraDependency   : ParseCommonSubSection,
> >         _Command           : ParseCommonSubSection,
> >         _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__':
> >     import sys
> >     EdkLogger.Initialize()
> >diff --git a/BaseTools/Source/Python/Common/TargetTxtClassObject.py
> >b/BaseTools/Source/Python/Common/TargetTxtClassObject.py
> >index 9d7673b41bb5..79a5acc01074 100644
> >--- a/BaseTools/Source/Python/Common/TargetTxtClassObject.py
> >+++ b/BaseTools/Source/Python/Common/TargetTxtClassObject.py
> >@@ -144,10 +144,12 @@ class TargetTxtClassObject(object):
> > def TargetTxtDict(ConfDir):
> >     Target = TargetTxtClassObject()
> >     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  # script.
> > #
> >diff --git a/BaseTools/Source/Python/Common/ToolDefClassObject.py
> >b/BaseTools/Source/Python/Common/ToolDefClassObject.py
> >index 5d692ea13cfc..0bfa263270c3 100644
> >--- a/BaseTools/Source/Python/Common/ToolDefClassObject.py
> >+++ b/BaseTools/Source/Python/Common/ToolDefClassObject.py
> >@@ -12,11 +12,11 @@ from __future__ import absolute_import  import 
> >Common.LongFilePathOs as os  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 import Common.GlobalData as GlobalData  from Common import 
> >GlobalData @@ -261,11 +261,11 @@ class ToolDefClassObject(object):
> > # @param ConfDir:  Conf dir
> > #
> > # @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]
> >         if ToolsDefFile:
> >             ToolDef.LoadToolDefFile(os.path.normpath(ToolsDefFile))
> >@@ -273,10 +273,12 @@ def ToolDefDict(ConfDir):
> >
> >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")))
> >+
> > ##
> > #
> > # This acts like the main() function for the script, unless it is 
> >'import'ed into another  # script.
> > #
> >diff --git a/BaseTools/Source/Python/GenFds/GenFds.py
> >b/BaseTools/Source/Python/GenFds/GenFds.py
> >index 5888997761bb..51943411ad1f 100644
> >--- a/BaseTools/Source/Python/GenFds/GenFds.py
> >+++ b/BaseTools/Source/Python/GenFds/GenFds.py
> >@@ -18,11 +18,11 @@ from glob import glob  from struct import unpack 
> >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 
> >from Common.StringUtils import NormPath  from Common.Misc import 
> >DirCache, PathClass, GuidStructureStringToGuidString @@ -205,12 
> >+205,10 @@ def GenFdsApi(FdsCommandDict,
> >WorkSpaceDataBase=None):
> >         GenFdsGlobalVariable.ConfDir = ConfDirectoryPath
> >         if not GlobalData.gConfDirectory:
> >             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]
> >                 if len(BuildTargetList) != 1:
> >                     EdkLogger.error("GenFds", OPTION_VALUE_INVALID, 
> >ExtraData="Only allows one instance for Target.") diff --git 
> >a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
> >b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
> >index c9c476cf6154..f49af9371b8d 100644
> >--- a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
> >+++ b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
> >@@ -20,13 +20,13 @@ from array import array
> >
> > 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
> >from Common.MultipleWorkspace import MultipleWorkspace as mws  import 
> >Common.GlobalData as GlobalData @@ -93,35 +93,25 @@ class
> >GenFdsGlobalVariable:
> >     #
> >     @staticmethod
> >     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_CO
> >NF]
> >-            if not BuildRuleFile:
> >-                BuildRuleFile = 'Conf/build_rule.txt'
> >-            GenFdsGlobalVariable.__BuildRuleDatabase = BuildRule(BuildRuleFile)
> >-            ToolDefinitionFile =
> >TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_C
> >ONF]
> >-            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][GenFdsGlo
> >balVariable.ToolChainTag]:
> >-                    GenFdsGlobalVariable.BuildRuleFamily =
> >ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY][GenFdsGlo
> >balVariable.ToolChainTag]
> >+        GenFdsGlobalVariable.__BuildRuleDatabase = BuildRuleObj
> >+        ToolDefinitionFile =
> >TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_C
> >ONF]
> >+        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][GenFdsGlo
> >balVariable.ToolChainTag]:
> >+                GenFdsGlobalVariable.BuildRuleFamily =
> >ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY][GenFdsGlo
> >balVariable.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
> >     #    @param Inf: object of InfBuildData
> >     #    @param Arch: current arch
> >@@ -834,11 +824,11 @@ class GenFdsGlobalVariable:
> > #  @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
> >+    ToolDb = ToolDef.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']:
> >@@ -850,19 +840,19 @@ def FindExtendTool(KeyStringList, 
> >CurrentArchList,
> >NameGuid):
> >
> >     if GenFdsGlobalVariable.GuidToolDefinition:
> >         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] + \
> >                   '_' + \
> >                   KeyList[2]
> >diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py
> >b/BaseTools/Source/Python/Workspace/DscBuildData.py
> >index 9f65ad54257d..bfd203aee805 100644
> >--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
> >+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
> >@@ -17,12 +17,12 @@ from Common.StringUtils import *  from 
> >Common.DataType import *  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 *
> >
> > from .WorkspaceCommon import GetDeclaredPcd @@ -3259,19 +3259,15 @@ 
> >class DscBuildData(PlatformBuildClassObject):
> >     @property
> >     def ToolChainFamily(self):
> >         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_C
> >ONF]
> >             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]
> >\
> >                    or not ToolDefinition[TAB_TOD_DEFINES_FAMILY][self._Toolchain]:
> >                     self._ToolChainFamily = TAB_COMPILER_MSFT diff 
> >--git a/BaseTools/Source/Python/build/build.py
> >b/BaseTools/Source/Python/build/build.py
> >index 8c3315619afa..5e13453a1254 100644
> >--- a/BaseTools/Source/Python/build/build.py
> >+++ b/BaseTools/Source/Python/build/build.py
> >@@ -28,12 +28,12 @@ import threading
> > from optparse import OptionParser
> > 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 *  from Common.BuildToolError import *  from 
> >Workspace.WorkspaceDatabase import WorkspaceDatabase @@ -714,12 
> >+714,12 @@ class Build():
> >         if self.SkuId:
> >             GlobalData.gSKUID_CMD = self.SkuId
> >         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
> >         GlobalData.BuildOptionPcd     = BuildOptions.OptionPcd if
> >BuildOptions.OptionPcd else []
> >         #Set global flag for build mode @@ -813,12 +813,12 @@ class
> >Build():
> >             EdkLogger.quiet("%-16s = %s" % ("PREBUILD", self.Prebuild))
> >         if self.Postbuild:
> >             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()
> >
> >         EdkLogger.info("")
> >         os.chdir(self.WorkspaceDir)
> >@@ -826,27 +826,10 @@ class Build():
> >     ## Load configuration
> >     #
> >     #   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:
> >             self.ArchList =
> >self.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_TARGET_ARCH]
> >         self.ArchList = tuple(self.ArchList)
> >--
> >2.20.1.windows.1
> 
> 
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-07-11 14:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-28  7:07 [Patch 1/1] BaseTools: Singleton the object to handle build conf file Bob Feng
2019-07-11  9:11 ` Liming Gao
2019-07-11  9:26   ` Bob Feng
     [not found]   ` <15B0502B4303BDC5.2265@groups.io>
2019-07-11 12:12     ` [edk2-devel] " Bob Feng
2019-07-11 14:30       ` Liming Gao
2019-07-11 14:57         ` Bob Feng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox