]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools:Fix GenFds issue for BuildOption replace GenFdsOption
authorFan, ZhijuX <zhijux.fan@intel.com>
Fri, 10 Jan 2020 08:29:45 +0000 (16:29 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Mon, 13 Jan 2020 02:08:46 +0000 (02:08 +0000)
BZ:https://bugzilla.tianocore.org/show_bug.cgi?id=2455

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

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

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

The Patch is going to fix this issue

Signed-off-by: Zhiju.Fan <zhijux.fan@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Bob Feng <bob.c.feng@intel.com>
Reviewed-by: Bob Feng <bob.c.feng@intel.com>
BaseTools/Source/Python/AutoGen/BuildEngine.py
BaseTools/Source/Python/Common/GlobalData.py
BaseTools/Source/Python/Common/TargetTxtClassObject.py
BaseTools/Source/Python/Common/ToolDefClassObject.py
BaseTools/Source/Python/Common/buildoptions.py [deleted file]
BaseTools/Source/Python/GenFds/GenFds.py
BaseTools/Source/Python/GenFds/GenFdsGlobalVariable.py
BaseTools/Source/Python/Workspace/DscBuildData.py
BaseTools/Source/Python/build/build.py
BaseTools/Source/Python/build/buildoptions.py [new file with mode: 0644]

index 069a3a1c9db3ab8da91a97f53a5a5350c4c078f2..d602414ca41f37155c9c6d00eec54ea3918840c3 100644 (file)
@@ -20,7 +20,7 @@ from Common.BuildToolError import *
 from Common.Misc import tdict, PathClass\r
 from Common.StringUtils import NormPath\r
 from Common.DataType import *\r
-from Common.TargetTxtClassObject import TargetTxt\r
+from Common.TargetTxtClassObject import TargetTxtDict\r
 gDefaultBuildRuleFile = 'build_rule.txt'\r
 AutoGenReqBuildRuleVerNum = '0.1'\r
 \r
@@ -588,24 +588,42 @@ class BuildRule:
         _UnknownSection    : SkipSection,\r
     }\r
 \r
-def GetBuildRule():\r
-    BuildRuleFile = None\r
-    if TAB_TAT_DEFINES_BUILD_RULE_CONF in TargetTxt.TargetTxtDictionary:\r
-        BuildRuleFile = TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_BUILD_RULE_CONF]\r
-    if not BuildRuleFile:\r
-        BuildRuleFile = gDefaultBuildRuleFile\r
-    RetVal = BuildRule(BuildRuleFile)\r
-    if RetVal._FileVersion == "":\r
-        RetVal._FileVersion = AutoGenReqBuildRuleVerNum\r
-    else:\r
-        if RetVal._FileVersion < AutoGenReqBuildRuleVerNum :\r
-            # If Build Rule's version is less than the version number required by the tools, halting the build.\r
-            EdkLogger.error("build", AUTOGEN_ERROR,\r
-                            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])"\\r
-                             % (RetVal._FileVersion, AutoGenReqBuildRuleVerNum))\r
-    return RetVal\r
-\r
-BuildRuleObj = GetBuildRule()\r
+class ToolBuildRule():\r
+\r
+    def __new__(cls, *args, **kw):\r
+        if not hasattr(cls, '_instance'):\r
+            orig = super(ToolBuildRule, cls)\r
+            cls._instance = orig.__new__(cls, *args, **kw)\r
+        return cls._instance\r
+\r
+    def __init__(self):\r
+        if not hasattr(self, 'ToolBuildRule'):\r
+            self._ToolBuildRule = None\r
+\r
+    @property\r
+    def ToolBuildRule(self):\r
+        if not self._ToolBuildRule:\r
+            self._GetBuildRule()\r
+        return self._ToolBuildRule\r
+\r
+    def _GetBuildRule(self):\r
+        BuildRuleFile = None\r
+        TargetObj = TargetTxtDict()\r
+        TargetTxt = TargetObj.Target\r
+        if TAB_TAT_DEFINES_BUILD_RULE_CONF in TargetTxt.TargetTxtDictionary:\r
+            BuildRuleFile = TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_BUILD_RULE_CONF]\r
+        if not BuildRuleFile:\r
+            BuildRuleFile = gDefaultBuildRuleFile\r
+        RetVal = BuildRule(BuildRuleFile)\r
+        if RetVal._FileVersion == "":\r
+            RetVal._FileVersion = AutoGenReqBuildRuleVerNum\r
+        else:\r
+            if RetVal._FileVersion < AutoGenReqBuildRuleVerNum :\r
+                # If Build Rule's version is less than the version number required by the tools, halting the build.\r
+                EdkLogger.error("build", AUTOGEN_ERROR,\r
+                                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])"\\r
+                                 % (RetVal._FileVersion, AutoGenReqBuildRuleVerNum))\r
+        self._ToolBuildRule = RetVal\r
 \r
 # This acts like the main() function for the script, unless it is 'import'ed into another\r
 # script.\r
index 0b3ebe035d1d148d504a5444a83cc2cd07375918..8ac29eb7a6fbbb971f6c26e894746149dd037e5e 100755 (executable)
@@ -70,7 +70,7 @@ gAutoGenPhase = False
 # The Conf dir outside the workspace dir\r
 #\r
 gConfDirectory = ''\r
