]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Workspace/DecBuildData.py
BaseTools: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / BaseTools / Source / Python / Workspace / DecBuildData.py
index 1fbd095f743cf03f4578ca70055de680ea6223dc..d58d88eca754c97530f186a2e8d8595c822bea10 100644 (file)
@@ -3,21 +3,17 @@
 #\r
 # Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>\r
 # (C) Copyright 2016 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
-# http://opensource.org/licenses/bsd-license.php\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
 #\r
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-#\r
-from Common.String import *\r
+from Common.StringUtils import *\r
 from Common.DataType import *\r
 from Common.Misc import *\r
 from types import *\r
 from collections import OrderedDict\r
-\r
+from CommonDataClass.DataClass import *\r
 from Workspace.BuildClassObject import PackageBuildClassObject, StructurePcd, PcdClassObject\r
+from Common.GlobalData import gGlobalDefines\r
+from re import compile\r
 \r
 ## Platform build information from DEC file\r
 #\r
@@ -99,41 +95,27 @@ class DecBuildData(PackageBuildClassObject):
         self._CommonIncludes    = None\r
         self._LibraryClasses    = None\r
         self._Pcds              = None\r
-        self.__Macros           = None\r
+        self._MacroDict         = None\r
         self._PrivateProtocols  = None\r
         self._PrivatePpis       = None\r
         self._PrivateGuids      = None\r
         self._PrivateIncludes   = None\r
 \r
     ## Get current effective macros\r
-    def _GetMacros(self):\r
-        if self.__Macros is None:\r
-            self.__Macros = {}\r
-            self.__Macros.update(GlobalData.gGlobalDefines)\r
-        return self.__Macros\r
+    @property\r
+    def _Macros(self):\r
+        if self._MacroDict is None:\r
+            self._MacroDict = dict(gGlobalDefines)\r
+        return self._MacroDict\r
 \r
     ## Get architecture\r
-    def _GetArch(self):\r
+    @property\r
+    def Arch(self):\r
         return self._Arch\r
 \r
-    ## Set architecture\r
-    #\r
-    #   Changing the default ARCH to another may affect all other information\r
-    # because all information in a platform may be ARCH-related. That's\r
-    # why we need to clear all internal used members, in order to cause all\r
-    # information to be re-retrieved.\r
-    #\r
-    #   @param  Value   The value of ARCH\r
-    #\r
-    def _SetArch(self, Value):\r
-        if self._Arch == Value:\r
-            return\r
-        self._Arch = Value\r
-        self._Clear()\r
-\r
     ## Retrieve all information in [Defines] section\r
     #\r
-    #   (Retriving all [Defines] information in one-shot is just to save time.)\r
+    #   (Retrieving all [Defines] information in one-shot is just to save time.)\r
     #\r
     def _GetHeaderInfo(self):\r
         RecordList = self._RawData[MODEL_META_DATA_HEADER, self._Arch]\r
@@ -144,7 +126,8 @@ class DecBuildData(PackageBuildClassObject):
         self._Header = 'DUMMY'\r
 \r
     ## Retrieve package name\r
-    def _GetPackageName(self):\r
+    @property\r
+    def PackageName(self):\r
         if self._PackageName is None:\r
             if self._Header is None:\r
                 self._GetHeaderInfo()\r
@@ -153,7 +136,8 @@ class DecBuildData(PackageBuildClassObject):
         return self._PackageName\r
 \r
     ## Retrieve file guid\r
-    def _GetFileGuid(self):\r
+    @property\r
+    def PackageName(self):\r
         if self._Guid is None:\r
             if self._Header is None:\r
                 self._GetHeaderInfo()\r
@@ -162,7 +146,8 @@ class DecBuildData(PackageBuildClassObject):
         return self._Guid\r
 \r
     ## Retrieve package version\r
-    def _GetVersion(self):\r
+    @property\r
+    def Version(self):\r
         if self._Version is None:\r
             if self._Header is None:\r
                 self._GetHeaderInfo()\r
@@ -171,11 +156,12 @@ class DecBuildData(PackageBuildClassObject):
         return self._Version\r
 \r
     ## Retrieve protocol definitions (name/value pairs)\r
-    def _GetProtocol(self):\r
+    @property\r
+    def Protocols(self):\r
         if self._Protocols is None:\r
             #\r
             # tdict is a special kind of dict, used for selecting correct\r
-            # protocol defition for given ARCH\r
+            # protocol definition for given ARCH\r
             #\r
             ProtocolDict = tdict(True)\r
             PrivateProtocolDict = tdict(True)\r
@@ -213,11 +199,12 @@ class DecBuildData(PackageBuildClassObject):
         return self._Protocols\r
 \r
     ## Retrieve PPI definitions (name/value pairs)\r
-    def _GetPpi(self):\r
+    @property\r
+    def Ppis(self):\r
         if self._Ppis is None:\r
             #\r
             # tdict is a special kind of dict, used for selecting correct\r
-            # PPI defition for given ARCH\r
+            # PPI definition for given ARCH\r
             #\r
             PpiDict = tdict(True)\r
             PrivatePpiDict = tdict(True)\r
