## @file
# This file contained the parser for INF file
#
# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials are licensed and made available
# under the terms and conditions of the BSD License which accompanies this
# distribution. The full text of the license may be found at
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
'''
InfParser
'''
##
# Import Modules
#
import re
import os
## OpenInfFile
#
#
FileLinesList = []
try:
try:
except BaseException:
finally:
except BaseException:
return FileLinesList
## InfParser
#
# This class defined the structure used in InfParser object
#
# @param InfObject: Inherited from InfSectionParser class
# @param Filename: Input value for Filename of INF file, default is
# None
# @param WorkspaceDir: Input value for current workspace directory,
# default is None
#
#
# Call parent class construct function
#
self.BootModeList = []
#
# Load Inf file if filename is not None
#
if Filename != None:
## Parse INF file
#
# Parse the file if it exists
#
# @param Filename: Input value for filename of INF file
#
#
# Initialize common data
#
LineNo = 0
SectionLines = []
#
# Flags
#
#
# While Section ends. parse whole section contents.
#
#
# Parse file content
#
CommentBlock = []
#
#
self.BootModeList = []
SectionType = ''
#
# One INF file can only has one [Defines] section.
#
#
# Convert special characters in lines to space character.
#
#
# Process Line Extender
#
#
# Process EdkI INF style comment if found
#
#
# Judge whether the INF file is Binary INF or not
#
if IsBinaryInf(FileLinesList):
InfSectionCommonDefObj = None
for Line in FileLinesList:
#
# blank line
#
#
# check whether file header comment section started
#
not HeaderCommentStart:
else:
#
# Append the first line to section lines.
#
continue
#
# Collect Header content.
#
if (Line.startswith(DT.TAB_COMMENT_SPLIT) and CurrentSection == DT.MODEL_META_DATA_FILE_HEADER) and\
continue
#
# Header content end
#
if (Line.startswith(DT.TAB_SPECIAL_COMMENT) or not Line.strip().startswith("#")) and HeaderCommentStart \
and not HeaderCommentEnd:
#
# Call Header comment parser.
#
SectionLines = []
continue
#
# Find a new section tab
# Or at the last line of INF file,
# need to process the last section.
#
if not LastSectionFalg:
continue
#
# Encountered a section. start with '[' and end with ']'
#
if not LastSectionFalg:
#
# check to prevent '#' inside section header
#
#
# Keep last time section header content for section parser
# usage.
#
#
# TailComments in section define.
#
TailComments = ''
if CommentIndex > -1:
if TailComments != '':
if CommentBlock != '':
CommentBlock = []
#
# Call section parser before section header parer to avoid encounter EDKI INF file
#
#
# Compare the new section name with current
#
if not FirstSectionStartFlag:
else:
else:
continue
if LastSectionFalg:
#
# End of section content collect.
# Parser the section content collected previously.
#
#
# Clear section lines
#
SectionLines = []
#
# End of for
#
#
# Found the first section, No file header.
#
if DefineSectionParsedFlag and not HeaderCommentEnd:
#
# EDKII INF should not have EDKI style comment
#
if EdkCommentStartPos != -1:
#
# extract [Event] [Hob] [BootMode] sections
#
## _CheckSectionHeaders
#
#
else:
ArchList = []
#
# Not cover Depex/UserExtension section header
# check.
#
else:
if (not IsValidArch(Arch)) and \
#
# Check if the ModuleType is valid
#
ChkModSectionList = ['LIBRARYCLASSES']
if (not IsValidInfMoudleTypeList(MoudleTypeList)):
## _CallSectionParsers
#
#
if not DefineSectionParsedFlag:
else:
#
# [Pcd] Sections, put it together
#
#
# Unknown section type found, raise error.
#
else:
else:
return DefineSectionParsedFlag
LineNum = 0
Element = []
for Line in FileLinesList:
LineNum += 1
if MatchObject:
Element = []
else:
else:
#
# if currently in special section, try to detect end of current section
#
if MatchObject:
Element = []
elif not Line:
Element = []
else:
Element = []
else:
else:
if CheckLocation:
if MatchObject:
elif Line:
## _ProcessLastSection
#
#
#
# The last line is a section header. will discard it.
#
)
else:
return SectionLines, CurrentSection
## _ConvertSecNameToType
#
#
SectionType = ''
else:
return SectionType