-\r
+gCmdConfDir = ''\r
 gBuildDirectory = ''\r
 #\r
 # The relative default database file path\r
index 723b9405bf8feea527e48f739d862ce15c2be442..363c38302b8e0b91d34e635661b8eda493be539f 100644 (file)
@@ -10,7 +10,7 @@
 #\r
 from __future__ import print_function\r
 from __future__ import absolute_import\r
-from Common.buildoptions import BuildOption,BuildTarget\r
+\r
 import Common.GlobalData as GlobalData\r
 import Common.LongFilePathOs as os\r
 from . import EdkLogger\r
@@ -144,29 +144,47 @@ class TargetTxtClassObject(object):
 #\r
 # @retval Target An instance of TargetTxtClassObject() with loaded target.txt\r
 #\r
-def TargetTxtDict():\r
-    Target = TargetTxtClassObject()\r
-    if BuildOption.ConfDirectory:\r
-        # Get alternate Conf location, if it is absolute, then just use the absolute directory name\r
-        ConfDirectoryPath = os.path.normpath(BuildOption.ConfDirectory)\r
-\r
-        if not os.path.isabs(ConfDirectoryPath):\r
-            # Since alternate directory name is not absolute, the alternate directory is located within the WORKSPACE\r
-            # This also handles someone specifying the Conf directory in the workspace. Using --conf=Conf\r
-            ConfDirectoryPath = mws.join(os.environ["WORKSPACE"], ConfDirectoryPath)\r
-    else:\r
-        if "CONF_PATH" in os.environ:\r
-            ConfDirectoryPath = os.path.normcase(os.path.normpath(os.environ["CONF_PATH"]))\r
+\r
+class TargetTxtDict():\r
+\r
+    def __new__(cls, *args, **kw):\r
+        if not hasattr(cls, '_instance'):\r
+            orig = super(TargetTxtDict, cls)\r
+            cls._instance = orig.__new__(cls, *args, **kw)\r
+        return cls._instance\r
+\r
+    def __init__(self):\r
+        if not hasattr(self, 'Target'):\r
+            self.TxtTarget = None\r
+\r
+    @property\r
+    def Target(self):\r
+        if not self.TxtTarget:\r
+            self._GetTarget()\r
+        return self.TxtTarget\r
+\r
+    def _GetTarget(self):\r
+        Target = TargetTxtClassObject()\r
+        ConfDirectory = GlobalData.gCmdConfDir\r
+        if ConfDirectory:\r
+            # Get alternate Conf location, if it is absolute, then just use the absolute directory name\r
+            ConfDirectoryPath = os.path.normpath(ConfDirectory)\r
+\r
+            if not os.path.isabs(ConfDirectoryPath):\r
+                # Since alternate directory name is not absolute, the alternate directory is located within the WORKSPACE\r
+                # This also handles someone specifying the Conf directory in the workspace. Using --conf=Conf\r
+                ConfDirectoryPath = mws.join(os.environ["WORKSPACE"], ConfDirectoryPath)\r
         else:\r
-            # Get standard WORKSPACE/Conf use the absolute path to the WORKSPACE/Conf\r
-            ConfDirectoryPath = mws.join(os.environ["WORKSPACE"], 'Conf')\r
-    GlobalData.gConfDirectory = ConfDirectoryPath\r
-    targettxt = os.path.normpath(os.path.join(ConfDirectoryPath, gDefaultTargetTxtFile))\r
-    if os.path.exists(targettxt):\r
-        Target.LoadTargetTxtFile(targettxt)\r
-    return Target\r
-\r
-TargetTxt = TargetTxtDict()\r
+            if "CONF_PATH" in os.environ:\r
+                ConfDirectoryPath = os.path.normcase(os.path.normpath(os.environ["CONF_PATH"]))\r
+            else:\r
+                # Get standard WORKSPACE/Conf use the absolute path to the WORKSPACE/Conf\r
+                ConfDirectoryPath = mws.join(os.environ["WORKSPACE"], 'Conf')\r
+        GlobalData.gConfDirectory = ConfDirectoryPath\r
+        targettxt = os.path.normpath(os.path.join(ConfDirectoryPath, gDefaultTargetTxtFile))\r
+        if os.path.exists(targettxt):\r
+            Target.LoadTargetTxtFile(targettxt)\r
+        self.TxtTarget = Target\r
 \r
 ##\r
 #\r
index 063fa005840a45ea711c889a1a2c9b81afb73e2a..8e70407cb9e94a1562332739873d6fc11e7934f4 100644 (file)
@@ -14,7 +14,7 @@ import re
 from . import EdkLogger\r
 \r
 from .BuildToolError import *\r
-from Common.TargetTxtClassObject import TargetTxt\r
+from Common.TargetTxtClassObject import TargetTxtDict\r
 from Common.LongFilePathSupport import OpenLongFilePath as open\r
 from Common.Misc import PathClass\r
 from Common.StringUtils import NormPath\r
@@ -262,20 +262,40 @@ class ToolDefClassObject(object):
 #\r
 # @retval ToolDef An instance of ToolDefClassObject() with loaded tools_def.txt\r
 #\r
