]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/DepexSection.py
Sync BaseTools Trunk (version r2387) to EDKII main trunk.
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / DepexSection.py
1 ## @file
2 # process depex section generation
3 #
4 # Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>
5 #
6 # 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.GetPackageList(GenFdsGlobalVariable.ActivePlatform,
43 Arch,
44 GenFdsGlobalVariable.TargetName,
45 GenFdsGlobalVariable.ToolChainTag):
46 if CName in PkgDb.Ppis:
47 return PkgDb.Ppis[CName]
48 if CName in PkgDb.Protocols:
49 return PkgDb.Protocols[CName]
50 if CName in PkgDb.Guids:
51 return PkgDb.Guids[CName]
52 return None
53
54 ## GenSection() method
55 #
56 # Generate compressed section
57 #
58 # @param self The object pointer
59 # @param OutputPath Where to place output file
60 # @param ModuleName Which module this section belongs to
61 # @param SecNum Index of section
62 # @param KeyStringList Filter for inputs of section generation
63 # @param FfsInf FfsInfStatement object that contains this section data
64 # @param Dict dictionary contains macro and its value
65 # @retval tuple (Generated file name list, section alignment)
66 #
67 def GenSection(self, OutputPath, ModuleName, SecNum, keyStringList, FfsFile = None, Dict = {}):
68
69 if self.ExpressionProcessed == False:
70 self.Expression = self.Expression.replace("\n", " ").replace("\r", " ")
71 ExpList = self.Expression.split()
72 ExpGuidDict = {}
73
74 for Exp in ExpList:
75 if Exp.upper() not in ('AND', 'OR', 'NOT', 'TRUE', 'FALSE', 'SOR', 'BEFORE', 'AFTER', 'END'):
76 GuidStr = self.__FindGuidValue(Exp)
77 if GuidStr == None:
78 EdkLogger.error("GenFds", RESOURCE_NOT_AVAILABLE,
79 "Depex GUID %s could not be found in build DB! (ModuleName: %s)" % (Exp, ModuleName))
80
81 ExpGuidDict[Exp] = GuidStr
82
83 for Item in ExpGuidDict:
84 self.Expression = self.Expression.replace(Item, ExpGuidDict[Item])
85
86 self.Expression = self.Expression.strip()
87 self.ExpressionProcessed = True
88
89 if self.DepexType == 'PEI_DEPEX_EXP':
90 ModuleType = 'PEIM'
91 SecType = 'PEI_DEPEX'
92 elif self.DepexType == 'DXE_DEPEX_EXP':
93 ModuleType = 'DXE_DRIVER'
94 SecType = 'DXE_DEPEX'
95 elif self.DepexType == 'SMM_DEPEX_EXP':
96 ModuleType = 'DXE_SMM_DRIVER'
97 SecType = 'SMM_DEPEX'
98 else:
99 EdkLogger.error("GenFds", FORMAT_INVALID,
100 "Depex type %s is not valid for module %s" % (self.DepexType, ModuleName))
101
102 InputFile = os.path.join (OutputPath, ModuleName + 'SEC' + SecNum + '.depex')
103 InputFile = os.path.normpath(InputFile)
104 Depex = DependencyExpression(self.Expression, ModuleType)
105 Depex.Generate(InputFile)
106
107 OutputFile = os.path.join (OutputPath, ModuleName + 'SEC' + SecNum + '.dpx')
108 OutputFile = os.path.normpath(OutputFile)
109
110 GenFdsGlobalVariable.GenerateSection(OutputFile, [InputFile], Section.Section.SectionType.get (SecType))
111 FileList = [OutputFile]
112 return FileList, self.Alignment