2 # This file is used to define class objects of INF file [Sources] 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
15 from Logger
import StringTable
as ST
16 from Logger
import ToolError
17 import Logger
.Log
as Logger
18 from Library
import GlobalData
20 from Library
.Misc
import Sdict
21 from Library
.ExpressionValidate
import IsValidFeatureFlagExp
22 from Object
.Parser
.InfCommonObject
import InfSectionCommonDef
23 from Library
.Misc
import ValidFile
24 from Library
.ParserValidate
import IsValidFamily
25 from Library
.ParserValidate
import IsValidPath
27 ## __GenSourceInstance
30 def GenSourceInstance(Item
, CurrentLineOfItem
, ItemObj
):
32 IsValidFileFlag
= False
34 if len(Item
) < 6 and len(Item
) >= 1:
36 # File | Family | TagName | ToolCode | FeatureFlagExpr
40 # Validate Feature Flag Express
42 if Item
[4].strip() == '':
43 Logger
.Error("InfParser",
44 ToolError
.FORMAT_INVALID
,
45 ST
.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING
,
46 File
=CurrentLineOfItem
[2],
47 Line
=CurrentLineOfItem
[1],
48 ExtraData
=CurrentLineOfItem
[0])
52 FeatureFlagRtv
= IsValidFeatureFlagExp(Item
[4].strip())
53 if not FeatureFlagRtv
[0]:
54 Logger
.Error("InfParser",
55 ToolError
.FORMAT_INVALID
,
56 ST
.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID
%(FeatureFlagRtv
[1]),
57 File
=CurrentLineOfItem
[2],
58 Line
=CurrentLineOfItem
[1],
59 ExtraData
=CurrentLineOfItem
[0])
60 ItemObj
.SetFeatureFlagExp(Item
[4])
62 if Item
[3].strip() == '':
63 ItemObj
.SetToolCode(Item
[3])
65 Logger
.Error("InfParser",
66 ToolError
.FORMAT_INVALID
,
67 ST
.ERR_INF_PARSER_TOOLCODE_NOT_PERMITTED
%(Item
[2]),
68 File
=CurrentLineOfItem
[2],
69 Line
=CurrentLineOfItem
[1],
70 ExtraData
=CurrentLineOfItem
[0])
72 if Item
[2].strip() == '':
73 ItemObj
.SetTagName(Item
[2])
75 Logger
.Error("InfParser",
76 ToolError
.FORMAT_INVALID
,
77 ST
.ERR_INF_PARSER_TAGNAME_NOT_PERMITTED
%(Item
[2]),
78 File
=CurrentLineOfItem
[2],
79 Line
=CurrentLineOfItem
[1],
80 ExtraData
=CurrentLineOfItem
[0])
82 if IsValidFamily(Item
[1].strip()):
84 # To align with UDP specification. "*" is not permitted in UDP specification
86 if Item
[1].strip() == "*":
88 ItemObj
.SetFamily(Item
[1])
90 Logger
.Error("InfParser",
91 ToolError
.FORMAT_INVALID
,
92 ST
.ERR_INF_PARSER_SOURCE_SECTION_FAMILY_INVALID
%(Item
[1]),
93 File
=CurrentLineOfItem
[2],
94 Line
=CurrentLineOfItem
[1],
95 ExtraData
=CurrentLineOfItem
[0])
98 # Validate file name exist.
100 FullFileName
= os
.path
.normpath(os
.path
.realpath(os
.path
.join(GlobalData
.gINF_MODULE_DIR
, Item
[0])))
101 if not (ValidFile(FullFileName
) or ValidFile(Item
[0])):
102 Logger
.Error("InfParser",
103 ToolError
.FORMAT_INVALID
,
104 ST
.ERR_FILELIST_EXIST
%(Item
[0]),
105 File
=CurrentLineOfItem
[2],
106 Line
=CurrentLineOfItem
[1],
107 ExtraData
=CurrentLineOfItem
[0])
110 # Validate file exist/format.
113 if IsValidPath(Item
[0], GlobalData
.gINF_MODULE_DIR
):
114 IsValidFileFlag
= True
116 Logger
.Error("InfParser",
117 ToolError
.FORMAT_INVALID
,
118 ST
.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID
%(Item
[0]),
119 File
=CurrentLineOfItem
[2],
120 Line
=CurrentLineOfItem
[1],
121 ExtraData
=CurrentLineOfItem
[0])
124 ItemObj
.SetSourceFileName(Item
[0])
126 Logger
.Error("InfParser",
127 ToolError
.FORMAT_INVALID
,
128 ST
.ERR_INF_PARSER_SOURCES_SECTION_CONTENT_ERROR
,
129 File
=CurrentLineOfItem
[2],
130 Line
=CurrentLineOfItem
[1],
131 ExtraData
=CurrentLineOfItem
[0])
135 ## InfSourcesItemObject()
138 class InfSourcesItemObject():
140 SourceFileName
= '', \
144 FeatureFlagExp
= ''):
145 self
.SourceFileName
= SourceFileName
147 self
.TagName
= TagName
148 self
.ToolCode
= ToolCode
149 self
.FeatureFlagExp
= FeatureFlagExp
150 self
.HeaderString
= ''
152 self
.SupArchList
= []
154 def SetSourceFileName(self
, SourceFilename
):
155 self
.SourceFileName
= SourceFilename
156 def GetSourceFileName(self
):
157 return self
.SourceFileName
159 def SetFamily(self
, Family
):
164 def SetTagName(self
, TagName
):
165 self
.TagName
= TagName
166 def GetTagName(self
):
169 def SetToolCode(self
, ToolCode
):
170 self
.ToolCode
= ToolCode
171 def GetToolCode(self
):
174 def SetFeatureFlagExp(self
, FeatureFlagExp
):
175 self
.FeatureFlagExp
= FeatureFlagExp
176 def GetFeatureFlagExp(self
):
177 return self
.FeatureFlagExp
179 def SetHeaderString(self
, HeaderString
):
180 self
.HeaderString
= HeaderString
181 def GetHeaderString(self
):
182 return self
.HeaderString
184 def SetTailString(self
, TailString
):
185 self
.TailString
= TailString
186 def GetTailString(self
):
187 return self
.TailString
189 def SetSupArchList(self
, SupArchList
):
190 self
.SupArchList
= SupArchList
191 def GetSupArchList(self
):
192 return self
.SupArchList
197 class InfSourcesObject(InfSectionCommonDef
):
199 self
.Sources
= Sdict()
200 InfSectionCommonDef
.__init
__(self
)
202 def SetSources(self
, SourceList
, Arch
= None):
204 for ArchItem
in Arch
:
208 if (ArchItem
== '' or ArchItem
is None):
210 __SupArchList
.append(ArchItem
)
212 for Item
in SourceList
:
213 ItemObj
= InfSourcesItemObject()
214 CurrentLineOfItem
= Item
[2]
217 ItemObj
= GenSourceInstance(Item
, CurrentLineOfItem
, ItemObj
)
219 ItemObj
.SetSupArchList(__SupArchList
)
221 if (ItemObj
) in self
.Sources
:
222 SourceContent
= self
.Sources
[ItemObj
]
223 SourceContent
.append(ItemObj
)
224 self
.Sources
[ItemObj
] = SourceContent
227 SourceContent
.append(ItemObj
)
228 self
.Sources
[ItemObj
] = SourceContent
232 def GetSources(self
):