-def ToolDefDict(ConfDir):\r
-    Target = TargetTxt\r
-    ToolDef = ToolDefClassObject()\r
-    if TAB_TAT_DEFINES_TOOL_CHAIN_CONF in Target.TargetTxtDictionary:\r
-        ToolsDefFile = Target.TargetTxtDictionary[TAB_TAT_DEFINES_TOOL_CHAIN_CONF]\r
-        if ToolsDefFile:\r
-            ToolDef.LoadToolDefFile(os.path.normpath(ToolsDefFile))\r
-        else:\r
-            ToolDef.LoadToolDefFile(os.path.normpath(os.path.join(ConfDir, gDefaultToolsDefFile)))\r
-    else:\r
-        ToolDef.LoadToolDefFile(os.path.normpath(os.path.join(ConfDir, gDefaultToolsDefFile)))\r
-    return ToolDef\r
 \r
-ToolDef = ToolDefDict((os.path.join(os.getenv("WORKSPACE"),"Conf")))\r
+\r
+class ToolDefDict():\r
+\r
+    def __new__(cls, ConfDir, *args, **kw):\r
+        if not hasattr(cls, '_instance'):\r
+            orig = super(ToolDefDict, cls)\r
+            cls._instance = orig.__new__(cls, *args, **kw)\r
+        return cls._instance\r
+\r
+    def __init__(self, ConfDir):\r
+        self.ConfDir = ConfDir\r
+        if not hasattr(self, 'ToolDef'):\r
+            self._ToolDef = None\r
+\r
+    @property\r
+    def ToolDef(self):\r
+        if not self._ToolDef:\r
+            self._GetToolDef()\r
+        return self._ToolDef\r
+\r
+    def _GetToolDef(self):\r
+        TargetObj = TargetTxtDict()\r
+        Target = TargetObj.Target\r
+        ToolDef = ToolDefClassObject()\r
+        if TAB_TAT_DEFINES_TOOL_CHAIN_CONF in Target.TargetTxtDictionary:\r
+            ToolsDefFile = Target.TargetTxtDictionary[TAB_TAT_DEFINES_TOOL_CHAIN_CONF]\r
+            if ToolsDefFile:\r
+                ToolDef.LoadToolDefFile(os.path.normpath(ToolsDefFile))\r
+            else:\r
+                ToolDef.LoadToolDefFile(os.path.normpath(os.path.join(self.ConfDir, gDefaultToolsDefFile)))\r
+        else:\r
+            ToolDef.LoadToolDefFile(os.path.normpath(os.path.join(self.ConfDir, gDefaultToolsDefFile)))\r
+        self._ToolDef = ToolDef\r
 \r
 ##\r
 #\r
