DEPEX section generation initial check-in.
authorjlin16 <jlin16@7335b38e-4728-0410-8992-fb3ffe349368>
Wed, 2 Jan 2008 09:18:09 +0000 (09:18 +0000)
committerjlin16 <jlin16@7335b38e-4728-0410-8992-fb3ffe349368>
Wed, 2 Jan 2008 09:18:09 +0000 (09:18 +0000)
git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@940 7335b38e-4728-0410-8992-fb3ffe349368

Source/Python/CommonDataClass/FdfClassObject.py
Source/Python/GenFds/DepexSection.py [new file with mode: 0644]
Source/Python/GenFds/FdfParser.py

index 01a24f4..e82ea46 100644 (file)
@@ -156,6 +156,18 @@ class SectionClassObject:
     def __init__(self):\r
         self.Alignment = None\r
         \r
+## Depex expression section in FDF\r
+#\r
+#        \r
+class DepexSectionClassObject (SectionClassObject):\r
+    ## The constructor\r
+    #\r
+    #   @param  self        The object pointer\r
+    #\r
+    def __init__(self):\r
+        self.DepexType = None\r
+        self.Expression = None\r
+\r
 ## Compress section data in FDF\r
 #\r
 #\r
diff --git a/Source/Python/GenFds/DepexSection.py b/Source/Python/GenFds/DepexSection.py
new file mode 100644 (file)
index 0000000..d74bc86
--- /dev/null
@@ -0,0 +1,105 @@
+## @file\r
+# process depex section generation\r
+#\r
+#  Copyright (c) 2007, Intel Corporation\r
+#\r
+#  All rights reserved. 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
+#\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
+##\r
+# Import Modules\r
+#\r
+import Section\r
+from GenFdsGlobalVariable import GenFdsGlobalVariable\r
+import subprocess\r
+from Ffs import Ffs\r
+import os\r
+from CommonDataClass.FdfClassObject import DepexSectionClassObject\r
+from AutoGen.GenDepex import DependencyExpression\r
+import shutil\r
+\r
+## generate data section\r
+#\r
+#\r
+class DepexSection (DepexSectionClassObject):\r
+    ## The constructor\r
+    #\r
+    #   @param  self        The object pointer\r
+    #\r
+    def __init__(self):\r
+        DepexSectionClassObject.__init__(self)\r
+    \r
+    def __FindGuidValue(self, CName):\r
+        for Arch in GenFdsGlobalVariable.ArchList:\r
+            for PkgDb in GenFdsGlobalVariable.WorkSpace.Build[Arch].PackageDatabase.values():\r
+                if CName in PkgDb.Ppis:\r
+                    return PkgDb.Ppis[CName]\r
+                if CName in PkgDb.Protocols:\r
+                    return PkgDb.Protocols[CName]\r
+                if CName in PkgDb.Guids:\r
+                    return PkgDb.Guids[CName]\r
+        return None\r
+    \r
+    ## GenSection() method\r
+    #\r
+    #   Generate compressed section\r
+    #\r
+    #   @param  self        The object pointer\r
+    #   @param  OutputPath  Where to place output file\r
+    #   @param  ModuleName  Which module this section belongs to\r
+    #   @param  SecNum      Index of section\r
+    #   @param  KeyStringList  Filter for inputs of section generation\r
+    #   @param  FfsInf      FfsInfStatement object that contains this section data\r
+    #   @param  Dict        dictionary contains macro and its value\r
+    #   @retval tuple       (Generated file name list, section alignment)\r
+    #    \r
+    def GenSection(self, OutputPath, ModuleName, SecNum, keyStringList, FfsFile = None, Dict = {}):\r
+        \r
+        self.Expression = self.Expression.replace("\n", " ").replace("\r", " ")\r
+        ExpList = self.Expression.split()\r
+        ExpGuidDict = {}\r
+        \r
+        for Exp in ExpList:\r
+            if Exp.upper() not in ('AND', 'OR', 'NOT', 'TRUE', 'FALSE', 'SOR', 'BEFORE', 'AFTER', 'END'):\r
+                GuidStr = self.__FindGuidValue(Exp)\r
+                if GuidStr == None:\r
+                    raise Exception ("Depex GUID %s could not be found in build DB! (ModuleName: %s)" % (Exp, ModuleName))\r
+                    sys.exit(1)\r
+                    \r
+                ExpGuidDict[Exp] = GuidStr\r
+                \r
+        for Item in ExpGuidDict:\r
+            self.Expression = self.Expression.replace(Item, ExpGuidDict[Item])\r
+            \r
+        self.Expression = self.Expression.strip()\r
+        ModuleType = (self.DepexType.startswith('PEI') and ['PEIM'] or ['DXE_DRIVER'])[0]\r
+        InputFile = os.path.join (OutputPath, ModuleName + 'SEC' + SecNum + '.dpx')\r
+        InputFile = os.path.normpath(InputFile)\r
+        \r
+        Dpx = DependencyExpression(self.Expression, ModuleType)\r
+        Dpx.Generate(InputFile)\r
+        \r
+        OutputFile = os.path.join (OutputPath, ModuleName + 'SEC' + SecNum + '.depex')\r
+        OutputFile = os.path.normpath(OutputFile)\r
+        SecType = (self.DepexType.startswith('PEI') and ['PEI_DEPEX'] or ['DXE_DEPEX'])[0]\r
+        \r
+        GenSectionCmd = (\r
+            'GenSec',\r
+             '-o', OutputFile,\r
+             '-s', Section.Section.SectionType.get (SecType),\r
+             InputFile,\r
+            )\r
+                         \r
+        #\r
+        # Call GenSection\r
+        #\r
+        \r
+        GenFdsGlobalVariable.CallExternalTool(GenSectionCmd, "GenSection Failed!")\r
+        FileList = [OutputFile]\r
+        return FileList, self.Alignment\r
index 8bb21fa..6141dd5 100644 (file)
@@ -25,6 +25,7 @@ import VerSection
 import UiSection\r
 import FvImageSection\r
 import DataSection\r
+import DepexSection\r
 import CompressSection\r
 import GuidSection\r
 import Capsule\r
@@ -1791,6 +1792,21 @@ class FdfParser:
                 \r
             Obj.SectionList.append(FvImageSectionObj) \r
            \r
+        elif self.__IsKeyword("PEI_DEPEX_EXP") or self.__IsKeyword("DXE_DEPEX_EXP"):\r
+            DepexSectionObj = DepexSection.DepexSection()\r
+            DepexSectionObj.Alignment = AlignValue\r
+            DepexSectionObj.DepexType = self.__Token\r
+            \r
+            if not self.__IsToken( "="):\r
+                raise Warning("expected '=' At Line %d" % self.CurrentLineNumber, self.FileName, self.CurrentLineNumber)\r
+            if not self.__IsToken( "{"):\r
+                raise Warning("expected '{' At Line %d" % self.CurrentLineNumber, self.FileName, self.CurrentLineNumber)\r
+            if not self.__SkipToToken( "}"):\r
+                raise Warning("expected Depex expression ending '}' At Line %d" % self.CurrentLineNumber, self.FileName, self.CurrentLineNumber)\r
+            \r
+            DepexSectionObj.Expression = self.__SkippedChars.rstrip('}')\r
+            Obj.SectionList.append(DepexSectionObj)\r
+        \r
         else:\r
             \r
             if not self.__GetNextWord():\r