conditional statement support initial check-in.
authorjlin16 <jlin16@7335b38e-4728-0410-8992-fb3ffe349368>
Fri, 11 Jan 2008 03:19:27 +0000 (03:19 +0000)
committerjlin16 <jlin16@7335b38e-4728-0410-8992-fb3ffe349368>
Fri, 11 Jan 2008 03:19:27 +0000 (03:19 +0000)
git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@944 7335b38e-4728-0410-8992-fb3ffe349368

Source/Python/GenFds/FdfParser.py
Source/Python/GenFds/GenFds.py

index 2d7a59e..00c6355 100644 (file)
@@ -36,7 +36,7 @@ import RuleSimpleFile
 import EfiSection\r
 import Vtf\r
 import ComponentStatement\r
-import GenFdsGlobalVariable\r
+#import GenFdsGlobalVariable\r
 \r
 import re\r
 import os\r
@@ -60,6 +60,21 @@ T_CHAR_BACKSLASH, T_CHAR_DOUBLE_QUOTE, T_CHAR_SINGLE_QUOTE, T_CHAR_STAR, T_CHAR_
 SEPERATOR_TUPLE = ('=', '|', ',', '{', '}') \r
 \r
 IncludeFileList = []\r
+# Macro passed from command line, which has greatest priority and can NOT be overridden by those in FDF\r
+InputMacroDict = {}\r
+# All Macro values when parsing file, not replace existing Macro\r
+AllMacroList = []\r
+\r
+def GetRealFileLine (File, Line):\r
+    \r
+    InsertedLines = 0\r
+    for Profile in IncludeFileList:\r
+        if Line >= Profile.InsertStartLineNumber and Line < Profile.InsertStartLineNumber + Profile.InsertAdjust + len(Profile.FileLinesList):\r
+            return (Profile.FileName, Line - Profile.InsertStartLineNumber + 1)\r
+        if Line >= Profile.InsertStartLineNumber + Profile.InsertAdjust + len(Profile.FileLinesList):\r
+            InsertedLines += Profile.InsertAdjust + len(Profile.FileLinesList)\r
+    \r
+    return (File, Line - InsertedLines)\r
 \r
 ## The exception class that used to report error messages when parsing FDF\r
 #\r
@@ -75,22 +90,26 @@ class Warning (Exception):
     #\r
     def __init__(self, Str, File = None, Line = None):\r
         \r
-        FileLineTuple = self.GetRealFileLine(File, Line)\r
+        FileLineTuple = GetRealFileLine(File, Line)\r
         self.FileName = FileLineTuple[0]\r
         self.LineNumber = FileLineTuple[1]\r
         self.message = Str + str(self.LineNumber)\r
         self.ToolName = 'FDF Parser'\r
         \r
-    def GetRealFileLine (self, File, Line):\r
-        \r
-        InsertedLines = 0\r
-        for Profile in IncludeFileList:\r
-            if Line >= Profile.InsertStartLineNumber and Line < Profile.InsertStartLineNumber + Profile.InsertAdjust + len(Profile.FileLinesList):\r
-                return (Profile.FileName, Line - Profile.InsertStartLineNumber + 1)\r
-            if Line >= Profile.InsertStartLineNumber + Profile.InsertAdjust + len(Profile.FileLinesList):\r
-                InsertedLines += Profile.InsertAdjust + len(Profile.FileLinesList)\r
-        \r
-        return (File, Line - InsertedLines)\r
+## The MACRO class that used to record macro value data when parsing include file\r
+#\r
+#\r
+class MacroProfile :\r
+    ## The constructor\r
+    #\r
+    #   @param  self        The object pointer\r
+    #   @param  FileName    The file that to be parsed\r
+    #\r
+    def __init__(self, FileName, Line):\r
+        self.FileName = FileName        \r
+        self.DefinedAtLine  = Line\r
+        self.MacroName = None\r
+        self.MacroValue = None\r
 \r
 ## The Include file content class that used to record file data when parsing include file\r
 #\r