diff --git a/BaseTools/Source/Python/Common/buildoptions.py b/BaseTools/Source/Python/Common/buildoptions.py
deleted file mode 100644 (file)
index a717c58..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-## @file\r
-# build a platform or a module\r
-#\r
-#  Copyright (c) 2014, Hewlett-Packard Development Company, L.P.<BR>\r
-#  Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved.<BR>\r
-#  Copyright (c) 2018, Hewlett Packard Enterprise Development, L.P.<BR>\r
-#\r
-#  SPDX-License-Identifier: BSD-2-Clause-Patent\r
-#\r
-\r
-# Version and Copyright\r
-from Common.BuildVersion import gBUILD_VERSION\r
-from optparse import OptionParser\r
-VersionNumber = "0.60" + ' ' + gBUILD_VERSION\r
-__version__ = "%prog Version " + VersionNumber\r
-__copyright__ = "Copyright (c) 2007 - 2018, Intel Corporation  All rights reserved."\r
-\r
-gParamCheck = []\r
-def SingleCheckCallback(option, opt_str, value, parser):\r
-    if option not in gParamCheck:\r
-        setattr(parser.values, option.dest, value)\r
-        gParamCheck.append(option)\r
-    else:\r
-        parser.error("Option %s only allows one instance in command line!" % option)\r
-\r
-def MyOptionParser():\r
-    Parser = OptionParser(description=__copyright__, version=__version__, prog="build.exe", usage="%prog [options] [all|fds|genc|genmake|clean|cleanall|cleanlib|modules|libraries|run]")\r
-    Parser.add_option("-a", "--arch", action="append", type="choice", choices=['IA32', 'X64', 'EBC', 'ARM', 'AARCH64'], dest="TargetArch",\r
-        help="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.")\r
-    Parser.add_option("-p", "--platform", action="callback", type="string", dest="PlatformFile", callback=SingleCheckCallback,\r
-        help="Build the platform specified by the DSC file name argument, overriding target.txt's ACTIVE_PLATFORM definition.")\r
-    Parser.add_option("-m", "--module", action="callback", type="string", dest="ModuleFile", callback=SingleCheckCallback,\r
-        help="Build the module specified by the INF file name argument.")\r
-    Parser.add_option("-b", "--buildtarget", type="string", dest="BuildTarget", help="Using the TARGET to build the platform, overriding target.txt's TARGET definition.",\r
-                      action="append")\r
-    Parser.add_option("-t", "--tagname", action="append", type="string", dest="ToolChain",\r
-        help="Using the Tool Chain Tagname to build the platform, overriding target.txt's TOOL_CHAIN_TAG definition.")\r
-    Parser.add_option("-x", "--sku-id", action="callback", type="string", dest="SkuId", callback=SingleCheckCallback,\r
-        help="Using this name of SKU ID to build the platform, overriding SKUID_IDENTIFIER in DSC file.")\r
-\r
-    Parser.add_option("-n", action="callback", type="int", dest="ThreadNumber", callback=SingleCheckCallback,\r
-        help="Build the platform using multi-threaded compiler. The value overrides target.txt's MAX_CONCURRENT_THREAD_NUMBER. When value is set to 0, tool automatically detect number of "\\r
-             "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.")\r
-\r
-    Parser.add_option("-f", "--fdf", action="callback", type="string", dest="FdfFile", callback=SingleCheckCallback,\r
-        help="The name of the FDF file to use, which overrides the setting in the DSC file.")\r
-    Parser.add_option("-r", "--rom-image", action="append", type="string", dest="RomImage", default=[],\r
-        help="The name of FD to be generated. The name must be from [FD] section in FDF file.")\r
-    Parser.add_option("-i", "--fv-image", action="append", type="string", dest="FvImage", default=[],\r
-        help="The name of FV to be generated. The name must be from [FV] section in FDF file.")\r
-    Parser.add_option("-C", "--capsule-image", action="append", type="string", dest="CapName", default=[],\r
-        help="The name of Capsule to be generated. The name must be from [Capsule] section in FDF file.")\r
-    Parser.add_option("-u", "--skip-autogen", action="store_true", dest="SkipAutoGen", help="Skip AutoGen step.")\r
-    Parser.add_option("-e", "--re-parse", action="store_true", dest="Reparse", help="Re-parse all meta-data files.")\r
-\r
-    Parser.add_option("-c", "--case-insensitive", action="store_true", dest="CaseInsensitive", default=False, help="Don't check case of file name.")\r
-\r
-    Parser.add_option("-w", "--warning-as-error", action="store_true", dest="WarningAsError", help="Treat warning in tools as error.")\r
-    Parser.add_option("-j", "--log", action="store", dest="LogFile", help="Put log in specified file as well as on console.")\r
-\r
-    Parser.add_option("-s", "--silent", action="store_true", type=None, dest="SilentMode",\r
-        help="Make use of silent mode of (n)make.")\r
-    Parser.add_option("-q", "--quiet", action="store_true", type=None, help="Disable all messages except FATAL ERRORS.")\r
-    Parser.add_option("-v", "--verbose", action="store_true", type=None, help="Turn on verbose output with informational messages printed, "\\r
-                                                                               "including library instances selected, final dependency expression, "\\r
-                                                                               "and warning messages, etc.")\r
-    Parser.add_option("-d", "--debug", action="store", type="int", help="Enable debug messages at specified level.")\r
-    Parser.add_option("-D", "--define", action="append", type="string", dest="Macros", help="Macro: \"Name [= Value]\".")\r
-\r
-    Parser.add_option("-y", "--report-file", action="store", dest="ReportFile", help="Create/overwrite the report to the specified filename.")\r
-    Parser.add_option("-Y", "--report-type", action="append", type="choice", choices=['PCD', 'LIBRARY', 'FLASH', 'DEPEX', 'BUILD_FLAGS', 'FIXED_ADDRESS', 'HASH', 'EXECUTION_ORDER'], dest="ReportType", default=[],\r
-        help="Flags that control the type of build report to generate.  Must be one of: [PCD, LIBRARY, FLASH, DEPEX, BUILD_FLAGS, FIXED_ADDRESS, HASH, EXECUTION_ORDER].  "\\r
-             "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]")\r
-    Parser.add_option("-F", "--flag", action="store", type="string", dest="Flag",\r
-        help="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. "\\r
-             "This option can also be specified by setting *_*_*_BUILD_FLAGS in [BuildOptions] section of platform DSC. If they are both specified, this value "\\r
-             "will override the setting in [BuildOptions] section of platform DSC.")\r
-    Parser.add_option("-N", "--no-cache", action="store_true", dest="DisableCache", default=False, help="Disable build cache mechanism")\r
-    Parser.add_option("--conf", action="store", type="string", dest="ConfDirectory", help="Specify the customized Conf directory.")\r
-    Parser.add_option("--check-usage", action="store_true", dest="CheckUsage", default=False, help="Check usage content of entries listed in INF file.")\r
-    Parser.add_option("--ignore-sources", action="store_true", dest="IgnoreSources", default=False, help="Focus to a binary build and ignore all source files")\r
-    Parser.add_option("--pcd", action="append", dest="OptionPcd", help="Set PCD value by command line. Format: \"PcdName=Value\" ")\r
-    Parser.add_option("-l", "--cmd-len", action="store", type="int", dest="CommandLength", help="Specify the maximum line length of build command. Default is 4096.")\r
-    Parser.add_option("--hash", action="store_true", dest="UseHashCache", default=False, help="Enable hash-based caching during build process.")\r
-    Parser.add_option("--binary-destination", action="store", type="string", dest="BinCacheDest", help="Generate a cache of binary files in the specified directory.")\r
-    Parser.add_option("--binary-source", action="store", type="string", dest="BinCacheSource", help="Consume a cache of binary files from the specified directory.")\r
-    Parser.add_option("--genfds-multi-thread", action="store_true", dest="GenfdsMultiThread", default=True, help="Enable GenFds multi thread to generate ffs file.")\r
-    Parser.add_option("--no-genfds-multi-thread", action="store_true", dest="NoGenfdsMultiThread", default=False, help="Disable GenFds multi thread to generate ffs file.")\r
-    Parser.add_option("--disable-include-path-check", action="store_true", dest="DisableIncludePathCheck", default=False, help="Disable the include path check for outside of package.")\r
-    (Opt, Args) = Parser.parse_args()\r
-    return (Opt, Args)\r
-\r
-BuildOption, BuildTarget = MyOptionParser()\r
index d8bc28e4d0f8ed4b85a07980dc76cd39a2cc14e5..d5511f4c40e57172b289dfffd05957658d487ce0 100644 (file)
@@ -20,7 +20,7 @@ from linecache import getlines
 from io import BytesIO\r
 \r
 import Common.LongFilePathOs as os\r
