]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Common/ToolDefClassObject.py
BaseTools: use set instead of list for a variable to be used with in
[mirror_edk2.git] / BaseTools / Source / Python / Common / ToolDefClassObject.py
index 753878a369f0711b6e80432116fbd3cce362c277..73ebdaf6b1793646fffcfc3fe06e1835c510fe99 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # This file is used to define each component of tools_def.txt file\r
 #\r
-# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2007 - 2018, 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
@@ -18,7 +18,6 @@ import Common.LongFilePathOs as os
 import re\r
 import EdkLogger\r
 \r
-from Dictionary import *\r
 from BuildToolError import *\r
 from TargetTxtClassObject import *\r
 from Common.LongFilePathSupport import OpenLongFilePath as open\r
@@ -27,6 +26,10 @@ from Common.String import NormPath
 import Common.GlobalData as GlobalData\r
 from Common import GlobalData\r
 from Common.MultipleWorkspace import MultipleWorkspace as mws\r
+from DataType import TAB_TOD_DEFINES_TARGET,TAB_TOD_DEFINES_TOOL_CHAIN_TAG,\\r
+                     TAB_TOD_DEFINES_TARGET_ARCH,TAB_TOD_DEFINES_COMMAND_TYPE\\r
+                     ,TAB_TOD_DEFINES_FAMILY,TAB_TOD_DEFINES_BUILDRULEFAMILY\r
+\r
 \r
 ##\r
 # Static variables used for pattern\r
@@ -53,7 +56,7 @@ class ToolDefClassObject(object):
         for Env in os.environ:\r
             self.MacroDictionary["ENV(%s)" % Env] = os.environ[Env]\r
 \r
-        if FileName != None:\r
+        if FileName is not None:\r
             self.LoadToolDefFile(FileName)\r
 \r
     ## LoadToolDefFile\r
@@ -76,6 +79,32 @@ class ToolDefClassObject(object):
 \r
         self.IncludeToolDefFile(FileName)\r
 \r
+        self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET] = list(set(self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET]))\r
+        self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TOOL_CHAIN_TAG] = list(set(self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TOOL_CHAIN_TAG]))\r
+        self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET_ARCH] = list(set(self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET_ARCH]))\r
+\r
+        self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_COMMAND_TYPE] = list(set(self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_COMMAND_TYPE]))\r
+\r
+        self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET].sort()\r
+        self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TOOL_CHAIN_TAG].sort()\r
+        self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET_ARCH].sort()\r
+        self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_COMMAND_TYPE].sort()\r
+\r
+        KeyList = [TAB_TOD_DEFINES_TARGET, TAB_TOD_DEFINES_TOOL_CHAIN_TAG, TAB_TOD_DEFINES_TARGET_ARCH, TAB_TOD_DEFINES_COMMAND_TYPE]\r
+        for Index in range(3, -1, -1):\r
+            for Key in dict(self.ToolsDefTxtDictionary):\r
+                List = Key.split('_')\r
+                if List[Index] == '*':\r
+                    for String in self.ToolsDefTxtDatabase[KeyList[Index]]:\r
+                        List[Index] = String\r
+                        NewKey = '%s_%s_%s_%s_%s' % tuple(List)\r
+                        if NewKey not in self.ToolsDefTxtDictionary:\r
+                            self.ToolsDefTxtDictionary[NewKey] = self.ToolsDefTxtDictionary[Key]\r
+                        continue\r
+                    del self.ToolsDefTxtDictionary[Key]\r
+                elif List[Index] not in self.ToolsDefTxtDatabase[KeyList[Index]]:\r
+                    del self.ToolsDefTxtDictionary[Key]\r
+\r
 \r
     ## IncludeToolDefFile\r
     #\r
@@ -201,31 +230,6 @@ class ToolDefClassObject(object):
                         EdkLogger.verbose("Line %d: The family is not specified, but BuildRuleFamily is specified for the tool chain: %s" % ((Index + 1), Name))\r
                     self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_BUILDRULEFAMILY][List[1]] = Value\r
 \r
-        self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET] = list(set(self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET]))\r
-        self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TOOL_CHAIN_TAG] = list(set(self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TOOL_CHAIN_TAG]))\r
-        self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET_ARCH] = list(set(self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET_ARCH]))\r
-        self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_COMMAND_TYPE] = list(set(self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_COMMAND_TYPE]))\r
-\r
-        self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET].sort()\r
-        self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TOOL_CHAIN_TAG].sort()\r
-        self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_TARGET_ARCH].sort()\r
-        self.ToolsDefTxtDatabase[TAB_TOD_DEFINES_COMMAND_TYPE].sort()\r
-\r
-        KeyList = [TAB_TOD_DEFINES_TARGET, TAB_TOD_DEFINES_TOOL_CHAIN_TAG, TAB_TOD_DEFINES_TARGET_ARCH, TAB_TOD_DEFINES_COMMAND_TYPE]\r
-        for Index in range(3, -1, -1):\r
-            for Key in dict(self.ToolsDefTxtDictionary):\r
-                List = Key.split('_')\r
-                if List[Index] == '*':\r
-                    for String in self.ToolsDefTxtDatabase[KeyList[Index]]:\r
-                        List[Index] = String\r
-                        NewKey = '%s_%s_%s_%s_%s' % tuple(List)\r
-                        if NewKey not in self.ToolsDefTxtDictionary:\r
-                            self.ToolsDefTxtDictionary[NewKey] = self.ToolsDefTxtDictionary[Key]\r
-                        continue\r
-                    del self.ToolsDefTxtDictionary[Key]\r
-                elif List[Index] not in self.ToolsDefTxtDatabase[KeyList[Index]]:\r
-                    del self.ToolsDefTxtDictionary[Key]\r
-\r
     ## ExpandMacros\r
     #\r
     # Replace defined macros with real value\r
@@ -235,14 +239,16 @@ class ToolDefClassObject(object):
     # @retval Value:  The string which has been replaced with real value\r
     #\r
     def ExpandMacros(self, Value):\r
+        # os.environ contains all environment variables uppercase on Windows which cause the key in the self.MacroDictionary is uppercase, but Ref may not\r
         EnvReference = gEnvRefPattern.findall(Value)\r
         for Ref in EnvReference:\r
-            if Ref not in self.MacroDictionary:\r
+            if Ref not in self.MacroDictionary and Ref.upper() not in self.MacroDictionary:\r
                 Value = Value.replace(Ref, "")\r
             else:\r
-                Value = Value.replace(Ref, self.MacroDictionary[Ref])\r
\r
-\r
+                if Ref in self.MacroDictionary:\r
+                    Value = Value.replace(Ref, self.MacroDictionary[Ref])\r
+                else:\r
+                    Value = Value.replace(Ref, self.MacroDictionary[Ref.upper()])\r
         MacroReference = gMacroRefPattern.findall(Value)\r
         for Ref in MacroReference:\r
             if Ref not in self.MacroDictionary:\r