@@ -173,7 +192,7 @@ class FdfParser:
         self.__Token = ""\r
         self.__SkippedChars = ""\r
         \r
-        self.__InsertedFileDict = {}\r
+        self.__WipeOffArea = []\r
 \r
     ## __IsWhiteSpace() method\r
     #\r
@@ -328,6 +347,57 @@ class FdfParser:
     def __StringToList(self):\r
         self.Profile.FileLinesList = [list(s) for s in self.Profile.FileLinesList]\r
     \r
+    def __ReplaceMacros(self, Str, File, Line):\r
+        MacroEnd = 0\r
+        while Str.find('$(', MacroEnd) >= 0:\r
+            MacroStart = Str.find('$(', MacroEnd)\r
+            if Str.find(')', MacroStart) > 0:\r
+                MacroEnd = Str.find(')', MacroStart)\r
+                Name = Str[MacroStart + 2 : MacroEnd]\r
+                Value = None\r
+                if Name in InputMacroDict:\r
+                    Value = InputMacroDict[Name]\r
+                   \r
+                else:\r
+                    for Profile in AllMacroList:\r
+                        if Profile.FileName == File and Profile.MacroName == Name and Profile.DefinedAtLine <= Line:\r
+                            Value = Profile.MacroValue\r
+                            \r
+                if Value != None:\r
+                    Str = Str.replace('$(' + Name + ')', Value)\r
+                    MacroEnd = MacroStart + len(Value) \r
+                \r
+            else:\r
+                raise Warning("Macro not complete At Line ", self.FileName, self.CurrentLineNumber)\r
+        return Str\r
+    \r
+    def __ReplaceFragment(self, StartPos, EndPos, Value = ' '):\r
+        if StartPos[0] == EndPos[0]:\r
+            Offset = StartPos[1]\r
+            while Offset <= EndPos[1]:\r
+                self.Profile.FileLinesList[StartPos[0]][Offset] = Value\r
+                Offset += 1\r
+            return\r
+        \r
+        Offset = StartPos[1]\r
+        while self.Profile.FileLinesList[StartPos[0]][Offset] not in ('\r', '\n'):\r
+            self.Profile.FileLinesList[StartPos[0]][Offset] = Value\r
+            Offset += 1\r
+        \r
+        Line = StartPos[0]\r
+        while Line < EndPos[0]:\r
+            Offset = 0\r
+            while self.Profile.FileLinesList[Line][Offset] not in ('\r', '\n'):\r
+                self.Profile.FileLinesList[Line][Offset] = Value\r
+                Offset += 1\r
+            Line += 1\r
+            \r
+        Offset = 0\r
+        while Offset <= EndPos[1]:\r
+            self.Profile.FileLinesList[EndPos[0]][Offset] = Value\r
+            Offset += 1\r
+            \r
+    \r
     ## PreprocessFile() method\r
     #\r
     #   Preprocess file contents, replace comments with spaces.\r
@@ -458,6 +528,244 @@ class FdfParser:
                 \r
         self.Rewind()\r
 \r
