2 # This file is used to define class objects of INF file [Depex] section.
3 # It will consumed by InfParser.
5 # Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
7 # This program and the accompanying materials are licensed and made available
8 # under the terms and conditions of the BSD License which accompanies this
9 # distribution. The full text of the license may be found at
10 # http://opensource.org/licenses/bsd-license.php
12 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 from Library
import DataType
as DT
20 from Library
import GlobalData
21 import Logger
.Log
as Logger
22 from Logger
import ToolError
23 from Logger
import StringTable
as ST
25 from Object
.Parser
.InfCommonObject
import InfSectionCommonDef
26 from Library
.ParserValidate
import IsValidArch
28 class InfDepexContentItem():
31 self
.SectionString
= ''
33 def SetSectionType(self
, SectionType
):
34 self
.SectionType
= SectionType
35 def GetSectionType(self
):
36 return self
.SectionType
38 def SetSectionString(self
, SectionString
):
39 self
.SectionString
= SectionString
40 def GetSectionString(self
):
41 return self
.SectionString
46 self
.DepexContent
= ''
50 self
.FeatureFlagExp
= ''
51 self
.InfDepexContentItemList
= []
53 def SetFeatureFlagExp(self
, FeatureFlagExp
):
54 self
.FeatureFlagExp
= FeatureFlagExp
55 def GetFeatureFlagExp(self
):
56 return self
.FeatureFlagExp
58 def SetSupArch(self
, Arch
):
63 def SetHelpString(self
, HelpString
):
64 self
.HelpString
= HelpString
65 def GetHelpString(self
):
66 return self
.HelpString
68 def SetModuleType(self
, Type
):
69 self
.ModuleType
= Type
70 def GetModuleType(self
):
71 return self
.ModuleType
73 def SetDepexConent(self
, Content
):
74 self
.DepexContent
= Content
75 def GetDepexContent(self
):
76 return self
.DepexContent
78 def SetInfDepexContentItemList(self
, InfDepexContentItemList
):
79 self
.InfDepexContentItemList
= InfDepexContentItemList
80 def GetInfDepexContentItemList(self
):
81 return self
.InfDepexContentItemList
87 class InfDepexObject(InfSectionCommonDef
):
91 self
.SectionContent
= ''
92 InfSectionCommonDef
.__init
__(self
)
94 def SetDepex(self
, DepexContent
, KeyList
=None, CommentList
=None):
95 for KeyItem
in KeyList
:
97 ModuleType
= KeyItem
[1]
98 InfDepexItemIns
= InfDepexItem()
103 if IsValidArch(Arch
.strip().upper()):
104 InfDepexItemIns
.SetSupArch(Arch
)
106 Logger
.Error("InfParser",
107 ToolError
.FORMAT_INVALID
,
108 ST
.ERR_INF_PARSER_DEFINE_NAME_INVALID
% (Arch
),
109 File
=GlobalData
.gINF_MODULE_NAME
,
113 # Validate Module Type
115 if ModuleType
and ModuleType
!= 'COMMON':
116 if ModuleType
in DT
.VALID_DEPEX_MODULE_TYPE_LIST
:
117 InfDepexItemIns
.SetModuleType(ModuleType
)
119 Logger
.Error("InfParser",
120 ToolError
.FORMAT_INVALID
,
121 ST
.ERR_INF_PARSER_DEPEX_SECTION_MODULE_TYPE_ERROR
% (ModuleType
),
122 File
=GlobalData
.gINF_MODULE_NAME
,
126 # Parser content in [Depex] section.
131 # Get Depex Expression
133 for Line
in DepexContent
:
134 LineContent
= Line
[0].strip()
135 if LineContent
.find(DT
.TAB_COMMENT_SPLIT
) > -1:
136 LineContent
= LineContent
[:LineContent
.find(DT
.TAB_COMMENT_SPLIT
)]
138 DepexString
= DepexString
+ LineContent
+ DT
.END_OF_LINE
141 if DepexString
.endswith(DT
.END_OF_LINE
):
142 DepexString
= DepexString
[:-1]
144 if not DepexString
.strip():
150 for HelpLine
in CommentList
:
151 HelpString
= HelpString
+ HelpLine
+ DT
.END_OF_LINE
152 if HelpString
.endswith(DT
.END_OF_LINE
):
153 HelpString
= HelpString
[:-1]
155 InfDepexItemIns
.SetDepexConent(DepexString
)
156 InfDepexItemIns
.SetHelpString(HelpString
)
158 self
.Depex
.append(InfDepexItemIns
)
165 def GetAllContent(self
):
166 return self
.AllContent