]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Workspace/MetaFileParser.py
BaseTools: Fix one bug of nest !include parser
[mirror_edk2.git] / BaseTools / Source / Python / Workspace / MetaFileParser.py
index 788eca17616146fbf3f7abc6da3ff3a2885086e4..a2ded0c845ae49bfd6e880ffc42c549592df29f7 100644 (file)
@@ -2,7 +2,7 @@
 # This file is used to parse meta files\r
 #\r
 # Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>\r
-# (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>\r
+# (C) Copyright 2015-2018 Hewlett Packard Enterprise Development LP<BR>\r
 # This program and the accompanying materials\r
 # are licensed and made available under the terms and conditions of the BSD License\r
 # which accompanies this distribution.  The full text of the license may be found at\r
@@ -26,12 +26,12 @@ import Common.GlobalData as GlobalData
 \r
 from CommonDataClass.DataClass import *\r
 from Common.DataType import *\r
-from Common.String import *\r
+from Common.StringUtils import *\r
 from Common.Misc import GuidStructureStringToGuidString, CheckPcdDatum, PathClass, AnalyzePcdData, AnalyzeDscPcd, AnalyzePcdExpression, ParseFieldValue\r
 from Common.Expression import *\r
 from CommonDataClass.Exceptions import *\r
 from Common.LongFilePathSupport import OpenLongFilePath as open\r
-\r
+from collections import defaultdict\r
 from MetaFileTable import MetaFileStorage\r
 from MetaFileCommentParser import CheckInfComment\r
 \r
@@ -163,7 +163,7 @@ class MetaFileParser(object):
         self._FileDir = self.MetaFile.Dir\r
         self._Defines = {}\r
         self._FileLocalMacros = {}\r
-        self._SectionsMacroDict = {}\r
+        self._SectionsMacroDict = defaultdict(dict)\r
 \r
         # for recursive parsing\r
         self._Owner = [Owner]\r
@@ -310,7 +310,7 @@ class MetaFileParser(object):
             if self._SectionName in self.DataType:\r
                 self._SectionType = self.DataType[self._SectionName]\r
                 # Check if the section name is valid\r
-                if self._SectionName not in SECTIONS_HAVE_ITEM_AFTER_ARCH and len(ItemList) > 3:\r
+                if self._SectionName not in SECTIONS_HAVE_ITEM_AFTER_ARCH_SET and len(ItemList) > 3:\r
                     EdkLogger.error("Parser", FORMAT_UNKNOWN_ERROR, "%s is not a valid section name" % Item,\r
                                     self.MetaFile, self._LineIndex + 1, self._CurrentLine)\r
             elif self._Version >= 0x00010005:\r
@@ -328,7 +328,7 @@ class MetaFileParser(object):
 \r
             # S2 may be Platform or ModuleType\r
             if len(ItemList) > 2:\r
-                if self._SectionName.upper() in SECTIONS_HAVE_ITEM_PCD:\r
+                if self._SectionName.upper() in SECTIONS_HAVE_ITEM_PCD_SET:\r
                     S2 = ItemList[2]\r
                 else:\r
                     S2 = ItemList[2].upper()\r
@@ -421,17 +421,16 @@ class MetaFileParser(object):
     def _ConstructSectionMacroDict(self, Name, Value):\r
         ScopeKey = [(Scope[0], Scope[1],Scope[2]) for Scope in self._Scope]\r
         ScopeKey = tuple(ScopeKey)\r
-        SectionDictKey = self._SectionType, ScopeKey\r
         #\r
         # DecParser SectionType is a list, will contain more than one item only in Pcd Section\r
         # As Pcd section macro usage is not alllowed, so here it is safe\r
         #\r
         if type(self) == DecParser:\r
             SectionDictKey = self._SectionType[0], ScopeKey\r
-        if SectionDictKey not in self._SectionsMacroDict:\r
-            self._SectionsMacroDict[SectionDictKey] = {}\r
-        SectionLocalMacros = self._SectionsMacroDict[SectionDictKey]\r
-        SectionLocalMacros[Name] = Value\r
+        else:\r
+            SectionDictKey = self._SectionType, ScopeKey\r
+\r
+        self._SectionsMacroDict[SectionDictKey][Name] = Value\r
 \r
     ## Get section Macros that are applicable to current line, which may come from other sections \r
     ## that share the same name while scope is wider\r
@@ -936,7 +935,7 @@ class DscParser(MetaFileParser):
                 self._SubsectionType = MODEL_UNKNOWN\r
                 self._SubsectionName = ''\r
                 self._Owner[-1] = -1\r
-                OwnerId = {}\r
+                OwnerId.clear()\r
                 continue\r
             # subsection header\r
             elif Line[0] == TAB_OPTION_START and Line[-1] == TAB_OPTION_END:\r
@@ -1296,7 +1295,7 @@ class DscParser(MetaFileParser):
         self._DirectiveEvalStack = []\r
         self._FileWithError = self.MetaFile\r
         self._FileLocalMacros = {}\r
-        self._SectionsMacroDict = {}\r
+        self._SectionsMacroDict.clear()\r
         GlobalData.gPlatformDefines = {}\r
 \r
         # Get all macro and PCD which has straitforward value\r
@@ -1552,10 +1551,21 @@ class DscParser(MetaFileParser):
 \r
             self.IncludedFiles.add (IncludedFile1)\r
 \r
+            # todo: rework the nested include checking logic\r
+            # Current nested include checking rely on dsc file order inside build.db.\r
+            # It is not reliable and will lead to build fail in some case.\r
+            #\r
+            # When project A and B include a common dsc file C.\r
+            # Build project A. It give dsc file A = ID 1 in build.db, and C ID = 2.\r
+            # Build project B. It give dsc file B ID = 3, and C ID still = 2.\r
+            # Then, we build project B fail, unless we clean build.db.\r
+            # In oldder BaseTools, the project B ID will still be 1,\r
+            # that's why it work before.\r
+\r
             # Does not allow lower level included file to include upper level included file\r
-            if Parser._From != Owner and int(Owner) > int (Parser._From):\r
-                EdkLogger.error('parser', FILE_ALREADY_EXIST, File=self._FileWithError,\r
-                    Line=self._LineIndex + 1, ExtraData="{0} is already included at a higher level.".format(IncludedFile1))\r
+            #if Parser._From != Owner and int(Owner) > int (Parser._From):\r
+            #   EdkLogger.error('parser', FILE_ALREADY_EXIST, File=self._FileWithError,\r
+            #       Line=self._LineIndex + 1, ExtraData="{0} is already included at a higher level.".format(IncludedFile1))\r
 \r
 \r
             # set the parser status with current status\r
@@ -1571,7 +1581,11 @@ class DscParser(MetaFileParser):
 \r
             # update current status with sub-parser's status\r
             self._SectionName = Parser._SectionName\r
-            self._SectionType = Parser._SectionType\r
+            if not self._InSubsection:\r
+                self._SectionType = Parser._SectionType\r
+            self._SubsectionType = Parser._SubsectionType\r
+            self._InSubsection = Parser._InSubsection\r
+\r
             self._Scope = Parser._Scope\r
             self._Enabled = Parser._Enabled\r
 \r