+    ## PreprocessIncludeFile() method\r
+    #\r
+    #   Preprocess file contents, replace !include statements with file contents.\r
+    #   In the end, rewind the file buffer pointer to the beginning\r
+    #\r
+    #   @param  self        The object pointer\r
+    #   \r
+    def PreprocessConditionalStatement(self):\r
+        # IfList is a stack of if branches with elements of list [Pos, CondSatisfied, BranchDetermined]\r
+        IfList = []\r
+        while self.__GetNextToken():\r
+            if self.__Token == 'DEFINE':\r
+                DefineLine = self.CurrentLineNumber - 1\r
+                DefineOffset = self.CurrentOffsetWithinLine - len('DEFINE')\r
+                if not self.__GetNextToken():\r
+                    raise Warning("expected Macro name At Line ", self.FileName, self.CurrentLineNumber)\r
+                Macro = self.__Token\r
+                if not self.__IsToken( "="):\r
+                    raise Warning("expected '=' At Line ", self.FileName, self.CurrentLineNumber)\r
+                \r
+                if not self.__GetNextToken():\r
+                    raise Warning("expected value At Line ", self.FileName, self.CurrentLineNumber)\r
+                \r
+                if self.__GetStringData():\r
+                    pass\r
+                Value = self.__Token\r
+                if not Macro in InputMacroDict:\r
+                    FileLineTuple = GetRealFileLine(self.FileName, DefineLine + 1)\r
+                    MacProfile = MacroProfile(FileLineTuple[0], FileLineTuple[1])\r
+                    MacProfile.MacroName = Macro\r
+                    MacProfile.MacroValue = Value\r
+                    AllMacroList.append(MacProfile)\r
+                self.__WipeOffArea.append(((DefineLine, DefineOffset), (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - 1)))\r
+            \r
+            elif self.__Token in ('!ifdef', '!ifndef', '!if'):\r
+                IfStartPos = (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - len(self.__Token))\r
+                IfList.append([IfStartPos, None, None])\r
+                CondLabel = self.__Token\r
+                \r
+                if not self.__GetNextToken():\r
+                    raise Warning("expected Macro name At Line ", self.FileName, self.CurrentLineNumber)\r
+                MacroName = self.__Token\r
+                NotFlag = False\r
+                if MacroName.startswith('!'):\r
+                    NotFlag = True\r
+                        \r
+                NotDefineFlag = False\r
+                if CondLabel == '!ifndef':\r
+                    NotDefineFlag = True\r
+                if CondLabel == '!ifdef' or CondLabel == '!ifndef':\r
+                    if NotFlag:\r
+                        raise Warning("'NOT' operation not allowed for Macro name At Line ", self.FileName, self.CurrentLineNumber)\r
+                    \r
+                if CondLabel == '!if':\r
+                        \r
+                    if not self.__GetNextOp():\r
+                        raise Warning("expected !endif At Line ", self.FileName, self.CurrentLineNumber)\r
+                    \r
+                    if self.__Token in ('!=', '==', '>', '<', '>=', '<='):\r
+                        Op = self.__Token\r
+                        if not self.__GetNextToken():\r
+                            raise Warning("expected value At Line ", self.FileName, self.CurrentLineNumber)\r
+                        if self.__GetStringData():\r
+                            pass\r
+                        MacroValue = self.__Token\r
+                        ConditionSatisfied = self.__EvaluateConditional(MacroName, IfList[-1][0][0] + 1, Op, MacroValue)\r
+                        ConditionSatisfied = NotFlag and (not ConditionSatisfied) or ConditionSatisfied\r
+                        BranchDetermined = ConditionSatisfied and True or False\r
+                    else:\r
+                        self.CurrentOffsetWithinLine -= len(self.__Token)                        \r
+                        ConditionSatisfied = self.__EvaluateConditional(MacroName, IfList[-1][0][0] + 1, None, 'Bool')\r
+                        ConditionSatisfied = NotFlag and (not ConditionSatisfied) or ConditionSatisfied\r
+                        BranchDetermined = ConditionSatisfied and True or False\r
+                    IfList[-1] = [IfList[-1][0], ConditionSatisfied, BranchDetermined]\r
+                    if ConditionSatisfied:\r
+                        self.__WipeOffArea.append((IfList[-1][0], (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - 1)))\r
+                        \r
+                else:\r
+                    ConditionSatisfied = self.__EvaluateConditional(MacroName, IfList[-1][0][0] + 1)\r
+                    ConditionSatisfied = NotDefineFlag and (not ConditionSatisfied) or ConditionSatisfied\r
+                    BranchDetermined = ConditionSatisfied and True or False\r
+                    IfList[-1] = [IfList[-1][0], ConditionSatisfied, BranchDetermined]\r
+                    if ConditionSatisfied:\r
+                        self.__WipeOffArea.append((IfStartPos, (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - 1)))\r
+                    \r
+            elif self.__Token in ('!elseif', '!else'):\r
+                ElseStartPos = (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - len(self.__Token))\r
+                if len(IfList) <= 0:\r
+                    raise Warning("Missing !if statement At Line ", self.FileName, self.CurrentLineNumber)\r
+                if IfList[-1][1]:\r
+                    IfList[-1] = [ElseStartPos, False, True]\r
+                    self.__WipeOffArea.append((ElseStartPos, (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - 1)))\r
+                else:\r
+                    self.__WipeOffArea.append((IfList[-1][0], ElseStartPos))\r
+                    IfList[-1] = [ElseStartPos, True, IfList[-1][2]]\r
+                    if self.__Token == '!elseif':\r
+                        if not self.__GetNextToken():\r
+                            raise Warning("expected Macro name At Line ", self.FileName, self.CurrentLineNumber)\r
+                        MacroName = self.__Token\r
+                        NotFlag = False\r
+                        if MacroName.startswith('!'):\r
+                            NotFlag = True\r
+                        \r
+                        if not self.__GetNextOp():\r
+                            raise Warning("expected !endif At Line ", self.FileName, self.CurrentLineNumber)\r
+                    \r
+                        if self.__Token in ('!=', '==', '>', '<', '>=', '<='):\r
+                            Op = self.__Token\r
+                            if not self.__GetNextToken():\r
+                                raise Warning("expected value At Line ", self.FileName, self.CurrentLineNumber)\r
+                            if self.__GetStringData():\r
+                                pass\r
+                            MacroValue = self.__Token\r
+                            ConditionSatisfied = self.__EvaluateConditional(MacroName, IfList[-1][0][0] + 1, Op, MacroValue)\r
+                            ConditionSatisfied = NotFlag and (not ConditionSatisfied) or ConditionSatisfied\r
+                        \r
+                        else:\r
+                            self.CurrentOffsetWithinLine -= len(self.__Token)                        \r
+                            ConditionSatisfied = self.__EvaluateConditional(MacroName, IfList[-1][0][0] + 1, None, 'Bool')\r
+                            ConditionSatisfied = NotFlag and (not ConditionSatisfied) or ConditionSatisfied\r
+                            \r
+                        IfList[-1] = [IfList[-1][0], ConditionSatisfied, IfList[-1][2]]\r
+                    \r
+                    if IfList[-1][1]:\r
+                        if IfList[-1][2]:\r
+                            IfList[-1][1] = False\r
+                        else:\r
+                            IfList[-1][2] = True\r
+                            self.__WipeOffArea.append((IfList[-1][0], (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - 1)))\r
+\r
+                \r
+            elif self.__Token == '!endif':\r
+                if IfList[-1][1]:\r
+                    self.__WipeOffArea.append(((self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - len('!endif')), (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - 1)))\r
+                else:\r
+                    self.__WipeOffArea.append((IfList[-1][0], (self.CurrentLineNumber - 1, self.CurrentOffsetWithinLine - 1)))\r
+                \r
+                IfList.pop()\r
+                \r
+                    \r
+        if len(IfList) > 0:\r
+            raise Warning("Missing !endif At Line ", self.FileName, self.CurrentLineNumber)\r
+        self.Rewind()\r
+\r
+    def __EvaluateConditional(self, Name, Line, Op = None, Value = None):\r
+        \r
+        FileLineTuple = GetRealFileLine(self.FileName, Line)\r
+        if Name in InputMacroDict:\r
+            MacroValue = InputMacroDict[Name]\r
+            if Op == None:\r
+                if Value == 'Bool' and Profile.MacroValue == None or MacroValue.upper() == 'FALSE':\r
+                    return False\r
+                return True\r
+            elif Op == '!=':\r
+                if Value != MacroValue:\r
+                    return True\r
+                else:\r
+                    return False\r
+            elif Op == '==':\r
+                if Value == MacroValue:\r
+                    return True\r
+                else:\r
+                    return False\r
+            else:\r
+                if (self.__IsHex(Value) or Value.isdigit()) and (self.__IsHex(MacroValue) or (MacroValue != None and MacroValue.isdigit())):\r
+                    InputVal = long(Value, 0)\r
+                    MacroVal = long(MacroValue, 0)\r
+                    if Op == '>':\r
+                        if MacroVal > InputVal:\r
+                            return True\r
+                        else:\r
+                            return False\r
+                    elif Op == '>=':\r
+                        if MacroVal >= InputVal:\r
+                            return True\r
+                        else:\r
+                            return False\r
+                    elif Op == '<':\r
+                        if MacroVal < InputVal:\r
+                            return True\r
+                        else:\r
+                            return False\r
+                    elif Op == '<=':\r
+                        if MacroVal <= InputVal:\r
+                            return True\r
+                        else:\r
+                            return False\r
+                    else:\r
+                        return False\r
+                else:\r
+                    raise Warning("Value %s is not a number At Line ", self.FileName, Line)\r
+                \r
+        for Profile in AllMacroList:\r
+            if Profile.FileName == FileLineTuple[0] and Profile.MacroName == Name and Profile.DefinedAtLine <= FileLineTuple[1]:\r
+                if Op == None:\r
+                    if Value == 'Bool' and Profile.MacroValue == None or Profile.MacroValue.upper() == 'FALSE':\r
+                        return False\r
+                    return True\r
+                elif Op == '!=':\r
+                    if Value != Profile.MacroValue:\r
+                        return True\r
+                    else:\r
+                        return False\r
+                elif Op == '==':\r
+                    if Value == Profile.MacroValue:\r
+                        return True\r
+                    else:\r
+                        return False\r
+                else:\r
+                    if (self.__IsHex(Value) or Value.isdigit()) and (self.__IsHex(Profile.MacroValue) or (Profile.MacroValue != None and Profile.MacroValue.isdigit())):\r
+                        InputVal = long(Value, 0)\r
+                        MacroVal = long(Profile.MacroValue, 0)\r
+                        if Op == '>':\r
+                            if MacroVal > InputVal:\r
+                                return True\r
+                            else:\r
+                                return False\r
+                        elif Op == '>=':\r
+                            if MacroVal >= InputVal:\r
+                                return True\r
+                            else:\r
+                                return False\r
+                        elif Op == '<':\r
+                            if MacroVal < InputVal:\r
+                                return True\r
+                            else:\r
+                                return False\r
+                        elif Op == '<=':\r
+                            if MacroVal <= InputVal:\r
+                                return True\r
+                            else:\r
+                                return False\r
+                        else:\r
+                            return False\r
+                    else:\r
+                        raise Warning("Value %s is not a number At Line ", self.FileName, Line)\r
+        \r
+        return False\r
 \r
     ## __IsToken() method\r
     #\r
