2 # This file contained the parser for [Packages] sections in INF file
4 # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>
6 # SPDX-License-Identifier: BSD-2-Clause-Patent
9 InfPackageSectionParser
15 import Logger
.Log
as Logger
16 from Logger
import StringTable
as ST
17 from Logger
.ToolError
import FORMAT_INVALID
18 from Parser
.InfParserMisc
import InfExpandMacro
19 from Library
import DataType
as DT
20 from Library
.Parsing
import MacroParser
21 from Library
.Misc
import GetSplitValueList
22 from Object
.Parser
.InfCommonObject
import InfLineCommentObject
23 from Parser
.InfParserMisc
import InfParserSectionRoot
25 class InfPackageSectionParser(InfParserSectionRoot
):
29 def InfPackageParser(self
, SectionString
, InfSectionObject
, FileName
):
31 # Macro defined in this section
36 StillCommentFalg
= False
40 # Parse section content
42 for Line
in SectionString
:
43 PkgLineContent
= Line
[0]
46 if PkgLineContent
.strip() == '':
50 # Find Header Comments
52 if PkgLineContent
.strip().startswith(DT
.TAB_COMMENT_SPLIT
):
54 # Last line is comments, and this line go on.
57 HeaderComments
.append(Line
)
60 # First time encounter comment
67 HeaderComments
.append(Line
)
68 StillCommentFalg
= True
71 StillCommentFalg
= False
73 if len(HeaderComments
) >= 1:
74 LineComment
= InfLineCommentObject()
75 LineCommentContent
= ''
76 for Item
in HeaderComments
:
77 LineCommentContent
+= Item
[0] + DT
.END_OF_LINE
78 LineComment
.SetHeaderComments(LineCommentContent
)
83 if PkgLineContent
.find(DT
.TAB_COMMENT_SPLIT
) > -1:
84 TailComments
= PkgLineContent
[PkgLineContent
.find(DT
.TAB_COMMENT_SPLIT
):]
85 PkgLineContent
= PkgLineContent
[:PkgLineContent
.find(DT
.TAB_COMMENT_SPLIT
)]
86 if LineComment
is None:
87 LineComment
= InfLineCommentObject()
88 LineComment
.SetTailComments(TailComments
)
92 Name
, Value
= MacroParser((PkgLineContent
, PkgLineNo
),
94 DT
.MODEL_META_DATA_PACKAGE
,
97 SectionMacros
[Name
] = Value
102 TokenList
= GetSplitValueList(PkgLineContent
, DT
.TAB_VALUE_SPLIT
, 1)
103 ValueList
[0:len(TokenList
)] = TokenList
106 # Replace with Local section Macro and [Defines] section Macro.
108 ValueList
= [InfExpandMacro(Value
, (FileName
, PkgLineContent
, PkgLineNo
),
109 self
.FileLocalMacros
, SectionMacros
, True)
110 for Value
in ValueList
]
112 PackageList
.append((ValueList
, LineComment
,
113 (PkgLineContent
, PkgLineNo
, FileName
)))
121 # Current section archs
124 for Item
in self
.LastSectionHeaderContent
:
125 if Item
[1] not in ArchList
:
126 ArchList
.append(Item
[1])
128 if not InfSectionObject
.SetPackages(PackageList
, Arch
= ArchList
):
129 Logger
.Error('InfParser',
131 ST
.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR\