]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Scripts/PackageDocumentTools/plugins/EdkPlugins/edk2/model/dec.py
BaseTools: Add PackageDocumentTools into Scripts folder
[mirror_edk2.git] / BaseTools / Scripts / PackageDocumentTools / plugins / EdkPlugins / edk2 / model / dec.py
diff --git a/BaseTools/Scripts/PackageDocumentTools/plugins/EdkPlugins/edk2/model/dec.py b/BaseTools/Scripts/PackageDocumentTools/plugins/EdkPlugins/edk2/model/dec.py
new file mode 100644 (file)
index 0000000..3bd0b7b
--- /dev/null
@@ -0,0 +1,319 @@
+## @file\r
+#\r
+# Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials are licensed and made available\r
+# under the terms and conditions of the BSD License which accompanies this\r
+# distribution. The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\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
+\r
+import plugins.EdkPlugins.basemodel.ini as ini\r
+import re, os\r
+from plugins.EdkPlugins.basemodel.message import *\r
+\r
+class DECFile(ini.BaseINIFile):\r
+\r
+    def GetSectionInstance(self, parent, name, isCombined=False):\r
+        return DECSection(parent, name, isCombined)\r
+\r
+    def GetComponents(self):\r
+        return self.GetSectionByName('Components')\r
+\r
+    def GetPackageRootPath(self):\r
+        return os.path.dirname(self.GetFilename()).strip()\r
+\r
+    def GetBaseName(self):\r
+        return self.GetDefine("PACKAGE_NAME").strip()\r
+\r
+    def GetVersion(self):\r
+        return self.GetDefine("PACKAGE_VERSION").strip()\r
+\r
+    def GetSectionObjectsByName(self, name, arch=None):\r
+        arr = []\r
+        sects = self.GetSectionByName(name)\r
+        for sect in sects:\r
+            # skip unmatched archtecture content\r
+            if not sect.IsArchMatch(arch):\r
+                continue\r
+\r
+            for obj in sect.GetObjects():\r
+                arr.append(obj)\r
+\r
+        return arr\r
+\r
+class DECSection(ini.BaseINISection):\r
+    def GetSectionINIObject(self, parent):\r
+        type = self.GetType()\r
+\r
+        if type.lower().find('defines') != -1:\r
+            return DECDefineSectionObject(self)\r
+        if type.lower().find('includes') != -1:\r
+            return DECIncludeObject(self)\r
+        if type.lower().find('pcd') != -1:\r
+            return DECPcdObject(self)\r
+        if type.lower() == 'libraryclasses':\r
+            return DECLibraryClassObject(self)\r
+        if type.lower() == 'guids':\r
+            return DECGuidObject(self)\r
+        if type.lower() == 'ppis':\r
+            return DECPpiObject(self)\r
+        if type.lower() == 'protocols':\r
+            return DECProtocolObject(self)\r
+\r
+        return DECSectionObject(self)\r
+\r
+    def GetType(self):\r
+        arr = self._name.split('.')\r
+        return arr[0].strip()\r
+\r
+    def GetArch(self):\r
+        arr = self._name.split('.')\r
+        if len(arr) == 1:\r
+            return 'common'\r
+        return arr[1]\r
+\r
+    def IsArchMatch(self, arch):\r
+        if arch == None or self.GetArch() == 'common':\r
+            return True\r
+\r
+        if self.GetArch().lower() != arch.lower():\r
+            return False\r
+\r
+        return True\r
+\r
+class DECSectionObject(ini.BaseINISectionObject):\r
+    def GetArch(self):\r
+        return self.GetParent().GetArch()\r
+\r
+class DECDefineSectionObject(DECSectionObject):\r
+    def __init__(self, parent):\r
+        DECSectionObject.__init__(self, parent)\r
+        self._key = None\r
+        self._value = None\r
+\r
+    def Parse(self):\r
+        assert (self._start == self._end), 'The object in define section must be in single line'\r
+\r
+        line = self.GetLineByOffset(self._start).strip()\r
+\r
+        line = line.split('#')[0]\r
+        arr  = line.split('=')\r
+        if len(arr) != 2:\r
+            ErrorMsg('Invalid define section object',\r
+                   self.GetFilename(),\r
+                   self.GetParent().GetName()\r
+                   )\r
+            return False\r
+\r
+        self._key   = arr[0].strip()\r
+        self._value = arr[1].strip()\r
+\r
+        return True\r
+\r
+    def GetKey(self):\r
+        return self._key\r
+\r
+    def GetValue(self):\r
+        return self._value\r
+\r
+class DECGuidObject(DECSectionObject):\r
+    _objs = {}\r
+\r
+    def __init__(self, parent):\r
+        DECSectionObject.__init__(self, parent)\r
+        self._name = None\r
+\r
+    def Parse(self):\r
+        line = self.GetLineByOffset(self._start).strip().split('#')[0]\r
+        self._name = line.split('=')[0].strip()\r
+        self._guid = line.split('=')[1].strip()\r
+        objdict = DECGuidObject._objs\r
+        if self._name not in objdict.keys():\r
+            objdict[self._name] = [self]\r
+        else:\r
+            objdict[self._name].append(self)\r
+\r
+        return True\r
+\r
+    def GetName(self):\r
+        return self._name\r
+\r
+    def GetGuid(self):\r
+        return self._guid\r
+\r
+    def Destroy(self):\r
+        objdict = DECGuidObject._objs\r
+        objdict[self._name].remove(self)\r
+        if len(objdict[self._name]) == 0:\r
+            del objdict[self._name]\r
+\r
+    @staticmethod\r
+    def GetObjectDict():\r
+        return DECGuidObject._objs\r
+\r
+class DECPpiObject(DECSectionObject):\r
+    _objs = {}\r
+    def __init__(self, parent):\r
+        DECSectionObject.__init__(self, parent)\r
+        self._name = None\r
+\r
+    def Parse(self):\r
+        line = self.GetLineByOffset(self._start).strip().split('#')[0]\r
+        self._name = line.split('=')[0].strip()\r
+        self._guid = line.split('=')[1].strip()\r
+        objdict = DECPpiObject._objs\r
+        if self._name not in objdict.keys():\r
+            objdict[self._name] = [self]\r
+        else:\r
+            objdict[self._name].append(self)\r
+\r
+        return True\r
+\r
+    def GetName(self):\r
+        return self._name\r
+\r
+    def GetGuid(self):\r
+        return self._guid\r
+\r
+    def Destroy(self):\r
+        objdict = DECPpiObject._objs\r
+        objdict[self._name].remove(self)\r
+        if len(objdict[self._name]) == 0:\r
+            del objdict[self._name]\r
+\r
+    @staticmethod\r
+    def GetObjectDict():\r
+        return DECPpiObject._objs\r
+\r
+class DECProtocolObject(DECSectionObject):\r
+    _objs = {}\r
+\r
+    def __init__(self, parent):\r
+        DECSectionObject.__init__(self, parent)\r
+        self._name = None\r
+\r
+    def Parse(self):\r
+        line = self.GetLineByOffset(self._start).strip().split('#')[0]\r
+        self._name = line.split('=')[0].strip()\r
+        self._guid = line.split('=')[1].strip()\r
+        objdict = DECProtocolObject._objs\r
+        if self._name not in objdict.keys():\r
+            objdict[self._name] = [self]\r
+        else:\r
+            objdict[self._name].append(self)\r
+\r
+        return True\r
+\r
+    def GetName(self):\r
+        return self._name\r
+\r
+    def GetGuid(self):\r
+        return self._guid\r
+\r
+    def Destroy(self):\r
+        objdict = DECProtocolObject._objs\r
+        objdict[self._name].remove(self)\r
+        if len(objdict[self._name]) == 0:\r
+            del objdict[self._name]\r
+\r
+\r
+    @staticmethod\r
+    def GetObjectDict():\r
+        return DECProtocolObject._objs\r
+\r
+class DECLibraryClassObject(DECSectionObject):\r
+    _objs = {}\r
+\r
+    def __init__(self, parent):\r
+        DECSectionObject.__init__(self, parent)\r
+        self.mClassName = None\r
+        self.mHeaderFile = None\r
+\r
+    def Parse(self):\r
+        line = self.GetLineByOffset(self._start).strip().split('#')[0]\r
+        self.mClassName, self.mHeaderFile = line.split('|')\r
+        objdict = DECLibraryClassObject._objs\r
+        if self.mClassName not in objdict.keys():\r
+            objdict[self.mClassName] = [self]\r
+        else:\r
+            objdict[self.mClassName].append(self)\r
+        return True\r
+\r
+    def GetClassName(self):\r
+        return self.mClassName\r
+\r
+    def GetName(self):\r
+        return self.mClassName\r
+\r
+    def GetHeaderFile(self):\r
+        return self.mHeaderFile\r
+\r
+    def Destroy(self):\r
+        objdict = DECLibraryClassObject._objs\r
+        objdict[self.mClassName].remove(self)\r
+        if len(objdict[self.mClassName]) == 0:\r
+            del objdict[self.mClassName]\r
+\r
+    @staticmethod\r
+    def GetObjectDict():\r
+        return DECLibraryClassObject._objs\r
+\r
+class DECIncludeObject(DECSectionObject):\r
+    def __init__(self, parent):\r
+        DECSectionObject.__init__(self, parent)\r
+\r
+    def GetPath(self):\r
+        return self.GetLineByOffset(self._start).split('#')[0].strip()\r
+\r
+class DECPcdObject(DECSectionObject):\r
+    _objs = {}\r
+\r
+    def __init__(self, parent):\r
+        DECSectionObject.__init__(self, parent)\r
+        self.mPcdName           = None\r
+        self.mPcdDefaultValue   = None\r
+        self.mPcdDataType       = None\r
+        self.mPcdToken          = None\r
+\r
+    def Parse(self):\r
+        line = self.GetLineByOffset(self._start).strip().split('#')[0]\r
+        (self.mPcdName, self.mPcdDefaultValue, self.mPcdDataType, self.mPcdToken) = line.split('|')\r
+        objdict = DECPcdObject._objs\r
+        if self.mPcdName not in objdict.keys():\r
+            objdict[self.mPcdName] = [self]\r
+        else:\r
+            objdict[self.mPcdName].append(self)\r
+\r
+        return True\r
+\r
+    def Destroy(self):\r
+        objdict = DECPcdObject._objs\r
+        objdict[self.mPcdName].remove(self)\r
+        if len(objdict[self.mPcdName]) == 0:\r
+            del objdict[self.mPcdName]\r
+\r
+    def GetPcdType(self):\r
+        return self.GetParent().GetType()\r
+\r
+    def GetPcdName(self):\r
+        return self.mPcdName\r
+\r
+    def GetPcdValue(self):\r
+        return self.mPcdDefaultValue\r
+\r
+    def GetPcdDataType(self):\r
+        return self.mPcdDataType\r
+\r
+    def GetPcdToken(self):\r
+        return self.mPcdToken\r
+\r
+    def GetName(self):\r
+        return self.GetPcdName().split('.')[1]\r
+\r
+    @staticmethod\r
+    def GetObjectDict():\r
+        return DECPcdObject._objs\r