@@ -255,11 +242,12 @@ class DecBuildData(PackageBuildClassObject):
         return self._Ppis\r
 \r
     ## Retrieve GUID definitions (name/value pairs)\r
-    def _GetGuid(self):\r
+    @property\r
+    def Guids(self):\r
         if self._Guids is None:\r
             #\r
             # tdict is a special kind of dict, used for selecting correct\r
-            # GUID defition for given ARCH\r
+            # GUID definition for given ARCH\r
             #\r
             GuidDict = tdict(True)\r
             PrivateGuidDict = tdict(True)\r
@@ -297,7 +285,8 @@ class DecBuildData(PackageBuildClassObject):
         return self._Guids\r
 \r
     ## Retrieve public include paths declared in this package\r
-    def _GetInclude(self):\r
+    @property\r
+    def Includes(self):\r
         if self._Includes is None or self._CommonIncludes is None:\r
             self._CommonIncludes = []\r
             self._Includes = []\r
@@ -305,7 +294,6 @@ class DecBuildData(PackageBuildClassObject):
             PublicInclues = []\r
             RecordList = self._RawData[MODEL_EFI_INCLUDE, self._Arch]\r
             Macros = self._Macros\r
-            Macros["EDK_SOURCE"] = GlobalData.gEcpSource\r
             for Record in RecordList:\r
                 File = PathClass(NormPath(Record[0], Macros), self._PackageDir, Arch=self._Arch)\r
                 LineNo = Record[-1]\r
@@ -332,7 +320,8 @@ class DecBuildData(PackageBuildClassObject):
         return self._Includes\r
 \r
     ## Retrieve library class declarations (not used in build at present)\r
-    def _GetLibraryClass(self):\r
+    @property\r
+    def LibraryClasses(self):\r
         if self._LibraryClasses is None:\r
             #\r
             # tdict is a special kind of dict, used for selecting correct\r
@@ -356,7 +345,8 @@ class DecBuildData(PackageBuildClassObject):
         return self._LibraryClasses\r
 \r
     ## Retrieve PCD declarations\r
-    def _GetPcds(self):\r
+    @property\r
+    def Pcds(self):\r
         if self._Pcds is None:\r
             self._Pcds = OrderedDict()\r
             self._Pcds.update(self._GetPcd(MODEL_PCD_FIXED_AT_BUILD))\r
@@ -366,19 +356,35 @@ class DecBuildData(PackageBuildClassObject):
             self._Pcds.update(self._GetPcd(MODEL_PCD_DYNAMIC_EX))\r
         return self._Pcds\r
 \r
+    def ParsePcdName(self,TokenCName):\r
+        TokenCName = TokenCName.strip()\r
+        if TokenCName.startswith("["):\r
+            if "." in TokenCName:\r
+                Demesionattr = TokenCName[:TokenCName.index(".")]\r
+                Fields = TokenCName[TokenCName.index(".")+1:]\r
+            else:\r
+                Demesionattr = TokenCName\r
+                Fields = ""\r
+        else:\r
+            Demesionattr = ""\r
+            Fields = TokenCName\r
+\r
+        return Demesionattr,Fields\r
 \r
     def ProcessStructurePcd(self, StructurePcdRawDataSet):\r
         s_pcd_set = OrderedDict()\r
-        for s_pcd,LineNo in StructurePcdRawDataSet:\r
+        for s_pcd, LineNo in StructurePcdRawDataSet:\r
             if s_pcd.TokenSpaceGuidCName not in s_pcd_set:\r
                 s_pcd_set[s_pcd.TokenSpaceGuidCName] = []\r
-            s_pcd_set[s_pcd.TokenSpaceGuidCName].append((s_pcd,LineNo))\r
+            s_pcd_set[s_pcd.TokenSpaceGuidCName].append((s_pcd, LineNo))\r
 \r
         str_pcd_set = []\r
         for pcdname in s_pcd_set:\r
             dep_pkgs = []\r
             struct_pcd = StructurePcd()\r
-            for item,LineNo in s_pcd_set[pcdname]:\r
+            for item, LineNo in s_pcd_set[pcdname]:\r
+                if not item.TokenCName:\r
+                    continue\r
                 if "<HeaderFiles>" in item.TokenCName:\r
                     struct_pcd.StructuredPcdIncludeFile.append(item.DefaultValue)\r
                 elif "<Packages>" in item.TokenCName:\r
@@ -391,7 +397,8 @@ class DecBuildData(PackageBuildClassObject):
                     struct_pcd.PkgPath = self.MetaFile.File\r
                     struct_pcd.SetDecDefaultValue(item.DefaultValue)\r
                 else:\r
-                    struct_pcd.AddDefaultValue(item.TokenCName, item.DefaultValue,self.MetaFile.File,LineNo)\r
+                    DemesionAttr, Fields = self.ParsePcdName(item.TokenCName)\r
+                    struct_pcd.AddDefaultValue(Fields, item.DefaultValue, self.MetaFile.File, LineNo,DemesionAttr)\r
 \r
             struct_pcd.PackageDecs = dep_pkgs\r
             str_pcd_set.append(struct_pcd)\r