@@ -585,7 +893,29 @@ class FdfParser:
             return True\r
         else:\r
             return False\r
-\r
+    \r
+    def __GetNextOp(self):\r
+        # Skip leading spaces, if exist.\r
+        self.__SkipWhiteSpace()\r
+        if self.__EndOfFile():\r
+            return False\r
+        # Record the token start position, the position of the first non-space char.\r
+        StartPos = self.CurrentOffsetWithinLine\r
+        while not self.__EndOfLine():\r
+            TempChar = self.__CurrentChar()\r
+            # Try to find the end char that is not a space\r
+            if not str(TempChar).isspace():\r
+                self.__GetOneChar()\r
+            else:\r
+                break\r
+        else:\r
+            return False\r
+        \r
+        if StartPos != self.CurrentOffsetWithinLine:\r
+            self.__Token = self.__CurrentLine()[StartPos : self.CurrentOffsetWithinLine]\r
+            return True\r
+        else:\r
+            return False\r
     ## __GetNextGuid() method\r
     #\r
     #   Get next token unit before a seperator\r
@@ -654,7 +984,17 @@ class FdfParser:
                     return True\r
         else:\r
             return False\r
-        \r
+    \r
+    def __IsHex(self, HexStr):\r
+        if not HexStr.upper().startswith("0X"):\r
+            return False\r
+        if len(self.__Token) <= 2:\r
+            return False\r
+        charList = [c for c in HexStr[2 : ] if not self.__HexDigit( c)]\r
+        if len(charList) == 0:\r
+            return True\r
+        else:\r
+            return False    \r
     ## __GetNextHexNumber() method\r
     #\r
     #   Get next HEX data before a seperator\r
