2 # process depex section generation
4 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
6 # SPDX-License-Identifier: BSD-2-Clause-Patent
12 from __future__
import absolute_import
14 from .GenFdsGlobalVariable
import GenFdsGlobalVariable
15 import Common
.LongFilePathOs
as os
16 from CommonDataClass
.FdfClass
import DepexSectionClassObject
17 from AutoGen
.GenDepex
import DependencyExpression
18 from Common
import EdkLogger
19 from Common
.BuildToolError
import *
20 from Common
.Misc
import PathClass
21 from Common
.DataType
import *
23 ## generate data section
26 class DepexSection (DepexSectionClassObject
):
29 # @param self The object pointer
32 DepexSectionClassObject
.__init
__(self
)
34 def __FindGuidValue(self
, CName
):
35 for Arch
in GenFdsGlobalVariable
.ArchList
:
36 PkgList
= GenFdsGlobalVariable
.WorkSpace
.GetPackageList(GenFdsGlobalVariable
.ActivePlatform
,
38 GenFdsGlobalVariable
.TargetName
,
39 GenFdsGlobalVariable
.ToolChainTag
)
40 for Inf
in GenFdsGlobalVariable
.FdfParser
.Profile
.InfList
:
41 ModuleData
= GenFdsGlobalVariable
.WorkSpace
.BuildObject
[
42 PathClass(Inf
, GenFdsGlobalVariable
.WorkSpaceDir
),
44 GenFdsGlobalVariable
.TargetName
,
45 GenFdsGlobalVariable
.ToolChainTag
47 for Pkg
in ModuleData
.Packages
:
48 if Pkg
not in PkgList
:
51 if CName
in PkgDb
.Ppis
:
52 return PkgDb
.Ppis
[CName
]
53 if CName
in PkgDb
.Protocols
:
54 return PkgDb
.Protocols
[CName
]
55 if CName
in PkgDb
.Guids
:
56 return PkgDb
.Guids
[CName
]
59 ## GenSection() method
61 # Generate compressed section
63 # @param self The object pointer
64 # @param OutputPath Where to place output file
65 # @param ModuleName Which module this section belongs to
66 # @param SecNum Index of section
67 # @param KeyStringList Filter for inputs of section generation
68 # @param FfsInf FfsInfStatement object that contains this section data
69 # @param Dict dictionary contains macro and its value
70 # @retval tuple (Generated file name list, section alignment)
72 def GenSection(self
, OutputPath
, ModuleName
, SecNum
, keyStringList
, FfsFile
= None, Dict
= None, IsMakefile
= False):
73 if self
.ExpressionProcessed
== False:
74 self
.Expression
= self
.Expression
.replace("\n", " ").replace("\r", " ")
75 ExpList
= self
.Expression
.split()
78 if Exp
.upper() not in ('AND', 'OR', 'NOT', 'TRUE', 'FALSE', 'SOR', 'BEFORE', 'AFTER', 'END'):
79 GuidStr
= self
.__FindGuidValue
(Exp
)
81 EdkLogger
.error("GenFds", RESOURCE_NOT_AVAILABLE
,
82 "Depex GUID %s could not be found in build DB! (ModuleName: %s)" % (Exp
, ModuleName
))
84 self
.Expression
= self
.Expression
.replace(Exp
, GuidStr
)
86 self
.Expression
= self
.Expression
.strip()
87 self
.ExpressionProcessed
= True
89 if self
.DepexType
== 'PEI_DEPEX_EXP':
90 ModuleType
= SUP_MODULE_PEIM
91 SecType
= BINARY_FILE_TYPE_PEI_DEPEX
92 elif self
.DepexType
== 'DXE_DEPEX_EXP':
93 ModuleType
= SUP_MODULE_DXE_DRIVER
94 SecType
= BINARY_FILE_TYPE_DXE_DEPEX
95 elif self
.DepexType
== 'SMM_DEPEX_EXP':
96 ModuleType
= SUP_MODULE_DXE_SMM_DRIVER
97 SecType
= BINARY_FILE_TYPE_SMM_DEPEX
99 EdkLogger
.error("GenFds", FORMAT_INVALID
,
100 "Depex type %s is not valid for module %s" % (self
.DepexType
, ModuleName
))
102 InputFile
= os
.path
.join (OutputPath
, ModuleName
+ SUP_MODULE_SEC
+ SecNum
+ '.depex')
103 InputFile
= os
.path
.normpath(InputFile
)
104 Depex
= DependencyExpression(self
.Expression
, ModuleType
)
105 Depex
.Generate(InputFile
)
107 OutputFile
= os
.path
.join (OutputPath
, ModuleName
+ SUP_MODULE_SEC
+ SecNum
+ '.dpx')
108 OutputFile
= os
.path
.normpath(OutputFile
)
110 GenFdsGlobalVariable
.GenerateSection(OutputFile
, [InputFile
], Section
.Section
.SectionType
.get (SecType
), IsMakefile
=IsMakefile
)
111 return [OutputFile
], self
.Alignment