@@ -412,16 +419,17 @@ class DecBuildData(PackageBuildClassObject):
         StrPcdSet = []\r
         RecordList = self._RawData[Type, self._Arch]\r
         for TokenSpaceGuid, PcdCName, Setting, Arch, PrivateFlag, Dummy1, Dummy2 in RecordList:\r
-            PcdDict[Arch, PcdCName, TokenSpaceGuid] = (Setting,Dummy2)\r
+            PcdDict[Arch, PcdCName, TokenSpaceGuid] = (Setting, Dummy2)\r
             if not (PcdCName, TokenSpaceGuid) in PcdSet:\r
                 PcdSet.append((PcdCName, TokenSpaceGuid))\r
 \r
+        DefinitionPosition = {}\r
         for PcdCName, TokenSpaceGuid in PcdSet:\r
             #\r
             # limit the ARCH to self._Arch, if no self._Arch found, tdict\r
             # will automatically turn to 'common' ARCH and try again\r
             #\r
-            Setting,LineNo = PcdDict[self._Arch, PcdCName, TokenSpaceGuid]\r
+            Setting, LineNo = PcdDict[self._Arch, PcdCName, TokenSpaceGuid]\r
             if Setting is None:\r
                 continue\r
 \r
@@ -442,41 +450,26 @@ class DecBuildData(PackageBuildClassObject):
                                         list(validlists),\r
                                         list(expressions)\r
                                         )\r
-            PcdObj.DefinitionPosition = (self.MetaFile.File,LineNo)\r
+            DefinitionPosition[PcdObj] = (self.MetaFile.File, LineNo)\r
             if "." in TokenSpaceGuid:\r
-                StrPcdSet.append((PcdObj,LineNo))\r
+                StrPcdSet.append((PcdObj, LineNo))\r
             else:\r
                 Pcds[PcdCName, TokenSpaceGuid, self._PCD_TYPE_STRING_[Type]] = PcdObj\r
 \r
         StructurePcds = self.ProcessStructurePcd(StrPcdSet)\r
         for pcd in StructurePcds:\r
             Pcds[pcd.TokenCName, pcd.TokenSpaceGuidCName, self._PCD_TYPE_STRING_[Type]] = pcd\r
-        StructPattern = re.compile(r'[_a-zA-Z][0-9A-Za-z_]*$')\r
+        StructPattern = compile(r'[_a-zA-Z][0-9A-Za-z_]*$')\r
         for pcd in Pcds.values():\r
             if pcd.DatumType not in [TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, TAB_VOID, "BOOLEAN"]:\r
-                if StructPattern.match(pcd.DatumType) is None:\r
-                    EdkLogger.error('build', FORMAT_INVALID, "DatumType only support BOOLEAN, UINT8, UINT16, UINT32, UINT64, VOID* or a valid struct name.", pcd.DefinitionPosition[0],pcd.DefinitionPosition[1])\r
-        for struct_pcd in Pcds.values():\r
-            if isinstance(struct_pcd,StructurePcd) and not struct_pcd.StructuredPcdIncludeFile:\r
-                EdkLogger.error("build", PCD_STRUCTURE_PCD_ERROR, "The structure Pcd %s.%s header file is not found in %s line %s \n" % (struct_pcd.TokenSpaceGuidCName, struct_pcd.TokenCName,struct_pcd.DefinitionPosition[0],struct_pcd.DefinitionPosition[1] ))\r
-\r
+                if not pcd.IsAggregateDatumType():\r
+                    EdkLogger.error('build', FORMAT_INVALID, "DatumType only support BOOLEAN, UINT8, UINT16, UINT32, UINT64, VOID* or a valid struct name.", DefinitionPosition[pcd][0], DefinitionPosition[pcd][1])\r
+                elif not pcd.IsArray() and not pcd.StructuredPcdIncludeFile:\r
+                    EdkLogger.error("build", PCD_STRUCTURE_PCD_ERROR, "The structure Pcd %s.%s header file is not found in %s line %s \n" % (pcd.TokenSpaceGuidCName, pcd.TokenCName, pcd.DefinitionPosition[0], pcd.DefinitionPosition[1] ))\r
         return Pcds\r
+\r
     @property\r
     def CommonIncludes(self):\r
         if self._CommonIncludes is None:\r
             self.Includes\r
         return self._CommonIncludes\r
-\r
-\r
-    _Macros = property(_GetMacros)\r
-    Arch = property(_GetArch, _SetArch)\r
-    PackageName = property(_GetPackageName)\r
-    Guid = property(_GetFileGuid)\r
-    Version = property(_GetVersion)\r
-\r
-    Protocols = property(_GetProtocol)\r
-    Ppis = property(_GetPpi)\r
-    Guids = property(_GetGuid)\r
-    Includes = property(_GetInclude)\r
-    LibraryClasses = property(_GetLibraryClass)\r
-    Pcds = property(_GetPcds)\r