2 # This file contained the parser for [Packages] sections in INF file
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.
15 InfPackageSectionParser
21 import Logger
.Log
as Logger
22 from Logger
import StringTable
as ST
23 from Logger
.ToolError
import FORMAT_INVALID
24 from Parser
.InfParserMisc
import InfExpandMacro
25 from Library
import DataType
as DT
26 from Library
.Parsing
import MacroParser
27 from Library
.Misc
import GetSplitValueList
28 from Object
.Parser
.InfCommonObject
import InfLineCommentObject
29 from Parser
.InfParserMisc
import InfParserSectionRoot
31 class InfPackageSectionParser(InfParserSectionRoot
):
35 def InfPackageParser(self
, SectionString
, InfSectionObject
, FileName
):
37 # Macro defined in this section
42 StillCommentFalg
= False
46 # Parse section content
48 for Line
in SectionString
:
49 PkgLineContent
= Line
[0]
52 if PkgLineContent
.strip() == '':
56 # Find Header Comments
58 if PkgLineContent
.strip().startswith(DT
.TAB_COMMENT_SPLIT
):
60 # Last line is comments, and this line go on.
63 HeaderComments
.append(Line
)
66 # First time encounter comment
73 HeaderComments
.append(Line
)
74 StillCommentFalg
= True
77 StillCommentFalg
= False
79 if len(HeaderComments
) >= 1:
80 LineComment
= InfLineCommentObject()
81 LineCommentContent
= ''
82 for Item
in HeaderComments
:
83 LineCommentContent
+= Item
[0] + DT
.END_OF_LINE
84 LineComment
.SetHeaderComments(LineCommentContent
)
89 if PkgLineContent
.find(DT
.TAB_COMMENT_SPLIT
) > -1:
90 TailComments
= PkgLineContent
[PkgLineContent
.find(DT
.TAB_COMMENT_SPLIT
):]
91 PkgLineContent
= PkgLineContent
[:PkgLineContent
.find(DT
.TAB_COMMENT_SPLIT
)]
92 if LineComment
== None:
93 LineComment
= InfLineCommentObject()
94 LineComment
.SetTailComments(TailComments
)
98 Name
, Value
= MacroParser((PkgLineContent
, PkgLineNo
),
100 DT
.MODEL_META_DATA_PACKAGE
,
101 self
.FileLocalMacros
)
103 SectionMacros
[Name
] = Value
108 TokenList
= GetSplitValueList(PkgLineContent
, DT
.TAB_VALUE_SPLIT
, 1)
109 ValueList
[0:len(TokenList
)] = TokenList
112 # Replace with Local section Macro and [Defines] section Macro.
114 ValueList
= [InfExpandMacro(Value
, (FileName
, PkgLineContent
, PkgLineNo
),
115 self
.FileLocalMacros
, SectionMacros
, True)
116 for Value
in ValueList
]
118 PackageList
.append((ValueList
, LineComment
,
119 (PkgLineContent
, PkgLineNo
, FileName
)))
127 # Current section archs
130 for Item
in self
.LastSectionHeaderContent
:
131 if Item
[1] not in ArchList
:
132 ArchList
.append(Item
[1])
134 if not InfSectionObject
.SetPackages(PackageList
, Arch
= ArchList
):
135 Logger
.Error('InfParser',
137 ST
.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR\