]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/DepexSection.py
BaseTools: remove redundant if comparison
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / DepexSection.py
1 ## @file
2 # process depex section generation
3 #
4 # Copyright (c) 2007 - 2018, 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 Common.LongFilePathOs as os
23 from CommonDataClass.FdfClass import DepexSectionClassObject
24 from AutoGen.GenDepex import DependencyExpression
25 from Common import EdkLogger
26 from Common.BuildToolError import *
27 from Common.Misc import PathClass
28 from Common.DataType import *
29
30 ## generate data section
31 #
32 #
33 class DepexSection (DepexSectionClassObject):
34 ## The constructor
35 #
36 # @param self The object pointer
37 #
38 def __init__(self):
39 DepexSectionClassObject.__init__(self)
40
41 def __FindGuidValue(self, CName):
42 for Arch in GenFdsGlobalVariable.ArchList:
43 PkgList = GenFdsGlobalVariable.WorkSpace.GetPackageList(GenFdsGlobalVariable.ActivePlatform,
44 Arch,
45 GenFdsGlobalVariable.TargetName,
46 GenFdsGlobalVariable.ToolChainTag)
47 for Inf in GenFdsGlobalVariable.FdfParser.Profile.InfList:
48 ModuleFile = PathClass(Inf, GenFdsGlobalVariable.WorkSpaceDir)
49 ModuleData = GenFdsGlobalVariable.WorkSpace.BuildObject[
50 ModuleFile,
51 Arch,
52 GenFdsGlobalVariable.TargetName,
53 GenFdsGlobalVariable.ToolChainTag
54 ]
55 for Pkg in ModuleData.Packages:
56 if Pkg not in PkgList:
57 PkgList.append(Pkg)
58 for PkgDb in PkgList:
59 if CName in PkgDb.Ppis:
60 return PkgDb.Ppis[CName]
61 if CName in PkgDb.Protocols:
62 return PkgDb.Protocols[CName]
63 if CName in PkgDb.Guids:
64 return PkgDb.Guids[CName]
65 return None
66
67 ## GenSection() method
68 #
69 # Generate compressed section
70 #
71 # @param self The object pointer
72 # @param OutputPath Where to place output file
73 # @param ModuleName Which module this section belongs to
74 # @param SecNum Index of section
75 # @param KeyStringList Filter for inputs of section generation
76 # @param FfsInf FfsInfStatement object that contains this section data
77 # @param Dict dictionary contains macro and its value
78 # @retval tuple (Generated file name list, section alignment)
79 #
80 def GenSection(self, OutputPath, ModuleName, SecNum, keyStringList, FfsFile = None, Dict = None, IsMakefile = False):
81 if self.ExpressionProcessed == False:
82 self.Expression = self.Expression.replace("\n", " ").replace("\r", " ")
83 ExpList = self.Expression.split()
84
85 for Exp in ExpList:
86 if Exp.upper() not in ('AND', 'OR', 'NOT', 'TRUE', 'FALSE', 'SOR', 'BEFORE', 'AFTER', 'END'):
87 GuidStr = self.__FindGuidValue(Exp)
88 if GuidStr is None:
89 EdkLogger.error("GenFds", RESOURCE_NOT_AVAILABLE,
90 "Depex GUID %s could not be found in build DB! (ModuleName: %s)" % (Exp, ModuleName))
91
92 self.Expression = self.Expression.replace(Exp, GuidStr)
93
94 self.Expression = self.Expression.strip()
95 self.ExpressionProcessed = True
96
97 if self.DepexType == 'PEI_DEPEX_EXP':
98 ModuleType = SUP_MODULE_PEIM
99 SecType = BINARY_FILE_TYPE_PEI_DEPEX
100 elif self.DepexType == 'DXE_DEPEX_EXP':
101 ModuleType = SUP_MODULE_DXE_DRIVER
102 SecType = BINARY_FILE_TYPE_DXE_DEPEX
103 elif self.DepexType == 'SMM_DEPEX_EXP':
104 ModuleType = SUP_MODULE_DXE_SMM_DRIVER
105 SecType = BINARY_FILE_TYPE_SMM_DEPEX
106 else:
107 EdkLogger.error("GenFds", FORMAT_INVALID,
108 "Depex type %s is not valid for module %s" % (self.DepexType, ModuleName))
109
110 InputFile = os.path.join (OutputPath, ModuleName + SUP_MODULE_SEC + SecNum + '.depex')
111 InputFile = os.path.normpath(InputFile)
112 Depex = DependencyExpression(self.Expression, ModuleType)
113 Depex.Generate(InputFile)
114
115 OutputFile = os.path.join (OutputPath, ModuleName + SUP_MODULE_SEC + SecNum + '.dpx')
116 OutputFile = os.path.normpath(OutputFile)
117
118 GenFdsGlobalVariable.GenerateSection(OutputFile, [InputFile], Section.Section.SectionType.get (SecType), IsMakefile=IsMakefile)
119 return [OutputFile], self.Alignment