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