From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by mx.groups.io with SMTP id smtpd.web11.31732.1578879950736928029 for ; Sun, 12 Jan 2020 17:45:50 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.120, mailfrom: bob.c.feng@intel.com) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Jan 2020 17:45:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,427,1571727600"; d="scan'208";a="247568770" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by fmsmga004.fm.intel.com with ESMTP; 12 Jan 2020 17:45:50 -0800 Received: from shsmsx606.ccr.corp.intel.com (10.109.6.216) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.439.0; Sun, 12 Jan 2020 17:45:49 -0800 Received: from shsmsx601.ccr.corp.intel.com (10.109.6.141) by SHSMSX606.ccr.corp.intel.com (10.109.6.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Mon, 13 Jan 2020 09:45:48 +0800 Received: from shsmsx601.ccr.corp.intel.com ([10.109.6.141]) by SHSMSX601.ccr.corp.intel.com ([10.109.6.141]) with mapi id 15.01.1713.004; Mon, 13 Jan 2020 09:45:48 +0800 From: "Bob Feng" To: "Fan, ZhijuX" , "devel@edk2.groups.io" CC: "Gao, Liming" Subject: Re: [PATCH V2] BaseTools:Fix GenFds issue for BuildOption replace GenFdsOption Thread-Topic: [PATCH V2] BaseTools:Fix GenFds issue for BuildOption replace GenFdsOption Thread-Index: AdXHkBKPq0xBBzczSeKw1AXu6q3W3gCIxZFg Date: Mon, 13 Jan 2020 01:45:47 +0000 Message-ID: <8d1a2fbd91c84134bde4e758e5543b25@intel.com> References: In-Reply-To: Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.36] MIME-Version: 1.0 Return-Path: bob.c.feng@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Bob Feng -----Original Message----- From: Fan, ZhijuX=20 Sent: Friday, January 10, 2020 4:30 PM To: devel@edk2.groups.io Cc: Gao, Liming ; Feng, Bob C Subject: [PATCH V2] BaseTools:Fix GenFds issue for BuildOption replace GenF= dsOption BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=3D2455 BuildOption is used by TargetTxtClassObj.py GenFdsOption is used by GenFds.= py When the GenFds tool is used alone (e.g. python3 -m GenFds.GenFds -h) Wi= th the OptionParser function, the first detected function prints the help m= essage import TargetTxtClassObj to GenFds, The BuildOption will be executed and replace GenFdsOption We removed all objects associated with this problem that were created direc= tly during the import process (e.g. BuildOption, BuildTarget =3D MyOptionPa= rser(), TargetTxt =3D TargetTxtDict()) The Patch is going to fix this issue Signed-off-by: Zhiju.Fan Cc: Liming Gao Cc: Bob Feng --- BaseTools/Source/Python/AutoGen/BuildEngine.py | 56 +++++++---- BaseTools/Source/Python/Common/GlobalData.py | 2 +- .../Source/Python/Common/TargetTxtClassObject.py | 64 +++++++++------ .../Source/Python/Common/ToolDefClassObject.py | 48 +++++++--- BaseTools/Source/Python/Common/buildoptions.py | 93 -----------------= - BaseTools/Source/Python/GenFds/GenFds.py | 4 +- .../Source/Python/GenFds/GenFdsGlobalVariable.py | 17 ++-- BaseTools/Source/Python/Workspace/DscBuildData.py | 9 +- BaseTools/Source/Python/build/build.py | 32 +++++-- BaseTools/Source/Python/build/buildoptions.py | 105 +++++++++++++++++= ++++ 10 files changed, 261 insertions(+), 169 deletions(-) delete mode 100644 = BaseTools/Source/Python/Common/buildoptions.py create mode 100644 BaseTools/Source/Python/build/buildoptions.py The method by which the optimization function gets the parameter value add = bugzilla to patch diff --git a/BaseTools/Source/Python/AutoGen/BuildEngine.py b/BaseTools/Sou= rce/Python/AutoGen/BuildEngine.py index 069a3a1c9d..d602414ca4 100644 --- a/BaseTools/Source/Python/AutoGen/BuildEngine.py +++ b/BaseTools/Source/Python/AutoGen/BuildEngine.py @@ -20,7 +20,7 @@ from Common.BuildToolError import * from Common.Misc imp= ort tdict, PathClass from Common.StringUtils import NormPath from Common.= DataType import * -from Common.TargetTxtClassObject import TargetTxt +from Common.TargetTxtClassObject import TargetTxtDict gDefaultBuildRuleFile =3D 'build_rule.txt' AutoGenReqBuildRuleVerNum =3D '0.1' =20 @@ -588,24 +588,42 @@ class BuildRule: _UnknownSection : SkipSection, } =20 -def GetBuildRule(): - BuildRuleFile =3D None - if TAB_TAT_DEFINES_BUILD_RULE_CONF in TargetTxt.TargetTxtDictionary: - BuildRuleFile =3D TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_BU= ILD_RULE_CONF] - if not BuildRuleFile: - BuildRuleFile =3D gDefaultBuildRuleFile - RetVal =3D BuildRule(BuildRuleFile) - if RetVal._FileVersion =3D=3D "": - RetVal._FileVersion =3D AutoGenReqBuildRuleVerNum - else: - if RetVal._FileVersion < AutoGenReqBuildRuleVerNum : - # If Build Rule's version is less than the version number requ= ired by the tools, halting the build. - EdkLogger.error("build", AUTOGEN_ERROR, - ExtraData=3D"The version number [%s] of build_= rule.txt is less than the version number required by the AutoGen.(the minim= um required version number is [%s])"\ - % (RetVal._FileVersion, AutoGenReqBuildRuleVe= rNum)) - return RetVal - -BuildRuleObj =3D GetBuildRule() +class ToolBuildRule(): + + def __new__(cls, *args, **kw): + if not hasattr(cls, '_instance'): + orig =3D super(ToolBuildRule, cls) + cls._instance =3D orig.__new__(cls, *args, **kw) + return cls._instance + + def __init__(self): + if not hasattr(self, 'ToolBuildRule'): + self._ToolBuildRule =3D None + + @property + def ToolBuildRule(self): + if not self._ToolBuildRule: + self._GetBuildRule() + return self._ToolBuildRule + + def _GetBuildRule(self): + BuildRuleFile =3D None + TargetObj =3D TargetTxtDict() + TargetTxt =3D TargetObj.Target + if TAB_TAT_DEFINES_BUILD_RULE_CONF in TargetTxt.TargetTxtDictionar= y: + BuildRuleFile =3D TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINE= S_BUILD_RULE_CONF] + if not BuildRuleFile: + BuildRuleFile =3D gDefaultBuildRuleFile + RetVal =3D BuildRule(BuildRuleFile) + if RetVal._FileVersion =3D=3D "": + RetVal._FileVersion =3D 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=3D"The version number [%s] of bu= ild_rule.txt is less than the version number required by the AutoGen.(the m= inimum required version number is [%s])"\ + % (RetVal._FileVersion, AutoGenReqBuildRu= leVerNum)) + self._ToolBuildRule =3D RetVal =20 # This acts like the main() function for the script, unless it is 'import'= ed into another # script. diff --git a/BaseTools/Source/Python/Common/GlobalData.py b/BaseTools/Sourc= e/Python/Common/GlobalData.py index 0b3ebe035d..8ac29eb7a6 100755 --- a/BaseTools/Source/Python/Common/GlobalData.py +++ b/BaseTools/Source/Python/Common/GlobalData.py @@ -70,7 +70,7 @@ gAutoGenPhase =3D False # The Conf dir outside the workspace dir # gConfDirectory =3D '' - +gCmdConfDir =3D '' gBuildDirectory =3D '' # # The relative default database file path diff --git a/BaseTools/Source/Py= thon/Common/TargetTxtClassObject.py b/BaseTools/Source/Python/Common/Target= TxtClassObject.py index 723b9405bf..57212172fe 100644 --- a/BaseTools/Source/Python/Common/TargetTxtClassObject.py +++ b/BaseTools/Source/Python/Common/TargetTxtClassObject.py @@ -10,7 +10,7 @@ # from __future__ import print_function from __future__ import absolute_import -from Common.buildoptions import BuildOption,BuildTarget + import Common.GlobalData as GlobalData import Common.LongFilePathOs as os from . import EdkLogger @@ -144,29 +144,47 @@ class TargetTxtClassObject(object): # # @retval Target An instance of TargetTxtClassObject() with loaded target.= txt # -def TargetTxtDict(): - Target =3D TargetTxtClassObject() - if BuildOption.ConfDirectory: - # Get alternate Conf location, if it is absolute, then just use th= e absolute directory name - ConfDirectoryPath =3D os.path.normpath(BuildOption.ConfDirectory) - - if not os.path.isabs(ConfDirectoryPath): - # Since alternate directory name is not absolute, the alternat= e directory is located within the WORKSPACE - # This also handles someone specifying the Conf directory in t= he workspace. Using --conf=3DConf - ConfDirectoryPath =3D mws.join(os.environ["WORKSPACE"], ConfDi= rectoryPath) - else: - if "CONF_PATH" in os.environ: - ConfDirectoryPath =3D os.path.normcase(os.path.normpath(os.env= iron["CONF_PATH"])) + +class TargetTxtDict(): + + def __new__(cls, *args, **kw): + if not hasattr(cls, '_instance'): + orig =3D super(TargetTxtDict, cls) + cls._instance =3D orig.__new__(cls, *args, **kw) + return cls._instance + + def __init__(self): + if not hasattr(self, 'Target'): + self.TxtTarget =3D None + + @property + def Target(self): + if not self.TxtTarget: + self._GetTarget() + return self.TxtTarget + + def _GetTarget(self): + Target =3D TargetTxtClassObject() + ConfDirectory =3D GlobalData.gCmdConfDir + if ConfDirectory: + # Get alternate Conf location, if it is absolute, then just us= e the absolute directory name + ConfDirectoryPath =3D os.path.normpath(ConfDirectory) + + if not os.path.isabs(ConfDirectoryPath): + # Since alternate directory name is not absolute, the alte= rnate directory is located within the WORKSPACE + # This also handles someone specifying the Conf directory = in the workspace. Using --conf=3DConf + ConfDirectoryPath =3D mws.join(os.environ["WORKSPACE"],=20 + ConfDirectoryPath) else: - # Get standard WORKSPACE/Conf use the absolute path to the WOR= KSPACE/Conf - ConfDirectoryPath =3D mws.join(os.environ["WORKSPACE"], 'Conf'= ) - GlobalData.gConfDirectory =3D ConfDirectoryPath - targettxt =3D os.path.normpath(os.path.join(ConfDirectoryPath, gDefaul= tTargetTxtFile)) - if os.path.exists(targettxt): - Target.LoadTargetTxtFile(targettxt) - return Target - -TargetTxt =3D TargetTxtDict() + if "CONF_PATH" in os.environ: + ConfDirectoryPath =3D os.path.normcase(os.path.normpath(os= .environ["CONF_PATH"])) + else: + # Get standard WORKSPACE/Conf use the absolute path to the= WORKSPACE/Conf + ConfDirectoryPath =3D mws.join(os.environ["WORKSPACE"], 'C= onf') + GlobalData.gConfDirectory =3D ConfDirectoryPath + targettxt =3D os.path.normpath(os.path.join(ConfDirectoryPath, gDe= faultTargetTxtFile)) + if os.path.exists(targettxt): + Target.LoadTargetTxtFile(targettxt) + self.TxtTarget =3D Target =20 ## # diff --git a/BaseTools/Source/Python/Common/ToolDefClassObject.py b/BaseToo= ls/Source/Python/Common/ToolDefClassObject.py index 063fa00584..8e70407cb9 100644 --- a/BaseTools/Source/Python/Common/ToolDefClassObject.py +++ b/BaseTools/Source/Python/Common/ToolDefClassObject.py @@ -14,7 +14,7 @@ import re from . import EdkLogger =20 from .BuildToolError import * -from Common.TargetTxtClassObject import TargetTxt +from Common.TargetTxtClassObject import TargetTxtDict from Common.LongFilePathSupport import OpenLongFilePath as open from Comm= on.Misc import PathClass from Common.StringUtils import NormPath @@ -262,2= 0 +262,40 @@ class ToolDefClassObject(object): # # @retval ToolDef An instance of ToolDefClassObject() with loaded tools_de= f.txt # -def ToolDefDict(ConfDir): - Target =3D TargetTxt - ToolDef =3D ToolDefClassObject() - if TAB_TAT_DEFINES_TOOL_CHAIN_CONF in Target.TargetTxtDictionary: - ToolsDefFile =3D Target.TargetTxtDictionary[TAB_TAT_DEFINES_TOOL_C= HAIN_CONF] - if ToolsDefFile: - ToolDef.LoadToolDefFile(os.path.normpath(ToolsDefFile)) - else: - ToolDef.LoadToolDefFile(os.path.normpath(os.path.join(ConfDir,= gDefaultToolsDefFile))) - else: - ToolDef.LoadToolDefFile(os.path.normpath(os.path.join(ConfDir, gDe= faultToolsDefFile))) - return ToolDef =20 -ToolDef =3D ToolDefDict((os.path.join(os.getenv("WORKSPACE"),"Conf"))) + +class ToolDefDict(): + + def __new__(cls, ConfDir, *args, **kw): + if not hasattr(cls, '_instance'): + orig =3D super(ToolDefDict, cls) + cls._instance =3D orig.__new__(cls, *args, **kw) + return cls._instance + + def __init__(self, ConfDir): + self.ConfDir =3D ConfDir + if not hasattr(self, 'ToolDef'): + self._ToolDef =3D None + + @property + def ToolDef(self): + if not self._ToolDef: + self._GetToolDef() + return self._ToolDef + + def _GetToolDef(self): + TargetObj =3D TargetTxtDict() + Target =3D TargetObj.Target + ToolDef =3D ToolDefClassObject() + if TAB_TAT_DEFINES_TOOL_CHAIN_CONF in Target.TargetTxtDictionary: + ToolsDefFile =3D Target.TargetTxtDictionary[TAB_TAT_DEFINES_TO= OL_CHAIN_CONF] + if ToolsDefFile: + ToolDef.LoadToolDefFile(os.path.normpath(ToolsDefFile)) + else: + ToolDef.LoadToolDefFile(os.path.normpath(os.path.join(self= .ConfDir, gDefaultToolsDefFile))) + else: + ToolDef.LoadToolDefFile(os.path.normpath(os.path.join(self.Con= fDir, gDefaultToolsDefFile))) + self._ToolDef =3D ToolDef =20 ## # diff --git a/BaseTools/Source/Python/Common/buildoptions.py b/BaseTools/Sou= rce/Python/Common/buildoptions.py deleted file mode 100644 index a717c58d8c..0000000000 --- a/BaseTools/Source/Python/Common/buildoptions.py +++ /dev/null @@ -1,93 +0,0 @@ -## @file -# build a platform or a module -# -# Copyright (c) 2014, Hewlett-Packard Development Company, L.P.
-# C= opyright (c) 2007 - 2019, Intel Corporation. All rights reserved.
-# C= opyright (c) 2018, Hewlett Packard Enterprise Development, L.P.
-# -# = SPDX-License-Identifier: BSD-2-Clause-Patent -# - -# Version and Copyright -from Common.BuildVersion import gBUILD_VERSION -from optparse import Optio= nParser -VersionNumber =3D "0.60" + ' ' + gBUILD_VERSION -__version__ =3D "= %prog Version " + VersionNumber -__copyright__ =3D "Copyright (c) 2007 - 20= 18, Intel Corporation All rights reserved." - -gParamCheck =3D [] -def SingleCheckCallback(option, opt_str, value, parser): - if option not in gParamCheck: - setattr(parser.values, option.dest, value) - gParamCheck.append(option) - else: - parser.error("Option %s only allows one instance in command line!"= % option) - -def MyOptionParser(): - Parser =3D OptionParser(description=3D__copyright__, version=3D__versi= on__, prog=3D"build.exe", usage=3D"%prog [options] [all|fds|genc|genmake|cl= ean|cleanall|cleanlib|modules|libraries|run]") - Parser.add_option("-a", "--arch", action=3D"append", type=3D"choice", = choices=3D['IA32', 'X64', 'EBC', 'ARM', 'AARCH64'], dest=3D"TargetArch", - help=3D"ARCHS is one of list: IA32, X64, ARM, AARCH64 or EBC, whic= h overrides target.txt's TARGET_ARCH definition. To specify more archs, ple= ase repeat this option.") - Parser.add_option("-p", "--platform", action=3D"callback", type=3D"str= ing", dest=3D"PlatformFile", callback=3DSingleCheckCallback, - help=3D"Build the platform specified by the DSC file name argument= , overriding target.txt's ACTIVE_PLATFORM definition.") - Parser.add_option("-m", "--module", action=3D"callback", type=3D"strin= g", dest=3D"ModuleFile", callback=3DSingleCheckCallback, - help=3D"Build the module specified by the INF file name argument."= ) - Parser.add_option("-b", "--buildtarget", type=3D"string", dest=3D"Buil= dTarget", help=3D"Using the TARGET to build the platform, overriding target= .txt's TARGET definition.", - action=3D"append") - Parser.add_option("-t", "--tagname", action=3D"append", type=3D"string= ", dest=3D"ToolChain", - help=3D"Using the Tool Chain Tagname to build the platform, overri= ding target.txt's TOOL_CHAIN_TAG definition.") - Parser.add_option("-x", "--sku-id", action=3D"callback", type=3D"strin= g", dest=3D"SkuId", callback=3DSingleCheckCallback, - help=3D"Using this name of SKU ID to build the platform, overridin= g SKUID_IDENTIFIER in DSC file.") - - Parser.add_option("-n", action=3D"callback", type=3D"int", dest=3D"Thr= eadNumber", callback=3DSingleCheckCallback, - help=3D"Build the platform using multi-threaded compiler. The valu= e overrides target.txt's MAX_CONCURRENT_THREAD_NUMBER. When value is set to= 0, tool automatically detect number of "\ - "processor threads, set value to 1 means disable multi-thread= build, and set value to more than 1 means user specify the threads number = to build.") - - Parser.add_option("-f", "--fdf", action=3D"callback", type=3D"string",= dest=3D"FdfFile", callback=3DSingleCheckCallback, - help=3D"The name of the FDF file to use, which overrides the setti= ng in the DSC file.") - Parser.add_option("-r", "--rom-image", action=3D"append", type=3D"stri= ng", dest=3D"RomImage", default=3D[], - help=3D"The name of FD to be generated. The name must be from [FD]= section in FDF file.") - Parser.add_option("-i", "--fv-image", action=3D"append", type=3D"strin= g", dest=3D"FvImage", default=3D[], - help=3D"The name of FV to be generated. The name must be from [FV]= section in FDF file.") - Parser.add_option("-C", "--capsule-image", action=3D"append", type=3D"= string", dest=3D"CapName", default=3D[], - help=3D"The name of Capsule to be generated. The name must be from= [Capsule] section in FDF file.") - Parser.add_option("-u", "--skip-autogen", action=3D"store_true", dest= =3D"SkipAutoGen", help=3D"Skip AutoGen step.") - Parser.add_option("-e", "--re-parse", action=3D"store_true", dest=3D"R= eparse", help=3D"Re-parse all meta-data files.") - - Parser.add_option("-c", "--case-insensitive", action=3D"store_true", d= est=3D"CaseInsensitive", default=3DFalse, help=3D"Don't check case of file = name.") - - Parser.add_option("-w", "--warning-as-error", action=3D"store_true", d= est=3D"WarningAsError", help=3D"Treat warning in tools as error.") - Parser.add_option("-j", "--log", action=3D"store", dest=3D"LogFile", h= elp=3D"Put log in specified file as well as on console.") - - Parser.add_option("-s", "--silent", action=3D"store_true", type=3DNone= , dest=3D"SilentMode", - help=3D"Make use of silent mode of (n)make.") - Parser.add_option("-q", "--quiet", action=3D"store_true", type=3DNone,= help=3D"Disable all messages except FATAL ERRORS.") - Parser.add_option("-v", "--verbose", action=3D"store_true", type=3DNon= e, help=3D"Turn on verbose output with informational messages printed, "\ - = "including library instances selected, final dependency expression, "\ - = "and warning messages, etc.") - Parser.add_option("-d", "--debug", action=3D"store", type=3D"int", hel= p=3D"Enable debug messages at specified level.") - Parser.add_option("-D", "--define", action=3D"append", type=3D"string"= , dest=3D"Macros", help=3D"Macro: \"Name [=3D Value]\".") - - Parser.add_option("-y", "--report-file", action=3D"store", dest=3D"Rep= ortFile", help=3D"Create/overwrite the report to the specified filename.") - Parser.add_option("-Y", "--report-type", action=3D"append", type=3D"ch= oice", choices=3D['PCD', 'LIBRARY', 'FLASH', 'DEPEX', 'BUILD_FLAGS', 'FIXED= _ADDRESS', 'HASH', 'EXECUTION_ORDER'], dest=3D"ReportType", default=3D[], - help=3D"Flags that control the type of build report to generate. = Must be one of: [PCD, LIBRARY, FLASH, DEPEX, BUILD_FLAGS, FIXED_ADDRESS, HA= SH, EXECUTION_ORDER]. "\ - "To specify more than one flag, repeat this option on the com= mand line and the default flag set is [PCD, LIBRARY, FLASH, DEPEX, HASH, BU= ILD_FLAGS, FIXED_ADDRESS]") - Parser.add_option("-F", "--flag", action=3D"store", type=3D"string", d= est=3D"Flag", - help=3D"Specify the specific option to parse EDK UNI file. Must be= one of: [-c, -s]. -c is for EDK framework UNI file, and -s is for EDK UEFI= UNI file. "\ - "This option can also be specified by setting *_*_*_BUILD_FLA= GS in [BuildOptions] section of platform DSC. If they are both specified, t= his value "\ - "will override the setting in [BuildOptions] section of platf= orm DSC.") - Parser.add_option("-N", "--no-cache", action=3D"store_true", dest=3D"D= isableCache", default=3DFalse, help=3D"Disable build cache mechanism") - Parser.add_option("--conf", action=3D"store", type=3D"string", dest=3D= "ConfDirectory", help=3D"Specify the customized Conf directory.") - Parser.add_option("--check-usage", action=3D"store_true", dest=3D"Chec= kUsage", default=3DFalse, help=3D"Check usage content of entries listed in = INF file.") - Parser.add_option("--ignore-sources", action=3D"store_true", dest=3D"I= gnoreSources", default=3DFalse, help=3D"Focus to a binary build and ignore = all source files") - Parser.add_option("--pcd", action=3D"append", dest=3D"OptionPcd", help= =3D"Set PCD value by command line. Format: \"PcdName=3DValue\" ") - Parser.add_option("-l", "--cmd-len", action=3D"store", type=3D"int", d= est=3D"CommandLength", help=3D"Specify the maximum line length of build com= mand. Default is 4096.") - Parser.add_option("--hash", action=3D"store_true", dest=3D"UseHashCach= e", default=3DFalse, help=3D"Enable hash-based caching during build process= .") - Parser.add_option("--binary-destination", action=3D"store", type=3D"st= ring", dest=3D"BinCacheDest", help=3D"Generate a cache of binary files in t= he specified directory.") - Parser.add_option("--binary-source", action=3D"store", type=3D"string"= , dest=3D"BinCacheSource", help=3D"Consume a cache of binary files from the= specified directory.") - Parser.add_option("--genfds-multi-thread", action=3D"store_true", dest= =3D"GenfdsMultiThread", default=3DTrue, help=3D"Enable GenFds multi thread = to generate ffs file.") - Parser.add_option("--no-genfds-multi-thread", action=3D"store_true", d= est=3D"NoGenfdsMultiThread", default=3DFalse, help=3D"Disable GenFds multi = thread to generate ffs file.") - Parser.add_option("--disable-include-path-check", action=3D"store_true= ", dest=3D"DisableIncludePathCheck", default=3DFalse, help=3D"Disable the i= nclude path check for outside of package.") - (Opt, Args) =3D Parser.parse_args() - return (Opt, Args) - -BuildOption, BuildTarget =3D MyOptionParser() diff --git a/BaseTools/Sourc= e/Python/GenFds/GenFds.py b/BaseTools/Source/Python/GenFds/GenFds.py index d8bc28e4d0..d5511f4c40 100644 --- a/BaseTools/Source/Python/GenFds/GenFds.py +++ b/BaseTools/Source/Python/GenFds/GenFds.py @@ -20,7 +20,7 @@ from linecache import getlines from io import BytesIO =20 import Common.LongFilePathOs as os -from Common.TargetTxtClassObject import TargetTxt +from Common.TargetTxtClassObject import TargetTxtDict from Common.DataType import * import Common.GlobalData as GlobalData from Common import EdkLogger @@ -210,6 +210,8 @@ def GenFdsApi(FdsCommandDict, WorkSpaceDataBase=3DNone)= : BuildConfigurationFile =3D os.path.normpath(os.path.join(ConfDirec= toryPath, "target.txt")) if os.path.isfile(BuildConfigurationFile) =3D=3D True: # if no build target given in command line, get it from target= .txt + TargetObj =3D TargetTxtDict() + TargetTxt =3D TargetObj.Target if not GenFdsGlobalVariable.TargetName: BuildTargetList =3D TargetTxt.TargetTxtDictionary[TAB_TAT_= DEFINES_TARGET] if len(BuildTargetList) !=3D 1: diff --git a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py b/BaseT= ools/Source/Python/GenFds/GenFdsGlobalVariable.py index 6e1ff7fe04..dc1727c466 100644 --- a/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py +++ b/BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py @@ -23,9 +23,9 @@ from Common.BuildToolError import COMMAND_FAILURE,GENFDS_= ERROR from Common import EdkLogger from Common.Misc import SaveFileOnChan= ge =20 -from Common.TargetTxtClassObject import TargetTxt -from Common.ToolDefClas= sObject import ToolDef -from AutoGen.BuildEngine import BuildRuleObj +from Common.TargetTxtClassObject import TargetTxtDict from=20 +Common.ToolDefClassObject import ToolDefDict from AutoGen.BuildEngine=20 +import ToolBuildRule import Common.DataType as DataType from Common.Misc import PathClass from Common.LongFilePathSupport import OpenLongFilePath as open @@ -96,12 = +96,15 @@ class GenFdsGlobalVariable: def _LoadBuildRule(): if GenFdsGlobalVariable.__BuildRuleDatabase: return GenFdsGlobalVariable.__BuildRuleDatabase - GenFdsGlobalVariable.__BuildRuleDatabase =3D BuildRuleObj - ToolDefinitionFile =3D TargetTxt.TargetTxtDictionary[DataType.TAB_= TAT_DEFINES_TOOL_CHAIN_CONF] + BuildRule =3D ToolBuildRule() + GenFdsGlobalVariable.__BuildRuleDatabase =3D BuildRule.ToolBuildRu= le + TargetObj =3D TargetTxtDict() + ToolDefinitionFile =3D=20 + TargetObj.Target.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHA + IN_CONF] if ToolDefinitionFile =3D=3D '': ToolDefinitionFile =3D "Conf/tools_def.txt" if os.path.isfile(ToolDefinitionFile): - ToolDefinition =3D ToolDef.ToolsDefTxtDatabase + ToolDefObj =3D ToolDefDict((os.path.join(os.getenv("WORKSPACE"= ), "Conf"))) + ToolDefinition =3D ToolDefObj.ToolDef.ToolsDefTxtDatabase if DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY in ToolDefinition = \ and GenFdsGlobalVariable.ToolChainTag in ToolDefinition[Dat= aType.TAB_TOD_DEFINES_BUILDRULEFAMILY] \ and ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY= ][GenFdsGlobalVariable.ToolChainTag]: @@ -830,6 +833,8 @@ class GenFdsGlobalVariable: # @param NameGuid The Guid name # def FindExtendTool(KeyStringList, CurrentArchList, NameGuid): + ToolDefObj =3D ToolDefDict((os.path.join(os.getenv("WORKSPACE"), "Conf= "))) + ToolDef =3D ToolDefObj.ToolDef ToolDb =3D ToolDef.ToolsDefTxtDatabase # if user not specify filter, try to deduce it from global data. if KeyStringList is None or KeyStringList =3D=3D []: diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/= Source/Python/Workspace/DscBuildData.py index 03a15bbf3e..c65a0dd346 100644 --- a/BaseTools/Source/Python/Workspace/DscBuildData.py +++ b/BaseTools/Source/Python/Workspace/DscBuildData.py @@ -19,8 +19,8 @@ from Common.Misc import * from types import * from Comm= on.Expression import * from CommonDataClass.CommonClass import SkuInfoClas= s -from Common.TargetTxtClassObject import TargetTxt -from Common.ToolDefCl= assObject import ToolDef +from Common.TargetTxtClassObject import TargetTxtDict from=20 +Common.ToolDefClassObject import ToolDefDict from .MetaDataTable import * from .MetaFileTable import * from .MetaFileParser import * @@ -3296,6 +3296,8 @@ class DscBuildData(PlatformBuildClassObject): @property def ToolChainFamily(self): self._ToolChainFamily =3D TAB_COMPILER_MSFT + TargetObj =3D TargetTxtDict() + TargetTxt =3D TargetObj.Target BuildConfigurationFile =3D os.path.normpath(os.path.join(GlobalDat= a.gConfDirectory, "target.txt")) if os.path.isfile(BuildConfigurationFile) =3D=3D True: ToolDefinitionFile =3D TargetTxt.TargetTxtDictionary[DataType.= TAB_TAT_DEFINES_TOOL_CHAIN_CONF] @@ -3303,7 +3305,8 @@ class DscBuildData(PlatformBuildClassObject): ToolDefinitionFile =3D "tools_def.txt" ToolDefinitionFile =3D os.path.normpath(mws.join(self.Work= spaceDir, 'Conf', ToolDefinitionFile)) if os.path.isfile(ToolDefinitionFile) =3D=3D True: - ToolDefinition =3D ToolDef.ToolsDefTxtDatabase + ToolDefObj =3D ToolDefDict((os.path.join(os.getenv("WORKSP= ACE"), "Conf"))) + ToolDefinition =3D ToolDefObj.ToolDef.ToolsDefTxtDatabase if TAB_TOD_DEFINES_FAMILY not in ToolDefinition \ or self._Toolchain not in ToolDefinition[TAB_TOD_DEFINE= S_FAMILY] \ or not ToolDefinition[TAB_TOD_DEFINES_FAMILY][self._Too= lchain]: diff --git a/BaseTools/Source/Python/build/build.py b/BaseTools/Source/Pyth= on/build/build.py index 3cc4220e2f..34acdccbdb 100755 --- a/BaseTools/Source/Python/build/build.py +++ b/BaseTools/Source/Python/build/build.py @@ -26,7 +26,7 @@ from threading import Thread,Event,BoundedSemaphore impo= rt threading from subprocess import Popen,PIPE, STDOUT from collections i= mport OrderedDict, defaultdict -from Common.buildoptions import BuildOption= ,BuildTarget + from AutoGen.PlatformAutoGen import PlatformAutoGen from AutoGen.ModuleAu= toGen import ModuleAutoGen from AutoGen.WorkspaceAutoGen import WorkspaceA= utoGen @@ -35,8 +35,9 @@ from AutoGen.AutoGenWorker import AutoGenWorkerInP= rocess,AutoGenManager,\ from AutoGen import GenMake from Common import Misc as Utils =20 -from Common.TargetTxtClassObject import TargetTxt -from Common.ToolDefClas= sObject import ToolDef +from Common.TargetTxtClassObject import TargetTxtDict from=20 +Common.ToolDefClassObject import ToolDefDict from buildoptions import=20 +MyOptionParser from Common.Misc import PathClass,SaveFileOnChange,RemoveDirectory from Common.StringUtils import NormPath from Common.MultipleWorkspace imp= ort MultipleWorkspace as mws @@ -731,11 +732,13 @@ class Build(): self.ConfDirectory =3D BuildOptions.ConfDirectory self.SpawnMode =3D True self.BuildReport =3D BuildReport(BuildOptions.ReportFile, Build= Options.ReportType) - self.TargetTxt =3D TargetTxt - self.ToolDef =3D ToolDef self.AutoGenTime =3D 0 self.MakeTime =3D 0 self.GenFdsTime =3D 0 + TargetObj =3D TargetTxtDict() + ToolDefObj =3D ToolDefDict((os.path.join(os.getenv("WORKSPACE"),"C= onf"))) + self.TargetTxt =3D TargetObj.Target + self.ToolDef =3D ToolDefObj.ToolDef GlobalData.BuildOptionPcd =3D BuildOptions.OptionPcd if BuildO= ptions.OptionPcd else [] #Set global flag for build mode GlobalData.gIgnoreSource =3D BuildOptions.IgnoreSources @@ -816,8 = +819,10 @@ class Build(): EdkLogger.quiet("%-16s =3D %s" % ("POSTBUILD", self.Postbuild)= ) if self.Prebuild: self.LaunchPrebuild() - self.TargetTxt =3D TargetTxt - self.ToolDef =3D ToolDef + TargetObj =3D TargetTxtDict() + ToolDefObj =3D ToolDefDict((os.path.join(os.getenv("WORKSPACE"= ), "Conf"))) + self.TargetTxt =3D TargetObj.Target + self.ToolDef =3D ToolDefObj.ToolDef if not (self.LaunchPrebuildFlag and os.path.exists(self.PlatformBu= ildPath)): self.InitBuild() =20 @@ -2438,9 +2443,15 @@ def LogBuildTime(Time): else: return None def ThreadNum(): + OptionParser =3D MyOptionParser() + if not OptionParser.BuildOption and not OptionParser.BuildTarget: + OptionParser.GetOption() + BuildOption, BuildTarget =3D OptionParser.BuildOption,=20 + OptionParser.BuildTarget ThreadNumber =3D BuildOption.ThreadNumber + GlobalData.gCmdConfDir =3D BuildOption.ConfDirectory if ThreadNumber is None: - ThreadNumber =3D TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_MAX= _CONCURRENT_THREAD_NUMBER] + TargetObj =3D TargetTxtDict() + ThreadNumber =3D=20 + TargetObj.Target.TargetTxtDictionary[TAB_TAT_DEFINES_MAX_CONCURRENT_TH + READ_NUMBER] if ThreadNumber =3D=3D '': ThreadNumber =3D 0 else: @@ -2475,7 +2486,10 @@ def Main(): # # Parse the options and args # - Option, Target =3D BuildOption, BuildTarget + OptionParser =3D MyOptionParser() + if not OptionParser.BuildOption and not OptionParser.BuildTarget: + OptionParser.GetOption() + Option, Target =3D OptionParser.BuildOption, OptionParser.BuildTarget GlobalData.gOptions =3D Option GlobalData.gCaseInsensitive =3D Option.CaseInsensitive =20 diff --git a/BaseTools/Source/Python/build/buildoptions.py b/BaseTools/Sour= ce/Python/build/buildoptions.py new file mode 100644 index 0000000000..4ad95b9f4f --- /dev/null +++ b/BaseTools/Source/Python/build/buildoptions.py @@ -0,0 +1,105 @@ +## @file +# build a platform or a module +# +# Copyright (c) 2014, Hewlett-Packard Development Company, L.P.
# =20 +Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved.
=20 +# Copyright (c) 2018, Hewlett Packard Enterprise Development, L.P.
=20 +# # SPDX-License-Identifier: BSD-2-Clause-Patent # + +# Version and Copyright +from Common.BuildVersion import gBUILD_VERSION from optparse import=20 +OptionParser VersionNumber =3D "0.60" + ' ' + gBUILD_VERSION __version__=20 +=3D "%prog Version " + VersionNumber __copyright__ =3D "Copyright (c) 2007= =20 +- 2018, Intel Corporation All rights reserved." + +gParamCheck =3D [] +def SingleCheckCallback(option, opt_str, value, parser): + if option not in gParamCheck: + setattr(parser.values, option.dest, value) + gParamCheck.append(option) + else: + parser.error("Option %s only allows one instance in command=20 +line!" % option) + + +class MyOptionParser(): + + def __new__(cls, *args, **kw): + if not hasattr(cls, '_instance'): + orig =3D super(MyOptionParser, cls) + cls._instance =3D orig.__new__(cls, *args, **kw) + return cls._instance + + def __init__(self): + if not hasattr(self, 'BuildOption'): + self.BuildOption =3D None + if not hasattr(self, 'BuildTarget'): + self.BuildTarget =3D None + + def GetOption(self): + Parser =3D OptionParser(description=3D__copyright__, version=3D__v= ersion__, prog=3D"build.exe", usage=3D"%prog [options] [all|fds|genc|genmak= e|clean|cleanall|cleanlib|modules|libraries|run]") + Parser.add_option("-a", "--arch", action=3D"append", type=3D"choic= e", choices=3D['IA32', 'X64', 'EBC', 'ARM', 'AARCH64'], dest=3D"TargetArch"= , + help=3D"ARCHS is one of list: IA32, X64, ARM, AARCH64 or EBC, = which overrides target.txt's TARGET_ARCH definition. To specify more archs,= please repeat this option.") + Parser.add_option("-p", "--platform", action=3D"callback", type=3D= "string", dest=3D"PlatformFile", callback=3DSingleCheckCallback, + help=3D"Build the platform specified by the DSC file name argu= ment, overriding target.txt's ACTIVE_PLATFORM definition.") + Parser.add_option("-m", "--module", action=3D"callback", type=3D"s= tring", dest=3D"ModuleFile", callback=3DSingleCheckCallback, + help=3D"Build the module specified by the INF file name argume= nt.") + Parser.add_option("-b", "--buildtarget", type=3D"string", dest=3D"= BuildTarget", help=3D"Using the TARGET to build the platform, overriding ta= rget.txt's TARGET definition.", + action=3D"append") + Parser.add_option("-t", "--tagname", action=3D"append", type=3D"st= ring", dest=3D"ToolChain", + help=3D"Using the Tool Chain Tagname to build the platform, ov= erriding target.txt's TOOL_CHAIN_TAG definition.") + Parser.add_option("-x", "--sku-id", action=3D"callback", type=3D"s= tring", dest=3D"SkuId", callback=3DSingleCheckCallback, + help=3D"Using this name of SKU ID to build the platform,=20 + overriding SKUID_IDENTIFIER in DSC file.") + + Parser.add_option("-n", action=3D"callback", type=3D"int", dest=3D= "ThreadNumber", callback=3DSingleCheckCallback, + help=3D"Build the platform using multi-threaded compiler. The = value overrides target.txt's MAX_CONCURRENT_THREAD_NUMBER. When value is se= t to 0, tool automatically detect number of "\ + "processor threads, set value to 1 means disable=20 + multi-thread build, and set value to more than 1 means user specify=20 + the threads number to build.") + + Parser.add_option("-f", "--fdf", action=3D"callback", type=3D"stri= ng", dest=3D"FdfFile", callback=3DSingleCheckCallback, + help=3D"The name of the FDF file to use, which overrides the s= etting in the DSC file.") + Parser.add_option("-r", "--rom-image", action=3D"append", type=3D"= string", dest=3D"RomImage", default=3D[], + help=3D"The name of FD to be generated. The name must be from = [FD] section in FDF file.") + Parser.add_option("-i", "--fv-image", action=3D"append", type=3D"s= tring", dest=3D"FvImage", default=3D[], + help=3D"The name of FV to be generated. The name must be from = [FV] section in FDF file.") + Parser.add_option("-C", "--capsule-image", action=3D"append", type= =3D"string", dest=3D"CapName", default=3D[], + help=3D"The name of Capsule to be generated. The name must be = from [Capsule] section in FDF file.") + Parser.add_option("-u", "--skip-autogen", action=3D"store_true", d= est=3D"SkipAutoGen", help=3D"Skip AutoGen step.") + Parser.add_option("-e", "--re-parse", action=3D"store_true",=20 + dest=3D"Reparse", help=3D"Re-parse all meta-data files.") + + Parser.add_option("-c", "--case-insensitive",=20 + action=3D"store_true", dest=3D"CaseInsensitive", default=3DFalse,=20 + help=3D"Don't check case of file name.") + + Parser.add_option("-w", "--warning-as-error", action=3D"store_true= ", dest=3D"WarningAsError", help=3D"Treat warning in tools as error.") + Parser.add_option("-j", "--log", action=3D"store",=20 + dest=3D"LogFile", help=3D"Put log in specified file as well as on=20 + console.") + + Parser.add_option("-s", "--silent", action=3D"store_true", type=3D= None, dest=3D"SilentMode", + help=3D"Make use of silent mode of (n)make.") + Parser.add_option("-q", "--quiet", action=3D"store_true", type=3DN= one, help=3D"Disable all messages except FATAL ERRORS.") + Parser.add_option("-v", "--verbose", action=3D"store_true", type= =3DNone, help=3D"Turn on verbose output with informational messages printed= , "\ + = "including library instances selected, final dependency expression= , "\ + = "and warning messages, etc.") + Parser.add_option("-d", "--debug", action=3D"store", type=3D"int",= help=3D"Enable debug messages at specified level.") + Parser.add_option("-D", "--define", action=3D"append",=20 + type=3D"string", dest=3D"Macros", help=3D"Macro: \"Name [=3D Value]\".") + + Parser.add_option("-y", "--report-file", action=3D"store", dest=3D= "ReportFile", help=3D"Create/overwrite the report to the specified filename= .") + Parser.add_option("-Y", "--report-type", action=3D"append", type= =3D"choice", choices=3D['PCD', 'LIBRARY', 'FLASH', 'DEPEX', 'BUILD_FLAGS', = 'FIXED_ADDRESS', 'HASH', 'EXECUTION_ORDER'], dest=3D"ReportType", default= =3D[], + help=3D"Flags that control the type of build report to generat= e. Must be one of: [PCD, LIBRARY, FLASH, DEPEX, BUILD_FLAGS, FIXED_ADDRESS= , HASH, EXECUTION_ORDER]. "\ + "To specify more than one flag, repeat this option on the= command line and the default flag set is [PCD, LIBRARY, FLASH, DEPEX, HASH= , BUILD_FLAGS, FIXED_ADDRESS]") + Parser.add_option("-F", "--flag", action=3D"store", type=3D"string= ", dest=3D"Flag", + help=3D"Specify the specific option to parse EDK UNI file. Mus= t be one of: [-c, -s]. -c is for EDK framework UNI file, and -s is for EDK = UEFI UNI file. "\ + "This option can also be specified by setting *_*_*_BUILD= _FLAGS in [BuildOptions] section of platform DSC. If they are both specifie= d, this value "\ + "will override the setting in [BuildOptions] section of p= latform DSC.") + Parser.add_option("-N", "--no-cache", action=3D"store_true", dest= =3D"DisableCache", default=3DFalse, help=3D"Disable build cache mechanism") + Parser.add_option("--conf", action=3D"store", type=3D"string", des= t=3D"ConfDirectory", help=3D"Specify the customized Conf directory.") + Parser.add_option("--check-usage", action=3D"store_true", dest=3D"= CheckUsage", default=3DFalse, help=3D"Check usage content of entries listed= in INF file.") + Parser.add_option("--ignore-sources", action=3D"store_true", dest= =3D"IgnoreSources", default=3DFalse, help=3D"Focus to a binary build and ig= nore all source files") + Parser.add_option("--pcd", action=3D"append", dest=3D"OptionPcd", = help=3D"Set PCD value by command line. Format: \"PcdName=3DValue\" ") + Parser.add_option("-l", "--cmd-len", action=3D"store", type=3D"int= ", dest=3D"CommandLength", help=3D"Specify the maximum line length of build= command. Default is 4096.") + Parser.add_option("--hash", action=3D"store_true", dest=3D"UseHash= Cache", default=3DFalse, help=3D"Enable hash-based caching during build pro= cess.") + Parser.add_option("--binary-destination", action=3D"store", type= =3D"string", dest=3D"BinCacheDest", help=3D"Generate a cache of binary file= s in the specified directory.") + Parser.add_option("--binary-source", action=3D"store", type=3D"str= ing", dest=3D"BinCacheSource", help=3D"Consume a cache of binary files from= the specified directory.") + Parser.add_option("--genfds-multi-thread", action=3D"store_true", = dest=3D"GenfdsMultiThread", default=3DTrue, help=3D"Enable GenFds multi thr= ead to generate ffs file.") + Parser.add_option("--no-genfds-multi-thread", action=3D"store_true= ", dest=3D"NoGenfdsMultiThread", default=3DFalse, help=3D"Disable GenFds mu= lti thread to generate ffs file.") + Parser.add_option("--disable-include-path-check", action=3D"store_= true", dest=3D"DisableIncludePathCheck", default=3DFalse, help=3D"Disable t= he include path check for outside of package.") + self.BuildOption, self.BuildTarget =3D Parser.parse_args() -- 2.14.1.windows.1