-from Common.TargetTxtClassObject import TargetTxt\r
+from Common.TargetTxtClassObject import TargetTxtDict\r
 from Common.DataType import *\r
 import Common.GlobalData as GlobalData\r
 from Common import EdkLogger\r
@@ -210,6 +210,8 @@ def GenFdsApi(FdsCommandDict, WorkSpaceDataBase=None):
         BuildConfigurationFile = os.path.normpath(os.path.join(ConfDirectoryPath, "target.txt"))\r
         if os.path.isfile(BuildConfigurationFile) == True:\r
             # if no build target given in command line, get it from target.txt\r
+            TargetObj = TargetTxtDict()\r
+            TargetTxt = TargetObj.Target\r
             if not GenFdsGlobalVariable.TargetName:\r
                 BuildTargetList = TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_TARGET]\r
                 if len(BuildTargetList) != 1:\r
index 6e1ff7fe04b644f245d856f3c5076003112678d4..dc1727c4666db66e9621f311f96dab4c7b1a8e19 100644 (file)
@@ -23,9 +23,9 @@ from Common.BuildToolError import COMMAND_FAILURE,GENFDS_ERROR
 from Common import EdkLogger\r
 from Common.Misc import SaveFileOnChange\r
 \r
-from Common.TargetTxtClassObject import TargetTxt\r
-from Common.ToolDefClassObject import ToolDef\r
-from AutoGen.BuildEngine import BuildRuleObj\r
+from Common.TargetTxtClassObject import TargetTxtDict\r
+from Common.ToolDefClassObject import ToolDefDict\r
+from AutoGen.BuildEngine import ToolBuildRule\r
 import Common.DataType as DataType\r
 from Common.Misc import PathClass\r
 from Common.LongFilePathSupport import OpenLongFilePath as open\r
@@ -96,12 +96,15 @@ class GenFdsGlobalVariable:
     def _LoadBuildRule():\r
         if GenFdsGlobalVariable.__BuildRuleDatabase:\r
             return GenFdsGlobalVariable.__BuildRuleDatabase\r
-        GenFdsGlobalVariable.__BuildRuleDatabase = BuildRuleObj\r
-        ToolDefinitionFile = TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF]\r
+        BuildRule = ToolBuildRule()\r
+        GenFdsGlobalVariable.__BuildRuleDatabase = BuildRule.ToolBuildRule\r
+        TargetObj = TargetTxtDict()\r
+        ToolDefinitionFile = TargetObj.Target.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF]\r
         if ToolDefinitionFile == '':\r
             ToolDefinitionFile = "Conf/tools_def.txt"\r
         if os.path.isfile(ToolDefinitionFile):\r
-            ToolDefinition = ToolDef.ToolsDefTxtDatabase\r
+            ToolDefObj = ToolDefDict((os.path.join(os.getenv("WORKSPACE"), "Conf")))\r
+            ToolDefinition = ToolDefObj.ToolDef.ToolsDefTxtDatabase\r
             if DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY in ToolDefinition \\r
                and GenFdsGlobalVariable.ToolChainTag in ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY] \\r
                and ToolDefinition[DataType.TAB_TOD_DEFINES_BUILDRULEFAMILY][GenFdsGlobalVariable.ToolChainTag]:\r
@@ -830,6 +833,8 @@ class GenFdsGlobalVariable:
 #  @param  NameGuid         The Guid name\r
 #\r
 def FindExtendTool(KeyStringList, CurrentArchList, NameGuid):\r
+    ToolDefObj = ToolDefDict((os.path.join(os.getenv("WORKSPACE"), "Conf")))\r
+    ToolDef = ToolDefObj.ToolDef\r
     ToolDb = ToolDef.ToolsDefTxtDatabase\r
     # if user not specify filter, try to deduce it from global data.\r
     if KeyStringList is None or KeyStringList == []:\r
index 03a15bbf3e16d5033559374d5c88f270f72a3fef..c65a0dd346e4547b63c5c417f1ab0d4151fca600 100644 (file)
@@ -19,8 +19,8 @@ from Common.Misc import *
 from types import *\r
 from Common.Expression import *\r
 from CommonDataClass.CommonClass import SkuInfoClass\r
