Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

234 lines
8.1 KiB
Python
Raw Permalink Normal View History

## @file
2018-07-05 17:40:04 +08:00
# This file is used to define class objects of INF file [Sources] section.
# It will consumed by InfParser.
#
2018-07-05 17:40:04 +08:00
# Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
'''
InfSourcesObject
'''
import os
from Logger import StringTable as ST
from Logger import ToolError
import Logger.Log as Logger
2018-07-05 17:40:04 +08:00
from Library import GlobalData
from Library.Misc import Sdict
2018-07-05 17:40:04 +08:00
from Library.ExpressionValidate import IsValidFeatureFlagExp
from Object.Parser.InfCommonObject import InfSectionCommonDef
2018-07-05 17:40:04 +08:00
from Library.Misc import ValidFile
from Library.ParserValidate import IsValidFamily
from Library.ParserValidate import IsValidPath
2018-07-05 17:40:04 +08:00
## __GenSourceInstance
#
#
def GenSourceInstance(Item, CurrentLineOfItem, ItemObj):
2018-07-05 17:40:04 +08:00
IsValidFileFlag = False
2018-07-05 17:40:04 +08:00
if len(Item) < 6 and len(Item) >= 1:
#
# File | Family | TagName | ToolCode | FeatureFlagExpr
#
if len(Item) == 5:
#
# Validate Feature Flag Express
#
if Item[4].strip() == '':
2018-07-05 17:40:04 +08:00
Logger.Error("InfParser",
ToolError.FORMAT_INVALID,
ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_MISSING,
2018-07-05 17:40:04 +08:00
File=CurrentLineOfItem[2],
Line=CurrentLineOfItem[1],
ExtraData=CurrentLineOfItem[0])
#
2018-07-05 17:40:04 +08:00
# Validate FFE
#
FeatureFlagRtv = IsValidFeatureFlagExp(Item[4].strip())
if not FeatureFlagRtv[0]:
2018-07-05 17:40:04 +08:00
Logger.Error("InfParser",
ToolError.FORMAT_INVALID,
ST.ERR_INF_PARSER_FEATURE_FLAG_EXP_SYNTAX_INVLID%(FeatureFlagRtv[1]),
2018-07-05 17:40:04 +08:00
File=CurrentLineOfItem[2],
Line=CurrentLineOfItem[1],
ExtraData=CurrentLineOfItem[0])
ItemObj.SetFeatureFlagExp(Item[4])
if len(Item) >= 4:
if Item[3].strip() == '':
ItemObj.SetToolCode(Item[3])
else:
2018-07-05 17:40:04 +08:00
Logger.Error("InfParser",
ToolError.FORMAT_INVALID,
ST.ERR_INF_PARSER_TOOLCODE_NOT_PERMITTED%(Item[2]),
2018-07-05 17:40:04 +08:00
File=CurrentLineOfItem[2],
Line=CurrentLineOfItem[1],
ExtraData=CurrentLineOfItem[0])
if len(Item) >= 3:
if Item[2].strip() == '':
ItemObj.SetTagName(Item[2])
else:
2018-07-05 17:40:04 +08:00
Logger.Error("InfParser",
ToolError.FORMAT_INVALID,
ST.ERR_INF_PARSER_TAGNAME_NOT_PERMITTED%(Item[2]),
2018-07-05 17:40:04 +08:00
File=CurrentLineOfItem[2],
Line=CurrentLineOfItem[1],
ExtraData=CurrentLineOfItem[0])
if len(Item) >= 2:
if IsValidFamily(Item[1].strip()):
#
# To align with UDP specification. "*" is not permitted in UDP specification
#
if Item[1].strip() == "*":
Item[1] = ""
ItemObj.SetFamily(Item[1])
else:
2018-07-05 17:40:04 +08:00
Logger.Error("InfParser",
ToolError.FORMAT_INVALID,
ST.ERR_INF_PARSER_SOURCE_SECTION_FAMILY_INVALID%(Item[1]),
2018-07-05 17:40:04 +08:00
File=CurrentLineOfItem[2],
Line=CurrentLineOfItem[1],
ExtraData=CurrentLineOfItem[0])
if len(Item) >= 1:
#
# Validate file name exist.
#
FullFileName = os.path.normpath(os.path.realpath(os.path.join(GlobalData.gINF_MODULE_DIR, Item[0])))
if not (ValidFile(FullFileName) or ValidFile(Item[0])):
2018-07-05 17:40:04 +08:00
Logger.Error("InfParser",
ToolError.FORMAT_INVALID,
ST.ERR_FILELIST_EXIST%(Item[0]),
2018-07-05 17:40:04 +08:00
File=CurrentLineOfItem[2],
Line=CurrentLineOfItem[1],
ExtraData=CurrentLineOfItem[0])
2018-07-05 17:40:04 +08:00
#
# Validate file exist/format.
#
2018-07-05 17:40:04 +08:00
if IsValidPath(Item[0], GlobalData.gINF_MODULE_DIR):
IsValidFileFlag = True
else:
2018-07-05 17:40:04 +08:00
Logger.Error("InfParser",
ToolError.FORMAT_INVALID,
ST.ERR_INF_PARSER_FILE_NOT_EXIST_OR_NAME_INVALID%(Item[0]),
2018-07-05 17:40:04 +08:00
File=CurrentLineOfItem[2],
Line=CurrentLineOfItem[1],
ExtraData=CurrentLineOfItem[0])
return False
if IsValidFileFlag:
2018-07-05 17:40:04 +08:00
ItemObj.SetSourceFileName(Item[0])
else:
2018-07-05 17:40:04 +08:00
Logger.Error("InfParser",
ToolError.FORMAT_INVALID,
ST.ERR_INF_PARSER_SOURCES_SECTION_CONTENT_ERROR,
2018-07-05 17:40:04 +08:00
File=CurrentLineOfItem[2],
Line=CurrentLineOfItem[1],
ExtraData=CurrentLineOfItem[0])
2018-07-05 17:40:04 +08:00
return ItemObj
## InfSourcesItemObject()
2018-07-05 17:40:04 +08:00
#
#
class InfSourcesItemObject():
def __init__(self, \
SourceFileName = '', \
Family = '', \
TagName = '', \
ToolCode = '', \
FeatureFlagExp = ''):
self.SourceFileName = SourceFileName
self.Family = Family
self.TagName = TagName
self.ToolCode = ToolCode
self.FeatureFlagExp = FeatureFlagExp
self.HeaderString = ''
self.TailString = ''
self.SupArchList = []
2018-07-05 17:40:04 +08:00
def SetSourceFileName(self, SourceFilename):
self.SourceFileName = SourceFilename
def GetSourceFileName(self):
return self.SourceFileName
2018-07-05 17:40:04 +08:00
def SetFamily(self, Family):
self.Family = Family
def GetFamily(self):
return self.Family
2018-07-05 17:40:04 +08:00
def SetTagName(self, TagName):
self.TagName = TagName
def GetTagName(self):
return self.TagName
2018-07-05 17:40:04 +08:00
def SetToolCode(self, ToolCode):
self.ToolCode = ToolCode
def GetToolCode(self):
return self.ToolCode
2018-07-05 17:40:04 +08:00
def SetFeatureFlagExp(self, FeatureFlagExp):
self.FeatureFlagExp = FeatureFlagExp
def GetFeatureFlagExp(self):
return self.FeatureFlagExp
2018-07-05 17:40:04 +08:00
def SetHeaderString(self, HeaderString):
self.HeaderString = HeaderString
def GetHeaderString(self):
return self.HeaderString
def SetTailString(self, TailString):
self.TailString = TailString
def GetTailString(self):
return self.TailString
2018-07-05 17:40:04 +08:00
def SetSupArchList(self, SupArchList):
self.SupArchList = SupArchList
def GetSupArchList(self):
2018-07-05 17:40:04 +08:00
return self.SupArchList
##
#
#
#
class InfSourcesObject(InfSectionCommonDef):
def __init__(self):
self.Sources = Sdict()
InfSectionCommonDef.__init__(self)
2018-07-05 17:40:04 +08:00
def SetSources(self, SourceList, Arch = None):
__SupArchList = []
for ArchItem in Arch:
#
# Validate Arch
2018-07-05 17:40:04 +08:00
#
if (ArchItem == '' or ArchItem is None):
2018-07-05 17:40:04 +08:00
ArchItem = 'COMMON'
__SupArchList.append(ArchItem)
for Item in SourceList:
ItemObj = InfSourcesItemObject()
CurrentLineOfItem = Item[2]
2018-07-05 17:40:04 +08:00
Item = Item[0]
ItemObj = GenSourceInstance(Item, CurrentLineOfItem, ItemObj)
2018-07-05 17:40:04 +08:00
ItemObj.SetSupArchList(__SupArchList)
2018-06-25 18:31:29 +08:00
if (ItemObj) in self.Sources:
SourceContent = self.Sources[ItemObj]
SourceContent.append(ItemObj)
self.Sources[ItemObj] = SourceContent
else:
SourceContent = []
SourceContent.append(ItemObj)
self.Sources[ItemObj] = SourceContent
2018-07-05 17:40:04 +08:00
return True
2018-07-05 17:40:04 +08:00
def GetSources(self):
return self.Sources