2011-08-26 07:46:26 +00:00
|
|
|
## @file
|
|
|
|
|
# This file is used to provide method for process AsBuilt INF file. It will consumed by InfParser
|
|
|
|
|
#
|
2018-06-07 13:06:44 +08:00
|
|
|
# Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
|
2011-08-26 07:46:26 +00:00
|
|
|
#
|
2019-04-03 16:03:11 -07:00
|
|
|
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
2011-08-26 07:46:26 +00:00
|
|
|
'''
|
|
|
|
|
InfAsBuiltProcess
|
|
|
|
|
'''
|
|
|
|
|
## Import modules
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
import re
|
|
|
|
|
from Library import GlobalData
|
|
|
|
|
import Logger.Log as Logger
|
|
|
|
|
from Logger import StringTable as ST
|
|
|
|
|
from Logger import ToolError
|
|
|
|
|
|
2018-06-07 13:06:44 +08:00
|
|
|
from Library.StringUtils import GetSplitValueList
|
2011-08-26 07:46:26 +00:00
|
|
|
from Library.Misc import GetHelpStringByRemoveHashKey
|
|
|
|
|
from Library.Misc import ValidFile
|
|
|
|
|
from Library.Misc import ProcessLineExtender
|
|
|
|
|
from Library.ParserValidate import IsValidPath
|
|
|
|
|
from Library.Parsing import MacroParser
|
|
|
|
|
from Parser.InfParserMisc import InfExpandMacro
|
|
|
|
|
|
|
|
|
|
from Library import DataType as DT
|
|
|
|
|
|
|
|
|
|
## GetLibInstanceInfo
|
|
|
|
|
#
|
|
|
|
|
# Get the information from Library Instance INF file.
|
|
|
|
|
#
|
|
|
|
|
# @param string. A string start with # and followed by INF file path
|
|
|
|
|
# @param WorkSpace. The WorkSpace directory used to combined with INF file path.
|
|
|
|
|
#
|
|
|
|
|
# @return GUID, Version
|
2013-08-23 02:18:16 +00:00
|
|
|
def GetLibInstanceInfo(String, WorkSpace, LineNo, CurrentInfFileName):
|
|
|
|
|
|
2011-08-26 07:46:26 +00:00
|
|
|
FileGuidString = ""
|
|
|
|
|
VerString = ""
|
2013-08-23 02:18:16 +00:00
|
|
|
|
2019-02-06 15:44:39 +08:00
|
|
|
OriginalString = String
|
2011-08-26 07:46:26 +00:00
|
|
|
String = String.strip()
|
|
|
|
|
if not String:
|
|
|
|
|
return None, None
|
|
|
|
|
#
|
|
|
|
|
# Remove "#" characters at the beginning
|
|
|
|
|
#
|
|
|
|
|
String = GetHelpStringByRemoveHashKey(String)
|
|
|
|
|
String = String.strip()
|
2013-08-23 02:18:16 +00:00
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# To deal with library instance specified by GUID and version
|
|
|
|
|
#
|
2024-09-18 16:40:08 +01:00
|
|
|
RegFormatGuidPattern = re.compile(r"\s*([0-9a-fA-F]){8}-"
|
2013-08-23 02:18:16 +00:00
|
|
|
"([0-9a-fA-F]){4}-"
|
|
|
|
|
"([0-9a-fA-F]){4}-"
|
|
|
|
|
"([0-9a-fA-F]){4}-"
|
2024-09-18 16:40:08 +01:00
|
|
|
r"([0-9a-fA-F]){12}\s*")
|
|
|
|
|
VersionPattern = re.compile(r'[\t\s]*\d+(\.\d+)?[\t\s]*')
|
2013-08-23 02:18:16 +00:00
|
|
|
GuidMatchedObj = RegFormatGuidPattern.search(String)
|
|
|
|
|
|
|
|
|
|
if String.upper().startswith('GUID') and GuidMatchedObj and 'Version' in String:
|
|
|
|
|
VersionStr = String[String.upper().find('VERSION') + 8:]
|
|
|
|
|
VersionMatchedObj = VersionPattern.search(VersionStr)
|
|
|
|
|
if VersionMatchedObj:
|
|
|
|
|
Guid = GuidMatchedObj.group().strip()
|
|
|
|
|
Version = VersionMatchedObj.group().strip()
|
2014-08-26 05:58:02 +00:00
|
|
|
return Guid, Version
|
2013-08-23 02:18:16 +00:00
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# To deal with library instance specified by file name
|
|
|
|
|
#
|
2019-02-06 15:44:39 +08:00
|
|
|
FileLinesList = GetFileLineContent(String, WorkSpace, LineNo, OriginalString)
|
2011-08-26 07:46:26 +00:00
|
|
|
|
2013-08-23 02:18:16 +00:00
|
|
|
|
2024-09-18 16:40:08 +01:00
|
|
|
ReFindFileGuidPattern = re.compile(r"^\s*FILE_GUID\s*=.*$")
|
|
|
|
|
ReFindVerStringPattern = re.compile(r"^\s*VERSION_STRING\s*=.*$")
|
2011-08-26 07:46:26 +00:00
|
|
|
|
|
|
|
|
for Line in FileLinesList:
|
|
|
|
|
if ReFindFileGuidPattern.match(Line):
|
|
|
|
|
FileGuidString = Line
|
|
|
|
|
if ReFindVerStringPattern.match(Line):
|
|
|
|
|
VerString = Line
|
2013-08-23 02:18:16 +00:00
|
|
|
|
2011-08-26 07:46:26 +00:00
|
|
|
if FileGuidString:
|
|
|
|
|
FileGuidString = GetSplitValueList(FileGuidString, '=', 1)[1]
|
|
|
|
|
if VerString:
|
|
|
|
|
VerString = GetSplitValueList(VerString, '=', 1)[1]
|
2013-08-23 02:18:16 +00:00
|
|
|
|
2011-08-26 07:46:26 +00:00
|
|
|
return FileGuidString, VerString
|
2013-08-23 02:18:16 +00:00
|
|
|
|
2011-08-26 07:46:26 +00:00
|
|
|
## GetPackageListInfo
|
|
|
|
|
#
|
|
|
|
|
# Get the package information from INF file.
|
|
|
|
|
#
|
|
|
|
|
# @param string. A string start with # and followed by INF file path
|
|
|
|
|
# @param WorkSpace. The WorkSpace directory used to combined with INF file path.
|
|
|
|
|
#
|
|
|
|
|
# @return GUID, Version
|
2014-08-26 05:58:02 +00:00
|
|
|
def GetPackageListInfo(FileNameString, WorkSpace, LineNo):
|
2011-08-26 07:46:26 +00:00
|
|
|
PackageInfoList = []
|
|
|
|
|
DefineSectionMacros = {}
|
|
|
|
|
PackageSectionMacros = {}
|
2014-08-26 05:58:02 +00:00
|
|
|
|
2011-08-26 07:46:26 +00:00
|
|
|
FileLinesList = GetFileLineContent(FileNameString, WorkSpace, LineNo, '')
|
2014-08-26 05:58:02 +00:00
|
|
|
|
2024-09-18 16:40:08 +01:00
|
|
|
RePackageHeader = re.compile(r'^\s*\[Packages.*\].*$')
|
|
|
|
|
ReDefineHeader = re.compile(r'^\s*\[Defines].*$')
|
2014-08-26 05:58:02 +00:00
|
|
|
|
2011-08-26 07:46:26 +00:00
|
|
|
PackageHederFlag = False
|
|
|
|
|
DefineHeaderFlag = False
|
|
|
|
|
LineNo = -1
|
|
|
|
|
for Line in FileLinesList:
|
|
|
|
|
LineNo += 1
|
|
|
|
|
Line = Line.strip()
|
2014-08-26 05:58:02 +00:00
|
|
|
|
2011-08-26 07:46:26 +00:00
|
|
|
if Line.startswith('['):
|
|
|
|
|
PackageHederFlag = False
|
2014-08-26 05:58:02 +00:00
|
|
|
DefineHeaderFlag = False
|
|
|
|
|
|
2011-08-26 07:46:26 +00:00
|
|
|
if Line.startswith("#"):
|
|
|
|
|
continue
|
2014-08-26 05:58:02 +00:00
|
|
|
|
2011-08-26 07:46:26 +00:00
|
|
|
if not Line:
|
2014-08-26 05:58:02 +00:00
|
|
|
continue
|
|
|
|
|
|
2011-08-26 07:46:26 +00:00
|
|
|
#
|
2018-07-05 17:40:04 +08:00
|
|
|
# Found [Packages] section
|
2011-08-26 07:46:26 +00:00
|
|
|
#
|
|
|
|
|
if RePackageHeader.match(Line):
|
|
|
|
|
PackageHederFlag = True
|
|
|
|
|
continue
|
2014-08-26 05:58:02 +00:00
|
|
|
|
2011-08-26 07:46:26 +00:00
|
|
|
#
|
|
|
|
|
# Found [Define] section
|
|
|
|
|
#
|
|
|
|
|
if ReDefineHeader.match(Line):
|
|
|
|
|
DefineHeaderFlag = True
|
|
|
|
|
continue
|
2014-08-26 05:58:02 +00:00
|
|
|
|
2011-08-26 07:46:26 +00:00
|
|
|
if DefineHeaderFlag:
|
|
|
|
|
#
|
|
|
|
|
# Find Macro
|
|
|
|
|
#
|
|
|
|
|
Name, Value = MacroParser((Line, LineNo),
|
|
|
|
|
FileNameString,
|
|
|
|
|
DT.MODEL_META_DATA_HEADER,
|
2014-08-26 05:58:02 +00:00
|
|
|
DefineSectionMacros)
|
|
|
|
|
|
2018-03-27 04:25:43 +08:00
|
|
|
if Name is not None:
|
2014-08-26 05:58:02 +00:00
|
|
|
DefineSectionMacros[Name] = Value
|
2011-08-26 07:46:26 +00:00
|
|
|
continue
|
2014-08-26 05:58:02 +00:00
|
|
|
|
2011-08-26 07:46:26 +00:00
|
|
|
if PackageHederFlag:
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Find Macro
|
|
|
|
|
#
|
|
|
|
|
Name, Value = MacroParser((Line, LineNo),
|
|
|
|
|
FileNameString,
|
|
|
|
|
DT.MODEL_META_DATA_PACKAGE,
|
|
|
|
|
DefineSectionMacros)
|
2018-03-27 04:25:43 +08:00
|
|
|
if Name is not None:
|
2014-08-26 05:58:02 +00:00
|
|
|
PackageSectionMacros[Name] = Value
|
2011-08-26 07:46:26 +00:00
|
|
|
continue
|
2014-08-26 05:58:02 +00:00
|
|
|
|
2011-08-26 07:46:26 +00:00
|
|
|
#
|
|
|
|
|
# Replace with Local section Macro and [Defines] section Macro.
|
2018-07-05 17:40:04 +08:00
|
|
|
#
|
2011-08-26 07:46:26 +00:00
|
|
|
Line = InfExpandMacro(Line, (FileNameString, Line, LineNo), DefineSectionMacros, PackageSectionMacros, True)
|
2014-08-26 05:58:02 +00:00
|
|
|
|
2011-08-26 07:46:26 +00:00
|
|
|
Line = GetSplitValueList(Line, "#", 1)[0]
|
|
|
|
|
Line = GetSplitValueList(Line, "|", 1)[0]
|
|
|
|
|
PackageInfoList.append(Line)
|
2014-08-26 05:58:02 +00:00
|
|
|
|
|
|
|
|
return PackageInfoList
|
|
|
|
|
|
2011-08-26 07:46:26 +00:00
|
|
|
def GetFileLineContent(FileName, WorkSpace, LineNo, OriginalString):
|
2014-08-26 05:58:02 +00:00
|
|
|
|
2011-08-26 07:46:26 +00:00
|
|
|
if not LineNo:
|
|
|
|
|
LineNo = -1
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Validate file name exist.
|
|
|
|
|
#
|
|
|
|
|
FullFileName = os.path.normpath(os.path.realpath(os.path.join(WorkSpace, FileName)))
|
|
|
|
|
if not (ValidFile(FullFileName)):
|
2014-08-26 05:58:02 +00:00
|
|
|
return []
|
|
|
|
|
|
2011-08-26 07:46:26 +00:00
|
|
|
#
|
|
|
|
|
# Validate file exist/format.
|
|
|
|
|
#
|
2013-08-23 02:18:16 +00:00
|
|
|
if not IsValidPath(FileName, WorkSpace):
|
2014-08-26 05:58:02 +00:00
|
|
|
return []
|
|
|
|
|
|
2011-08-26 07:46:26 +00:00
|
|
|
FileLinesList = []
|
2014-08-26 05:58:02 +00:00
|
|
|
|
2013-08-23 02:18:16 +00:00
|
|
|
try:
|
|
|
|
|
FullFileName = FullFileName.replace('\\', '/')
|
2018-12-17 15:18:01 +08:00
|
|
|
Inputfile = open(FullFileName, "r")
|
2011-08-26 07:46:26 +00:00
|
|
|
try:
|
2013-08-23 02:18:16 +00:00
|
|
|
FileLinesList = Inputfile.readlines()
|
2011-08-26 07:46:26 +00:00
|
|
|
except BaseException:
|
2013-08-23 02:18:16 +00:00
|
|
|
Logger.Error("InfParser", ToolError.FILE_READ_FAILURE, ST.ERR_FILE_OPEN_FAILURE, File=FullFileName)
|
|
|
|
|
finally:
|
|
|
|
|
Inputfile.close()
|
|
|
|
|
except BaseException:
|
|
|
|
|
Logger.Error("InfParser",
|
|
|
|
|
ToolError.FILE_READ_FAILURE,
|
|
|
|
|
ST.ERR_FILE_OPEN_FAILURE,
|
|
|
|
|
File=FullFileName)
|
2014-08-26 05:58:02 +00:00
|
|
|
|
2013-08-23 02:18:16 +00:00
|
|
|
FileLinesList = ProcessLineExtender(FileLinesList)
|
2014-08-26 05:58:02 +00:00
|
|
|
|
2011-08-26 07:46:26 +00:00
|
|
|
return FileLinesList
|