-from Common.TargetTxtClassObject import TargetTxt\r
-from Common.ToolDefClassObject import ToolDef\r
+from Common.TargetTxtClassObject import TargetTxtDict\r
+from Common.ToolDefClassObject import ToolDefDict\r
 from .MetaDataTable import *\r
 from .MetaFileTable import *\r
 from .MetaFileParser import *\r
@@ -3296,6 +3296,8 @@ class DscBuildData(PlatformBuildClassObject):
     @property\r
     def ToolChainFamily(self):\r
         self._ToolChainFamily = TAB_COMPILER_MSFT\r
+        TargetObj = TargetTxtDict()\r
+        TargetTxt = TargetObj.Target\r
         BuildConfigurationFile = os.path.normpath(os.path.join(GlobalData.gConfDirectory, "target.txt"))\r
         if os.path.isfile(BuildConfigurationFile) == True:\r
             ToolDefinitionFile = TargetTxt.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF]\r
@@ -3303,7 +3305,8 @@ class DscBuildData(PlatformBuildClassObject):
                 ToolDefinitionFile = "tools_def.txt"\r
                 ToolDefinitionFile = os.path.normpath(mws.join(self.WorkspaceDir, 'Conf', ToolDefinitionFile))\r
             if os.path.isfile(ToolDefinitionFile) == True:\r
-                ToolDefinition = ToolDef.ToolsDefTxtDatabase\r
+                ToolDefObj = ToolDefDict((os.path.join(os.getenv("WORKSPACE"), "Conf")))\r
+                ToolDefinition = ToolDefObj.ToolDef.ToolsDefTxtDatabase\r
                 if TAB_TOD_DEFINES_FAMILY not in ToolDefinition \\r
                    or self._Toolchain not in ToolDefinition[TAB_TOD_DEFINES_FAMILY] \\r
                    or not ToolDefinition[TAB_TOD_DEFINES_FAMILY][self._Toolchain]:\r
index 3cc4220e2ff85e88a99287a5a32c37e44113140d..34acdccbdbd00a3d10f9c6c42004f59a96ff0063 100755 (executable)
@@ -26,7 +26,7 @@ from threading import Thread,Event,BoundedSemaphore
 import threading\r
 from subprocess import Popen,PIPE, STDOUT\r
 from collections import OrderedDict, defaultdict\r
-from Common.buildoptions import BuildOption,BuildTarget\r
+\r
 from AutoGen.PlatformAutoGen import PlatformAutoGen\r
 from AutoGen.ModuleAutoGen import ModuleAutoGen\r
 from AutoGen.WorkspaceAutoGen import WorkspaceAutoGen\r
@@ -35,8 +35,9 @@ from AutoGen.AutoGenWorker import AutoGenWorkerInProcess,AutoGenManager,\
 from AutoGen import GenMake\r
 from Common import Misc as Utils\r
 \r
-from Common.TargetTxtClassObject import TargetTxt\r
-from Common.ToolDefClassObject import ToolDef\r
+from Common.TargetTxtClassObject import TargetTxtDict\r
+from Common.ToolDefClassObject import ToolDefDict\r
+from buildoptions import MyOptionParser\r
 from Common.Misc import PathClass,SaveFileOnChange,RemoveDirectory\r
 from Common.StringUtils import NormPath\r
 from Common.MultipleWorkspace import MultipleWorkspace as mws\r
@@ -731,11 +732,13 @@ class Build():
         self.ConfDirectory = BuildOptions.ConfDirectory\r
         self.SpawnMode      = True\r
         self.BuildReport    = BuildReport(BuildOptions.ReportFile, BuildOptions.ReportType)\r
-        self.TargetTxt      = TargetTxt\r
-        self.ToolDef        = ToolDef\r
         self.AutoGenTime    = 0\r
         self.MakeTime       = 0\r
         self.GenFdsTime     = 0\r
+        TargetObj = TargetTxtDict()\r
+        ToolDefObj = ToolDefDict((os.path.join(os.getenv("WORKSPACE"),"Conf")))\r
+        self.TargetTxt = TargetObj.Target\r
+        self.ToolDef = ToolDefObj.ToolDef\r
         GlobalData.BuildOptionPcd     = BuildOptions.OptionPcd if BuildOptions.OptionPcd else []\r
         #Set global flag for build mode\r
         GlobalData.gIgnoreSource = BuildOptions.IgnoreSources\r
@@ -816,8 +819,10 @@ class Build():
             EdkLogger.quiet("%-16s = %s" % ("POSTBUILD", self.Postbuild))\r
         if self.Prebuild:\r
             self.LaunchPrebuild()\r
-            self.TargetTxt = TargetTxt\r
-            self.ToolDef   = ToolDef\r
+            TargetObj = TargetTxtDict()\r
+            ToolDefObj = ToolDefDict((os.path.join(os.getenv("WORKSPACE"), "Conf")))\r
+            self.TargetTxt = TargetObj.Target\r
+            self.ToolDef = ToolDefObj.ToolDef\r
         if not (self.LaunchPrebuildFlag and os.path.exists(self.PlatformBuildPath)):\r
             self.InitBuild()\r
 \r