@@ -667,14 +1007,7 @@ class FdfParser:
     def __GetNextHexNumber(self):\r
         if not self.__GetNextToken():\r
             return False\r
-        if not self.__Token.upper().startswith("0X"):\r
-            self.__UndoToken()\r
-            return False\r
-        if len(self.__Token) <= 2:\r
-            self.__UndoToken()\r
-            return False\r
-        charList = [c for c in self.__Token[2 : ] if not self.__HexDigit( c)]\r
-        if len(charList) == 0:\r
+        if self.__IsHex(self.__Token):\r
             return True\r
         else:\r
             self.__UndoToken()\r
@@ -739,8 +1072,21 @@ class FdfParser:
                 raise Warning("Missing Quote \" for String At Line ", self.FileName, self.CurrentLineNumber)\r
             if currentLineNumber != self.CurrentLineNumber:\r
                 raise Warning("Missing Quote \" for String At Line ", self.FileName, self.CurrentLineNumber)\r
-            self.__Token = self.__SkippedChars.rstrip('"')\r
+            self.__Token = self.__SkippedChars.rstrip('\"')\r
             return True\r
+        \r
+        elif self.__Token.startswith("\'") or self.__Token.startswith("L\'"):\r
+            self.__UndoToken()\r
+            self.__SkipToToken("\'")\r
+            currentLineNumber = self.CurrentLineNumber\r
+            \r
+            if not self.__SkipToToken("\'"):\r
+                raise Warning("Missing Quote \' for String At Line ", self.FileName, self.CurrentLineNumber)\r
+            if currentLineNumber != self.CurrentLineNumber:\r
+                raise Warning("Missing Quote \' for String At Line ", self.FileName, self.CurrentLineNumber)\r
+            self.__Token = self.__SkippedChars.rstrip('\'')\r
+            return True\r
+        \r
         else:\r
             return False\r
             \r
