]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Workspace/MetaFileParser.py
Sync BaseTool trunk (version r2423) into EDKII BaseTools. The change mainly includes:
[mirror_edk2.git] / BaseTools / Source / Python / Workspace / MetaFileParser.py
index bfa70543965218c08ef7c4e387c787e9ba7eabe5..d907b11ba11ac07053fe9c1688deee8eeb1ddf64 100644 (file)
@@ -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]