@@ -2438,9 +2443,15 @@ def LogBuildTime(Time):
     else:\r
         return None\r
 def ThreadNum():\r
+    OptionParser = MyOptionParser()\r
+    if not OptionParser.BuildOption and not OptionParser.BuildTarget:\r
+        OptionParser.GetOption()\r
+    BuildOption, BuildTarget = OptionParser.BuildOption, OptionParser.BuildTarget\r
     ThreadNumber = BuildOption.ThreadNumber\r
+    GlobalData.gCmdConfDir = BuildOption.ConfDirectory\r
     if ThreadNumber is None:\r
-        ThreadNumber = TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER]\r
+        TargetObj = TargetTxtDict()\r
+        ThreadNumber = TargetObj.Target.TargetTxtDictionary[TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER]\r
         if ThreadNumber == '':\r
             ThreadNumber = 0\r
         else:\r
@@ -2475,7 +2486,10 @@ def Main():
     #\r
     # Parse the options and args\r
     #\r
-    Option, Target = BuildOption, BuildTarget\r
+    OptionParser = MyOptionParser()\r
+    if not OptionParser.BuildOption and not OptionParser.BuildTarget:\r
+        OptionParser.GetOption()\r
+    Option, Target = OptionParser.BuildOption, OptionParser.BuildTarget\r
     GlobalData.gOptions = Option\r
     GlobalData.gCaseInsensitive = Option.CaseInsensitive\r
 \r