@@ -811,7 +1157,17 @@ class FdfParser:
             self.PreprocessIncludeFile()\r
             self.__StringToList()\r
             self.PreprocessFile()\r
-            \r
+            self.PreprocessConditionalStatement()\r
+            self.__StringToList()\r
+            for Pos in self.__WipeOffArea:\r
+                self.__ReplaceFragment(Pos[0], Pos[1])\r
+            self.Profile.FileLinesList = ["".join(list) for list in self.Profile.FileLinesList]\r
+            Index = 0\r
+            while Index < len(self.Profile.FileLinesList):\r
+                FileLineTuple = GetRealFileLine(self.FileName, Index + 1)\r
+                self.Profile.FileLinesList[Index] = self.__ReplaceMacros(self.Profile.FileLinesList[Index], FileLineTuple[0], FileLineTuple[1])\r
+                Index += 1\r
+                \r
             while self.__GetFd():\r
                 pass\r
 \r
@@ -829,7 +1185,7 @@ class FdfParser:
             \r
         except Warning, X:\r
             self.__UndoToken()\r
-            FileLineTuple = X.GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
+            FileLineTuple = GetRealFileLine(self.FileName, self.CurrentLineNumber)\r
             X.message += '\nGot Token: \"%s\" from File %s\n' % (self.__Token, FileLineTuple[0]) + \\r
                 'Previous Token: \"%s\" At line: %d, Offset Within Line: %d\n' \\r
                     % (self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine :].rstrip('\n').rstrip('\r'), FileLineTuple[1], self.CurrentOffsetWithinLine)\r
