2 # This file is used to define class objects of INF file [Depex] section.
3 # It will consumed by InfParser.
5 # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
7 # SPDX-License-Identifier: BSD-2-Clause-Patent
13 from Library
import DataType
as DT
14 from Library
import GlobalData
15 import Logger
.Log
as Logger
16 from Logger
import ToolError
17 from Logger
import StringTable
as ST
19 from Object
.Parser
.InfCommonObject
import InfSectionCommonDef
20 from Library
.ParserValidate
import IsValidArch
22 class InfDepexContentItem():
25 self
.SectionString
= ''
27 def SetSectionType(self
, SectionType
):
28 self
.SectionType
= SectionType
29 def GetSectionType(self
):
30 return self
.SectionType
32 def SetSectionString(self
, SectionString
):
33 self
.SectionString
= SectionString
34 def GetSectionString(self
):
35 return self
.SectionString
40 self
.DepexContent
= ''
44 self
.FeatureFlagExp
= ''
45 self
.InfDepexContentItemList
= []
47 def SetFeatureFlagExp(self
, FeatureFlagExp
):
48 self
.FeatureFlagExp
= FeatureFlagExp
49 def GetFeatureFlagExp(self
):
50 return self
.FeatureFlagExp
52 def SetSupArch(self
, Arch
):
57 def SetHelpString(self
, HelpString
):
58 self
.HelpString
= HelpString
59 def GetHelpString(self
):
60 return self
.HelpString
62 def SetModuleType(self
, Type
):
63 self
.ModuleType
= Type
64 def GetModuleType(self
):
65 return self
.ModuleType
67 def SetDepexConent(self
, Content
):
68 self
.DepexContent
= Content
69 def GetDepexContent(self
):
70 return self
.DepexContent
72 def SetInfDepexContentItemList(self
, InfDepexContentItemList
):
73 self
.InfDepexContentItemList
= InfDepexContentItemList
74 def GetInfDepexContentItemList(self
):
75 return self
.InfDepexContentItemList
81 class InfDepexObject(InfSectionCommonDef
):
85 self
.SectionContent
= ''
86 InfSectionCommonDef
.__init
__(self
)
88 def SetDepex(self
, DepexContent
, KeyList
=None, CommentList
=None):
89 for KeyItem
in KeyList
:
91 ModuleType
= KeyItem
[1]
92 InfDepexItemIns
= InfDepexItem()
97 if IsValidArch(Arch
.strip().upper()):
98 InfDepexItemIns
.SetSupArch(Arch
)
100 Logger
.Error("InfParser",
101 ToolError
.FORMAT_INVALID
,
102 ST
.ERR_INF_PARSER_DEFINE_NAME_INVALID
% (Arch
),
103 File
=GlobalData
.gINF_MODULE_NAME
,
107 # Validate Module Type
109 if ModuleType
and ModuleType
!= 'COMMON':
110 if ModuleType
in DT
.VALID_DEPEX_MODULE_TYPE_LIST
:
111 InfDepexItemIns
.SetModuleType(ModuleType
)
113 Logger
.Error("InfParser",
114 ToolError
.FORMAT_INVALID
,
115 ST
.ERR_INF_PARSER_DEPEX_SECTION_MODULE_TYPE_ERROR
% (ModuleType
),
116 File
=GlobalData
.gINF_MODULE_NAME
,
120 # Parser content in [Depex] section.
125 # Get Depex Expression
127 for Line
in DepexContent
:
128 LineContent
= Line
[0].strip()
129 if LineContent
.find(DT
.TAB_COMMENT_SPLIT
) > -1:
130 LineContent
= LineContent
[:LineContent
.find(DT
.TAB_COMMENT_SPLIT
)]
132 DepexString
= DepexString
+ LineContent
+ DT
.END_OF_LINE
135 if DepexString
.endswith(DT
.END_OF_LINE
):
136 DepexString
= DepexString
[:-1]
138 if not DepexString
.strip():
144 for HelpLine
in CommentList
:
145 HelpString
= HelpString
+ HelpLine
+ DT
.END_OF_LINE
146 if HelpString
.endswith(DT
.END_OF_LINE
):
147 HelpString
= HelpString
[:-1]
149 InfDepexItemIns
.SetDepexConent(DepexString
)
150 InfDepexItemIns
.SetHelpString(HelpString
)
152 self
.Depex
.append(InfDepexItemIns
)
159 def GetAllContent(self
):
160 return self
.AllContent