]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/UPT/Object/Parser/InfDepexObject.py
BaseTools: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / BaseTools / Source / Python / UPT / Object / Parser / InfDepexObject.py
1 ## @file
2 # This file is used to define class objects of INF file [Depex] section.
3 # It will consumed by InfParser.
4 #
5 # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
6 #
7 # SPDX-License-Identifier: BSD-2-Clause-Patent
8
9 '''
10 InfDepexObject
11 '''
12
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
18
19 from Object.Parser.InfCommonObject import InfSectionCommonDef
20 from Library.ParserValidate import IsValidArch
21
22 class InfDepexContentItem():
23 def __init__(self):
24 self.SectionType = ''
25 self.SectionString = ''
26
27 def SetSectionType(self, SectionType):
28 self.SectionType = SectionType
29 def GetSectionType(self):
30 return self.SectionType
31
32 def SetSectionString(self, SectionString):
33 self.SectionString = SectionString
34 def GetSectionString(self):
35 return self.SectionString
36
37
38 class InfDepexItem():
39 def __init__(self):
40 self.DepexContent = ''
41 self.ModuleType = ''
42 self.SupArch = ''
43 self.HelpString = ''
44 self.FeatureFlagExp = ''
45 self.InfDepexContentItemList = []
46
47 def SetFeatureFlagExp(self, FeatureFlagExp):
48 self.FeatureFlagExp = FeatureFlagExp
49 def GetFeatureFlagExp(self):
50 return self.FeatureFlagExp
51
52 def SetSupArch(self, Arch):
53 self.SupArch = Arch
54 def GetSupArch(self):
55 return self.SupArch
56
57 def SetHelpString(self, HelpString):
58 self.HelpString = HelpString
59 def GetHelpString(self):
60 return self.HelpString
61
62 def SetModuleType(self, Type):
63 self.ModuleType = Type
64 def GetModuleType(self):
65 return self.ModuleType
66
67 def SetDepexConent(self, Content):
68 self.DepexContent = Content
69 def GetDepexContent(self):
70 return self.DepexContent
71
72 def SetInfDepexContentItemList(self, InfDepexContentItemList):
73 self.InfDepexContentItemList = InfDepexContentItemList
74 def GetInfDepexContentItemList(self):
75 return self.InfDepexContentItemList
76
77 ## InfDepexObject
78 #
79 #
80 #
81 class InfDepexObject(InfSectionCommonDef):
82 def __init__(self):
83 self.Depex = []
84 self.AllContent = ''
85 self.SectionContent = ''
86 InfSectionCommonDef.__init__(self)
87
88 def SetDepex(self, DepexContent, KeyList=None, CommentList=None):
89 for KeyItem in KeyList:
90 Arch = KeyItem[0]
91 ModuleType = KeyItem[1]
92 InfDepexItemIns = InfDepexItem()
93
94 #
95 # Validate Arch
96 #
97 if IsValidArch(Arch.strip().upper()):
98 InfDepexItemIns.SetSupArch(Arch)
99 else:
100 Logger.Error("InfParser",
101 ToolError.FORMAT_INVALID,
102 ST.ERR_INF_PARSER_DEFINE_NAME_INVALID % (Arch),
103 File=GlobalData.gINF_MODULE_NAME,
104 Line=KeyItem[2])
105
106 #
107 # Validate Module Type
108 #
109 if ModuleType and ModuleType != 'COMMON':
110 if ModuleType in DT.VALID_DEPEX_MODULE_TYPE_LIST:
111 InfDepexItemIns.SetModuleType(ModuleType)
112 else:
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,
117 Line=KeyItem[2])
118
119 #
120 # Parser content in [Depex] section.
121 #
122 DepexString = ''
123 HelpString = ''
124 #
125 # Get Depex Expression
126 #
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)]
131 if LineContent:
132 DepexString = DepexString + LineContent + DT.END_OF_LINE
133 continue
134
135 if DepexString.endswith(DT.END_OF_LINE):
136 DepexString = DepexString[:-1]
137
138 if not DepexString.strip():
139 continue
140
141 #
142 # Get Help Text
143 #
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]
148
149 InfDepexItemIns.SetDepexConent(DepexString)
150 InfDepexItemIns.SetHelpString(HelpString)
151
152 self.Depex.append(InfDepexItemIns)
153
154 return True
155
156 def GetDepex(self):
157 return self.Depex
158
159 def GetAllContent(self):
160 return self.AllContent