@@ -1305,7 +1661,8 @@ class FdfParser:
         DataString += ","\r
         \r
         while self.__IsToken(","):\r
-            self.__GetNextHexNumber()\r
+            if not self.__GetNextHexNumber():\r
+                raise Warning("Invalid Hex number At Line ", self.FileName, self.CurrentLineNumber)\r
             if len(self.__Token) > 4:\r
                 raise Warning("Hex byte(must be 2 digits) too long At Line ", self.FileName, self.CurrentLineNumber)\r
             DataString += self.__Token\r
@@ -1364,8 +1721,7 @@ class FdfParser:
         if S.startswith("[") and not S.startswith("[FV."):\r
             if not S.startswith("[CAPSULE.") \\r
                 and not S.startswith("[VTF.") and not S.startswith("[RULE."):\r
-                raise Warning("Unknown section or section appear sequence error At Line %d.\n \\r
-                            The correct sequence should be [FD.], [FV.], [Capsule.], [VTF.], [Rule.]" % self.CurrentLineNumber, self.FileName, self.CurrentLineNumber)\r
+                raise Warning("Unknown section or section appear sequence error \n(The correct sequence should be [FD.], [FV.], [Capsule.], [VTF.], [Rule.]) At Line ", self.FileName, self.CurrentLineNumber)\r
             self.__UndoToken()\r
             return False\r
 \r
@@ -1533,8 +1889,8 @@ class FdfParser:
             raise Warning("expected INF file path At Line ", self.FileName, self.CurrentLineNumber)\r
         ffsInf.InfFileName = self.__Token\r
         \r
-        if ffsInf.InfFileName.find('$') >= 0:\r
-            ffsInf.InfFileName = GenFdsGlobalVariable.GenFdsGlobalVariable.MacroExtend(ffsInf.InfFileName, MacroDict)\r
+#        if ffsInf.InfFileName.find('$') >= 0:\r
+#            ffsInf.InfFileName = GenFdsGlobalVariable.GenFdsGlobalVariable.MacroExtend(ffsInf.InfFileName, MacroDict)\r
             \r
         if not ffsInf.InfFileName in self.Profile.InfList:\r
             self.Profile.InfList.append(ffsInf.InfFileName)\r
@@ -2110,8 +2466,7 @@ class FdfParser:
         S = self.__Token.upper()\r
         if S.startswith("[") and not S.startswith("[CAPSULE."):\r
             if not S.startswith("[VTF.") and not S.startswith("[RULE."):\r
-                raise Warning("Unknown section or section appear sequence error At Line %d.\n \\r
-                            The correct sequence should be [FD.], [FV.], [Capsule.], [VTF.], [Rule.]" % self.CurrentLineNumber, self.FileName, self.CurrentLineNumber)\r
+                raise Warning("Unknown section or section appear sequence error \n(The correct sequence should be [FD.], [FV.], [Capsule.], [VTF.], [Rule.]) At Line ", self.FileName, self.CurrentLineNumber)\r
             self.__UndoToken()\r
             return False\r
 \r
@@ -2233,8 +2588,7 @@ class FdfParser:
 \r
         S = self.__Token.upper()\r
         if S.startswith("[") and not S.startswith("[RULE."):\r
-            raise Warning("Unknown section or section appear sequence error At Line %d.\n \\r
-                            The correct sequence should be [FD.], [FV.], [Capsule.], [VTF.], [Rule.]" % self.CurrentLineNumber, self.FileName, self.CurrentLineNumber)\r
+            raise Warning("Unknown section or section appear sequence error \n(The correct sequence should be [FD.], [FV.], [Capsule.], [VTF.], [Rule.]) At Line ", self.FileName, self.CurrentLineNumber)\r
 \r
         self.__UndoToken()\r
         if not self.__IsToken("[Rule.", True):\r
@@ -2791,8 +3145,7 @@ class FdfParser:
         S = self.__Token.upper()\r
         if S.startswith("[") and not S.startswith("[VTF."):\r
             if not S.startswith("[RULE."):\r
-                raise Warning("Unknown section or section appear sequence error At Line %d.\n \\r
-                            The correct sequence should be [FD.], [FV.], [Capsule.], [VTF.], [Rule.]" % self.CurrentLineNumber, self.FileName, self.CurrentLineNumber)\r
+                raise Warning("Unknown section or section appear sequence error \n(The correct sequence should be [FD.], [FV.], [Capsule.], [VTF.], [Rule.]) At Line ", self.FileName, self.CurrentLineNumber)\r
             self.__UndoToken()\r
             return False\r
 \r
@@ -3098,7 +3451,11 @@ class FdfParser:
         \r
 if __name__ == "__main__":\r
     parser = FdfParser("..\LakeportX64Pkg.fdf")\r
-    parser.ParseFile()\r
-    parser.CycleReferenceCheck()\r
-    print "Success!"\r
+    try:\r
+        parser.ParseFile()\r
+        parser.CycleReferenceCheck()\r
+    except Warning, X:\r
+            print X.message\r
+    else:\r
+        print "Success!"\r
 \r
index 5fd7d88..910fe3a 100644 (file)
@@ -159,6 +159,15 @@ def main():
             GenFdsGlobalVariable.ErrorLogger ("Directory %s not found" % (OutputDir))\r
             sys.exit(1)\r
     \r
+        if Options.Macros:\r
+            for Pair in Options.Macros:\r
+                Pair.strip('"')\r
+                List = Pair.split('=')\r
+                if len(List) == 2:\r
+                    FdfParser.InputMacroDict[List[0].strip()] = List[1].strip()\r
+                else:\r
+                    FdfParser.InputMacroDict[List[0].strip()] = None\r
+                    \r
         """ Parse Fdf file, has to place after build Workspace as FDF may contain macros from DSC file """\r
         try:\r
             FdfParserObj = FdfParser.FdfParser(FdfFilename)\r
@@ -202,7 +211,7 @@ def main():
 #   @retval Args  Target of build command\r
 #    \r
 def myOptionParser():\r
-    usage = "%prog [options] -f input_file -a arch_list -b build_target -p active_platform -t tool_chain_tag"\r
+    usage = "%prog [options] -f input_file -a arch_list -b build_target -p active_platform -t tool_chain_tag -y \"MacroName [= MacroValue]\""\r
     Parser = OptionParser(usage=usage,description=__copyright__,version="%prog " + str(versionNumber))\r
     Parser.add_option("-f", "--file", dest="filename", help="Name of FDF file to convert")\r
     Parser.add_option("-a", "--arch", dest="archList", help="comma separated list containing one or more of: IA32, X64, IPF or EBC which should be built, overrides target.txt?s TARGET_ARCH")\r
@@ -216,6 +225,7 @@ def myOptionParser():
     Parser.add_option("-i", "--FvImage", dest="uiFvName", help="Buld the FV image using the [FV] section named by UiFvName")\r
     Parser.add_option("-b", "--buildtarget", action="store", type="choice", choices=['DEBUG','RELEASE'], dest="BuildTarget", help="Build TARGET is one of list: DEBUG, RELEASE.")\r
     Parser.add_option("-t", "--tagname", action="store", type="string", dest="ToolChain", help="Using the tools: TOOL_CHAIN_TAG name to build the platform.")\r
+    Parser.add_option("-y", "--define", action="append", type="string", dest="Macros", help="Macro: \"Name [= Value]\".")\r
     (Options, args) = Parser.parse_args()\r
     return Options\r
 \r