From 2bcc713e74b944bb5aefb433ef33fb4002a62d76 Mon Sep 17 00:00:00 2001
From: lgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>
Date: Fri, 25 Nov 2011 06:21:03 +0000
Subject: Sync BaseTool trunk (version r2423) into EDKII BaseTools.  The change
 mainly includes:   1. Fix !include issues   2. Fix Trim to skip the postfix
 'U' for hexadecimal and decimal numbers   3. Fix building error C2733 when
 building C++ code.   4. Add GCC46 tool chain definition   5. Add new RVCT and
 RVCTLINUX tool chains

Signed-off-by: lgao4


git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12782 6f19259b-4bc3-4df7-8a09-765794883524
---
 .../Source/Python/Workspace/MetaFileParser.py      | 54 +++++++++++++++++-----
 1 file changed, 43 insertions(+), 11 deletions(-)

(limited to 'BaseTools/Source/Python/Workspace')

diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py b/BaseTools/Source/Python/Workspace/MetaFileParser.py
index bfa7054396..d907b11ba1 100644
--- a/BaseTools/Source/Python/Workspace/MetaFileParser.py
+++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py
@@ -769,7 +769,7 @@ class DscParser(MetaFileParser):
                 self._InSubsection = False
                 self._SubsectionType = MODEL_UNKNOWN
                 self._SubsectionName = ''
-                self._Owner.pop()
+                self._Owner[-1] = -1
                 continue
             # subsection header
             elif Line[0] == TAB_OPTION_START and Line[-1] == TAB_OPTION_END:
@@ -1247,19 +1247,48 @@ class DscParser(MetaFileParser):
                                  MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF]:
                     break
         elif self._ItemType == MODEL_META_DATA_INCLUDE:
-            # The included file must be relative to workspace
-            IncludedFile = NormPath(ReplaceMacro(self._ValueList[1], self._Macros, RaiseError=True))
-            IncludedFile = PathClass(IncludedFile, GlobalData.gWorkspace)
-            ErrorCode, ErrorInfo = IncludedFile.Validate()
+            # The included file must be relative to workspace or same directory as DSC file
+            __IncludeMacros = {}
+            #
+            # Allow using system environment variables  in path after !include
+            #
+            __IncludeMacros['WORKSPACE'] = GlobalData.gGlobalDefines['WORKSPACE']
+            if "ECP_SOURCE" in GlobalData.gGlobalDefines.keys():
+                __IncludeMacros['ECP_SOURCE'] = GlobalData.gGlobalDefines['ECP_SOURCE']
+            #
+            # During GenFds phase call DSC parser, will go into this branch.
+            #
+            elif "ECP_SOURCE" in GlobalData.gCommandLineDefines.keys():
+                __IncludeMacros['ECP_SOURCE'] = GlobalData.gCommandLineDefines['ECP_SOURCE']
+
+            __IncludeMacros['EFI_SOURCE'] = GlobalData.gGlobalDefines['EFI_SOURCE']
+            __IncludeMacros['EDK_SOURCE'] = GlobalData.gGlobalDefines['EDK_SOURCE']
+            #
+            # Allow using MACROs comes from [Defines] section to keep compatible. 
+            #
+            __IncludeMacros.update(self._Macros)
+            
+            IncludedFile = NormPath(ReplaceMacro(self._ValueList[1], __IncludeMacros, RaiseError=True))
+            #
+            # First search the include file under the same directory as DSC file
+            #
+            IncludedFile1 = PathClass(IncludedFile, self.MetaFile.Dir)
+            ErrorCode, ErrorInfo1 = IncludedFile1.Validate()
             if ErrorCode != 0:
-                EdkLogger.error('parser', ErrorCode, File=self._FileWithError, 
-                                Line=self._LineIndex+1, ExtraData=ErrorInfo)
+                #
+                # Also search file under the WORKSPACE directory
+                #
+                IncludedFile1 = PathClass(IncludedFile, GlobalData.gWorkspace)
+                ErrorCode, ErrorInfo2 = IncludedFile1.Validate()
+                if ErrorCode != 0:
+                    EdkLogger.error('parser', ErrorCode, File=self._FileWithError, 
+                                    Line=self._LineIndex+1, ExtraData=ErrorInfo1 + "\n"+ ErrorInfo2)
 
-            self._FileWithError = IncludedFile
+            self._FileWithError = IncludedFile1
 
-            IncludedFileTable = MetaFileStorage(self._Table.Cur, IncludedFile, MODEL_FILE_DSC, False)
+            IncludedFileTable = MetaFileStorage(self._Table.Cur, IncludedFile1, MODEL_FILE_DSC, False)
             Owner = self._Content[self._ContentIndex-1][0]
-            Parser = DscParser(IncludedFile, self._FileType, IncludedFileTable, 
+            Parser = DscParser(IncludedFile1, self._FileType, IncludedFileTable, 
                                Owner=Owner, From=Owner)
 
             # set the parser status with current status
@@ -1280,7 +1309,10 @@ class DscParser(MetaFileParser):
             Records = IncludedFileTable.GetAll()
             if Records:
                 self._Content[self._ContentIndex:self._ContentIndex] = Records
-
+                self._Content.pop(self._ContentIndex-1)
+                self._ValueList = None
+                self._ContentIndex -= 1
+                
     def __ProcessSkuId(self):
         self._ValueList = [ReplaceMacro(Value, self._Macros, RaiseError=True)
                            for Value in self._ValueList]
-- 
cgit v1.2.3