]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools: Extend the Macro used in the FDF !include statement
authorYonghong Zhu <yonghong.zhu@intel.com>
Sun, 22 Jan 2017 01:59:32 +0000 (09:59 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Mon, 23 Jan 2017 13:10:49 +0000 (21:10 +0800)
Current it only support the system environment variables in the !include
statement, $(WORKSPACE), $(PACKAGES_PATH), $(EFI_SOURCE), $(EDK_SOURCE),
$(ECP_SOURCE), this patch extend the usage to support the Global macros
and the macro which defined before the statement.

Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Yonghong Zhu <yonghong.zhu@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
BaseTools/Source/Python/GenFds/FdfParser.py

index e1295f2ee7f6475d6e5198dbb2406274080f43cc..27688e2ff8355c4742e13e16852267e5cfcc15f3 100644 (file)
@@ -620,27 +620,46 @@ class FdfParser:
     def PreprocessIncludeFile(self):\r
            # nested include support\r
         Processed = False\r
+        MacroDict = {}\r
         while self.__GetNextToken():\r
 \r
-            if self.__Token == '!include':\r
+            if self.__Token == 'DEFINE':\r
+                if not self.__GetNextToken():\r
+                    raise Warning("expected Macro name", self.FileName, self.CurrentLineNumber)\r
+                Macro = self.__Token\r
+                if not self.__IsToken( "="):\r
+                    raise Warning("expected '='", self.FileName, self.CurrentLineNumber)\r
+                Value = self.__GetExpression()\r
+                MacroDict[Macro] = Value\r
+\r
+            elif self.__Token == '!include':\r
                 Processed = True\r
                 IncludeLine = self.CurrentLineNumber\r
                 IncludeOffset = self.CurrentOffsetWithinLine - len('!include')\r
                 if not self.__GetNextToken():\r
                     raise Warning("expected include file name", self.FileName, self.CurrentLineNumber)\r
                 IncFileName = self.__Token\r
-                __IncludeMacros = {}\r
-                for Macro in ['WORKSPACE', 'ECP_SOURCE', 'EFI_SOURCE', 'EDK_SOURCE']:\r
+                PreIndex = 0\r
+                StartPos = IncFileName.find('$(', PreIndex)\r
+                EndPos = IncFileName.find(')', StartPos+2)\r
+                while StartPos != -1 and EndPos != -1:\r
+                    Macro = IncFileName[StartPos+2 : EndPos]\r
                     MacroVal = self.__GetMacroValue(Macro)\r
-                    if MacroVal:\r
-                        __IncludeMacros[Macro] = MacroVal\r
+                    if not MacroVal:\r
+                        if Macro in MacroDict:\r
+                            MacroVal = MacroDict[Macro]\r
+                    if MacroVal != None:\r
+                        IncFileName = IncFileName.replace('$(' + Macro + ')', MacroVal, 1)\r
+                        if MacroVal.find('$(') != -1:\r
+                            PreIndex = StartPos\r
+                        else:\r
+                            PreIndex = StartPos + len(MacroVal)\r
+                    else:\r
+                        raise Warning("The Macro %s is not defined" %Macro, self.FileName, self.CurrentLineNumber)\r
+                    StartPos = IncFileName.find('$(', PreIndex)\r
+                    EndPos = IncFileName.find(')', StartPos+2)\r
 \r
-                try:\r
-                    IncludedFile = NormPath(ReplaceMacro(IncFileName, __IncludeMacros, RaiseError=True))\r
-                except:\r
-                    raise Warning("only these system environment variables are permitted to start the path of the included file: "\r
-                                  "$(WORKSPACE), $(ECP_SOURCE), $(EFI_SOURCE), $(EDK_SOURCE)",\r
-                                  self.FileName, self.CurrentLineNumber)\r
+                IncludedFile = NormPath(IncFileName)\r
                 #\r
                 # First search the include file under the same directory as FDF file\r
                 #\r