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 # 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.
21 from Logger
import StringTable
as ST
22 from Logger
import ToolError
23 import Logger
.Log
as Logger
24 from Library
import GlobalData
26 from Library
.Misc
import Sdict
27 from Library
.ExpressionValidate
import IsValidFeatureFlagExp
28 from Object
.Parser
.InfCommonObject
import InfSectionCommonDef
29 from Library
.Misc
import ValidFile
30 from Library
.ParserValidate
import IsValidFamily
31 from Library
.ParserValidate
import IsValidPath
33 ## __GenSourceInstance
36 def GenSourceInstance(Item
, CurrentLineOfItem
, ItemObj
):
38 IsValidFileFlag
= False
40 if len(Item
) < 6 and len(Item
) >= 1:
42 # File | Family | TagName | ToolCode | FeatureFlagExpr
46 # Validate Feature Flag Express
48 if Item
[4].strip() == '':
49 Logger
.Error("InfParser",
50 ToolError
.FORMAT_INVALID
,
51 ST
.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING
,
52 File
=CurrentLineOfItem
[2],
53 Line
=CurrentLineOfItem
[1],
54 ExtraData
=CurrentLineOfItem
[0])
58 FeatureFlagRtv
= IsValidFeatureFlagExp(Item
[4].strip())
59 if not FeatureFlagRtv
[0]:
60 Logger
.Error("InfParser",
61 ToolError
.FORMAT_INVALID
,
62 ST
.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID
%(FeatureFlagRtv
[1]),
63 File
=CurrentLineOfItem
[2],
64 Line
=CurrentLineOfItem
[1],
65 ExtraData
=CurrentLineOfItem
[0])
66 ItemObj
.SetFeatureFlagExp(Item
[4])
68 if Item
[3].strip() == '':
69 ItemObj
.SetToolCode(Item
[3])
71 Logger
.Error("InfParser",
72 ToolError
.FORMAT_INVALID
,
73 ST
.ERR_INF_PARSER_TOOLCODE_NOT_PERMITTED
%(Item
[2]),
74 File
=CurrentLineOfItem
[2],
75 Line
=CurrentLineOfItem
[1],
76 ExtraData
=CurrentLineOfItem
[0])
78 if Item
[2].strip() == '':
79 ItemObj
.SetTagName(Item
[2])
81 Logger
.Error("InfParser",
82 ToolError
.FORMAT_INVALID
,
83 ST
.ERR_INF_PARSER_TAGNAME_NOT_PERMITTED
%(Item
[2]),
84 File
=CurrentLineOfItem
[2],
85 Line
=CurrentLineOfItem
[1],
86 ExtraData
=CurrentLineOfItem
[0])
88 if IsValidFamily(Item
[1].strip()):
90 # To align with UDP specification. "*" is not permitted in UDP specification
92 if Item
[1].strip() == "*":
94 ItemObj
.SetFamily(Item
[1])
96 Logger
.Error("InfParser",
97 ToolError
.FORMAT_INVALID
,
98 ST
.ERR_INF_PARSER_SOURCE_SECTION_FAMILY_INVALID
%(Item
[1]),
99 File
=CurrentLineOfItem
[2],
100 Line
=CurrentLineOfItem
[1],
101 ExtraData
=CurrentLineOfItem
[0])
104 # Validate file name exist.
106 FullFileName
= os
.path
.normpath(os
.path
.realpath(os
.path
.join(GlobalData
.gINF_MODULE_DIR
, Item
[0])))
107 if not (ValidFile(FullFileName
) or ValidFile(Item
[0])):
108 Logger
.Error("InfParser",
109 ToolError
.FORMAT_INVALID
,
110 ST
.ERR_FILELIST_EXIST
%(Item
[0]),
111 File
=CurrentLineOfItem
[2],
112 Line
=CurrentLineOfItem
[1],
113 ExtraData
=CurrentLineOfItem
[0])
116 # Validate file exist/format.
119 if IsValidPath(Item
[0], GlobalData
.gINF_MODULE_DIR
):
120 IsValidFileFlag
= True
122 Logger
.Error("InfParser",
123 ToolError
.FORMAT_INVALID
,
124 ST
.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID
%(Item
[0]),
125 File
=CurrentLineOfItem
[2],
126 Line
=CurrentLineOfItem
[1],
127 ExtraData
=CurrentLineOfItem
[0])
130 ItemObj
.SetSourceFileName(Item
[0])
132 Logger
.Error("InfParser",
133 ToolError
.FORMAT_INVALID
,
134 ST
.ERR_INF_PARSER_SOURCES_SECTION_CONTENT_ERROR
,
135 File
=CurrentLineOfItem
[2],
136 Line
=CurrentLineOfItem
[1],
137 ExtraData
=CurrentLineOfItem
[0])
141 ## InfSourcesItemObject()
144 class InfSourcesItemObject():
146 SourceFileName
= '', \
150 FeatureFlagExp
= ''):
151 self
.SourceFileName
= SourceFileName
153 self
.TagName
= TagName
154 self
.ToolCode
= ToolCode
155 self
.FeatureFlagExp
= FeatureFlagExp
156 self
.HeaderString
= ''
158 self
.SupArchList
= []
160 def SetSourceFileName(self
, SourceFilename
):
161 self
.SourceFileName
= SourceFilename
162 def GetSourceFileName(self
):
163 return self
.SourceFileName
165 def SetFamily(self
, Family
):
170 def SetTagName(self
, TagName
):
171 self
.TagName
= TagName
172 def GetTagName(self
):
175 def SetToolCode(self
, ToolCode
):
176 self
.ToolCode
= ToolCode
177 def GetToolCode(self
):
180 def SetFeatureFlagExp(self
, FeatureFlagExp
):
181 self
.FeatureFlagExp
= FeatureFlagExp
182 def GetFeatureFlagExp(self
):
183 return self
.FeatureFlagExp
185 def SetHeaderString(self
, HeaderString
):
186 self
.HeaderString
= HeaderString
187 def GetHeaderString(self
):
188 return self
.HeaderString
190 def SetTailString(self
, TailString
):
191 self
.TailString
= TailString
192 def GetTailString(self
):
193 return self
.TailString
195 def SetSupArchList(self
, SupArchList
):
196 self
.SupArchList
= SupArchList
197 def GetSupArchList(self
):
198 return self
.SupArchList
203 class InfSourcesObject(InfSectionCommonDef
):
205 self
.Sources
= Sdict()
206 InfSectionCommonDef
.__init
__(self
)
208 def SetSources(self
, SourceList
, Arch
= None):
210 for ArchItem
in Arch
:
214 if (ArchItem
== '' or ArchItem
is None):
216 __SupArchList
.append(ArchItem
)
218 for Item
in SourceList
:
219 ItemObj
= InfSourcesItemObject()
220 CurrentLineOfItem
= Item
[2]
223 ItemObj
= GenSourceInstance(Item
, CurrentLineOfItem
, ItemObj
)
225 ItemObj
.SetSupArchList(__SupArchList
)
227 if (ItemObj
) in self
.Sources
:
228 SourceContent
= self
.Sources
[ItemObj
]
229 SourceContent
.append(ItemObj
)
230 self
.Sources
[ItemObj
] = SourceContent
233 SourceContent
.append(ItemObj
)
234 self
.Sources
[ItemObj
] = SourceContent
238 def GetSources(self
):