]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/DepexSection.py
1c8c82a72e5b8ea90be5f28938c0ce01bcd6d190
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / DepexSection.py
1 ## @file
2 # process depex section generation
3 #
4 # Copyright (c) 2007, Intel Corporation
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are licensed and made available under the terms and conditions of the BSD License
8 # which accompanies this distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
10 #
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 #
14
15 ##
16 # Import Modules
17 #
18 import Section
19 from GenFdsGlobalVariable import GenFdsGlobalVariable
20 import subprocess
21 from Ffs import Ffs
22 import os
23 from CommonDataClass.FdfClass import DepexSectionClassObject
24 from AutoGen.GenDepex import DependencyExpression
25 import shutil
26 from Common import EdkLogger
27 from Common.BuildToolError import *
28
29 ## generate data section
30 #
31 #
32 class DepexSection (DepexSectionClassObject):
33 ## The constructor
34 #
35 # @param self The object pointer
36 #
37 def __init__(self):
38 DepexSectionClassObject.__init__(self)
39
40 def __FindGuidValue(self, CName):
41 for Arch in GenFdsGlobalVariable.ArchList:
42 for PkgDb in GenFdsGlobalVariable.WorkSpace.PackageList:
43 if CName in PkgDb.Ppis:
44 return PkgDb.Ppis[CName]
45 if CName in PkgDb.Protocols:
46 return PkgDb.Protocols[CName]
47 if CName in PkgDb.Guids:
48 return PkgDb.Guids[CName]
49 return None
50
51 ## GenSection() method
52 #
53 # Generate compressed section
54 #
55 # @param self The object pointer
56 # @param OutputPath Where to place output file
57 # @param ModuleName Which module this section belongs to
58 # @param SecNum Index of section
59 # @param KeyStringList Filter for inputs of section generation
60 # @param FfsInf FfsInfStatement object that contains this section data
61 # @param Dict dictionary contains macro and its value
62 # @retval tuple (Generated file name list, section alignment)
63 #
64 def GenSection(self, OutputPath, ModuleName, SecNum, keyStringList, FfsFile = None, Dict = {}):
65
66 self.Expression = self.Expression.replace("\n", " ").replace("\r", " ")
67 ExpList = self.Expression.split()
68 ExpGuidDict = {}
69
70 for Exp in ExpList:
71 if Exp.upper() not in ('AND', 'OR', 'NOT', 'TRUE', 'FALSE', 'SOR', 'BEFORE', 'AFTER', 'END'):
72 GuidStr = self.__FindGuidValue(Exp)
73 if GuidStr == None:
74 EdkLogger.error("GenFds", RESOURCE_NOT_AVAILABLE,
75 "Depex GUID %s could not be found in build DB! (ModuleName: %s)" % (Exp, ModuleName))
76
77 ExpGuidDict[Exp] = GuidStr
78
79 for Item in ExpGuidDict:
80 self.Expression = self.Expression.replace(Item, ExpGuidDict[Item])
81
82 self.Expression = self.Expression.strip()
83 ModuleType = (self.DepexType.startswith('PEI') and ['PEIM'] or ['DXE_DRIVER'])[0]
84 if self.DepexType.startswith('SMM'):
85 ModuleType = 'SMM_DRIVER'
86 InputFile = os.path.join (OutputPath, ModuleName + 'SEC' + SecNum + '.dpx')
87 InputFile = os.path.normpath(InputFile)
88
89 Dpx = DependencyExpression(self.Expression, ModuleType)
90 Dpx.Generate(InputFile)
91
92 OutputFile = os.path.join (OutputPath, ModuleName + 'SEC' + SecNum + '.depex')
93 if self.DepexType.startswith('SMM'):
94 OutputFile = os.path.join (OutputPath, ModuleName + 'SEC' + SecNum + '.smm')
95 OutputFile = os.path.normpath(OutputFile)
96 SecType = (self.DepexType.startswith('PEI') and ['PEI_DEPEX'] or ['DXE_DEPEX'])[0]
97 if self.DepexType.startswith('SMM'):
98 SecType = 'SMM_DEPEX'
99
100 GenFdsGlobalVariable.GenerateSection(OutputFile, [InputFile], Section.Section.SectionType.get (SecType))
101 FileList = [OutputFile]
102 return FileList, self.Alignment