BaseTools/Source/Python/Common/ToolDefClassObject.py:
authorjljusten <jljusten@7335b38e-4728-0410-8992-fb3ffe349368>
Thu, 11 Oct 2007 23:24:32 +0000 (23:24 +0000)
committerjljusten <jljusten@7335b38e-4728-0410-8992-fb3ffe349368>
Thu, 11 Oct 2007 23:24:32 +0000 (23:24 +0000)
  Allow 'DEFINE' macros to use previously defined macros.  For example:
    DEFINE A = foo
    DEFINE B = DEF(A)bar
  will make B equal foobar.

git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@819 7335b38e-4728-0410-8992-fb3ffe349368

Source/Python/Common/ToolDefClassObject.py

index 1d8fa91..592e276 100755 (executable)
@@ -77,18 +77,14 @@ class ToolDefClassObject(object):
                                         File=FileName, Line=Index+1)\r
                     Value = Value.replace(Ref, self.MacroDictionary[Ref])\r
 \r
+                Value = self.ExpandMacros(Value)\r
+\r
                 MacroName = MacroDefinition[0].strip()\r
                 self.MacroDictionary["DEF(%s)" % MacroName] = Value\r
                 EdkLogger.debug(EdkLogger.DEBUG_9, "Line %d: Found macro: %s = %s" % ((Index + 1), MacroName, Value))\r
                 continue\r
 \r
-            MacroReference = gMacroRefPattern.findall(Value)\r
-            for Ref in MacroReference:\r
-                if Ref not in self.MacroDictionary:\r
-                    EdkLogger.error("tools_def.txt parser", PARSER_ERROR,\r
-                                    "Macro [%s] has not been defined" % Ref,\r
-                                    File=FileName, Line=Index+1)\r
-                Value = Value.replace(Ref, self.MacroDictionary[Ref])\r
+            Value = self.ExpandMacros(Value)\r
 \r
             List = Name.split('_')\r
             if len(List) != 5:\r
@@ -133,6 +129,18 @@ class ToolDefClassObject(object):
                 elif List[Index] not in self.ToolsDefTxtDatabase[KeyList[Index]]:\r
                     del self.ToolsDefTxtDictionary[Key]\r
 \r
+    def ExpandMacros(self, Value):\r
+\r
+        MacroReference = gMacroRefPattern.findall(Value)\r
+        for Ref in MacroReference:\r
+            if Ref not in self.MacroDictionary:\r
+                EdkLogger.error("tools_def.txt parser", PARSER_ERROR,\r
+                                "Macro [%s] has not been defined" % Ref,\r
+                                File=FileName, Line=Index+1)\r
+            Value = Value.replace(Ref, self.MacroDictionary[Ref])\r
+\r
+        return Value\r
+\r
 def ToolDefDict(WorkSpace):\r
     Target = TargetTxtClassObject()\r
     Target.LoadTargetTxtFile(WorkSpace + '\\Conf\\target.txt')\r