2 # This file contained the miscellaneous functions for INF parser
4 # Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
6 # This program and the accompanying materials are licensed and made available
7 # under the terms and conditions of the BSD License which accompanies this
8 # distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
25 from Library
import DataType
as DT
28 from Library
.String
import gMACRO_PATTERN
29 from Library
.String
import ReplaceMacro
30 from Object
.Parser
.InfMisc
import ErrorInInf
31 from Logger
.StringTable
import ERR_MARCO_DEFINITION_MISS_ERROR
38 # Sections can exist in INF file
41 DT
.TAB_UNKNOWN
.upper() : DT
.MODEL_UNKNOWN
,
42 DT
.TAB_HEADER
.upper() : DT
.MODEL_META_DATA_FILE_HEADER
,
43 DT
.TAB_INF_DEFINES
.upper() : DT
.MODEL_META_DATA_DEFINE
,
44 DT
.TAB_BUILD_OPTIONS
.upper() : DT
.MODEL_META_DATA_BUILD_OPTION
,
45 DT
.TAB_LIBRARY_CLASSES
.upper() : DT
.MODEL_EFI_LIBRARY_CLASS
,
46 DT
.TAB_PACKAGES
.upper() : DT
.MODEL_META_DATA_PACKAGE
,
47 DT
.TAB_INF_FIXED_PCD
.upper() : DT
.MODEL_PCD_FIXED_AT_BUILD
,
48 DT
.TAB_INF_PATCH_PCD
.upper() : DT
.MODEL_PCD_PATCHABLE_IN_MODULE
,
49 DT
.TAB_INF_FEATURE_PCD
.upper() : DT
.MODEL_PCD_FEATURE_FLAG
,
50 DT
.TAB_INF_PCD_EX
.upper() : DT
.MODEL_PCD_DYNAMIC_EX
,
51 DT
.TAB_INF_PCD
.upper() : DT
.MODEL_PCD_DYNAMIC
,
52 DT
.TAB_SOURCES
.upper() : DT
.MODEL_EFI_SOURCE_FILE
,
53 DT
.TAB_GUIDS
.upper() : DT
.MODEL_EFI_GUID
,
54 DT
.TAB_PROTOCOLS
.upper() : DT
.MODEL_EFI_PROTOCOL
,
55 DT
.TAB_PPIS
.upper() : DT
.MODEL_EFI_PPI
,
56 DT
.TAB_DEPEX
.upper() : DT
.MODEL_EFI_DEPEX
,
57 DT
.TAB_BINARIES
.upper() : DT
.MODEL_EFI_BINARY_FILE
,
58 DT
.TAB_USER_EXTENSIONS
.upper() : DT
.MODEL_META_DATA_USER_EXTENSION
61 # TAB_NMAKE.upper() : MODEL_META_DATA_NMAKE
67 # Expand MACRO definition with MACROs defined in [Defines] section and specific section.
68 # The MACROs defined in specific section has high priority and will be expanded firstly.
70 # @param LineInfo Contain information of FileName, LineContent, LineNo
71 # @param GlobalMacros MACROs defined in INF [Defines] section
72 # @param SectionMacros MACROs defined in INF specific section
73 # @param Flag If the flag set to True, need to skip macros in a quoted string
75 def InfExpandMacro(Content
, LineInfo
, GlobalMacros
=None, SectionMacros
=None, Flag
=False):
76 if GlobalMacros
== None:
78 if SectionMacros
== None:
81 FileName
= LineInfo
[0]
82 LineContent
= LineInfo
[1]
85 NewLineInfo
= (FileName
, LineNo
, LineContent
)
88 # First, replace MARCOs with value defined in specific section
90 Content
= ReplaceMacro (Content
,
93 (LineContent
, LineNo
),
97 # Then replace MARCOs with value defined in [Defines] section
99 Content
= ReplaceMacro (Content
,
102 (LineContent
, LineNo
),
106 MacroUsed
= gMACRO_PATTERN
.findall(Content
)
108 # no macro found in String, stop replacing
110 if len(MacroUsed
) == 0:
113 for Macro
in MacroUsed
:
114 gQuotedMacro
= re
.compile(".*\".*\$\(%s\).*\".*"%(Macro))
115 if not gQuotedMacro
.match(Content
):
117 # Still have MACROs can't be expanded.
119 ErrorInInf (ERR_MARCO_DEFINITION_MISS_ERROR
,
120 LineInfo
=NewLineInfo
)
127 # Judge whether the INF file is Binary INF or Common INF
129 # @param FileLineList A list contain all INF file content.
131 def IsBinaryInf(FileLineList
):
135 ReIsSourcesSection
= re
.compile("^\s*\[Sources.*\]\s.*$", re
.IGNORECASE
)
136 ReIsBinarySection
= re
.compile("^\s*\[Binaries.*\]\s.*$", re
.IGNORECASE
)
137 BinarySectionFoundFlag
= False
139 for Line
in FileLineList
:
140 if ReIsSourcesSection
.match(Line
):
142 if ReIsBinarySection
.match(Line
):
143 BinarySectionFoundFlag
= True
145 if BinarySectionFoundFlag
:
153 # Judge whether the string contain the information of ## @LIB_INSTANCES.
159 def IsLibInstanceInfo(String
):
160 ReIsLibInstance
= re
.compile("^\s*##\s*@LIB_INSTANCES\s*$")
161 if ReIsLibInstance
.match(String
):
167 ## IsAsBuildOptionInfo
169 # Judge whether the string contain the information of ## @ASBUILD.
175 def IsAsBuildOptionInfo(String
):
176 ReIsAsBuildInstance
= re
.compile("^\s*##\s*@AsBuilt\s*$")
177 if ReIsAsBuildInstance
.match(String
):
183 class InfParserSectionRoot(object):
186 # Macros defined in [Define] section are file scope global
188 self
.FileLocalMacros
= {}
191 # Current Section Header content.
193 self
.SectionHeaderContent
= []
196 # Last time Section Header content.
198 self
.LastSectionHeaderContent
= []
202 self
.InfDefSection
= None
203 self
.InfBuildOptionSection
= None
204 self
.InfLibraryClassSection
= None
205 self
.InfPackageSection
= None
206 self
.InfPcdSection
= None
207 self
.InfSourcesSection
= None
208 self
.InfUserExtensionSection
= None
209 self
.InfProtocolSection
= None
210 self
.InfPpiSection
= None
211 self
.InfGuidSection
= None
212 self
.InfDepexSection
= None
213 self
.InfPeiDepexSection
= None
214 self
.InfDxeDepexSection
= None
215 self
.InfSmmDepexSection
= None
216 self
.InfBinariesSection
= None
217 self
.InfHeader
= None
218 self
.InfSpecialCommentSection
= None