]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Common/TargetTxtClassObject.py
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / BaseTools / Source / Python / Common / TargetTxtClassObject.py
index f8459c892e365845e2cd0d32706b27cfa84a276f..363c38302b8e0b91d34e635661b8eda493be539f 100644 (file)
@@ -2,24 +2,23 @@
 # This file is used to define each component of Target.txt file\r
 #\r
 # Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
-# This program and the accompanying materials\r
-# are licensed and made available under the terms and conditions of the BSD License\r
-# which accompanies this distribution.  The full text of the license may be found at\r
-# http://opensource.org/licenses/bsd-license.php\r
-#\r
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
 #\r
 \r
 ##\r
 # Import Modules\r
 #\r
+from __future__ import print_function\r
+from __future__ import absolute_import\r
+\r
+import Common.GlobalData as GlobalData\r
 import Common.LongFilePathOs as os\r
-import EdkLogger\r
-import DataType\r
-from BuildToolError import *\r
-import GlobalData\r
+from . import EdkLogger\r
+from . import DataType\r
+from .BuildToolError import *\r
+\r
 from Common.LongFilePathSupport import OpenLongFilePath as open\r
+from Common.MultipleWorkspace import MultipleWorkspace as mws\r
 \r
 gDefaultTargetTxtFile = "target.txt"\r
 \r
@@ -145,10 +144,47 @@ class TargetTxtClassObject(object):
 #\r
 # @retval Target An instance of TargetTxtClassObject() with loaded target.txt\r
 #\r
-def TargetTxtDict(ConfDir):\r
-    Target = TargetTxtClassObject()\r
-    Target.LoadTargetTxtFile(os.path.normpath(os.path.join(ConfDir, gDefaultTargetTxtFile)))\r
-    return Target\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
+            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
@@ -158,6 +194,6 @@ def TargetTxtDict(ConfDir):
 if __name__ == '__main__':\r
     pass\r
     Target = TargetTxtDict(os.getenv("WORKSPACE"))\r
-    print Target.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER]\r
-    print Target.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TARGET]\r
-    print Target.TargetTxtDictionary\r
+    print(Target.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER])\r
+    print(Target.TargetTxtDictionary[DataType.TAB_TAT_DEFINES_TARGET])\r
+    print(Target.TargetTxtDictionary)\r