diff --git a/BaseTools/Source/Python/build/buildoptions.py b/BaseTools/Source/Python/build/buildoptions.py
new file mode 100644 (file)
index 0000000..61ab2db
--- /dev/null
@@ -0,0 +1,105 @@
+## @file\r
+# build a platform or a module\r
+#\r
+#  Copyright (c) 2014, Hewlett-Packard Development Company, L.P.<BR>\r
+#  Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2018, Hewlett Packard Enterprise Development, L.P.<BR>\r
+#\r
+#  SPDX-License-Identifier: BSD-2-Clause-Patent\r
+#\r
+\r
+# Version and Copyright\r
+from Common.BuildVersion import gBUILD_VERSION\r
+from optparse import OptionParser\r
+VersionNumber = "0.60" + ' ' + gBUILD_VERSION\r
+__version__ = "%prog Version " + VersionNumber\r
+__copyright__ = "Copyright (c) 2007 - 2018, Intel Corporation  All rights reserved."\r
+\r
+gParamCheck = []\r
+def SingleCheckCallback(option, opt_str, value, parser):\r
+    if option not in gParamCheck:\r
+        setattr(parser.values, option.dest, value)\r
+        gParamCheck.append(option)\r
+    else:\r
+        parser.error("Option %s only allows one instance in command line!" % option)\r
+\r
+\r
+class MyOptionParser():\r
+\r
+    def __new__(cls, *args, **kw):\r
+        if not hasattr(cls, '_instance'):\r
+            orig = super(MyOptionParser, cls)\r
+            cls._instance = orig.__new__(cls, *args, **kw)\r
+        return cls._instance\r
+\r
+    def __init__(self):\r
+        if not hasattr(self, 'BuildOption'):\r
+            self.BuildOption = None\r
+        if not hasattr(self, 'BuildTarget'):\r
+            self.BuildTarget = None\r
+\r
+    def GetOption(self):\r
+        Parser = OptionParser(description=__copyright__, version=__version__, prog="build.exe", usage="%prog [options] [all|fds|genc|genmake|clean|cleanall|cleanlib|modules|libraries|run]")\r
+        Parser.add_option("-a", "--arch", action="append", type="choice", choices=['IA32', 'X64', 'EBC', 'ARM', 'AARCH64'], dest="TargetArch",\r
+            help="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.")\r
+        Parser.add_option("-p", "--platform", action="callback", type="string", dest="PlatformFile", callback=SingleCheckCallback,\r
+            help="Build the platform specified by the DSC file name argument, overriding target.txt's ACTIVE_PLATFORM definition.")\r
+        Parser.add_option("-m", "--module", action="callback", type="string", dest="ModuleFile", callback=SingleCheckCallback,\r
+            help="Build the module specified by the INF file name argument.")\r
+        Parser.add_option("-b", "--buildtarget", type="string", dest="BuildTarget", help="Using the TARGET to build the platform, overriding target.txt's TARGET definition.",\r
+                          action="append")\r
+        Parser.add_option("-t", "--tagname", action="append", type="string", dest="ToolChain",\r
+            help="Using the Tool Chain Tagname to build the platform, overriding target.txt's TOOL_CHAIN_TAG definition.")\r
+        Parser.add_option("-x", "--sku-id", action="callback", type="string", dest="SkuId", callback=SingleCheckCallback,\r
+            help="Using this name of SKU ID to build the platform, overriding SKUID_IDENTIFIER in DSC file.")\r
+\r
+        Parser.add_option("-n", action="callback", type="int", dest="ThreadNumber", callback=SingleCheckCallback,\r
+            help="Build the platform using multi-threaded compiler. The value overrides target.txt's MAX_CONCURRENT_THREAD_NUMBER. When value is set to 0, tool automatically detect number of "\\r
+                 "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.")\r
+\r
+        Parser.add_option("-f", "--fdf", action="callback", type="string", dest="FdfFile", callback=SingleCheckCallback,\r
+            help="The name of the FDF file to use, which overrides the setting in the DSC file.")\r
+        Parser.add_option("-r", "--rom-image", action="append", type="string", dest="RomImage", default=[],\r
+            help="The name of FD to be generated. The name must be from [FD] section in FDF file.")\r
+        Parser.add_option("-i", "--fv-image", action="append", type="string", dest="FvImage", default=[],\r
+            help="The name of FV to be generated. The name must be from [FV] section in FDF file.")\r
+        Parser.add_option("-C", "--capsule-image", action="append", type="string", dest="CapName", default=[],\r
+            help="The name of Capsule to be generated. The name must be from [Capsule] section in FDF file.")\r
+        Parser.add_option("-u", "--skip-autogen", action="store_true", dest="SkipAutoGen", help="Skip AutoGen step.")\r
+        Parser.add_option("-e", "--re-parse", action="store_true", dest="Reparse", help="Re-parse all meta-data files.")\r
+\r
+        Parser.add_option("-c", "--case-insensitive", action="store_true", dest="CaseInsensitive", default=False, help="Don't check case of file name.")\r
+\r
+        Parser.add_option("-w", "--warning-as-error", action="store_true", dest="WarningAsError", help="Treat warning in tools as error.")\r
+        Parser.add_option("-j", "--log", action="store", dest="LogFile", help="Put log in specified file as well as on console.")\r
+\r
+        Parser.add_option("-s", "--silent", action="store_true", type=None, dest="SilentMode",\r
+            help="Make use of silent mode of (n)make.")\r
+        Parser.add_option("-q", "--quiet", action="store_true", type=None, help="Disable all messages except FATAL ERRORS.")\r
+        Parser.add_option("-v", "--verbose", action="store_true", type=None, help="Turn on verbose output with informational messages printed, "\\r
+                                                                                   "including library instances selected, final dependency expression, "\\r
+                                                                                   "and warning messages, etc.")\r
+        Parser.add_option("-d", "--debug", action="store", type="int", help="Enable debug messages at specified level.")\r
+        Parser.add_option("-D", "--define", action="append", type="string", dest="Macros", help="Macro: \"Name [= Value]\".")\r
+\r
+        Parser.add_option("-y", "--report-file", action="store", dest="ReportFile", help="Create/overwrite the report to the specified filename.")\r
+        Parser.add_option("-Y", "--report-type", action="append", type="choice", choices=['PCD', 'LIBRARY', 'FLASH', 'DEPEX', 'BUILD_FLAGS', 'FIXED_ADDRESS', 'HASH', 'EXECUTION_ORDER'], dest="ReportType", default=[],\r
+            help="Flags that control the type of build report to generate.  Must be one of: [PCD, LIBRARY, FLASH, DEPEX, BUILD_FLAGS, FIXED_ADDRESS, HASH, EXECUTION_ORDER].  "\\r
+                 "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]")\r
+        Parser.add_option("-F", "--flag", action="store", type="string", dest="Flag",\r
+            help="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. "\\r
+                 "This option can also be specified by setting *_*_*_BUILD_FLAGS in [BuildOptions] section of platform DSC. If they are both specified, this value "\\r
+                 "will override the setting in [BuildOptions] section of platform DSC.")\r
+        Parser.add_option("-N", "--no-cache", action="store_true", dest="DisableCache", default=False, help="Disable build cache mechanism")\r
+        Parser.add_option("--conf", action="store", type="string", dest="ConfDirectory", help="Specify the customized Conf directory.")\r
+        Parser.add_option("--check-usage", action="store_true", dest="CheckUsage", default=False, help="Check usage content of entries listed in INF file.")\r
+        Parser.add_option("--ignore-sources", action="store_true", dest="IgnoreSources", default=False, help="Focus to a binary build and ignore all source files")\r
+        Parser.add_option("--pcd", action="append", dest="OptionPcd", help="Set PCD value by command line. Format: \"PcdName=Value\" ")\r
+        Parser.add_option("-l", "--cmd-len", action="store", type="int", dest="CommandLength", help="Specify the maximum line length of build command. Default is 4096.")\r
+        Parser.add_option("--hash", action="store_true", dest="UseHashCache", default=False, help="Enable hash-based caching during build process.")\r
+        Parser.add_option("--binary-destination", action="store", type="string", dest="BinCacheDest", help="Generate a cache of binary files in the specified directory.")\r
+        Parser.add_option("--binary-source", action="store", type="string", dest="BinCacheSource", help="Consume a cache of binary files from the specified directory.")\r
+        Parser.add_option("--genfds-multi-thread", action="store_true", dest="GenfdsMultiThread", default=True, help="Enable GenFds multi thread to generate ffs file.")\r
+        Parser.add_option("--no-genfds-multi-thread", action="store_true", dest="NoGenfdsMultiThread", default=False, help="Disable GenFds multi thread to generate ffs file.")\r
+        Parser.add_option("--disable-include-path-check", action="store_true", dest="DisableIncludePathCheck", default=False, help="Disable the include path check for outside of package.")\r
+        self.BuildOption, self.BuildTarget = Parser.parse_args()\r